Ranking
#1

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;
}
Reply
#2

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)
Reply
#3

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?
Reply
#4

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)
Reply
#5

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);
Reply
#6

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

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
Reply
#8

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
Reply
#9

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

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).
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)