[HELP] Money System
#1

Money System
Been willing to know if anyone could assist me with a money system where we don't use GTASA cash, instead using different cash for the server.

A explaination to how I expect it to function:
The system would allow players to buy items such as weapons using alternative cash to GTASA dollars. The cash the player has can be seen by typing '/wallet'.

It'll come up with text shown like this:
# Your Cash #
5

The player can than use /buy [amount] [item] to purchase items, with an error message saying:
Not enough cash!
if the player hasn't got enough cash - or if successful:
You have purchased AMOUNT ITEM.
eg.
You have purchased 1 M4.

The player can also use /sell [amount] [item] to sell an item they currently own, with an error message saying:
You have not got that amount of that item!
if the player has not got the right amount of that item as he specified in the command - or if successful:
You have sold AMOUNT ITEM.
eg.
You have sold 1 AK47.

And the player can be able to check their bag by typing '/bag'.
This will come up with text like shown below:
# Your Bag #
SLOT 1: [ITEM]
SLOT 2: [ITEM]
SLOT 3: [ITEM]

Weapons are allocated into a different place, called the equipment. Players type /equipment to get a text such as this:
# Your Equipment #
PRIMARY: [RIFLES/SMGS/SHOTGUNS]
SECONDARY: [PISTOLS]
MELEE: [MELEE WEAPONS]

I do not expect to learn overnight, but I do hope to get started, if anyone can help.
Thanks,
Sacman A.K.A L4D or Giorgio
Reply
#2

You could do:

pawn Код:
new PlayerCash[MAX_PLAYERS];
Then like when you want to check the players cash:
Use a format string like so:
pawn Код:
new String[30];
format(String,sizeof(String),"Your Cash: %d",PlayerCash[playerid]);
SendClientMessage(playerid,COLOR,String);
You wont be able to use ammunation to buy weapons using this type so you will have to create a type of weapon purchasing system...
For example, if the M4 costs 500 this is how you would check it:
pawn Код:
if(PlayerCash[playerid] >= 500)
{
//give the player the m4 or do whatever because the players cash is above 500
PlayerCash[playerid] -= 500;//this will take the 500 from the players cash for purchasing the M4.
}
else
{
SendClientMessage(playerid,COLOR,"You do not have enough cash to buy a M4!");
}
That's pretty much the cash thing, but the bag thing, I wotn explain since i have to go now.
Reply
#3

Quote:
Originally Posted by Miokie*
You could do:

pawn Код:
new PlayerCash[MAX_PLAYERS];
Then like when you want to check the players cash:
Use a format string like so:
pawn Код:
new String[30];
format(String,sizeof(String),"Your Cash: %d",PlayerCash[playerid]);
SendClientMessage(playerid,COLOR,String);
How to get make people receive money? Eg. If someone sells an item, how do i make it so it gives the player cash.
Reply
#4

pawn Код:
stock MoneyPlus(playerid, amount)
{
  PlayerCash[playerid]+=amount;
}
stock MoneyMinus(playerid, amount)
{
  if(PlayerCash[playerid]-amount>=0)
  {
    PlayerCash[playerid]-=amount;
    return 1;
  }
  return 0;
}
Just a example to the one above.
Reply
#5

Couldnt you just use defines for it?
Код:
// top
new
	pCash[MAX_PLAYERS];

#define GiveUserMoney(%1,%2) pCash[%1] += %2
#define GetUserMoney(%1) pCash[%1]
#define ResetUserMoney(%1) pCash[%1] = 0
Then you are able to use those functions

instead of "GivePlayerMoney(playerid, amount)", use "GiveUserMoney(playerid, amount)"
Instead of "GetPlayerMoney(playerid)", use "GetUserMoney(playerid)"
instead of "ResetPlayerMoney(playerid)" user "ResetUserMoney(playerid)"

So you could for example use
Код:
if(GetUserMoney(playerid) < 200) return SendClientMessage(playerid, COLOR, "You dont have the cash");
GiveUserMoney(playerid, -200); // Remove 200 from the cash of the player
The item System should be easy, it could for example look like ( just an example you need to change it for your needs)
Код:
// top
#define ITEM_NONE 0
#define ITEM_CONDOM 1
#define ITEM_DRUGS 2
#define ITEM_DRINKS 3
#define ITEM_PHONE 4
// more items here

