You are not logged in.    Login    New User    Forum Home    Search

Location:
JBPLAY  \  Meteor 2  \  Help and Guidance  \  Knasp's Scripting Question

Back to Threads

Viewing Thread: Knasp's Scripting Question

 

Canuck

Joined: 31 August 2007
Posts: 419
26 November 2008 01:19 (UK time)

Knasp wrote:
Thanks for the welcoming everyone :)


Perhaps you could help me with a scripting problem?

I want the player to be able to purchase items from a toolbar and I've been making progress thanks to aleksanteris wonderful Scoping scripts.
The problem is that the item in question should have a limited stock, so that it could run out.

Any ideas?




I wrote:

Hmmm....maybe create a new 'blank' item that doesn't show up on the hud or anything and use it to keep track of how many items have been purchased? For example, if there was an item on the toolbar that had a stock of 10, you would give the player 10 of the 'blank' item at the start of the map and take one away every time the player bought the item from the toolbar. You could script the toolbar so that when the player had no 'blank' items left, they couldn't purchase another item. So if the player clicked on a button to buy, say, a rocket:


void BuyRocket()
{
if (SC_GetItemCount("Blank1")==0)
{
SC_GameMessage("Sorry, there are no more rockets in stock!");
}
else
{
SC_GiveItem("Rocket",1);
SC_GiveItem("Blank1",-1);
}
}


You'd have a different 'blank' item for each item that could be purchased, so if there was a button to buy a grenade, the script would look like this:


void BuyGrenade()
{
if (SC_GetItemCount("Blank2")==0)
{
SC_GameMessage("Sorry, there are no more grenades in stock!");
}
else
{
SC_GiveItem("Grenade",1);
SC_GiveItem("Blank2",-1);
}
}


I've used a system similar to this for various things, and it seems to work fairly well.


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1478
26 November 2008 17:41 (UK time)

Yay, finally things start staying on-topic =D


This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


You need to login to create posts in this thread.

Knasp

Joined: 18 June 2004
Posts: 158
26 November 2008 23:35 (UK time)

Thanks man, but how would it work in Co-op? Cause that will be important for me.

You need to login to create posts in this thread.

Canuck

Joined: 31 August 2007
Posts: 419
27 November 2008 00:00 (UK time)

I really don't know. I guess the only way to find out would be to try it.

You need to login to create posts in this thread.

arezey

Joined: 16 June 2005
Posts: 1599
27 November 2008 06:54 (UK time)

Nice to see somebody saw use for the stuff I wrote for Scoping. Maybe use StaticFlags[] in place for items? That would look less 'dirty' IMO.

You need to login to create posts in this thread.

Knasp

Joined: 18 June 2004
Posts: 158
27 November 2008 14:05 (UK time)

I'm sorry, but to be more specific:

Is it possible to create a variable for example:

int x = 4

and each time anyone in the MP game buys/picks up one of these things from the toolbar the stock decreases by 1 until there's 0 left, when you can't buy anymore?

You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1478
27 November 2008 18:44 (UK time)

Sure, you can indeed declare your own variables, but keep in mind that variables (except StaticFlags) are only valid for the current map you're in. So if you declare an int x, and go to another map, the game suddenly doesn't know of any x anymore.


This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


You need to login to create posts in this thread.

Canuck

Joined: 31 August 2007
Posts: 419
27 November 2008 22:02 (UK time)

Okay, it's been put to the test. If you use static flags, you can have buyable items with a limited stock. Here's a test map. I also managed to make the items cost the player money and made the stock replenishible.

Edited: 27 November 2008 22:06


You need to login to create posts in this thread.

Canuck

Joined: 31 August 2007
Posts: 419
27 November 2008 22:05 (UK time)

And I suppose I should show how I did it: Here's the map's script file.


#title ""
#author "Canuck"

#include meteor2

// tell M2 which functions it can use
export OnMapStart;
export EnterStore;
export LeaveStore;
export BuyGL;
export BuyGren;
export PriceCheck;
export Stock;
export OnEnterVehicle_8;
export OnWaypointReached_24;

void OnMapStart()
{
//Amount of stuff to buy
StaticFlags[0] = 1;
StaticFlags[1] = 15;
SC_GameMessage("Take that money, go to the store, and buy stuff!");
}

