PDA

View Full Version : Script refusing to Equip


VarsityPuppet
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;
break;
case 1:
EquipR = Red;
break;
case 2:
EquipR = Green;
break;
case 3:
EquipR = Yellow;
break;
case 4:
EquipR = Violet;
break;
case 5:
EquipR = Bronze;
break;
case 6:
EquipR = Orange;
break;
case 7:
EquipR = Silver;
break;
case 8:
EquipR = White;
break;
case 9:
EquipR = Viridian;
break;
default:
EquipR = Red;
break;
}

CancelCombat(OBJECT_SELF);

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.

VarsityPuppet
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 ));

}