[HELP] /givecash [SOLVED]
#1

pawn Код:
if(strcmp(cmd, "/givecash", true) == 0) {
       new string[256];
      new playermoney;
      new sendername[MAX_PLAYER_NAME];
      new giveplayer[MAX_PLAYER_NAME];
      new giveplayerid, moneys, idxx;
      new tmp[256];
        tmp = strtok(cmdtext, idxx);

        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
            return 1;
        }
        giveplayerid = strval(tmp);

        tmp = strtok(cmdtext, idxx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
            return 1;
        }
        moneys = strval(tmp);

        //printf("givecash_command: %d %d",giveplayerid,moneys);


        if (IsPlayerConnected(giveplayerid)) {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            playermoney = GetPlayerMoney(playerid);
            if (moneys > 0 && playermoney >= moneys) {
                GivePlayerMoney(playerid, (0 - moneys));
                GivePlayerMoney(giveplayerid, moneys);
                format(string, sizeof(string), "You have sent %s(%d), $%d.", giveplayer,giveplayerid, moneys);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                format(string, sizeof(string), "You have recieved $%d from %s(%d).", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
            }
            else {
                SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount.");
            }
        }
        else {
                format(string, sizeof(string), "%d is not an active player.", giveplayerid);
                SendClientMessage(playerid, COLOR_YELLOW, string);
            }
        return 1;
    }
Here is code I use for /givecash command....
It should work like this...

If Player wants to give some of his cash to another player, he uses /givecash ID amount, if he doesnt have enough money - returns him message "Invalid transaction", if it was wrong ID then "ID is not an active player"... It it was successful then send cash to another player and remove cash from sender...

Why this commands works for ID 0 only??

Whatever ID I use, it always gives money to ID 0 :S
Reply
#2

Anybody?
Reply
#3

https://sampwiki.blast.hk/wiki/Fast_Commands#givecash
Reply
#4

take thes bothe elses off from the end !
Reply
#5

Quote:
Originally Posted by LyQue
Here is code I use for /givecash command....
It should work like this...

If Player wants to give some of his cash to another player, he uses /givecash ID amount, if he doesnt have enough money - returns him message "Invalid transaction", if it was wrong ID then "ID is not an active player"... It it was successful then send cash to another player and remove cash from sender...

Why this commands works for ID 0 only??

Whatever ID I use, it always gives money to ID 0 :S
pawn Код:
if(strcmp(cmd, "/givecash", true) == 0) {
      new string[256];
      new playermoney;
      new sendername[MAX_PLAYER_NAME];
      new giveplayer[MAX_PLAYER_NAME];
      new giveplayerid, moneys, idxx;
      new tmp[256];
        tmp = strtok(cmdtext, idxx);

        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
            return 1;
        }
        giveplayerid = ReturnUser(tmp);

        tmp = strtok(cmdtext, idxx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
            return 1;
        }
        moneys = strval(tmp);

        //printf("givecash_command: %d %d",giveplayerid,moneys);


        if (IsPlayerConnected(giveplayerid)) {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            playermoney = GetPlayerMoney(playerid);
            if (moneys > 0 && playermoney >= moneys) {
                GivePlayerMoney(playerid, (0 - moneys));
                GivePlayerMoney(giveplayerid, moneys);
                format(string, sizeof(string), "You have sent %s(%d), $%d.", giveplayer,giveplayerid, moneys);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                format(string, sizeof(string), "You have recieved $%d from %s(%d).", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
            }
            else {
                SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount.");
            }
        }
        else {
                format(string, sizeof(string), "%d is not an active player.", giveplayerid);
                SendClientMessage(playerid, COLOR_YELLOW, string);
            }
        return 1;
    }
Reply
#6

Problem not found.. - EDIT : founded you have idxx not idx

This is my givecash cmd :P working fine - only - you can give money to yourself too
Код:
 	if(strcmp(cmd, "/givecash", true) == 0)
	 {
	  	new tmp[256];
		new string[128];
		new playermoney;
		new sendername[MAX_PLAYER_NAME];
		new giveplayer[MAX_PLAYER_NAME];
 		new giveplayerid, moneys;
		tmp = strtok(cmdtext, idx);

		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOR_5, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
		giveplayerid = strval(tmp);

		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOR_5, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
		moneys = strval(tmp);

		//printf("givecash_command: %d %d",giveplayerid,moneys);

		if (IsPlayerConnected(giveplayerid))
		{
			GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			playermoney = GetPlayerMoney(playerid);

			if (moneys > 0 && playermoney >= moneys)
			{
				GivePlayerMoney(playerid, (0 - moneys));
				GivePlayerMoney(giveplayerid, moneys);
				format(string, sizeof(string), "You gave %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
				SendClientMessage(playerid, COLOR_GREEN, string);
				format(string, sizeof(string), "You got $%d from %s(player: %d).", moneys, sendername, playerid);
				SendClientMessage(giveplayerid, COLOR_GREEN, string);
				PlayerPlaySound(playerid,1084,0.0,0.0,0.0);
				printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
				}
			else
			{
				SendClientMessage(playerid, COLOR_RED, "Jou dont have so much ;)");
			}
		}
		else
		{
			format(string, sizeof(string), "%d not found.", giveplayerid);
			SendClientMessage(playerid, COLOR_RED, string);
		}
		return 1;
	}
Reply
#7

Ok thanks guys, problem solved
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)