You could do something more like so:
-Add a variable to the cake blue print itself: "SLICES" | int | 20
-Give it the Unique Power Self Only "unlimited uses per day".
-Make sure the cake has a unique tag and use the following tag based script (name the script the same as the tag of the cake):
#include "x2_inc_switches"
void main()
{
int iEvent = GetUserDefinedItemEventNumber();
if (iEvent != X2_ITEM_EVENT_ACTIVATE) return;
object oCake = GetItemActivated();
object oPC = GetItemActivator();
int iSlices = GetLocalInt(oCake, "SLICES");
if (iSlices == 1)
{
CreateItemOnObject("slice res ref", oPC);
DestroyObject(oCake);
}
else
{
CreateItemOnObject("slice res ref", oPC);
SetLocalInt(oCake, "SLICES", iSlices - 1);
}
}
Make sure you plug in the correct res ref of the slice you are supposed to create.
Hope that helps. Good luck.P.S. Or I'm way overcomplicating things. haha. You should just do what Lightfoot suggests. In the Cakes properties (General Tab) give it 20 charges. Then give it the property Unique Power Self Only, 1 Charge/Use. Then your script only needs to create a slice on the activator. No variables on the cake or any of that junk. Simple.
Modifié par GhostOfGod, 07 septembre 2011 - 06:54 .