SA-MP Forums Archive
Ranking - 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: Ranking (/showthread.php?tid=457108)



Ranking - dEcooR - 09.08.2013

Hello,i wanna ask how i should make some message that player reached rank.

heres example of my code its at onplayerupdate so message would be spam..so how i should use pvars to got message only once?

Код:
new K = pInfo[playerid][Kills];
if(K<100)
{
	pRank[playerid] = Kid;
}
else if(K>100 && K<= 300)
{
	pRank[playerid] = Master;
}



Re: Ranking - Misiur - 09.08.2013

I don't think you should do this in OPU callback, I'd recommend using timer (5-10 seconds intervals). Now, in separate function:

pawn Код:
forward CheckRank(playerid);
public CheckRank(playerid) {
    new previousRank = pRank[playerid];
    switch(pInfo[playerid][Kills]) {
        case 100..300: pRank[playerid] = Master;
        default: {
            pRank[playerid] = Kid;
        }
    }
    if(pRank[playerid] != previousRank) {
        SendClientMessage(playerid, -1, "Hey, you've got promoted! Congratulations");
    }
}
"Default" will cover for both 0-99 and some random values (bigger than 300 in your case)


Re: Ranking - dEcooR - 09.08.2013

I had used this sometimes

Код:
switch(pInfo[playerid][Kills])
{
      case 100..300:
}
but it didnt work for me :/ dude what then if i got total 10 ranks,and want to make message for each rank?


Re: Ranking - Misiur - 09.08.2013

Switch is your best friend

pawn Код:
#define strcpy(%0,%1) strcat(((%0)[0] = EOS, (%0)), %1)

forward CheckRank(playerid);
public CheckRank(playerid) {
    new
        previousRank = pRank[playerid],
        rankmsg[82],
        rankname[24];
       
    switch(pInfo[playerid][Kills]) {
        case 100..300: {
            pRank[playerid] = Master;
            strcpy(rankname, "Master");
        }
        case 301..500: {
            pRank[playerid] = Mastah;
            strcpy(rankname, "Mastah");
        }
        case 501..750: {
            pRank[playerid] = Promaster;
            strcpy(rankname, "Promaster");
        }
        default: {
            pRank[playerid] = Kid;
            strcpy(rankname, "Kid");
        }
    }
    if(pRank[playerid] != previousRank) {
        strcpy(rankmsg, "Hey, you've got promoted! Congratulations - you are now a ");
        strcat(rankmsg, rankname);
        SendClientMessage(playerid, -1, rankmsg);
    }
}
Remeber to declare all variables (Master/Mastah/Promaster/Kid)


Re: Ranking - dEcooR - 09.08.2013

Hmm lol ill try that thnx for now,i will tell u what happnd


EDIT:dude now i thot this eror and 3 warnings

warning 201: redefinition of constant/macro (symbol "strcpy(%0,%1)")

on this #define strcpy(%0,%1) strcat(((%0)[0] = EOS, (%0)), %1)

and 3 warnings tag mismatch on this lol where i didnt warns ever

INI_String("RegDate", pInfo[playerid][RegDate],64);
INI_String("pIP",pInfo[playerid][pIP],16);
INI_String("LastActive",pInfo[playerid][LastActive],64);


Re: Ranking - Misiur - 09.08.2013

Looks like you have strcpy macro already. Delete the define line and recompile


Re: Ranking - dEcooR - 09.08.2013

Yes looks like,but i dont got defined it yet in my gm,may it defined somewhere in Y_INI ? btw now its compiled fine i hope it will works


Re: Ranking - Vince - 09.08.2013

Why do you need timers for standalone events? Doesn't it make more sense to just update ranks when a player kills someone? https://sampwiki.blast.hk/wiki/OnPlayerDeath


Re: Ranking - dEcooR - 09.08.2013

I dont understand you right,what do you mean when kill someone so should i make that switch in public onplayerdeath?


Re: Ranking - Misiur - 09.08.2013

Yup, instead of timer move that to OnPlayerDeath (just remember that you are giving points to killerid, not playerid) (this will also fix message on connect).