(08-14-2011, 09:07 PM)TimmayIsHawt Wrote: if it doesn't work, how will I be able to do it then? I'm still confused about global variables and how it works, so I really don't know how I should start if it doesn't work out.
A global variable can be used across your whole custom story. There is a file called "global.hps" which is a file that is created in your custom story's "maps" folder or where you put all your scripts and maps for your custom story. In that file that you make, that's called "global.hps", you can setup global variables that can check something throught your maps. In this case it will be "Key01", for the sake of examples. This is what the "global.hps" file will look like when including a global variable called, "KeyCheck01":
void OnGameStart()
{
SetGlobalVarInt("KeyCheck01", 0);
}
So now, corresponding to the example I previously posted, in "Map01.hps" you could add this in your script:
void OnStart()
{
SetEntityPlayerInteractCallback("Key01", "Func01", true);
}
void Func01(string &in asEntity)
{
SetGlobalVariableInt("KeyCheck01", 1);
}
void OnEnter()
{
if (GetGlobalVarInt("KeyCheck01") == 1)
{
GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);
}
}
void OnLeave()
{
if (GeGlobalVarInt("KeyCheck01") == 1)
{
RemoveItem("Key01");
}
}
Then in the script file called "Map02.hps", have this:
void OnEnter()
{
if (GetGlobalVarInt("KeyCheck01") == 1)
{
GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);
}
}
void OnLeave()
{
if (GeGlobalVarInt("KeyCheck01") == 1)
{
RemoveItem("Key01");
}
}
Then still in the "Map02.hps" script file, you'll have to add this line of code into the function where the key gets used and removed when it unlocks the door:
SetGlobalVarInt("KeyCheck01", 0);
Where I had this, I don't know exactly what the key is, so I just copy and pasted it out of the wiki, which does require for you to fill it out with the correct information about the key.
GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);
I hope this helps!