May 22, 2012, 05:00:43 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: [Example] Pickup All  (Read 1742 times)
Squat
Hero Member
*****
Posts: 592


View Profile
« on: September 02, 2008, 11:33:09 AM »

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
Quote
OPRP

LoadObject Box without Collision2.box

ControllerInputCenter 0 0 0
ControllerInputBoxSize 4 4 4
ControllerType Scripted
ControllerSetting ScriptFile CheeseBit_Global.gsl

CheeseBit_Global.gsl
Quote
int cheesebits;
int count;

void Initialize( Object@ object)
{
object.SetControllerSetting("cheesebits", 0);
object.SetControllerSetting("count", 0);

}

void DynamicsAdvance( Object@ object, float seconds)
{

}

CheeseBit.OPR
Quote
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
Quote
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.
« Last Edit: September 03, 2008, 02:53:15 PM by Squat » Logged
zknack
Full Member
***
Posts: 207


View Profile
« Reply #1 on: September 02, 2008, 11:52:48 AM »

Well done Squat- I like the simplicity of this one :-)

Others should be able to utilize this for things like coins/money in game, as well as shops, and 'gather quests' through
changing things just a little bit.

Very well done once again :-)
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #2 on: September 02, 2008, 11:59:52 AM »

Thanks man, the main thing I learned on this one that's huge is getting a handle on the HUD and being able to print to it.

I used the ammo slot, which I changed to look like the cheese.

I am very interested in learning how to make an in-game journal complete with pages and icons of items aswell as fitted containers, description windows and a link to the player's attributes. Basically an inventory window.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #3 on: September 02, 2008, 12:36:31 PM »

Great contribution! I could follow everything and this can easily just be copy pasted Smiley
Logged
zknack
Full Member
***
Posts: 207


View Profile
« Reply #4 on: September 02, 2008, 12:41:33 PM »

I'm working (albeit slowly) on getting an inventory screen working, using what I learned/the core ideas behind my heart script.

My basic concept thus far is:
*create the inventory panel
*then define 'button image' locations
*define the button images to 'be visible' and 'be clickable' when the prerequirement is met
               ----ie., when they collect 4 cheese pieces it shows on the inventory that they have '1 wheel of cheese'
*define the button values when clicked to remove the current player item, and give them the clicked one
*have the removed item now be the item shown on the inventory screen- with according definitions and abilities.

While it shouldn't be too difficult- it's just getting the first one working properly...
But this is me after all, I still can't get 'empty heart containers' to show /me shrugs
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #5 on: September 02, 2008, 01:47:14 PM »

You my friend are making really quick progress so i believe in you.

I have problems already with this script, thats how good i am Smiley Here is the problem. I get an error at runtime at this line:

Code:
countreport = cheeseglobal.GetControllerSettingInt("count"); //pass floating count

If i comment it out the next line is the failure. It's so strange. This is how i did:

1. Added a plain box. Named it CheeseBit_Global in editor. Added the stuff for CheeseBit_Global.OPR
2. Added another box and named it cheese. Gave it all the lines from CheeseBit.OPR
3. Added both .gsl files in the geometry folder so it could be read instantly from same folder.

It does delete the box when i step on it but i dont get any text nor does it give a count on the FPS template
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #6 on: September 02, 2008, 03:19:08 PM »

Ah, nevermind. I just spelled the name wrong in the editor. Capitals can be a pain Smiley

Now i have added a new form and put the counter inside it instead. Thanks for this. First time i make a custom form. I have yet to learn how to add a picture to form. Now i just have the plain old GC skin as background. I wish to just add text floating in air
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #7 on: September 02, 2008, 03:57:05 PM »

All I've done so far on customizing forms is open up the FPS_Gui and change the picture manually and resave as the same name. I then went and explored the menu scripts until I found the name of the field and an example that changed it, like weapons.gsl. I haven't gotten much into the GUI yet as I'm still trying to put together a sleugh of gameplay oriented scripts and get a handle on all the object controls. I look forward to seeing what you figure out zknack cause I'm gonna be there pretty soon.
Logged
zknack
Full Member
***
Posts: 207


View Profile
« Reply #8 on: September 02, 2008, 04:05:48 PM »

You might benefit from checking out my heart system if you havent, as it has a decent custom health gui
on it/in it.The gui upgrades in game based on the the objects/health containers picked up. It also upgrades their
actual amount of health- which can be very benefitial ;-)

I've decided to keep it hosted for now, as I decided to step up my hosting plan.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #9 on: September 02, 2008, 04:24:28 PM »

Ah, yeah, the heart script. Of course. Will look a bit at the GUI there too Smiley
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #10 on: September 02, 2008, 08:08:18 PM »

Do us a favor and let us know if you take that down. We can host it someplace for you or perhaps there's space on the website aswell we can utilize. I've already grabbed it and have been tearing it apart for days now. It's usually the first place I go to for sample lines of code adn I'm gonna use it for learning the GUI too.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #11 on: September 03, 2008, 01:09:30 AM »

I haven't looked yet but wouldn't a workaround be that if you don't have any hearts you could have another form with an empty heart and show that form and hide original. As soon as you have 1/4 you hide that form and show original. That is jus a simple workaround.

I will look later but I'm not a coder Smiley
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #12 on: September 03, 2008, 01:16:20 PM »

I've noticed one problem with this script so far that I'm unsure about so I'll just ask.

if(params.player != null) //player interaction

That's triggering when my AI characters are going over the cheesebits and it's crediting me for it aswell.

While I don't want this, I like it for other things. Maybe a helper pet that can get stuff for you that you can send out, or chasing after something. BUT!

I want more control over who exactly triggers, so what would we do under that line to get it to read the name of the player too? Only my character should be named "Player", correct? My other ones have 'make player' checked off but their names are like "Bob and Freddy". However, their params aren't null so that's why they're triggering. At the very least, I want them to get their own share of the cheese.

I'd like to do maybe a quick pick-up race test where the AI seeks the closest bit of cheese and heads for it, then seeks the next one. That would give the opportunity to put up another score hud to track the bot scores aswell as refine the pickup code so your enemies don't steal all your fatlootZ. Unless they pocket them into their own inventories and you can kill 'em for it back, that'd be an interesting twist on the RPG since even the whimpiest peon could of wandered over something priceless.
Logged
Javier
Newbie
*
Posts: 47



View Profile
« Reply #13 on: September 03, 2008, 03:18:17 PM »

Good script. Very usefull for learning purposes.
Thanks.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #14 on: September 03, 2008, 04:27:06 PM »

I am trying to make an animation when you are done. Like a victory pose. So far i am testing on the enemy because i use FPS, it wouldnt show on my character Smiley

Here is what i have so far, that i add in Cheese_Pickup.gsl:

Under the line canrespawn = false; in Bool

Code:
Object@ enemah = GetGameManager().GetWorld().GetObject("Enemy");
enemah.PlayAnim("Die1");
enemah.SetMotionVariableFloat("TimeVar", 0.0);

When i have collected all objects i can see that the enemy actually change to Die1 animation but 0.5 sec later it returns to the animation it had before. How can i set the animation to Die1 and it stays?
Logged
Pages: [1] 2
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!