Here's a simple script to allow you to place as many pickup items of the same type into your world as you like, by hand, and then have the total be calculated.
It then reports a victory when you get them all.
You can place as many of the objects in your world as you like.
Create a simple box without collision, set it to invisible and name it something like 'CheeseBit_Global'. You can use any other object for getting tracked, I used a bit of cheese.
CheeseBit_Global.OPR
OPRP
LoadObject Box without Collision2.box
ControllerInputCenter 0 0 0
ControllerInputBoxSize 4 4 4
ControllerType Scripted
ControllerSetting ScriptFile CheeseBit_Global.gsl
CheeseBit_Global.gsl
int cheesebits;
int count;
void Initialize( Object@ object)
{
object.SetControllerSetting("cheesebits", 0);
object.SetControllerSetting("count", 0);
}
void DynamicsAdvance( Object@ object, float seconds)
{
}
CheeseBit.OPR
OPRP
LoadObject CheeseBit.obj
ControllerInputCenter 0.0000 0.0000 0.0000
ControllerInputBoxSize 4.0000 4.0000 4.0000
ControllerType Scripted
ControllerSetting ScriptFile Cheese_Pickup.gsl
Cheese_Pickup.gsl
bool canrespawn = false; //here for example, do NOT use with this script
float respawnTime = 1;
int cheesebits = 0;
float timeToRespawn = 0;
int countreport;
int counttotal;
bool done = false;
void Initialize( Object@ object)
{
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle for Global controller
countreport = cheeseglobal.GetControllerSettingInt("count"); //pass floating count
countreport+=1; //this object increases countreport on load (does 1 time per object)
cheeseglobal.SetControllerSetting("count", countreport); //update the global controller
int counttotal = cheeseglobal.GetControllerSettingInt("count"); //get total to use in final result
GetControl( "AmmoText", "FPS_HUD").SetTextPlain( "0/"+counttotal); //initiate the HUD
GetGameManager().ShowTextPlain("THERE ARE " + counttotal + " BITS OF CHEESE!", 1); //initial message
}
void DynamicsAdvance( Object@ object, float seconds)
{
if(!done) //first time setup goes here
{
done = true;
}
if (object.IsVisible()) //only if it's showing
{
// for fun let's make it spin in circles
//~ object.GetCurMatrix().Rotate( 1, 0, 0); //leave out with objects having mass
}
else
{
if (timeToRespawn > 0)
{
timeToRespawn -= seconds;
if (timeToRespawn <= 0)
{
timeToRespawn = 0;
object.Show();
}
}
}
}
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
if(params.player != null) //player interaction
{
if(event == "EnterProximity")
{
if(object.IsVisible()) //if we are visible pickup, if not then dont
{
object.Delete(); //deletes this bit of cheese
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle to global controller
cheesebits = cheeseglobal.GetControllerSettingInt("cheesebits"); //pass current count from controller
cheesebits++; //increase current count by 1
cheeseglobal.SetControllerSetting("cheesebits", cheesebits); //pass count back to controller
String cheesecount = ""+cheesebits; //convert int to string for console print of current count
int counttotal = cheeseglobal.GetControllerSettingInt("count"); //need to pass from controller again to update value
GetControl( "AmmoText", "FPS_HUD").SetTextPlain( cheesecount + "/" + counttotal); //update hud with cheese count
if(cheesebits == counttotal) //check if curret = total
{ //code any victory dance, reward or gameplay here
GetGameManager().ShowTextPlain("YOU FOUND ALL " + counttotal + " BITS OF CHEESE!", 4); //Print victory to screen
canrespawn = false;
} //end victory code
}
}
return true;
}
return false;
}
The entire dynamicsadvance block can be deleted aswell as the respawn variables and any lines pertaining to them. I kept them in because respawning things is needed if you wanted ammo or health pickups that come back. If you do want respawn, change object.delete to object.hide otherwise it's gone from the world.
I used delete because I wanted it gone and not to come back and the main reason for that is that the total-tracking won't update so you would win with icons still present and if it did update the totals when they respawned, you'd never win.