SA-MP Forums Archive
Need some help with /givemoney :S - 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: Need some help with /givemoney :S (/showthread.php?tid=258922)



Need some help with /givemoney :S - >>Th0r<< - 02.06.2011

Well my code is this



Код:
if (strcmp("/givemoney", cmdtext, true) == 0){
	new tmp[256], tmp2[256];
	tmp = strtok(cmdtext, idx);
	tmp2 = strtok(cmdtext, idx);
	
	if(!strlen(tmp)) {
	SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney [playerid] [amount]");
	return 1;
	}
	if(!strlen(tmp2)) {
	SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney [playerid] [amount]");
	return 1;
	}
	new receiver, money;
	receiver = strval(tmp);
	money = strval(tmp2);
	
	if(GetPlayerMoney(playerid) < money) {
	SendClientMessage(playerid, 0xFFFFFFFF, "You dont have that much in your pocket foo'");
	return 1;
	}
	
	new string[128];
	new playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playername, sizeof(playername));
	new playername2[MAX_PLAYER_NAME];
	GetPlayerName(receiver, playername2, sizeof(playername2));

	format(string, sizeof(string), "You recieved %d$ from %s", money, playername);
	SendClientMessage(playerid,0xFFFFFFFF,string);
	format(string, sizeof(string), "You gave %d$ to %s", money, playername2);
	SendClientMessage(playerid,0xFFFFFFFF,string);
	
	GivePlayerMoney(playerid, (0 - money));
	GivePlayerMoney(receiver, money);
	
	return 1;
}
	
	

	return 0;
}
And its pasted in OnPlayerCommandText
and the error messages i get when i compile are those:

Код:
C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OHNOES~1.PWN(231) : error 017: undefined symbol "idx"
C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OHNOES~1.PWN(232) : error 017: undefined symbol "idx"



Re: Need some help with /givemoney :S - Lorenc_ - 02.06.2011

new idx;

Im pretty sure its an array so try like:

new idx[128];


Re: Need some help with /givemoney :S - >>Th0r<< - 02.06.2011

i did new idx[128];
but then it gave me this as an error:

C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OH NOES~1.PWN(229) : warning 217: loose indentation
C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OH NOES~1.PWN(231) : error 035: argument type mismatch (argument 2)
C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OH NOES~1.PWN(232) : error 035: argument type mismatch (argument 2)
C:\PROGRA~1\ROCKST~1\GTASAN~1\SAMP03~1\GAMEMO~1\OH NOES~1.PWN(269) : warning 217: loose indentation


Re: Need some help with /givemoney :S - Jack Shred - 02.06.2011

Check line 231 and 232 for any wrong arguments, loose indentation means the lines aren't in the same order.

I also suggest you to check out sscanf/zcmd, they're way better then strtok & strcmp


Re: Need some help with /givemoney :S - Ironboy - 02.06.2011

Better you use this.

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

        tmp = strtok(cmdtext, idx);

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

        tmp = strtok(cmdtext, idx);
        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(ID: %d), $%d.", giveplayer,giveplayerid, moneys);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                format(string, sizeof(string), "You have recieved $%d from %s(ID: %d).", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                printf("%s(playerid:%d) has transfered %d to %s(ID:%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;
    }