Raised This Month: $ Target: $400
 0% 

attach sprite


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sn3amtz
Senior Member
Join Date: Jan 2015
Location: France
Old 12-20-2015 , 10:19   attach sprite
Reply With Quote #1

I want to attach a sprite when is player idle enable sprite and disable when is active



Code:
#include <amxmodx> 
#include <fun> 

#define MIN_AFK_TIME 30        // I use this incase stupid admins accidentally set mp_afktime to something silly. 
#define WARNING_TIME 15        // Start warning the user this many seconds before they are about to be kicked. 
#define CHECK_FREQ 5        // This is also the warning message frequency. 

new g_oldangles[33][3] 
new g_afktime[33] 
new bool:g_spawned[33] = {true, ...} 

public plugin_init() { 
    register_plugin("AFK Kicker","1.0b","Cheesy Peteza")  
    register_cvar("afk_version", "1.0b", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) 

    register_cvar("mp_afktime", "90")    // Kick people AFK longer than this time 
    register_cvar("mp_afkminplayers", "8")    // Only kick AFKs when there is atleast this many players on the server 
    set_task(float(CHECK_FREQ),"checkPlayers",_,_,_,"b") 
    register_event("ResetHUD", "playerSpawned", "be") 
} 

public checkPlayers() { 
    for (new i = 1; i <= get_maxplayers(); i++) { 
        if (is_user_alive(i) && is_user_connected(i) && !is_user_bot(i) && !is_user_hltv(i) && g_spawned[i]) { 
            new newangle[3] 
            get_user_origin(i, newangle) 

            if ( newangle[0] == g_oldangles[i][0] && newangle[1] == g_oldangles[i][1] && newangle[2] == g_oldangles[i][2] ) { 
                g_afktime[i] += CHECK_FREQ 
                check_afktime(i) 
            } else { 
                g_oldangles[i][0] = newangle[0] 
                g_oldangles[i][1] = newangle[1] 
                g_oldangles[i][2] = newangle[2] 
                g_afktime[i] = 0 
            } 
        } 
    } 
    return PLUGIN_HANDLED 
} 

check_afktime(id) { 
    new numplayers = get_playersnum() 
    new minplayers = get_cvar_num("mp_afkminplayers") 
                     
    if (numplayers >= minplayers) { 
        new maxafktime = get_cvar_num("mp_afktime") 
        if (maxafktime < MIN_AFK_TIME) { 
            log_amx("cvar mp_afktime %i is too low. Minimum value is %i.", maxafktime, MIN_AFK_TIME) 
            maxafktime = MIN_AFK_TIME 
            set_cvar_num("mp_afktime", MIN_AFK_TIME) 
        } 

        if ( maxafktime-WARNING_TIME <= g_afktime[id] < maxafktime) { 
            new timeleft = maxafktime - g_afktime[id] 
            client_print(id, print_chat, "[AFK Kicker] You have %i seconds to move or you get godmode for being AFK", timeleft) 
        } else if (g_afktime[id] > maxafktime) { 
            new name[32] 
                 get_user_name(id, name, 31) 
                 client_print(0, print_chat, "[AFK Kicker] %s is in godmode state for being AFK longer than %i seconds", name, maxafktime) 
                           set_user_godmode(id, 1) 
                 
        } 
    } 
} 

public client_connect(id) { 
    g_afktime[id] = 0 
    return PLUGIN_HANDLED 
} 

public client_putinserver(id) { 
    g_afktime[id] = 0 
    return PLUGIN_HANDLED 
} 

public playerSpawned(id) { 
    g_spawned[id] = false 
    new sid[1] 
    sid[0] = id 
    set_task(0.75, "delayedSpawn",_, sid, 1)    // Give the player time to drop to the floor when spawning 
    return PLUGIN_HANDLED 
} 

public delayedSpawn(sid[]) { 
    get_user_origin(sid[0], g_oldangles[sid[0]]) 
    g_spawned[sid[0]] = true 
    return PLUGIN_HANDLED 
}

Last edited by Sn3amtz; 12-22-2015 at 06:35.
Sn3amtz is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 12-20-2015 , 22:10   Re: AFK attach sprite
Reply With Quote #2

