AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error Respawn (https://forums.alliedmods.net/showthread.php?t=131739)

Bello2 07-08-2010 10:08

Error Respawn
 
The error that this cause is that: When respawning a player there are times when it was as a spectator, Instead of reviving
The method that i'm using is this:

PHP Code:

ExecuteHamBHam_CS_RoundRespawnid ); 

To try to solve the problem i have done this small code:

PHP Code:

if (!can_spawn(id)) return;
{
     
//revive
}

stock can_spawn(id)
{
   if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED || is_user_alive(id))
      return 
false
    
   
return true


The problem is that it is not working and moreover i strip this error:

Code:

L 07/07/2010 - 23:53:17: Start of error session.
L 07/07/2010 - 23:53:17: Info (map "de_train") (file "addons/amxmodx/logs/error_20100707.log")
L 07/07/2010 - 23:53:17: [CSTRIKE] Invalid player 9
L 07/07/2010 - 23:53:17: [AMXX] Displaying debug trace (plugin "respawn.amxx")
L 07/07/2010 - 23:53:17: [AMXX] Run time error 10: native error (native "cs_get_user_team")
L 07/07/2010 - 23:53:17: [AMXX]    [0] deathmatch.sma::can_spawn (line 51)
L 07/07/2010 - 23:53:17: [AMXX]    [1] deathmatch.sma::revive (line 35)


drekes 07-08-2010 12:04

Re: Error Respawn
 
try checking if he is connected

PHP Code:

stock can_spawn(id)
{
   if( !
is_user_connected(id) || cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED ||  is_user_alive(id))
      return 
false
    
   
return true



Bello2 07-08-2010 12:12

Re: Error Respawn
 
Quote:

Originally Posted by drekes (Post 1232058)
try checking if he is connected

PHP Code:

stock can_spawn(id)
{
   if( !
is_user_connected(id) || cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED ||  is_user_alive(id))
      return 
false
    
   
return true



Ok perfect.

a question:

That stock worked better?

1.
PHP Code:

stock can_spawn(id)
{
   if( !
is_user_connected(id) || cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED ||  is_user_alive(id))
      return 
false
    
   
return true


2.
PHP Code:

stock can_spawn(id) return ( !is_user_connected(id) && (cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED || is_user_alive(id))) ? false true 


drekes 07-08-2010 12:35

Re: Error Respawn
 
i think it's the second one is a little bit better. Not sure though and it won't matter much.

ot_207 07-08-2010 12:36

Re: Error Respawn
 
Even better a macro:
PHP Code:

#define can_spawn(%0) !(( !is_user_connected((%0) && (cs_get_user_team((%0) == CS_TEAM_SPECTATOR || cs_get_user_team((%0) == CS_TEAM_UNASSIGNED || is_user_alive((%0)))) 


drekes 07-08-2010 12:45

Re: Error Respawn
 
Quote:

Originally Posted by ot_207 (Post 1232096)
Even better a macro:
PHP Code:

#define can_spawn(%0) !(( !is_user_connected((%0) && (cs_get_user_team((%0) == CS_TEAM_SPECTATOR || cs_get_user_team((%0) == CS_TEAM_UNASSIGNED || is_user_alive((%0)))) 


So macro's are better then stocks?

ConnorMcLeod 07-08-2010 13:05

Re: Error Respawn
 
Bello2, show the code where you call can_spawn, i guess you call it at a wrong place.
You shouldn't need to check if player is connected.

Bello2 07-08-2010 13:25

Re: Error Respawn
 
Quote:

Originally Posted by ot_207 (Post 1232096)
Even better a macro:
PHP Code:

#define can_spawn(%0) !(( !is_user_connected((%0) && (cs_get_user_team((%0) == CS_TEAM_SPECTATOR || cs_get_user_team((%0) == CS_TEAM_UNASSIGNED || is_user_alive((%0)))) 


This is the code:

PHP Code:

public plugin_init() 

    
register_plugin("respawn","1.0","Bello2")
    
register_event("DeathMsg","death","a"
    
register_cvar("dm_enabled","0")
    
register_cvar("dm_protection","1")
    
register_cvar("dm_protection_time","3")
}

public 
death() 

    if (
get_cvar_num("dm_enabled"))
    {
        new 
id read_data(2)
        
set_task(0.5,"revive",id)
    }
}

public 
revive(id)
{
    if (!
can_spawn(id)) return;
    
    
ExecuteHamBHam_CS_RoundRespawnid );
    
    if (
get_cvar_num("dm_protection"))
    {
        new 
Float:ProtectTime get_cvar_float("dm_protection_time")
        
        
set_user_godmodeid);
        
set_taskProtectTime "stopprotect"id );
    }
}

stock can_spawn(id)
{
   if( !
is_user_connected(id) && ( cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED || is_user_alive(id) ) )
      return 
false
    
   
return true
}

public 
stopprotect(id)
{
    if( 
is_user_aliveid ) )
        
set_user_godmodeid);


@Ot, as be the code applying your macro?

@Connor that is the code

ConnorMcLeod 07-08-2010 13:54

Re: Error Respawn
 
Ok, then you have to check if player is connected du to the delayed respawn.
Little optimization on code, so you use only 1 time the team :
PHP Code:

stock can_spawn(id)
{
    if(    
is_user_connected(id)
    &&    !
is_user_alive(id)
    &&    (
CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT)    )
    {
        return 
true
    
}
    return 
false


or

PHP Code:

stock can_spawn(id)
{
    return ( 
is_user_connected(id) && !is_user_alive(id) && (CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT) )


or

PHP Code:

#define can_respawn(%1)    ( is_user_connected(%0) && !is_user_alive(%0) && (CS_TEAM_T <= cs_get_user_team(%0) <= CS_TEAM_CT) ) 


Bello2 07-08-2010 14:03

Re: Error Respawn
 
Ok then with the macro be in this way:

PHP Code:

#define can_respawn(%1)    ( is_user_connected(%0) && !is_user_alive(%0) && (CS_TEAM_T <= cs_get_user_team(%0) <= CS_TEAM_CT) )  

public plugin_init() 

    
register_plugin("respawn","1.0","Bello2")
    
register_event("DeathMsg","death","a"
    
register_cvar("dm_enabled","0")
    
register_cvar("dm_protection","1")
    
register_cvar("dm_protection_time","3")
}

public 
death() 

    if (
get_cvar_num("dm_enabled"))
    {
        new 
id read_data(2)
        
set_task(0.5,"revive",id)
    }
}

public 
revive(id)
{
    if (!
can_respawn(id)) return;
    
    
ExecuteHamBHam_CS_RoundRespawnid );
    
    if (
get_cvar_num("dm_protection"))
    {
        new 
Float:ProtectTime get_cvar_float("dm_protection_time")
        
        
set_user_godmodeid);
        
set_taskProtectTime "stopprotect"id );
    }
}

public 
stopprotect(id)
{
    if( 
is_user_aliveid ) )
        
set_user_godmodeid);


Or this evil? What i want to know is how I can call the macro, because i do not have much experience with the macros...


All times are GMT -4. The time now is 07:16.

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