Score Messages
#1

Ok guys, this is just a simple template I created to understand, but when I tried it out for testing, it didn't come to my expectation. If I can understand this, I can advance. Well, I use a simple cmd right?, like etc. /test and I have a check if(GetPlayerScore) and like it should display msgs due to the player's score, well it works, but suppose If I have score 2000, it displays both messages, which I only want the 1500 score message to display, but also the 100 score message is displayed along, any ideas?

Код:
if(!strcmp(cmdtext, "/test", true))
{
	if(GetPlayerScore(playerid)  < 100)
	{
           SendClientMessage(playerid, 0xFF0000FF, "TEST 1");
        }
        else
        {
           SendClientMessage(playerid, 0xFF0000FF, "LOW SCORE");
        }
        if(GetPlayerScore(playerid)  < 1500)
	{
           SendClientMessage(playerid, 0xFF0000FF, "TEST 2 Sucess");
        }
        return 1;
Reply
#2

its easy man just do instead of GetPlayerScore(playerid) <1500 replace it with this
PHP код:
if(100<GetPlayerScore(playerid)<1500//to include that it must be over 100 
you see you're making it send the message for the lower than 100 and lower than 1500 but if its 50 its lower than 100 AND 1500 so to make the 1500 valid you make it check that its bigger than 100 and lower than 1500
Reply
#3

It still displays both messages, even when I'm 5000. Maybe something with the arrows? < >?

Код:
if(!strcmp(cmdtext, "/test", true))
{
if(GetPlayerScore(playerid)  > 0)
{
    SendClientMessage(playerid, 0xFF0000FF, "TEST 1");
}
if(0<GetPlayerScore(playerid)>1500)
{
    SendClientMessage(playerid, 0xFF0000FF, "TEST 2 Sucess");
}
if(1500<GetPlayerScore(playerid)>5000)
{
    SendClientMessage(playerid, 0xFF0000FF, "TEST 3 Sucess");
}
return 1;
Reply
#4

Your operators are wrong. < is smaller so the else statement would not be low score but greater instead.

https://sampwiki.blast.hk/wiki/Control_Structures#Operators

As for the multiple messages, use else if and check from greater to lower.
Reply
#5

no no you've got it all wrong man, first of all look at this :
PHP код:
if(GetPlayerScore(playerid)  > 0// this is basically going to be sent every time because its just if bigger than 0 
and then you have this:
PHP код:
if(0<GetPlayerScore(playerid)>1500)//if bigger than 0 and bigger than 1500 so the bigger than 0 here is invalid 
and the last one states:
PHP код:
if(1500<GetPlayerScore(playerid)>5000)//if smaller than 1500 and bigger than 5000 so that is valid. 
look at this correct example:
PHP код:
if(!strcmp(cmdtext"/test"true))
    {
    if( 
500<GetPlayerScore(playerid)  < 1000)//bigger than 500 and lower than 1000
    
{
        
SendClientMessage(playerid0xFF0000FF"TEST 1");
        }
        if(
1000<GetPlayerScore(playerid)<1500)//bigger than 1000 and lower than 1500
    
{
        
SendClientMessage(playerid0xFF0000FF"TEST 2 Sucess");
        }
        if(
1500<GetPlayerScore(playerid)<2000)//bigger than 1500 and lower than 2000
    
{
        
SendClientMessage(playerid0xFF0000FF"TEST 3 Sucess");
        }
        return 
1;
    } 
but there's something here, if its equal to the numbers stated above some cases wont send messages so its best to use <= and >= to make it if bigger than or equal to // smaller than or equal to.
EDIT: actually i recommend the link konst mentioned and the else if would be better to avoid confusion too, good luck man.
Reply
#6

Thank you, I'll do my best.
Reply
#7

I will try to explain your login here.

If your player has score less then 100, send TEST 1
if not (else) send LOW SCORE

After that (Its another if, you didnt chain it in previous) if player score is less then 1500 send TEST 2


One way to do it would be:

Check if player has score greater then 1500
Send test 2 message
if not, check if his score is greater then 100,
if it is send test 1 message
and if its not higher then 1500 and 100, only then send low score message.

pawn Код:
if(GetPlayerScore(playerid)  > 1500)
{
    SendClientMessage(playerid, 0xFF0000FF, "TEST 2 Sucess");
}
else if(GetPlayerScore(playerid)  > 100)
{
    SendClientMessage(playerid, 0xFF0000FF, "TEST 1");
}
else
{
    SendClientMessage(playerid, 0xFF0000FF, "LOW SCORE");
}
return 1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)