void EnterStore()
{
SC_CreateToolbar( 0, "Buy Stuff", 200, 40, 1, 1);
SC_AddToolbarButton( 0, "Buy Grenade Launcher", "Hud\\Weapon_M79-01_01.pcx", "run BuyGL", 1);
SC_AddToolbarButton( 0, "", BUTTON_SEPERATOR, "",1);
SC_AddToolbarButton( 0, "Buy Grenade Rounds", "Projectiles\\Grenade01_01.pcx", "run BuyGren", 1);
SC_SetSectorTriggerEnabled(5,1);
SC_CreateToolbar( 1, "Prices and Stock", 290, 40, 1, 1);
SC_AddToolbarButton( 1, "Price List", "Powerups\\credit01_02.pcx", "run PriceCheck", 1);
SC_AddToolbarButton( 1, "Check Stock", "Objects\\crate02_01.pcx", "run Stock", 1);
}

void LeaveStore()
{
SC_DestroyToolbar(0,1);
SC_DestroyToolbar(1,1);
SC_SetSectorTriggerEnabled(4,1);
}

void BuyGL()
{
int s;
s = StaticFlags[0];
if (StaticFlags[0] < 1)
{
SC_GameMessage("There are no Grenade Launchers left in stock!");
}
if (StaticFlags[0] > 0)
{
if (SC_GetItemCount("Credit") > 99)
{
SC_GiveItem("Grenade Launcher",1);
SC_GiveItem("Credit",-100);
SC_GameMessage("Bought Grenade Launcher");
s = StaticFlags[0]-1;
StaticFlags[0] = s;
}
else
{
SC_GameMessage("You don't have enough money to buy that!");
}
}
}

void BuyGren()
{
int t;
t = StaticFlags[1];
if (StaticFlags[1] < 1)
{
SC_GameMessage("There are no Grenade Rounds left in stock!");
}
if (StaticFlags[1] > 0)
{
if (SC_GetItemCount("Credit") > 4)
{
SC_GiveItem("Grenade",1);
SC_GiveItem("Credit",-5);
SC_GameMessage("Bought a Grenade Round");
t = StaticFlags[1]-1;
StaticFlags[1] = t;
}
else
{
SC_GameMessage("You don't have enough money to buy that!");
}
}
}

void PriceCheck()
{
SC_MessageBox("A Grenade Launcher is 100 credits; Grenade Rounds cost 5 credits each.");
}

void Stock()
{
SC_MessageBox("To get more grenade rounds to buy, take the delivery truck to the supply depot.");
}

void OnEnterVehicle_8()
{
SC_BindObjectToWaypoint(8,0);
}

void OnWaypointReached_24()
{
int z;
z=StaticFlags[1];
SC_PlayerGetOutOfVehicle(0);
StaticFlags[1]=z+15;
}


I'm afraid I didn't label the script very well, so if you have questions...ask.:)

You need to login to create posts in this thread.

Knasp

Joined: 18 June 2004
Posts: 158
28 November 2008 09:43 (UK time)

Sweet! I'll try it out when I get home.

You need to login to create posts in this thread.

Knasp

Joined: 18 June 2004
Posts: 158
28 November 2008 22:59 (UK time)

Works perfect Canuck! :D
Thanks alot for your effort.

Now I just have to figure out how to spawn something at random, or at least have the spawning loop in a random fashion.

Edited: 28 November 2008 23:02


You need to login to create posts in this thread.

Canuck

Joined: 31 August 2007
Posts: 419
30 November 2008 03:13 (UK time)

You mean spawn something at a random time, or in a random place, or both?

You need to login to create posts in this thread.

me_mantis

Joined: 26 September 2003
Posts: 1152
12 December 2008 17:02 (UK time)

check out the ravagers of time main map (barsor) it's got a guy on waypoints, and everytime he hits one, it calls a function. Then, waypoint function can be used to run a time based event... like randomly placing something!

It's fun, but make sure that the guy on waypoints is invincible, and unsquishable, and unblockable.

cheers!

You need to login to create posts in this thread.

Canuck

Joined: 31 August 2007
Posts: 419
13 December 2008 04:44 (UK time)

Like this!

You need to login to create posts in this thread.



Forums system (C) 1999-2023 by James Bunting.

Terms of Use