How does INVALID_PLAYER_ID work?
#1

Hey,

If you use "sscanf" you may use "INVALID_PLAYER_ID" to check if the player-id exists and someone is using it.
But how does it work? Any idea?
Reply
#2

Erm, i know Y_Less is an amazing scripter, but i dont think the words INVALID_PLAYER_ID would mean he would want his script to check for if a player(id) EXISTS?

Then again, i havent read the documentation (which i probably should do) and there probably is an algorithm somewhere that causes it to do so.

Can i just ask, where did you read that INVALID_PLAYER_ID does what you said it does?
Reply
#3

sscanf returns INVALID_PLAYER_ID if the player is invalid.
Reply
#4

Quote:
Originally Posted by The_Moddler
View Post
sscanf returns INVALID_PLAYER_ID if the player is invalid.
I thought so. I cant quite see why it wouldnt, the word INVALID_PLAYER_ID are pretty self explantatory. Sorry if i caused confusion !Phoenix!
Reply
#5

Wiki:
pawn Code:
if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
So if the id in sscanf(params, "u", id) is invalid " INVALID_PLAYER_ID" will be 0?
-> You can only use it with this special id?

Or does the retrieval of the " INVALID_PLAYER_ID" content runs something like a function?
Reply
#6

INVALID_PLAYER_ID is equal to (0xFFFF)

(Source, a_samp.inc)
pawn Code:
#define INVALID_PLAYER_ID                       (0xFFFF)
Reply
#7

Reply
#8

Sorry i should of explained better, i meant that INVALID_PLAYER_ID does not run a function or anything, it merely is (0xFFFF) and nothing more.
Reply
#9

I realized that but I don't understand how this can be used for an if-statement.
(You see I really want to understand how this unimposing comparison works)
Maybe the answer is unbelievable simple, but I don't get it...

(thanks funky)
Reply
#10

So.
Using it under OnPlayerDeath:
pawn Code:
if( killerid == INVALID_PLAYER_ID )
{
    SendClientMessage( playerid, 0xAAAAAA, "You have suicided, thefore you have no killer, no one killed you" );
}
Just an example.
Reply
#11

sscanf checks if you use "u" and if it searches for a name or player ID with the "u" parameter and doesn't find anyone online with the information you provide, then it returns INVALID_PLAYER_ID instead of the players actual ID, you can compare the ID variable you assign with sscanf to INVALID_PLAYER_ID if the player isn't connected.

pawn Code:
new id; // Variable. The user ID from sscanf needs to be stored in this. If the player isn't connected, INVALID_PLAYER_ID is put as the variable value.
if(sscanf(params, "u", id)) {
// They didn't even provide anything after the command name.
}
else {
// They provided something after the command name, our name. Are they connected?
if(id == INVALID_PLAYER_ID) {
// If this gets called, then the player isn't connected.
return 1;
}
}
Reply
#12

So INVALID_PLAYER_ID simply stands for "The playerid is overall not valid"?
Wouldn't that mean that if it's valid you still have to check if the player is connected?

//-------------
Calgon answered my question while I was writing this reply.
Reply
#13

INVALID_PLAYER_ID does mean that an invalid player ID was specified, well that's what sscanf sets as the playerid if it can't find valid search criteria.

If INVALID_PLAYER_ID is returned then you don't need any more checks if you use sscanf to parse the userid/name - they aren't connected at all.
Reply
#14

That makes sense; thank you!
(see my last post)
Reply
#15

Also, you can use !IsPlayerConnected:
pawn Code:
if( !IsPlayerConnected( playerid ) )
 // If this gets called, player is not on the server
Reply
#16

How can i use INVALID_PLAYER_ID ?
TO ALL ID at the TAB BAR?
sry I ONLY SCRIPT LITTLE.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)