How to check money
#1

I want to check how much money a player has and then set a random amount to give to another player.



So i want to make a /ransom command. This command is used when a player is kidnapped. The ransom should be random. I want it so the player who is kidnapped types /ransom and a random amount of money that they have is given to the kidnapper.


I can do the giving the player the money part, i just need to know how to check to see how much money a player has, and then make a random amount to give to another player.
Reply
#2

This might help:
Код:
new amount=random(GetPlayerMoney(target))+1; //+1 otherwise the ransom will be 0
GivePlayerMoney(target,-amount);
GivePlayerMoney(playerid,amount);
Alternately You can set a minimum random amount:
Код:
new amount;
while(amount<1000)amount=random(GetPlayerMoney(target))+1;
GivePlayerMoney......
note that in the second one you need to make sure that they HAVE the minimum otherwise it will freeze your server.
Reply
#3

This is my ransom command. Right now the person who is kidnapped can give a player as much cash as he wants too and the kidnapper could decide to release him or not.


Can you help me edit it to the random thing I'm trying to do?



So here is the command:


pawn Код:
if(strcmp(cmd, "/ransom", true) == 0)
{
    if(IsSpawned[playerid] == 0) {
        SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
        return 1;
    }
    if(cuffed[playerid] == 1) {
        SendClientMessage(playerid,COLOR_ERROR,"You are handcuffed. You cannot use this command");
        return 1;
    }
    if(isKidnapped[playerid] == 0) {
        SendClientMessage(playerid,COLOR_ERROR,"Only players who are kidnapped can use this command!");
        return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ransom (id) (amount)");
        return 1;
    }
    if(!IsNumeric(tmp)) {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ransom(id) (amount) ID Must be a number");
        return 1;
    }
    if(strval(tmp) == playerid) {
        SendClientMessage(playerid, COLOR_ERROR, "You cannot send cash to yourself");
        return 1;
    }
    giveplayerid = strval(tmp);
    if(!IsPlayerConnected(giveplayerid)) {
        format(szstring, sizeof(szstring), "ID (%d) is not an active player", giveplayerid);
        SendClientMessage(playerid, COLOR_ERROR, szstring);
        return 1;
    }
    new sendername[24];
    new receivername[24];
    GetPlayerName(playerid,sendername, 24);
    GetPlayerName(giveplayerid,receivername, 24);
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 8) {
        format(szstring, sizeof(szstring), "%s(%d) Is not close enough. You cannot give cash to that player",receivername,giveplayerid);
        SendClientMessage(playerid, COLOR_ERROR, szstring);
        return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ransom (id) (amount)");
        return 1;
    }
    if(!IsNumeric(tmp)) {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ransom(id) (amount) Amount must be a number");
        return 1;
    }
    new cashsend = strval(tmp);
    if(cashsend <= 0 || cashsend >= 100001) {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: Minimum $1 / Maximum $100000");
        return 1;
    }
    if(GetPlayerMoney(giveplayerid) + cashsend >= 2000001) {
        SendClientMessage(playerid, 0xA9A9A9AA, "|_Cash Send Failed_|");
        format(szstring, sizeof(szstring), "%s(%d) Does not have enough pockets to carry that ammount of cash ",receivername,giveplayerid);
        SendClientMessage(playerid, 0x00C7FFAA, szstring);
        return 1;
    }
    if(GetPlayerMoney(playerid) >= cashsend) {
        GivePlayerMoney(playerid,-cashsend);
        GivePlayerMoney(giveplayerid,cashsend);
        SendClientMessage(playerid, 0xA9A9A9AA, "|_Cash Sent_|");
        format(szstring, sizeof(szstring), "You have sent $%d to %s(%d)",cashsend,receivername,giveplayerid);
        SendClientMessage(playerid, 0x00C7FFAA, szstring);
        SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Cash Received_|");
        SendClientMessage(giveplayerid, 0xA9A9A9AA, "You can now choose to release the player, or keep him kidnapped!");
        format(szstring, sizeof(szstring), "%s(%d) Has sent you $%d",sendername,playerid,cashsend);
        SendClientMessage(giveplayerid, 0x00C7FFAA, szstring);
        format(szstring, sizeof(szstring), "Sender %s(%d) Has sent $%d to receiver %s(%d)",sendername,playerid,cashsend,receivername,giveplayerid);
        printf("%s",szstring);
    }
    else
    if(GetPlayerMoney(playerid) < cashsend) {
        SendClientMessage(playerid, 0xA9A9A9AA, "|_Cash Send Failed_|");
        format(szstring, sizeof(szstring), "You cannot afford to send $%d",cashsend);
        SendClientMessage(playerid, COLOR_ERROR, szstring);
    }
    return 1;
}
Reply
#4