#define MAX_ITEMS 5 // increase if you use more items
#define MAX_ITEMSLOT 3 // amount of items player can carry, remember you need to save each item
#define MAX_ITEMAMOUNT 20 // the max amount of an item a player can carry

new
	pItem[MAX_PLAYERS][MAX_ITEMSLOT],
	pItemAmount[MAX_PLAYERS][MAX_ITEMSLOT];


stock GiveUserItem(playerid, item, amount)
{
	/*
		returns 0 if NOT successfull
		returns 1 if successfull
	*/
	new
		slot = MAX_ITEMSLOT;
	for(new i = 0; i < MAX_ITEMSLOT; i++)
	{
		if(pItem[playerid][i] == ITEM_NONE || pItem[playerid][i] == item)
		{
			slot = i;
			break;	
		}
	}
	if(slot == MAX_ITEMSLOT) return 0;
	if((pItemAmount[playerid][slot]+amount) > MAX_ITEMAMOUNT) return 0;
	pItem[playerid][slot] = item;
	pItemAmount[playerid][slot] += amount;
	if(pItemAmount[playerid][slot] <= 0) pItem[playerid][slot] = ITEM_NONE;
	return 1;	
}

stock GetUserItem(playerid, item)
{
	/*
		returns the amount of an item
	*/
	for(new i = 0; i < MAX_ITEMSLOT; i++)
	{
		if(pItem[playerid][i] == item) return pItemAmount[playerid][i];			
	}
	return 0;
}

stock GetItem(item)
{
	new
		string[30];
	switch(item)
	{
		case ITEM_CONDOM: format(string, sizeof(string), "Condom");
		case ITEM_DRUGS: format(string, sizeof(string), "Drogen");
		case ITEM_DRINKS: format(string, sizeof(string), "Drinks");
		case ITEM_PHONE: format(string, sizeof(string), "Phone");
		// Add more items here
		default: format(string, sizeof(string), "Nothing");
	}
	return string;
}
So you can use different functions with it:
Quote:

GiveUserItem(playerid, item, amount): Give or Remove an item of a player ( returns 1 if successfull and 0 if not)
GetUserItem(playerid, item): Amount of the item in the bag ( returns the amount of the item in the bag of the player)
GetItem(item); returns the name of the item

So an basic exmaple could be a shop which sells Phones and Condoms:
Код:
// buy command
new
	item, 
	amount,
	string[80];

if(sscanf(params, "dd", item,amount)) // check the parameters with sscanf or strtok
{
	SendClientMessage(playerid, COLOR, "USAGE: /buy [item] [amount]");
	format(string, sizeof(string), "Available Items -> Phone:%d | Condom:%d ", ITEM_PHONE, ITEM_CONDOM);
	SendClientMessage(playerid, COLOR, string);
	return 1;
} 
if(amount <= 0) return SendClientMessage(playerid, COLOR, " Wrong amount");
if(item != ITEM_PHONE && item != ITEM_CONDOM) return SendClientMessage(playerid, COLOR, "You cant bought this here");

new
	bool:success = GiveUserItem(playerid, item, amount);
if(!success) return SendClientMessage(playerid, COLOR, "Check your bag, you cant put this item in the bag right now"); 

format(string, sizeof(string), "You bought %d %s", amount, GetItem(item));
SendClientMessage(playerid, COLOR, string);


// in the call command you could then check

if(GetUserItem(playerid, ITEM_PHONE) == 0) return SendClientMessage(playerid, COLOR, "You dont have a phone");
You could also do everything dynamic and save the stuff of the shop in other Arrays, so the things the shop sells are set in a database. Of course you need to save both the Player Items and the Shop Items in a Database and load them in order to create a Item System
Reply
#6

Quote:
Originally Posted by Doktor
Couldnt you just use defines for it?
Код:
// top
new
	pCash[MAX_PLAYERS];

#define GiveUserMoney(%1,%2) pCash[%1] += %2
#define GetUserMoney(%1) pCash[%1]
#define ResetUserMoney(%1) pCash[%1] = 0
Then you are able to use those functions

instead of "GivePlayerMoney(playerid, amount)", use "GiveUserMoney(playerid, amount)"
Instead of "GetPlayerMoney(playerid)", use "GetUserMoney(playerid)"
instead of "ResetPlayerMoney(playerid)" user "ResetUserMoney(playerid)"

