How does INVALID_PLAYER_ID actually work?
#1

Now, this may seem a bit silly but I am basically curious about how INVALID_PLAYER_ID works. Let's start with this example:

pawn Код:
public OnPlayerUpdate(playerid)
{
     if(playerid != INVALID_PLAYER_ID)
     {
            .///
     }
     return 1;
}
This would allow the code to go through if the player is connected. But my question is what exactly is INVALID_PLAYER_ID? A function? If it's a constant value then this would make zero sense.

This is what the compiler sees this as:

if(0 !=

So, playerID obviously can be anything, but what about INVALID_PLAYER_ID? If it's a constant then it certainly can't be 0,1,2,3,4,5,6... How does this work?

Is it basically just a marco for a native function like IsPlayerConnected?

Thanks.

EDIT: In a_samp it's defined as
pawn Код:
#define INVALID_PLAYER_ID                       (0xFFFF)
This makes zero sense, is this like a memory address? Or is it basically something to do with bits?
Reply
#2

Its a simple define, from code you can see its defined as hexadecimal number

0xFFFF - FFFF is 65535 in decimal whitch is maximum signed integer for 32bit

65535 as player id is invalid for sure and thats why its used as invalid player id
Reply
#3

That doesn't answer my question. Let's say no one is using playerID 0. And when I run a global timer(which I wouldn't but you get the point) to check if player 0 is online every 5 minutes...

pawn Код:
if(0 == 65535)
{
   // player is offline
}
This doesn't make any sense. This is not equal(0 doesn't equal 65535 that'd be crazy!), so how does the compiler actually process this information?
Reply
#4

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
65535 in decimal whitch is maximum signed integer for 32bit
16 bit. Also some callbacks use this value, namely OnPlayerDeath.

Quote:
Originally Posted by Puppy
Посмотреть сообщение
That doesn't answer my question. Let's say no one is using playerID 0. And when I run a global timer(which I wouldn't but you get the point) to check if player 0 is online every 5 minutes...

pawn Код:
if(0 == 65535)
{
   // player is offline
}
This doesn't make any sense. This is not equal(0 doesn't equal 65535 that'd be crazy!), so how does the compiler actually process this information?
Don't confuse it with IsPlayerConnected, because for the most part they can't be used interchangeably.
Reply
#5

Quote:
Originally Posted by Puppy
Посмотреть сообщение
This makes zero sense, is this like a memory address?
nope

Quote:
Originally Posted by Puppy
Or is it basically something to do with bits?
yup

Quote:
Originally Posted by DRIFT_HUNTER
0xFFFF - FFFF is 65535 in decimal whitch is maximum signed integer for 32bit
16*

Quote:
Originally Posted by DRIFT_HUNTER
65535 as player id is invalid for sure and thats why its used as invalid player id
so is -1..

just the max val of 2 byte int (samp got 1000p on the linux server..cool)
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
16 bit. Also some callbacks use this value, namely OnPlayerDeath.



Don't confuse it with IsPlayerConnected, because for the most part they can't be used interchangeably.
16bit unsigned, 32bit signed :P
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
16bit unsigned, 32bit signed :P
uh..no
Reply
#8

Quote:
Originally Posted by Ada32
Посмотреть сообщение
uh..no
Oooopsss.... my bad
Anyway 65535 is maximum unsigned in 16 bits, and C/C++ integer is 2 bytes (2*8 = 16bits)
Reply
#9

Used to indicate that no player matches the description

E.g. The killerid on suicide.
https://sampwiki.blast.hk/wiki/OnPlayerDeath
Reply
#10

I know what it does, it's just I am stumped upon the fact of how it works anyways thanks for the help so far, can someone explain this in layman(simple) terms?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)