SA-MP Forums Archive
[HELP] /givecash [SOLVED] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] /givecash [SOLVED] (/showthread.php?tid=129631)



[HELP] /givecash [SOLVED] - leapfish - 22.02.2010

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


Re: [HELP] /givecash - leapfish - 23.02.2010

Anybody?


Re: [HELP] /givecash - Torran - 23.02.2010

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


Re: [HELP] /givecash - GaGlets(R) - 23.02.2010

take thes bothe elses off from the end !


Re: [HELP] /givecash - Razvann - 23.02.2010

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;
    }



Re: [HELP] /givecash - GaGlets(R) - 23.02.2010

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;
	}



Re: [HELP] /givecash - leapfish - 23.02.2010

Ok thanks guys, problem solved