View Full Version : Script refusing to Equip

10-29-2009, 02:15 PM
I'm using this script as a custom function in default onspawn script.

I'm positive this it's creating the item on the creature, but they don't equip the sabers right away. I have to fight with them for a bit, and actually damage them with a lightsaber before they pull it out... It has nothing to do with the onspawn script though

Anyways, here's the script I've been using:

void EquipSabers(){

object Blue = GetObjectByTag("g_w_lghtsbr01");
object Red = GetObjectByTag("g_w_lghtsbr02");
object Green = GetObjectByTag("g_w_lghtsbr03");
object Yellow = GetObjectByTag("g_w_lghtsbr04");
object Violet = GetObjectByTag("g_w_lghtsbr05");
object Bronze = GetObjectByTag("g_w_lghtsbr07");
object Orange = GetObjectByTag("g_w_lghtsbr08");
object Silver = GetObjectByTag("g_w_lghtsbr09");
object White = GetObjectByTag("g_w_lghtsbr10");
object Viridian = GetObjectByTag("g_w_lghtsbr11");

object EquipR;

//I really wanted to use a switch here. They seem more efficient than If statements

switch (Random(9))
case 0:
EquipR = Blue;
case 1:
EquipR = Red;
case 2:
EquipR = Green;
case 3:
EquipR = Yellow;
case 4:
EquipR = Violet;
case 5:
EquipR = Bronze;
case 6:
EquipR = Orange;
case 7:
EquipR = Silver;
case 8:
EquipR = White;
case 9:
EquipR = Viridian;
EquipR = Red;


object oSaber = CreateItemOnObject(GetTag(EquipR), OBJECT_SELF, 1);
DelayCommand(0.5, AssignCommand(OBJECT_SELF, ActionEquipItem(oSaber, INVENTORY_SLOT_RIGHTWEAPON)));


I will acknowledge that there is one problem with the script: some of those saber tags aren't valid (even though they're in the templates.bif). Because of this, occasionally a saber will not be created on an object.

10-29-2009, 04:56 PM
Okay... well, now I feel stupid. I actually managed to fix my script somehow before I actually posted it.. and then I forgot to write in the correct Equipment slot. Anyways, it now works.

For the rest of you who seem to have problems with getting scripts to equip (it happens quite often), here's the way to do it:

//Store the created object in a variable.
object oSaber = CreateItemOnObject(GetTag(EquipR), OBJECT_SELF, 1);

//So that way when Assign a person to equip it, it'll actually equip the created object
AssignCommand(OBJECT_SELF, ActionEquipItem(oSaber, INVENTORY_SLOT_RIGHTWEAPON, 1 ));