Bump. Please help.
Reply
#5

okay. this is what you gotta do. with thje kidnapper you made the id and playerid in "global variables" then you check if the person is being kidnapped and if he still has a kidnapper. then you release the kidnapped dont wait for a stupid person to release the kidnapped
Reply
#6

Quote:
Originally Posted by Kar
Посмотреть сообщение
okay. this is what you gotta do. with thje kidnapper you made the id and playerid in "global variables" then you check if the person is being kidnapped and if he still has a kidnapper. then you release the kidnapped dont wait for a stupid person to release the kidnapped
Yeah, that's what i'm trying to do.


What i want is, When a player is kidnapped, they are able to type /cutrope (which works) and if that fails /ransom. What /ransom does is, it checks how much money the person who is kidnapped has, and chooses a random amount depending on how much they have and gives it to the kidnapper and the kidnapped player is automatically released.



I know how to do the release part and most of the command, i just need help on how to check for the amount and how to set the amount to random to give to the kidnapper.
Reply
#7

pawn Код:
if(GetPlayerMoney(playerid) < ransommoney) return SendClientMessage(playerid,urcolor,"Msg Here");
if he has it

GivePlayerMoney(kidnappervariable,ransommoney);
Reply
#8

How do i check for the ransom money and stuff.


Lol, can you show me how to do it, and then i can make it for another command of mine but in a different way.
Reply
#9

Please? Someone, All i need is how to check a players money amount and make a random amount to give to another player.
Reply
#10

new randmoney = random(104785);
GivePlayerMoney(playerid,randmoney);
Reply
#11

Quote:
Originally Posted by Kar
Посмотреть сообщение
new randmoney = random(104785);
GivePlayerMoney(playerid,randmoney);
That will only give the player a random amount out of no where.


What i'd like to do is. Check to see how much 1 player has, and take a random amount out of that players pocket and give it to the other player.
Reply
#12

well explain urself better..

pawn Код:
if(GetPlayerMoney(giveplayerid) > 0)
{
new pcash = GetPlayerMoney(giveplayerid);
new robcash = random(pcash);
GivePlayerMoney(giveplayerid) -= robcash;
GivePlayerMoney(playerid) += robcash;
}
Reply
#13

I get errors on this line:


GivePlayerMoney(giveplayerid) -= robcash;

warning 202: number of arguments does not match definition
error 022: must be lvalue (non-constant)
warning 215: expression has no effect
error 022: must be lvalue (non-constant)


Also, can you explain to me your code, i love learning as people show me things. I'm sorry for not explaining myself. Thank you for replying to my posts.
Reply
#14

pawn Код:
if(GetPlayerMoney(giveplayerid) > 0) // the victim is defined as giveplayerid
{
new pcash = GetPlayerMoney(giveplayerid); // gets the money of the one who's getting robbed
new robcash = random(pcash); // makes a random amount of the victim's money
GivePlayerMoney(giveplayerid, -robcash); // subtracts the money from the victim
GivePlayerMoney(playerid, robcash); // adds the money to the robber
}
Reply
#15

lol how did u get errors? it was obvious you ahd to convert it..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)