I'm not sure Pixel, but I know if there's anything in the game telling him to also animate, it will overwrite as soon as it's taken. Perhaps examine the idle animation code? I haven't tried to control animations yet.
I've taken the original script and revamped it into something a little more robust. I had thought about the things that it was missing and now I think it's actually kind of useful.
It still tracks the total you place by hand and reports if you win. It now starts a timer based on the respawn time and prints it to the screen. If the timer goes out, all the objects unhide and your score is set to zero. If you get them all within the time, you win and they no longer respawn. It's pretty customizable, the easiest thing being just setting canrespawn to 0 in the global controller, which kills the timer aswell.
I figure this is perfect for giving the player a particular path that he must follow within a particular time. Most often, I'd imagine this would work best with 2 objects for start and end. I plan to use it for tutorials in the timed state and regular powerups when not respawning.
I would like somebody to help me in disabling the object's collisions on hide because you still bump into them and it tosses you over the input boxes completely.
CheeseBit_Global.gsl
int cheesebits;
int count;
bool canrespawn;
bool timing;
bool showall;
float respawnTime;
float Timer;
void Initialize( Object@ object)
{
object.SetControllerSetting("showall", 0);
object.SetControllerSetting("respawnTime", 10); //set the total timer here
Timer = object.GetControllerSettingFloat("respawnTime"); //grab value
object.SetControllerSetting("cheesebits", 0);
object.SetControllerSetting("count", 0);
object.SetControllerSetting("canrespawn", 1); //set to 0 for no respawning or timer
object.SetControllerSetting("timing", 0); //shut off timer
}
void DynamicsAdvance( Object@ object, float seconds)
{
canrespawn = object.GetControllerSettingBool("canrespawn"); //grab global respawn value
if(canrespawn==true) //only if respawn is on
{
timing = object.GetControllerSettingBool("timing"); //get timer on/off status
if(timing) //only if global timer is going
{
if(Timer <= 1) //only if TIME UP
{
if(!showall) //only if NOT set to showall
{
object.SetControllerSetting("showall", 1); //set showall to 1
GetGameManager().ShowTextPlain("YOU LOSE! Hint:(go faster)", 3); //report loss
}
Timer = object.GetControllerSettingFloat("respawnTime"); //grab global respawn time
object.SetControllerSetting("timing", 0); //set the timer to off
}
else //TIME NOT UP YET
{
object.SetControllerSetting("showall", 0); //grab showall status
Timer-=seconds; //delete actual game-time from local timer variable
int convert = Timer; //convert value to integer (remove decimal places)
String clock = ""+convert; //convert integer to string
GetGameManager().ShowTextPlain(clock, 1); //print string value to screen
}
}
else //global timer is NOT going
{
object.SetControllerSetting("showall", 0); //set showall status to off
Timer = object.GetControllerSettingFloat("respawnTime"); //grab global respawn time (gets missed above if passed over)
object.SetControllerSetting("timing", 0); //reset the timer to off
}
}
}
Cheese_Pickup.gsl
bool canrespawn;
bool timing;
bool cancount = false;
bool gotten = false; //without this, no respawn deletes all bits at start
float respawnTime; //set the time to pick up ALL items, starts counting from first item picked up and stops when 0
float timeToRespawn = 0; //don't alter, needs to be set to 0
int cheesebits = 0;
bool showall;
int countreport;
int counttotal;
bool done = false;
void Initialize( Object@ object)
{
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle for Global controller
respawnTime = cheeseglobal.GetControllerSettingFloat("respawnTime");
countreport = cheeseglobal.GetControllerSettingInt("count"); //pass floating count
countreport+=1; //this object increases countreport on load ( each object does 1 time)
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!", 5); //initial message
}
void DynamicsAdvance( Object@ object, float seconds)
{
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle for Global controller
showall = cheeseglobal.GetControllerSettingBool("showall");
if(!done) //first time setup goes here
{
done = true;
}
canrespawn = cheeseglobal.GetControllerSettingBool("canrespawn"); //get global respawn variable
if(!canrespawn)
{
if(gotten) //only if this object is gotten already
object.Delete(); //dumps this bit of cheese if global respawn ever goes false
}
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
{
//..Kill this whole block if you want the bits to respawn individually based on when they were gotten. Beware timer issues.
if(showall) //passed when timer counts to 0, every object does this at once.
{
object.Show(); //reveals this object
//UPDATE CHEESE COUNTS AGAIN
cheesebits = cheeseglobal.GetControllerSettingInt("cheesebits"); //pass current count from controller
cheesebits--; //DEcrease current count by 1
cheeseglobal.SetControllerSetting("cheesebits", cheesebits); //pass count back to controller
int counttotal = cheeseglobal.GetControllerSettingInt("count"); //need to pass from controller again to update value
GetControl( "AmmoText", "FPS_HUD").SetTextPlain( cheesebits + "/" + counttotal); //update hud with cheese count
}
//..Kill to here
if (timeToRespawn > 0)
{
timeToRespawn -= seconds;
if (timeToRespawn <= 0)
{
timeToRespawn = 0;
object.Show();
//UPDATE CHEESE COUNTS
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle to global controller
cheesebits = cheeseglobal.GetControllerSettingInt("cheesebits"); //pass current count from controller
cheesebits--; //DEcrease current count by 1
cheeseglobal.SetControllerSetting("cheesebits", cheesebits); //pass count back to controller
int counttotal = cheeseglobal.GetControllerSettingInt("count"); //need to pass from controller again to update value
GetControl( "AmmoText", "FPS_HUD").SetTextPlain( cheesebits + "/" + counttotal); //update hud with cheese count
}
}
}
}
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params) //handled per tick if within input box
{
if(params.player != null) //player interaction
{
if(event == "EnterProximity") //handled one time upon entry to input box
{
Object@ cheeseglobal = GetGameManager().GetWorld().GetObject("cheesebit_global"); //get handle to global controller
timing = cheeseglobal.GetControllerSettingBool("timing"); //get status of the global timer
if(!timing) //only if the global timer is !NOT running
{
cheeseglobal.SetControllerSetting("timing", 1); //set the global timer to run
}
gotten = true; //we have gotten this item once
if(object.IsVisible()) //if we are visible pickup, if not then dont
{
if(canrespawn) //only if global respawn is on
{
object.Hide(); //hides this bit, remains in world with collisions/scripts active
//need code to disable collisions or inputs are sketchy on close pieces
}
else
{
object.Delete(); //deletes this bit of cheese if we can't respawn, all local scripts are deleted too
}
//UPDATE CHEESE COUNTS YET AGAIN
cheesebits = cheeseglobal.GetControllerSettingInt("cheesebits"); //pass current count from controller
cheesebits++; //increase current count by 1
cheeseglobal.SetControllerSetting("cheesebits", cheesebits); //pass count back to controller
int counttotal = cheeseglobal.GetControllerSettingInt("count"); //need to pass from controller again to update value
GetControl( "AmmoText", "FPS_HUD").SetTextPlain( cheesebits + "/" + 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
cheeseglobal.SetControllerSetting("timing", 0); //shut off timer
cheeseglobal.SetControllerSetting("canrespawn", 0); //shut off respawn
} //end victory code
else
{
if(canrespawn) //only if global respawn is on
{
timeToRespawn = respawnTime; //starts respawn timer
}
}
}
}
return true;
}
return false;
}
I still haven't tackled the fact that AI picks them up too.
I'm going to pick this up a bit later as I want to go start experimenting with raycasting, just to see if I can't maybe report the name of every object I aim at and hit P or something..with a range..and maybe report the distance. Then I want to see if we can cast rays from an object's bone direction so that if I animate an AI character looking left and right during idle, it'll affect what he sees.
Things are going to start getting pretty complicated pretty quickly here, I can see a little more clearly now. But in the end, it's always layering in what you want to happen one at a time and figuring out when to do it and how to cover your bases before and after each and every new thing is implemented, lol. It's easy.