SA-MP Forums Archive
Fix this small code ill +rep - 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)
+--- Thread: Fix this small code ill +rep (/showthread.php?tid=466323)



Fix this small code ill +rep - FireWarrior101 - 27.09.2013

pawn Код:
for (new i = 0; i < MAX_PLAYERS; i++)
 {
 kill[killerid]++;
 death[playerid]++;
 SetPlayerScore(i)(killerid,GetPlayerScore(playerid)+1[i]);
 SetPlayerMoney(killerid,GetPlayerMoney(playerid)+1000);
 SendClientMessage(killerid,COLOR_YELLOW,"You recieved +1000 money & +1 score.");
 }
i wanna use sscanf for kills otherwise the killer gets the same score that the player who died has


Re: Fix this small code ill +rep - Voxel - 27.09.2013

Remove the for (new i = 0; i < MAX_PLAYERS; i++) because that makes it so everyone gains the score if theres a kill if im right.
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    kill[killerid]++;
    death[playerid]++;
    SetPlayerScorekillerid,GetPlayerScore(killerid)+1); //changed playerid to killerid
    SetPlayerMoney(killerid,GetPlayerMoney(killerid)+1000); //changed playerid to killerid because you have the person who died the cash and points.
    SendClientMessage(killerid,COLOR_YELLOW,"You recieved +1000 money & +1 score.");
}
if this doesnt work without the (new i = 0; i < MAX_PLAYERS; i++) you could try adding it back but i reccomend trying it without first and with the above code. good luck ;0!


Re: Fix this small code ill +rep - Konstantinos - 27.09.2013

Do you even what sscanf is? Sscanf is used to split a string. You do not need it at all.

The bad thing you do is loop through all the players and if there are 50 players, it will add 50 kills to the killer and 50 deaths to the player. It will also cause runtime error about index out of bounds if you do not check if the killer is valid. Your problem is that you get the player's score and add +1000, not the killer's one.

pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
    death[playerid]++;
    if( killerid != INVALID_PLAYER_ID )
    {
        kill[ killerid ]++;
        SetPlayerScore( killerid, GetPlayerScore( killerid ) + 1 );
        SetPlayerMoney( killerid, GetPlayerMoney( killerid ) + 1000 );
        SendClientMessage( killerid, COLOR_YELLOW, "You recieved +1000 money & +1 score." );
    }
    return 1;
}