Strange variable/player file problem
#1

pawn Code:
BankCash[playerid] = dUserINT(PlayerName(playerid)).("bankcash");
    new MoneyInPack =dUserINT(PlayerName(playerid)).("HasPackMoney");
    BankCash[playerid] +=MoneyInPack;
    HasPackMoney[playerid]=0;
The goal of the code is to take the players money from his Backpack ... deposit it into his bank account and set the backpack amount to 0.
It does ... nothing.
I've tried a few different ways to do it, this is the most recent.

The players packback keeps the same amount and the bank account doesn't increase.

Before you ask; this IS all the code you will need. All the other code in the command would have nothing to do with this part.
This is a very strange problem; one I can't seem to figure out, any help would be appreciated.
Reply
#2

could you explain what some of those functions do. e.g. dUserINT
Reply
#3

Could you explain exactly step by step what you're trying to do on each line.

e.g., Read value from file and store to this...

Reply
#4

pawn Code:
BankCash[playerid] = dUserINT(PlayerName(playerid)).("bankcash");
^^ Is letting the script know that when BankCash[playerid] is used that it's to read from the playerfiles bankcash line. (bankcash is the amount the player has in his bank account.)

pawn Code:
new MoneyInPack =dUserINT(PlayerName(playerid)).("HasPackMoney");
Makes MoneyInPack read from the players HasPackMoney line. (HasPackMoney is the amount of money the player has in his backpack.)

pawn Code:
BankCash[playerid] +=MoneyInPack;
Gets the players Bank account to increase by the amount the player has in his bank account.

pawn Code:
HasPackMoney[playerid]=0;
Gets the amount in the players backpack to reset to $0.
Reply
#5

Well from what I can see you need to set the value in the DUDB file back to 0, otherwise next time you use the command it will read the same number as before.

pawn Code:
BankCash[playerid] = dUserINT(PlayerName(playerid)).("bankcash");
BankCash[playerid] += dUserINT(PlayerName(playerid)).("HasPackMoney");
dUserSetINT(PlayerName(playerid)).("HasPackMoney", 0);
Reply
#6

That code fixed one of the problems.
It set the backpack to 0 ... but still didn't give the player the money in his bank account.

Then this code got it working:
pawn Code:
BankCash[playerid] = dUserINT(PlayerName(playerid)).("bankcash");
    new Total = HasPackMoney[playerid] + BankCash[playerid];
    dUserSetINT(PlayerName(playerid)).("bankcash", Total);
    dUserSetINT(PlayerName(playerid)).("HasPackMoney", 0);
Thanks alot for your help m8.
Reply
#7

Ok, I've another similar problem now.

pawn Code:
BankCash[giveplayerid] = dUserINT(PlayerName(giveplayerid)).("bankcash");
    new Total = cashsend + BankCash[giveplayerid];
    dUserSetINT(PlayerName(giveplayerid)).("bankcash", Total);
    BankCash[giveplayerid]=Total;
    new Minus = BankCash[playerid] - cashsend;
    BankCash[playerid]=Minus;
    dUserSetINT(PlayerName(playerid)).("bankcash", Minus);
This is meant to get the 'cashsend' (The amount is set in the command) and transfer it from playerid's bank account to giveplayerid's.
Giveplayerid gets the cash ... playerid loses too much.
Reply
#8

I don't know if this'll make a different but here's a bit of a re-arrangement:

pawn Code:
BankCash[giveplayerid] = cashsend + dUserINT(PlayerName(giveplayerid)).("bankcash");
    dUserSetINT(PlayerName(giveplayerid)).("bankcash", BankCash[giveplayerid]);
    BankCash[playerid] = dUserINT(PlayerName(playerid)).("bankcash") - cashsend;
    dUserSetINT(PlayerName(playerid)).("bankcash", BankCash[playerid]);
Reply
#9

I already got it, thanks tho m8.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)