Code:
/** AMX Mod X Script  *  *  Copyright © UNKNOW_YEAR Cheesy Peteza,  *                        UNKNOW_YEAR Others Authors,  *                        2015 Addons zz  *  *  This program is free software; you can redistribute it and/or modify it  *  under the terms of the GNU General Public License as published by the  *  Free Software Foundation; either version 2 of the License, or ( at  *  your option ) any later version.  *  *  This program is distributed in the hope that it will be useful, but  *  WITHOUT ANY WARRANTY; without even the implied warranty of  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  *  See the GNU General Public License for more details.  *  *  You should have received a copy of the GNU General Public License  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *  * *********************************************************** Change Log 2015-12-21 | v1.1 - Addons zz  * Added support to attach a sprite when is player AFK and disable when is active.  * Fixed infinity godmod after being AFK.  */ #include <amxmodx> #include <fun> #define VERSION "1.1" #define MIN_AFK_TIME    30 /* I use this incase stupid admins accidentally set mp_afktime to something silly. */ #define WARNING_TIME    15 /* Start warning the user this many seconds before they are about to be kicked. */ #define CHECK_FREQ  5 /* This is also the warning message frequency. */ new g_afktime[33]; new g_was_afk[33]; new g_oldangles[33][3]; new bool:g_spawned[33] = { true, ... }; new g_spirte_id; public plugin_init() {     register_plugin( "AFK Kicker", VERSION, "Cheesy Peteza" );     register_cvar( "afk_version", VERSION, FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_SPONLY );     register_cvar( "mp_afktime", "90" ); /* Kick people AFK longer than this time */     register_cvar( "mp_afkminplayers", "8" ); /* Only kick AFKs when there is atleast this many players on the server */     set_task( float( CHECK_FREQ ), "checkPlayers", _, _, _, "b" );     register_event( "ResetHUD", "playerSpawned", "be" ); } public checkPlayers() {     for ( new id = 1; id <= get_maxplayers(); id++ )     {         if ( is_user_alive( id ) && is_user_connected( id ) && !is_user_bot( id ) && !is_user_hltv( id ) && g_spawned[id] )         {             new newangle[3];             get_user_origin( id, newangle );             if ( newangle[0] == g_oldangles[id][0] && newangle[1] == g_oldangles[id][1] && newangle[2] == g_oldangles[id][2] )             {                 g_afktime[id] += CHECK_FREQ;                 check_afktime( id );             }             else             {                 g_oldangles[id][0]  = newangle[0];                 g_oldangles[id][1]  = newangle[1];                 g_oldangles[id][2]  = newangle[2];                 g_afktime[id]       = 0;                 if ( g_was_afk[id] )                 {                     new name[32];                     get_user_name( id, name, 31 );                     set_user_godmode( id );                     remove_sprite( id );                     g_was_afk[id] = 0;                     client_print( 0, print_chat, "[AFK Kicker] %s is NOT in godmode state for STOP being AFK.", name );                 }             }         }     }     return(PLUGIN_HANDLED); } check_afktime( id ) {     new numplayers  = get_playersnum();     new minplayers  = get_cvar_num( "mp_afkminplayers" );     if ( numplayers >= minplayers )     {         new maxafktime = get_cvar_num( "mp_afktime" );         if ( maxafktime < MIN_AFK_TIME )         {             log_amx( "cvar mp_afktime %i is too low. Minimum value is %i.", maxafktime, MIN_AFK_TIME );             maxafktime = MIN_AFK_TIME;             set_cvar_num( "mp_afktime", MIN_AFK_TIME );         }         if ( maxafktime - WARNING_TIME <= g_afktime[id] < maxafktime )         {             new timeleft = maxafktime - g_afktime[id];             client_print( id, print_chat, "[AFK Kicker] You have %i seconds to move or you get godmode for being AFK", timeleft );         }         else if ( g_afktime[id] > maxafktime )         {             if ( !g_was_afk[id] )             {                 new name[32];                 get_user_name( id, name, 31 );                 client_print( 0, print_chat, "[AFK Kicker] %s is in godmode state for being AFK longer than %i seconds", name, maxafktime );                 set_user_godmode( id, 1 );                 attach_sprite( id );                 g_was_afk[id] = 1;             }         }     } } public plugin_precache() {     g_spirte_id = precache_model( "sprites/afk_sprite.spr" ); } stock remove_sprite( user_id ) {     if ( !is_user_connected( user_id ) )     {         return;     }     message_begin( MSG_ALL, SVC_TEMPENTITY );     write_byte( TE_KILLPLAYERATTACHMENTS );     write_byte( user_id );     message_end(); } stock attach_sprite( user_id ) {     if ( !is_user_connected( user_id ) )     {         return;     }     message_begin( MSG_ALL, SVC_TEMPENTITY );     write_byte( TE_PLAYERATTACHMENT );     write_byte( user_id );     write_coord( 60 );     write_short( g_spirte_id );     write_short( 9000 );     message_end(); } public client_connect( id ) {     g_afktime[id] = 0;     return(PLUGIN_HANDLED); } public client_putinserver( id ) {     g_afktime[id] = 0;     return(PLUGIN_HANDLED); } public playerSpawned( id ) {     g_spawned[id] = false;     new sid[1];     sid[0] = id;     set_task( 0.75, "delayedSpawn", _, sid, 1 ); /* Give the player time to drop to the floor when spawning */     return(PLUGIN_HANDLED); } public delayedSpawn( sid[] ) {     get_user_origin( sid[0], g_oldangles[sid[0]] );     g_spawned[sid[0]] = true;     return(PLUGIN_HANDLED); }
Attached Files
File Type: zip sprites.zip (708 Bytes, 42 views)
File Type: sma Get Plugin or Get Source (afk_kicker.sma - 529 views - 5.1 KB)

Last edited by addons_zz; 12-21-2015 at 14:55.
addons_zz is offline
Sn3amtz
Senior Member
Join Date: Jan 2015
Location: France
Old 12-22-2015 , 09:27   Re: attach sprite
Reply With Quote #3

Thank you ! And how remove sprite after client dicsconnects?

Last edited by Sn3amtz; 12-22-2015 at 09:28.
Sn3amtz is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:11.


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