IsPlayerConnected question
#1

hi,

i know this is a kinda noob question but im wondering what exactly this IsPlayerConnected function does.
E.g. i use this in my map change code like this:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
    SetPlayerPos(i,X,Y,Z);
    }
}
Now i think everyone knows what this does
But can i also use this loop without the IsPlayerConnected function?
Would it be even better or faster?
Or would there be any bugs possible if i use this code without the IsPlayerConnected thing?
I hope u can help me with my stupid and strange question

regards, blackwolf.
Reply
#2

It's better to use it because it will skip players are not connected and save memory, else it will just set health of a player that's not even connected.

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if (!IsPlayerConnected(i)) continue;
    SetPlayerPos(i, x, y, z);
}
I still and will always recommend foreach, easy and faster than ever loops.
pawn Код:
foreach(Player, i)
{
    SetPlayerPos(i, x, y, z);
}
Checking if the player is online is not even needed in that case.
Reply
#3

if(IsPlayerConnected(i)

Is to ask before running the cycle if the player is connected, is due to this function and you know if a player connected to this ID

srry-.-
Reply
#4

Quote:
Originally Posted by Mr.GeEk
Посмотреть сообщение
if(IsPlayerConnected(i)

Es para preguntar antes de correr el ciclo si el jugador estб conectado, es lo debido poner esa funciуn ya que sabes si hay un jugador conectado con tal ID
Go to the Spanish forums.
Reply
#5

yeah, thx alot for ur answer
ive already planned to replace all my loops with ******'s (god of samp ) foreach loop for a long time.
But now uve motivated me to do it right now
So nothing else is needed?
Only this foreach loop?
Ive also heard that it is alot faster and way more efficient.
And no stupid IsPlayerConnected anymore?
sounds nice
Reply
#6

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
yeah, thx alot for ur answer
ive already planned to replace all my loops with ******'s (god of samp ) foreach loop for a long time.
But now uve motivated me to do it right now
So nothing else is needed?
Only this foreach loop?
Ive also heard that it is alot faster and way more efficient.
And no stupid IsPlayerConnected anymore?
sounds nice
Yes.
Reply
#7

thank u alot my SAMP bros

regards, wolf.
Reply
#8

Most functions have inbuilt IsPlayerConnected checks, and they simply won't work if the player is not connected.
Reply
#9

k, thx alot Vince
Reply
#10

thx alot ******

well about the god thing:

Sorry if I hurt u but do u know how many tutorials + includes + plugins or what ever uve already made?
And how many people uve already helped by releasing ur great stuff and replying 4500+ times?
Thats kinda GodLike for me
But I agree with u that the top level of respect should be reserved for Kyeman and the developers.
But please dont tell me u werent good at pawno (or and other scripting/programming languages) cause that what ive seen released by u so far is just amazing

Anyway, thx alot and pls keep up the good work, sorry, the EXCELLENT work

best regards, blackwolf.

//edit: mhh, i just saw your y_class release
This might be usefull for me as well soon
thx again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)