Aller au contenu

Photo

Changing NPC Weapons


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Devling99

Devling99
  • Members
  • 13 messages
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 IPB

#2
_Guile

_Guile
  • Members
  • 685 messages
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 .


#3
Devling99

Devling99
  • Members
  • 13 messages
Thank you very much :D 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?

#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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 IPB


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.

#5
Devling99

Devling99
  • Members
  • 13 messages
The Variables is changed in game

#6
_Guile

_Guile
  • Members
  • 685 messages

Devling99 wrote...

The Variables is changed in game


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

#7
Devling99

Devling99
  • Members
  • 13 messages

_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