Bank system
#1

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:

pawn Код:
if(params == "all")
but that didn't work...

I'm using dcmd and sscanf by the way.

Thanks
Reply
#2

bump
Reply
#3

First get how much cash the player has.

https://sampwiki.blast.hk/wiki/GetPlayerMoney
Reply
#4

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.
Reply
#5

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?
Reply
#6

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.
Reply
#7

how exactly would I use IsNumeric, whenever I put in the amount I get an error:

pawn Код:
if(!IsNumeric(amount))
What do I replace "amount" with?
Reply
#8

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
how exactly would I use IsNumeric, whenever I put in the amount I get an error:

pawn Код:
if(!IsNumeric(amount))
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.
Reply
#9

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?
Reply
#10

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?
pawn Код:
new amount;
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]"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)