Author Topic: Changing NPC Weapons  (Read 317 times)

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Changing NPC Weapons
« on: April 23, 2011, 10:21:06 am »


               Hey, i am looking for a script that can change an NPC Weapon, by changing a variable.

atm i have some guards standing around in a town and i want to be able, to change their weapon.
for an examble:

if a integer variable named "GuardWeapon" was equal to "1" They would have a "Longsword",
if the "GuardWeapon" were increased to "2" they would change from a "Longsword" into a "+3 Longsword"

btw it is also very important that they dont change weapons from a "Longsword" to a "+3 Longsword" when they enter combat, if the "GuardWeapon" is equal to 1.

i am not a very experienced scripter, so i couldnt work out a script for something like this, i dont know if it is even possible.'Image
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Changing NPC Weapons
« Reply #1 on: April 23, 2011, 02:27:27 pm »


               void main()
{

 //NOTE: oGuard Must Be Defined
 //(Determined by where you are using this script)
 object oGuard = GetEnteringObject();  // OBJECT_SELF (Most likely use)

 int nInt = GetLocalInt(oGuard, "GuardWeapon");

 //For adding more weapons (of the same tagname + the Integer)
 string sInt = IntToString(nInt);

 //Change all of the weapons in the Guard inventory to the same tagname except
 //on the very end add 1/2/3 etc..(e.g. tagname_1 / tagname_2  (tagname_) + (#)

 //change this to the tagname used for all weapons - nInt
 // e.g. weapon_tagname_  (not weapon_tagname_1)
 // (To avoid confustion always use  _   at the end of all weapon tagnames)

 string sTag = "tagname_of_weapon_";

 string sJoin = sTag + sInt; //Tells us which weapon we are looking for..

 object oWeapon =  GetItemPossessedBy(oGuard, sJoin); //find the weapon

 //make the guard equip the weapon..
 AssignCommand(oGuard, ActionEquipItem(oWeapon, INVENTORY_SLOT_RIGHTHAND));

//Main Script End
}

///////////////////////// HERE IS THE SCRIPT REFINED W/O COMMENTS /////////////////

void main()
{
 object oGuard = GetEnteringObject(); 
 int nInt = GetLocalInt(oGuard, "GuardWeapon");
 string sInt = IntToString(nInt);
 string sTag = "tagname_of_weapon_";
 string sJoin = sTag + sInt;
 object oWeapon =  GetItemPossessedBy(oGuard, sJoin); //find the weapon

 AssignCommand(oGuard, ActionEquipItem(oWeapon, INVENTORY_SLOT_RIGHTHAND));
}
               
               

               


                     Modifié par _Guile, 23 avril 2011 - 01:32 .
                     
                  


            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Changing NPC Weapons
« Reply #2 on: April 23, 2011, 04:50:27 pm »


               Thank you very much '<img'> btw a thought came across my mind, when the guard have diffrent weapons in their inventroy, wont they just equip the best of them when they enter combat?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Changing NPC Weapons
« Reply #3 on: April 23, 2011, 06:45:34 pm »


               

Devling99 wrote...

Hey, i am looking for a script that can change an NPC Weapon, by changing a variable.

atm i have some guards standing around in a town and i want to be able, to change their weapon.
for an examble:

if a integer variable named "GuardWeapon" was equal to "1" They would have a "Longsword",
if the "GuardWeapon" were increased to "2" they would change from a "Longsword" into a "+3 Longsword"

btw it is also very important that they dont change weapons from a "Longsword" to a "+3 Longsword" when they enter combat, if the "GuardWeapon" is equal to 1.

i am not a very experienced scripter, so i couldnt work out a script for something like this, i dont know if it is even possible.'Image


I have a Question on this.  Are your changing the integer variable dynamicly( while the game is running) or is it a static change( only changed in the toolset).

Your best bet is to only allow the NPC to have one weapon at a time, That way there is no question what weapon they will use.  You are also correct that the standard AI would equip there best weapon.
               
               

               
            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Changing NPC Weapons
« Reply #4 on: April 23, 2011, 06:54:27 pm »


               The Variables is changed in game
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Changing NPC Weapons
« Reply #5 on: April 23, 2011, 06:58:03 pm »


               

Devling99 wrote...

The Variables is changed in game


That's what I assumed when I made you the script above..
               
               

               
            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Changing NPC Weapons
« Reply #6 on: April 23, 2011, 07:14:40 pm »


               

_Guile wrote...

Devling99 wrote...

The Variables is changed in game


That's what I assumed when I made you the script above..


With your script they need to have all the weapons in the inventory at the same time.

and then i am just afraid that my Guards will equip the best weapon, when they enter combat instead of the one there were suposed to have equiped