PDA

View Full Version : How to spawn an item based on your alignment?


SithRevan
07-21-2006, 05:49 PM
I was wondering how to spawn an item bsed on my alignment or if it is even possible to do such a thing, if it is would somebody help me with the script to do it, thanks.

stoffe
07-21-2006, 06:43 PM
I was wondering how to spawn an item bsed on my alignment or if it is even possible to do such a thing, if it is would somebody help me with the script to do it, thanks.

It's possible, here's a quick example of how it could be done:

void main() {
string sResref;
int iGood = GetGoodEvilValue(GetFirstPC());

if (iGood > 60)
sResref = "gooditem";
else if (iGood < 40)
sResref = "evilitem";
else
sResref = "neutralitem";

CreateItemOnObject(sResref, GetObjectByTag("mybox"));
}


This would put one out of 3 possible items inside the container with the Tag "mybox", depending on the force alignment of the main character:
gooditem.uti for a lightsider, evilitem.uti for a darksider and neutralitem.uti for those in the gray zone in between.

SithRevan
07-21-2006, 07:02 PM
thanks, that explains a lot.

SithRevan
07-21-2006, 07:20 PM
I was wondering if that script could be used on placeables like containers, footlockers, bones, ect.

stoffe
07-21-2006, 07:46 PM
I was wondering if that script could be used on placeables like containers, footlockers, bones, ect.

Shouldn't be any problems, though if you assign the script to the placeable you can replace the GetObjectByTag("mybox") part with OBJECT_SELF instead. You probably want to make sure it only fires once as well if the player opens the container more than once.

The modified example script in this case could look like:


void main() {
if (!GetLocalBoolean(OBJECT_SELF, 57)) {
string sResref;
int iGood = GetGoodEvilValue(GetFirstPC());

if (iGood > 60)
sResref = "gooditem";
else if (iGood < 40)
sResref = "evilitem";
else
sResref = "neutralitem";

CreateItemOnObject(sResref, OBJECT_SELF);
SetLocalBoolean(OBJECT_SELF, 57, TRUE);
}
}


Save the script, compile it to NCS, put in the override folder along with the placeable UTP. Then assign it to the OnOpen event script slot of the placeable (in the UTP file) and it should fill the container with the proper item the first time it is opened. (You put the name of the script, minus the ".ncs" extension, in the OnOpen field in the UTP.)

Make sure all the other event script fields are empty if you used an existing container as a blueprint for your new container.