PDA

View Full Version : Set Score with Command


Longibotti
18/04/2011, 12:33 PM
Hello =)
I want to make an little Script, which allows to change the score of a Player.
Ive seen some levelsystems, but they dont work with commands. I need to have something like

/setplayerscore [ID/NAME] [Score]

Does anybody knows how?

Stigg
18/04/2011, 01:04 PM
Should you out:

http://wiki.sa-mp.com/wiki/Changing_player's_score_under_misc_condition

Longibotti
18/04/2011, 01:10 PM
Thanks for the fast answer, but i know how to do it, when some1 kills another player.

I just don't know how to put it in a command (/setscore [ID/NAME] [SCORE])

nuriel8833
18/04/2011, 01:40 PM
if(strcmp(cmd, "/setscore", true) == 0)
{
new sendername[MAX_PLAYER_NAME];
new tmp[256];
new tmp2[256];
tmp = strtok(cmdtext, idx);
new givenplayer = strval(tmp);
tmp2 = strtok(cmdtext, idx);
new score = strval(tmp2);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setscore [playerid] [Score]");
if(!IsPlayerConnected(otherplayer)) return SendClientMessage(playerid, COLOR_WHITE, "Invaild player ID!");
SetPlayerScore(givenplayer,score);
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "Admin \"%s\" has just set your score to %d!", sendername, score);
SendClientMessage(otherplayer, COLOR_GREEN, string);
return 1;
}


I just hope you know how to change everything else (like colors and stuff)
If you don't contact me

xir
18/04/2011, 01:57 PM
Instead of that command above, I will give you a cmd with zcmd & sscanf which is alot better.

strcmp & strtok is old & outdated

Here is a cmd with sscanf & zcmd

COMMAND:setscore(playerid, params[])
{
new string[128], pName[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], pID, score;
if(sscanf(params, "ud", pID, score)) return SendClientMessage(playerid, -1, "Usage: /setscore <playerid> <score>");
if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "This player is not connected");
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(pID, pName, sizeof(pName));
format(string, sizeof(string), "%s has given you %d score", name, score);
SendClientMessage(pID, -1, string);
format(string, sizeof(string), "You have given %d score to %s", score, pName);
SendClientMessage(playerid, -1, string);
SetPlayerScore(pID, score);
return 1;
}

Longibotti
18/04/2011, 02:42 PM
Thank you 2, helped me very much :)

GAMER_PS2
19/10/2011, 09:41 AM
@xir dude i agree