AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   If player is alive, it means, that he is connected to server? (https://forums.alliedmods.net/showthread.php?t=255153)

danonix 01-11-2015 09:00

If player is alive, it means, that he is connected to server?
 
Hello, I found this, and now I wonder, if player is not alive, it means, that he is connected to server or not?
@edit - wrong named topic - I meant IS NOT ALIVE, not ALIVE
PHP Code:

static cell AMX_NATIVE_CALL is_user_connected(AMX *amxcell *params/* 1 param */
{
    
int index params[1];
    
    if (
index || index gpGlobals->maxClients)
        return 
0;
    
    
CPlayerpPlayer GET_PLAYER_POINTER_I(index);
    
    return(
pPlayer->ingame 0);
}

extern bool g_bmod_tfc;
static 
cell AMX_NATIVE_CALL is_user_alive(AMX *amxcell *params/* 1 param */
{
    
int index params[1];
    
    if (
index || index gpGlobals->maxClients)
    {
        return 
0;
    }
    
    
CPlayerpPlayer GET_PLAYER_POINTER_I(index);

    if (
g_bmod_tfc)
    {
        
edict_t *pPlayer->pEdict;
        if (
e->v.flags FL_SPECTATOR || 
            (!
e->v.team || !e->v.playerclass))
        {
            return 
0;
        }
    }
    
    return((
pPlayer->ingame && pPlayer->IsAlive()) ? 0);



zmd94 01-11-2015 09:07

Re: If player is alive, it means, that he is connected to server?
 
Player still connecting to the server.

danonix 01-11-2015 09:11

Re: If player is alive, it means, that he is connected to server?
 
Quote:

Originally Posted by zmd94 (Post 2247770)
Player still connecting to the server.

So player which is not alive is connected to server? I am right?

jimaway 01-11-2015 09:15

Re: If player is alive, it means, that he is connected to server?
 
if player is not alive you have to check is_user_connected to find out if he is in the server

is_user_alive returns true if player is alive and false when player is not alive or not connected to the server

HamletEagle 01-11-2015 09:18

Re: If player is alive, it means, that he is connected to server?
 
If a player is alive how he could not be connected to server ? So:
1. is_user_alive check if player is connected and if player is alive.
2. is_user_connected checks only if player is connected, it can be alive or dead.
3. checking just is_user_alive to know if player is connected or not is not accurate, because it can be dead but still connected(like he was killed during the round and wait for respawn).

danonix 01-11-2015 09:22

Re: If player is alive, it means, that he is connected to server?
 
Quote:

Originally Posted by HamletEagle (Post 2247778)
If a player is alive how he could not be connected to server ? So:
1. is_user_alive check if player is connected and if player is alive.
2. is_user_connected checks only if player is connected, it can be alive or dead.
3. checking just is_user_alive to know if player is connected or not is not accurate, because it can be dead but still connected(like he was killed during the round and wait for respawn).

Well, I know that if is player alive, he must be connected to server, but though, that if player is not alive, it still means that he is connected to server because of this piece of code
Code:

return((pPlayer->ingame && pPlayer->IsAlive()) ? 1 : 0);
But still - player in game ( returns 1 ) && player is alive( returns 1) - player alive - returns 1
player in game ( returns 1 ) && player is not alive ( returns 0 ) function returns 0
player in game ( returns 0 ) && player is not alive ( returns 0 ) function returns 0

So, if player is not alive i have to check, that if he is connected to server.

HamletEagle 01-11-2015 10:06

Re: If player is alive, it means, that he is connected to server?
 
Yes, if not alive then you need to check if he is connected, but this depend on the context.

aron9forever 01-11-2015 10:29

Re: If player is alive, it means, that he is connected to server?
 
very interesting question
the conclusion is that if is_user_alive returns 0 it does not necessarily mean he's connected to the server
you can go ahead and continue a function if(is_user_alive)
but in the else{ you'll have to do an is_user_connected check}

by means of optimization, theoretically , this is the best way, other than first checking if he's connected or not and then the alive or not

danonix 01-11-2015 11:25

Re: If player is alive, it means, that he is connected to server?
 
Quote:

Originally Posted by HamletEagle (Post 2247792)
Yes, if not alive then you need to check if he is connected, but this depend on the context.

Could you explain?

zmd94 01-11-2015 11:38

Re: If player is alive, it means, that he is connected to server?
 
It is better if you tell what you want to do. Then, it is more easier for us to help you.


All times are GMT -4. The time now is 15:19.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.