So you could for example use
Код:
if(GetUserMoney(playerid) < 200) return SendClientMessage(playerid, COLOR, "You dont have the cash");
GiveUserMoney(playerid, -200); // Remove 200 from the cash of the player
The item System should be easy, it could for example look like ( just an example you need to change it for your needs)
Код:
// top
#define ITEM_NONE 0
#define ITEM_CONDOM 1
#define ITEM_DRUGS 2
#define ITEM_DRINKS 3
#define ITEM_PHONE 4
// more items here

#define MAX_ITEMS 5 // increase if you use more items
#define MAX_ITEMSLOT 3 // amount of items player can carry, remember you need to save each item
#define MAX_ITEMAMOUNT 20 // the max amount of an item a player can carry

new
	pItem[MAX_PLAYERS][MAX_ITEMSLOT],
	pItemAmount[MAX_PLAYERS][MAX_ITEMSLOT];


stock GiveUserItem(playerid, item, amount)
{
	/*
		returns 0 if NOT successfull
		returns 1 if successfull
	*/
	new
		slot = MAX_ITEMSLOT;
	for(new i = 0; i < MAX_ITEMSLOT; i++)
	{
		if(pItem[playerid][i] == ITEM_NONE || pItem[playerid][i] == item)
		{
			slot = i;
			break;	
		}
	}
	if(slot == MAX_ITEMSLOT) return 0;
	if((pItemAmount[playerid][slot]+amount) > MAX_ITEMAMOUNT) return 0;
	pItem[playerid][slot] = item;
	pItemAmount[playerid][slot] += amount;
	if(pItemAmount[playerid][slot] <= 0) pItem[playerid][slot] = ITEM_NONE;
	return 1;	
}

stock GetUserItem(playerid, item)
{
	/*
		returns the amount of an item
	*/
	for(new i = 0; i < MAX_ITEMSLOT; i++)
	{
		if(pItem[playerid][i] == item) return pItemAmount[playerid][i];			
	}
	return 0;
}

stock GetItem(item)
{
	new
		string[30];
	switch(item)
	{
		case ITEM_CONDOM: format(string, sizeof(string), "Condom");
		case ITEM_DRUGS: format(string, sizeof(string), "Drogen");
		case ITEM_DRINKS: format(string, sizeof(string), "Drinks");
		case ITEM_PHONE: format(string, sizeof(string), "Phone");
		// Add more items here
		default: format(string, sizeof(string), "Nothing");
	}
	return string;
}
So you can use different functions with it:
Quote:

GiveUserItem(playerid, item, amount): Give or Remove an item of a player ( returns 1 if successfull and 0 if not)
GetUserItem(playerid, item): Amount of the item in the bag ( returns the amount of the item in the bag of the player)
GetItem(item); returns the name of the item

So an basic exmaple could be a shop which sells Phones and Condoms:
Код:
// buy command
new
	item, 
	amount,
	string[80];

if(sscanf(params, "dd", item,amount)) // check the parameters with sscanf or strtok
{
	SendClientMessage(playerid, COLOR, "USAGE: /buy [item] [amount]");
	format(string, sizeof(string), "Available Items -> Phone:%d | Condom:%d ", ITEM_PHONE, ITEM_CONDOM);
	SendClientMessage(playerid, COLOR, string);
	return 1;
} 
if(amount <= 0) return SendClientMessage(playerid, COLOR, " Wrong amount");
if(item != ITEM_PHONE && item != ITEM_CONDOM) return SendClientMessage(playerid, COLOR, "You cant bought this here");

new
	bool:success = GiveUserItem(playerid, item, amount);
if(!success) return SendClientMessage(playerid, COLOR, "Check your bag, you cant put this item in the bag right now"); 

format(string, sizeof(string), "You bought %d %s", amount, GetItem(item));
SendClientMessage(playerid, COLOR, string);


// in the call command you could then check

if(GetUserItem(playerid, ITEM_PHONE) == 0) return SendClientMessage(playerid, COLOR, "You dont have a phone");
You could also do everything dynamic and save the stuff of the shop in other Arrays, so the things the shop sells are set in a database. Of course you need to save both the Player Items and the Shop Items in a Database and load them in order to create a Item System
This should be my last few questions regarding the money system.
How can I database it? (IS there a way to plug in the cash system to xtremeadmin2?)
How could i do a /inventory command to see what items i currently hold.
How do i make a player able to drop an item using /dropitem [slot]? (or item name - whichever is easier)
How do i make a player able to /use [item]? (I don't really need to learn to use the effects - maybe in future i will need to request how to get a specific object to work as i want)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)