Bank system -
mrcoolballs - 22.03.2011
I'm making a bank system for my server, which is pretty easy, but I'm unsure how to do this certain thing.
What I'm trying to do is, say if someone types, "/bank all", instead of "/bank 1000", it will bank all the money they have on them.
I tried something like this:
but that didn't work...
I'm using dcmd and sscanf by the way.
Thanks
Re: Bank system -
mrcoolballs - 22.03.2011
bump
Re: Bank system -
Stigg - 22.03.2011
First get how much cash the player has.
https://sampwiki.blast.hk/wiki/GetPlayerMoney
Re: Bank system -
Mike Garber - 22.03.2011
I don't know how you would do It, since sscanf searches for either integer/float etc. or a string, not both integer/string.
If you can figure It out though, you should not compare "params" but the string.
I don't think this will work, but try this;
It might work to /bank all but not to /bank 1000 for example.
pawn Код:
dcmd_bank(playerid, params[])
{
new amount[12];
if(!sscanf(params,"s[12]",amount))
{
if(!sscanf(amount,"all"))
{
// Bank all money
}
else
{
// Normal number
}
}
return 1;
}
I'd suggest doing it with dialogs instead, much easier.
Re: Bank system -
mrcoolballs - 22.03.2011
I have almost got it working now.
This is the command:
pawn Код:
dcmd_bank(playerid,params[])
{
new amount, name[24], file[256];
if(PlayerInfo[playerid][Logged] == 0) return 0;
if(strcmp(params,"all",false) == 0) return SendClientMessage(playerid,WHITE,"Test");
if(sscanf(params,"i",amount)) return SendClientMessage(playerid,WHITE,"USAGE: /Bank <Amount>");
if(amount > GetPlayerMoney(playerid) || amount <= 0) return SendClientMessage(playerid,WHITE,"Invalid amount.");
GetPlayerName(playerid,name,24);
format(file,sizeof(file),"cool/users/%s.txt",name);
PlayerInfo[playerid][BMoney] += amount;
dini_IntSet(file,"BMoney",PlayerInfo[playerid][BMoney]);
format(file,sizeof(file),"You have stored $%d dollars into your bank account. Your current balance is $%d.",amount,PlayerInfo[playerid][BMoney]);
SendClientMessage(playerid,LIGHTBLUE,file);
GivePlayerMoney(playerid,-amount);
return 1;
}
I made it just send a test if it works, so far this is what happens:
if I type "/bank 1000" it will deposit $1000 dollars, and if I type "/bank all" it will return the message "Test".
The only problem is that if I type "/bank", without anything else, instead of returning, "USAGE: /Bank <Amount>", it returns "Test".
Can anyone help me finish it?
Re: Bank system -
Zh3r0 - 22.03.2011
Quote:
Originally Posted by Mike Garber
I don't know how you would do It, since sscanf searches for either integer/float etc. or a string, not both integer/string.
If you can figure It out though, you should not compare "params" but the string.
I don't think this will work, but try this;
It might work to /bank all but not to /bank 1000 for example.
pawn Код:
dcmd_bank(playerid, params[]) { new amount[12]; if(!sscanf(params,"s[12]",amount)) { if(!sscanf(amount,"all")) { // Bank all money } else { // Normal number } } return 1; }
I'd suggest doing it with dialogs instead, much easier.
|
That might either crash or give Argument type mismatch.
It's easier to use IsNumeric and if not then search for "all" and if it doesn't find "all" as a parameter then send error.
Re: Bank system -
mrcoolballs - 22.03.2011
how exactly would I use IsNumeric, whenever I put in the amount I get an error:
What do I replace "amount" with?
Re: Bank system -
Zh3r0 - 22.03.2011
Quote:
Originally Posted by mrcoolballs
how exactly would I use IsNumeric, whenever I put in the amount I get an error:
What do I replace "amount" with?
|
Well, using !IsNumeric will check if the number is NOT numeric, which means it's a string.
Using IsNumeric without the ! means it's a number.
pawn Код:
if ( IsNumeric( String ) )
{
Var[ playerid ] = strval( string ); //numbers
}
else
{
format( String, sizeof( String ), "%d", Var ); //string
}
else means the opposite of the above function.
Re: Bank system -
mrcoolballs - 22.03.2011
Okay, I understand that now, I am almost done, now I need to know how to search for "all".
I tried:
pawn Код:
new thing;
if(IsNumeric(amount))
{
//player types /bank <numbers>
thing = strval(amount);
}
else
{
//player types /bank all
if(amount == "all") return 0;// return 0 just to test if it works
}
But that gives me the error:
array must be indexed (variable "amount")
Would it be better to use strfind?
Re: Bank system -
Zh3r0 - 22.03.2011
Quote:
Originally Posted by mrcoolballs
Okay, I understand that now, I am almost done, now I need to know how to search for "all".
I tried:
pawn Код:
new thing; if(IsNumeric(amount)) { //player types /bank <numbers> thing = strval(amount); } else { //player types /bank all if(amount == "all") return 0;// return 0 just to test if it works }
But that gives me the error:
array must be indexed (variable "amount")
Would it be better to use strfind?
|
now must be a string.
pawn Код:
new amount[3]; //word "all" has 1,2,3, YES 3 Characters!(However, use a larger number for larger numbers inserted (EX: 1000000) needs 7 char size.
And the specifier of sscanf now is "s[3]"