AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Spawn protection timer (https://forums.alliedmods.net/showthread.php?t=253330)

TrIxS 12-20-2014 06:21

Spawn protection timer
 
Hey! I want do spawn protection plugin, with normal timer. I want to get the colors to display green when there is 5sec from 3sec yellow and then red. Sorry my English knowledge is not good

Code:

if ( get_pcvar_num(pSPmsg) == 1 ) {
            new FTime = get_cvar_num("mp_freezetime")
        new Float:pSPtime = get_cvar_float("sp_time")
        new pSPsec = get_cvar_num("sp_time");
       
        if ( pSPsec >= 5 ) set_hudmessage( 0, 255, 0, -1.0, -1.0, 1, 1.0, pSPtime+FTime, 0.1, 0.1, 4 )
        else if ( pSPsec >= 3 ) set_hudmessage( 155, 155, 0, -1.0, -1.0, 1, 6.0, pSPtime+FTime, 0.4, 0.6, 4 );
        else set_hudmessage( 155, 0, 0, -1.0, -1.0, 1, 6.0, pSPtime+FTime, 0.4, 0.6, 4 );

        ShowSyncHudMsg( 0, g_msgsync, "Spawn Protection %d seconds left", pSPsec );
}

Full code
Code:

#include <amxmodx>
#include <hamsandwich>
#include <fun>
 
#define PLUGIN "Spawn Protection"
#define VERSION "1.2"
#define AUTHOR "Safety1st"
 
#define GLOW_THICK 10  // set glow shell thickness here from 1 to 100; comment to disable glow

new pSPtime, pSPmsg;
new g_msgsync;

public plugin_init() {
    register_plugin( PLUGIN, VERSION, AUTHOR )
 
    pSPtime = register_cvar( "sp_time", "5" )  // cvar for controlling protection time
    pSPmsg = register_cvar( "sp_message", "1") // cvar for controlling protection message show
   
    g_msgsync = CreateHudSyncObj();
 
    RegisterHam( Ham_Spawn, "player", "FwdSpawnPost", .Post = 1 )
}
 
#if defined GLOW_THICK
new giSPthick
 
public plugin_cfg() {
    giSPthick = clamp( GLOW_THICK, 1, 100 )
}
#endif
 
public FwdSpawnPost(id) {
    // check is needed because HamSpawn is called for spectators too
    if ( !is_user_alive(id) )
        return
 
    // enable protection
    set_user_godmode( id, .godmode = 1 )
   
    if ( get_pcvar_num(pSPmsg) == 1 ) {
            new FTime = get_cvar_num("mp_freezetime")
        new Float:pSPtime = get_cvar_float("sp_time")
        new pSPsec = get_cvar_num("sp_time");
       
        if ( pSPsec >= 5 ) set_hudmessage( 0, 255, 0, -1.0, -1.0, 1, 1.0, pSPtime+FTime, 0.1, 0.1, 4 )
        else if ( pSPsec >= 3 ) set_hudmessage( 155, 155, 0, -1.0, -1.0, 1, 6.0, pSPtime+FTime, 0.4, 0.6, 4 );
        else set_hudmessage( 155, 0, 0, -1.0, -1.0, 1, 6.0, pSPtime+FTime, 0.4, 0.6, 4 );

        ShowSyncHudMsg( 0, g_msgsync, "Spawn Protection %d seconds left", pSPsec );
    }
 
#if defined GLOW_THICK
    if ( giSPthick ) {
        switch ( get_user_team(id) ) {
            case 0  : {
                // game without teams, random color
                set_user_rendering( id, kRenderFxGlowShell, random(255), random(255), random(255), kRenderNormal, giSPthick )
            }
            case 1  : set_user_rendering( id, kRenderFxGlowShell, 255, 132, 0, kRenderNormal, giSPthick ) // orange
            default : set_user_rendering( id, kRenderFxGlowShell, 30, 182, 0, kRenderNormal, giSPthick /* blue */ )
        }
    }
#endif
 
    set_task( get_pcvar_float( pSPtime ), "DisableProtection", id )
}
 
public DisableProtection(id) {
    if ( !is_user_connected(id) )
        return
 
    set_user_godmode(id)    // disable godmode
 
#if defined GLOW_THICK
    if ( giSPthick )
        set_user_rendering( id, kRenderFxNone, 0, 0, 0, kRenderNormal, 0 )
#endif
}


akcaliberg 12-21-2014 12:24

Re: Spawn protection timer
 
You need to set a task to make a timer. For example:

PHP Code:

public StartTimer(param[1]) {
    
    if(!
param[0]) {
        
// Time's up
        
return PLUGIN_HANDLED
    
}
    
    
// Set hud message
    // Show hud message
    
    
param[0]--;
    
set_task(1.0,"StartTimer",_,param,sizeof(param));    


And if you want to start the timer you need to give it a start point.

PHP Code:

new param[1];
param[0] = get_cvar_num("mp_freezetime") + get_cvar_num("sp_time");
StartTimer(param); 



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

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