Not sure why it works with the PC's name as the tag and not the CD key. But I think it would be easier to just store the crate as a local object on the PC. That way it works even if the PC isn't in the same area as the crate.
Try this:
#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
if(nEvent != X2_ITEM_EVENT_ACTIVATE)return;
object oPC = GetItemActivator();
object oItem = GetItemActivated();
string sName = GetName(oPC);
string sCDKey = GetPCPublicCDKey(oPC);
float fFace = GetFacing(oPC);
location lLoc = GetLocation(oPC);
string sNameEnd = GetStringRight(sName, 1);
int iState = GetLocalInt(oPC, "STORE_STATE");
if (iState == 0)
{
object oCrate = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_box2", lLoc, FALSE, sCDKey);
SetLocalObject(oPC, "Crate", oCrate); //Make the crate personal
AssignCommand(oCrate, SetFacing(fFace));
SetPlotFlag(oCrate, TRUE);
SetLocalString(oCrate, "PLAYER_CD_KEY", sCDKey);
if (sNameEnd == "s" || sNameEnd == "S") SetName(oCrate, sName + "'s Store.");
else SetName(oCrate, sName + "'s Store.");
SetLocalInt(oPC, "STORE_STATE", 1);
}
else
{
DestroyObject(GetLocalObject(oPC, "Crate")); //Destroy personal crate
SetLocalInt(oPC, "STORE_STATE", 0);
}
}
-420
Modifié par 420, 05 août 2010 - 05:47 .