Return "?" - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Return "?" (
/showthread.php?tid=213562)
Return "?" -
Kwarde - 19.01.2011
Well, sorry for the unclear title but,
I've made the function "GetPlayerWithHighestScore", and it's working, but I wanna know one thing for sure.
pawn Код:
GetPlayerWithHighestScore()
{
new HighestScore = -999999999, ID = INVALID_PLAYER_ID;
for(new i = 0; i < 500; i++){
if(!IsPlayerConnected(i)) continue;
if(GetPlayerScore(i) > HighestScore){
HighestScore = GetPlayerScore(i);
ID = i;
}
continue;
}
return ID != INVALID_PLAYER_ID ? ID : -1;
}
About the
return ID != INVALID_PLAYER_ID ? ID : -1;
Am I true, if I say that this means...
Return "ID" when it's not 'INVALID_PLAYER_ID', otherwise, return '-1'
Just wanna know for sure :P - I like scripting etc, and I'm a bit good with it, but I just wanna know for sure... I wanna understand ANYTHING I make
Thanks in advance,
Kevin
Re: Return "?" -
Joe Staff - 19.01.2011
You can just do
because it can't possibly be anything else other than -1 through 499.
BTW -1 == INVALID_PLAYER_ID
Re: Return "?" -
Kwarde - 19.01.2011
Eh, actually that didn't work
- I've done that before, and it did always return '1', even when I was alone (so, ID 0).
And btw, INVALID_PLAYER_ID is " (0xFFFF) " in a_samp :P
But thanks for your response
- But about what I asked, is that true?
Quote:
Return "ID" when it's not 'INVALID_PLAYER_ID', otherwise, return '-1'
|
Re: Return "?" -
RyDeR` - 19.01.2011
pawn Код:
stock GetPlayerWithHighestScore()
{
new
scoreMax = cellmin,
scoreTemp,
playerid = -1
;
for(new i; i != MAX_PLAYERS; ++i)
{
if(IsPlayerConnected(i))
{
if((scoreTemp = GetPlayerScore(i)) > scoreMax)
{
scoreMax = scoreTemp;
playerid = i;
}
}
}
return playerid;
}
This one works perfect. Actually you don't need the ? : statement because it'll return -1 as long as you don't assign anything, so actually, if there's no player connected it'll return -1.
Re: Return "?" -
Kwarde - 19.01.2011
Quote:
if there's no player connected it'll return -1.
|
I know, that's what I wanted :P