AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if player WAS alive when he join spectator team (https://forums.alliedmods.net/showthread.php?t=82523)

Mlk27 12-24-2008 21:42

Check if player WAS alive when he join spectator team
 
how do we check if a player join spectator when he was still alive? currently this what i have but the chat message doesnt seem to be printed when i use is_user_alive

Code:

public plugin_init()
{
        // bla bla....
              register_event( "TeamInfo", "join_team", "a")
}

public join_team()
{
        new id = read_data(1)
       
        static user_team[32]
        read_data(2, user_team, 31);

        if(user_team[0] == 'S' && is_user_alive(id))
                client_print(0, print_chat, "Someone entered Spectator"
}


SnoW 12-25-2008 06:36

Re: Check if player is alive when he join spectator team
 
Code:

set_task(0.5, "check_alive", id);
Code:

public check_alive(id)
{
      if(is_user_alive(id))
          //blablaa
}


Mlk27 12-25-2008 07:29

Re: Check if player is alive when he join spectator team
 
are there other ways beside using set_tsk with repeative flag?

Dores 12-25-2008 08:52

Re: Check if player is alive when he join spectator team
 
Something like this:
PHP Code:

#include <amxmodx>

#define VERSION "1.0"

new bool:g_bAlive33 ];

public 
plugin_init()
{
    
register_plugin"Spectator Was Alive?"VERSION"Dores" );
    
    
register_event"DeathMsg""ev_Death""a" );
    
register_event"ResetHUD""ev_NotOnlyRespawnButThatsWhatINeed""b" );
    
register_event"TeamInfo""ev_TeamInfo""a" );
}

public 
ev_Death()
{
    
g_bAliveread_data) ] = false;
}

public 
ev_NotOnlyRespawnButThatsWhatINeedid )
{
    
g_bAlive bool:( is_user_aliveid ) );
}

public 
ev_TeamInfo()
{
    static 
id id read_data);
    
    static 
team15 ] ; read_data2teamcharsmaxteam ) );
    
    if( 
team] == 'S' && g_bAliveid ] )
    {
        
g_bAliveid ] = false;
        
client_print0print_chat"LoL Moved to Spectator team while being alive!" );
    }


Or instead of hooking ResetHUD use this:
PHP Code:

#include <fakemeta>

public plugin_init()
{
      
register_forwardFM_Spawn"Forward_Spawn");
}

// [...]
public Forward_Spawnent )
{
      static 
szClass32 ] ; peventpev_classnameszClasscharsmaxszClass ) );
      if( !
equalszClass"player" ) )
      {
            return;
      }
      
      
g_bAliveent ] = bool:( is_user_aliveent ) );
}

// Or this:
#include <hamsandwich>

public plugin_init()
{
      
RegisterHamHam_Spawn"player""Forward_PlayerSpawn");
}

public 
Forward_PlayerSpawnid )
{
      
g_bAliveid ] = bool:( is_user_aliveid ) );



Exolent[jNr] 12-25-2008 12:31

Re: Check if player is alive when he join spectator team
 
Quote:

Originally Posted by Dores (Post 732941)
PHP Code:

    register_event"ResetHUD""ev_Respawn""b" ); 


NO!

Even if it doesn't matter if it is used in this case, you shouldn't name the function "ev_Respawn".
That event is called more than just when a player spawns, and if a new scripter sees that, they will think it is the correct way to hook spawning.

Dores 12-25-2008 12:51

Re: Check if player is alive when he join spectator team
 
Fixed?

EDIT:
Quote:

Originally Posted by Exolent[jNr] (Post 733007)
You could've used "ev_ResetHUD", but that's fine, too.

I know. :stupid:

Exolent[jNr] 12-25-2008 12:52

Re: Check if player is alive when he join spectator team
 
You could've used "ev_ResetHUD", but that's fine, too.

Mlk27 12-25-2008 19:32

Re: Check if player is alive when he join spectator team
 
@Dores
thanks so much!

@Exolent
yea you are right about ResetHUD cause i've always thought this event is called only when players spawn. any idea why it's called resetHUD by the way? such a horrible name, people might have thought it's used when hud on screen are being reset.

Exolent[jNr] 12-25-2008 23:14

Re: Check if player is alive when he join spectator team
 
It is used when a player's HUD is reset.
The event is called when:
  • player spawns
  • player starts recording a demo
  • sv_restart is change to a value greater than 0

Mlk27 01-07-2009 07:26

Re: Check if player is alive when he join spectator team
 
im starting to think that this isn't possible =\ when you join spec, you'll definately be killed so hooking DeathMsg event to check if player was still alive before he joins spectator is kinda pointless cause it will always return false there..

Code:
#include <amxmodx> #include <fakemeta> new bool:g_bAlive[33] public plugin_init() {     register_plugin("Bad Frag for Evader", "0.1", "Me")     register_event("TeamInfo", "Event_JoinTeam", "a")     register_event("DeathMsg", "Event_Death", "a")     register_event("ResetHUD", "Event_ResetHud", "b") } public client_disconnect(id) {     if(!is_user_bot(id))     {         g_bAlive[id] = false         log_to_file("evade.log", "client_disconnect: %s", g_bAlive[id] ? "true" : "false")     } } public Event_ResetHud(id) {     if(!is_user_bot(id))     {         g_bAlive[id] = bool:(is_user_alive(id))         log_to_file("evade.log", "Event_ResetHud: %s", g_bAlive[id] ? "true" : "false")     } } public Event_Death() {     new id = read_data(2)           if(!is_user_bot(id))     {         g_bAlive[id] = bool:(is_user_alive(id))         log_to_file("evade.log", "Event_Death: %s", g_bAlive[id] ? "true" : "false")     } } public Event_JoinTeam() {     new id = read_data(1)     static user_team[32]     read_data(2, user_team, charsmax(user_team))     if(user_team[0] == 'S' && g_bAlive[id])     {         g_bAlive[id] = false         log_to_file("evade.log", "Entered spec")     }     return PLUGIN_CONTINUE; }

evade.log
Code:

L 01/07/2009 - 01:21:29: Log file started (file "cstrike\addons\amxmodx\logs\evade.log") (game "cstrike") (amx "1.8.0.3660")
L 01/07/2009 - 01:21:29: Event_ResetHud: false
L 01/07/2009 - 01:21:32: Event_ResetHud: true
L 01/07/2009 - 01:21:40: Event_ResetHud: true
L 01/07/2009 - 01:21:54: Event_Death: false
L 01/07/2009 - 01:22:04: client_disconnect: false

any more ideas?


All times are GMT -4. The time now is 09:06.

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