Raised This Month: $ Target: $400
 0% 

[SOLVED]Model Change


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
DoviuX
Senior Member
Join Date: Jun 2009
Location: Lithuania
Old 08-13-2009 , 06:52   [SOLVED]Model Change
Reply With Quote #1

Changes Admin Model In CT's

Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>

new const ADMIN_MODEL[] = "UmbrellaAdmin" // The model we're gonna use for admins
#define MODELSET_TASK 100 // an offset for our models task
#define MODELCHANGE_DELAY 0.1 // delay between model changes
new Float:g_models_targettime // target time for the last model change
new Float:g_roundstarttime // last round start time

new g_has_custom_model[33] // whether the player is using a custom model
new g_player_model[33][32] // player's model name (string)
new g_admin[33] // whether the player is a admin

/*================================================================================
 [Plugin Start]
=================================================================================*/

public plugin_precache()
{
    new modelpath[100]
    formatex( modelpath, charsmax( modelpath ), "models/player/%s/%s.mdl", ADMIN_MODEL, ADMIN_MODEL )
    engfunc( EngFunc_PrecacheModel, modelpath )
}

public plugin_init()
{
    register_plugin( "AdminModel", "0.3", "DoviuX" )
    
    register_event( "HLTV", "event_round_start", "a", "1=0", "2=0" )
    RegisterHam( Ham_Spawn, "player", "fw_PlayerSpawn", 1 )
    
    register_forward( FM_SetClientKeyValue, "fw_SetClientKeyValue" )
    register_forward( FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged" )
}

/*================================================================================
 [Round Start Event]
=================================================================================*/

public event_round_start()
{
    g_roundstarttime = get_gametime()
}

/*================================================================================
 [Player Spawn Event]
=================================================================================*/

public fw_PlayerSpawn( id )
{
    // Not alive or didn't join a team yet
    if ( !is_user_alive( id ) || !cs_get_user_team( id ) )
        return;
    
    // Set to admin if on Counter-Terrorist Team
    if (get_user_flags(id) & ADMIN_LEVEL_A)
    g_admin[id] = cs_get_user_team( id ) == CS_TEAM_CT ? true : false;
    
    // Remove previous tasks (if any)
    remove_task( id + MODELSET_TASK )
    
    // Check whether the player is a admin
    if ( g_admin[id] )
    {
        // Store our custom model in g_player_model[id]
        copy( g_player_model[id], charsmax( g_player_model[] ), ADMIN_MODEL )
        
        // Get current model
        new currentmodel[32]
        fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
        
        // Check whether it matches the custom model
        if ( !equal( currentmodel, g_player_model[id] ) )
        {
            // An additional delay is offset at round start
            // since SVC_BAD is more likely to be triggered there
            if ( get_gametime() - g_roundstarttime < 5.0 )
                set_task( 5.0 * MODELCHANGE_DELAY, "fm_user_model_update", id + MODELSET_TASK )
            else
                fm_user_model_update( id + MODELSET_TASK )
        }
    }
    // Not a admin, but still has a custom model
    else if ( g_has_custom_model[id] )
    {
        // Reset it back to the default one
        fm_reset_user_model( id )
    }
}

/*================================================================================
 [Forwards]
=================================================================================*/

public fw_SetClientKeyValue( id, const infobuffer[], const key[] )
{   
    // Block CS model changes
    if ( g_has_custom_model[id] && equal( key, "model" ) )
        return FMRES_SUPERCEDE;
    
    return FMRES_IGNORED;
}

public fw_ClientUserInfoChanged( id )
{
    // Player doesn't have a custom model
    if ( !g_has_custom_model[id] )
        return FMRES_IGNORED;
    
    // Get current model
    static currentmodel[32]
    fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
    
    // Check whether it matches the custom model - if not, set it again
    if ( !equal( currentmodel, g_player_model[id] ) && !task_exists( id + MODELSET_TASK ) )
        fm_set_user_model( id + MODELSET_TASK )
    
    return FMRES_IGNORED;
}

/*================================================================================
 [Tasks]
=================================================================================*/

public fm_user_model_update( taskid )
{
    static Float:current_time
    current_time = get_gametime()
    
    // Do we need a delay?
    if ( current_time - g_models_targettime >= MODELCHANGE_DELAY )
    {
        fm_set_user_model( taskid )
        g_models_targettime = current_time
    }
    else
    {
        set_task( (g_models_targettime + MODELCHANGE_DELAY) - current_time, "fm_set_user_model", taskid )
        g_models_targettime = g_models_targettime + MODELCHANGE_DELAY
    }
}

public fm_set_user_model( player )
{
    // Get actual player id
    player -= MODELSET_TASK
    
    // Set new model
    engfunc( EngFunc_SetClientKeyValue, player, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", g_player_model[player] )
    
    // Remember this player has a custom model
    g_has_custom_model[player] = true
}

/*================================================================================
 [Stocks]
=================================================================================*/

stock fm_get_user_model( player, model[], len )
{
    // Retrieve current model
    engfunc( EngFunc_InfoKeyValue, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", model, len )
}

stock fm_reset_user_model( player )
{
    // Player doesn't have a custom model any longer
    g_has_custom_model[player] = false
    
    dllfunc( DLLFunc_ClientUserInfoChanged, player, engfunc( EngFunc_GetInfoKeyBuffer, player ) )
}
Changes All Normal Player Ct's skin To all:

Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>

new const HUMAN_MODEL[] = "Umbrella" // The model we're gonna use for Humans
#define MODELSET_TASK 100 // an offset for our models task
#define MODELCHANGE_DELAY 0.1 // delay between model changes
new Float:g_models_targettime // target time for the last model change
new Float:g_roundstarttime // last round start time

new g_has_custom_model[33] // whether the player is using a custom model
new g_player_model[33][32] // player's model name (string)
new g_human[33] // whether the player is a human

/*================================================================================
 [Plugin Start]
=================================================================================*/

public plugin_precache()
{
    new modelpath[100]
    formatex( modelpath, charsmax( modelpath ), "models/player/%s/%s.mdl", HUMAN_MODEL, HUMAN_MODEL )
    engfunc( EngFunc_PrecacheModel, modelpath )
}

public plugin_init()
{
    register_plugin( "Human Models", "0.3", "DoviuX" )
    
    register_event( "HLTV", "event_round_start", "a", "1=0", "2=0" )
    RegisterHam( Ham_Spawn, "player", "fw_PlayerSpawn", 1 )
    
    register_forward( FM_SetClientKeyValue, "fw_SetClientKeyValue" )
    register_forward( FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged" )
}

/*================================================================================
 [Round Start Event]
=================================================================================*/

public event_round_start()
{
    g_roundstarttime = get_gametime()
}

/*================================================================================
 [Player Spawn Event]
=================================================================================*/

public fw_PlayerSpawn( id )
{
    // Not alive or didn't join a team yet
    if ( !is_user_alive( id ) || !cs_get_user_team( id ) )
        return;
    
    // Set to zombie if on Terrorist team
    if (get_user_flags(id) & ADMIN_USER)
    g_human[id] = cs_get_user_team( id ) == CS_TEAM_CT ? true : false;
    
    // Remove previous tasks (if any)
    remove_task( id + MODELSET_TASK )
    
    // Check whether the player is a human
    if ( g_human[id] )
    {
        // Store our custom model in g_player_model[id]
        copy( g_player_model[id], charsmax( g_player_model[] ), HUMAN_MODEL )
        
        // Get current model
        new currentmodel[32]
        fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
        
        // Check whether it matches the custom model
        if ( !equal( currentmodel, g_player_model[id] ) )
        {
            // An additional delay is offset at round start
            // since SVC_BAD is more likely to be triggered there
            if ( get_gametime() - g_roundstarttime < 5.0 )
                set_task( 5.0 * MODELCHANGE_DELAY, "fm_user_model_update", id + MODELSET_TASK )
            else
                fm_user_model_update( id + MODELSET_TASK )
        }
    }
    // Not a human, but still has a custom model
    else if ( g_has_custom_model[id] )
    {
        // Reset it back to the default one
        fm_reset_user_model( id )
    }
}

/*================================================================================
 [Forwards]
=================================================================================*/

public fw_SetClientKeyValue( id, const infobuffer[], const key[] )
{   
    // Block CS model changes
    if ( g_has_custom_model[id] && equal( key, "model" ) )
        return FMRES_SUPERCEDE;
    
    return FMRES_IGNORED;
}

public fw_ClientUserInfoChanged( id )
{
    // Player doesn't have a custom model
    if ( !g_has_custom_model[id] )
        return FMRES_IGNORED;
    
    // Get current model
    static currentmodel[32]
    fm_get_user_model( id, currentmodel, charsmax( currentmodel ) )
    
    // Check whether it matches the custom model - if not, set it again
    if ( !equal( currentmodel, g_player_model[id] ) && !task_exists( id + MODELSET_TASK ) )
        fm_set_user_model( id + MODELSET_TASK )
    
    return FMRES_IGNORED;
}

/*================================================================================
 [Tasks]
=================================================================================*/

public fm_user_model_update( taskid )
{
    static Float:current_time
    current_time = get_gametime()
    
    // Do we need a delay?
    if ( current_time - g_models_targettime >= MODELCHANGE_DELAY )
    {
        fm_set_user_model( taskid )
        g_models_targettime = current_time
    }
    else
    {
        set_task( (g_models_targettime + MODELCHANGE_DELAY) - current_time, "fm_set_user_model", taskid )
        g_models_targettime = g_models_targettime + MODELCHANGE_DELAY
    }
}

public fm_set_user_model( player )
{
    // Get actual player id
    player -= MODELSET_TASK
    
    // Set new model
    engfunc( EngFunc_SetClientKeyValue, player, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", g_player_model[player] )
    
    // Remember this player has a custom model
    g_has_custom_model[player] = true
}

/*================================================================================
 [Stocks]
=================================================================================*/

stock fm_get_user_model( player, model[], len )
{
    // Retrieve current model
    engfunc( EngFunc_InfoKeyValue, engfunc( EngFunc_GetInfoKeyBuffer, player ), "model", model, len )
}

stock fm_reset_user_model( player )
{
    // Player doesn't have a custom model any longer
    g_has_custom_model[player] = false
    
    dllfunc( DLLFunc_ClientUserInfoChanged, player, engfunc( EngFunc_GetInfoKeyBuffer, player ) )
}

Last edited by DoviuX; 08-13-2009 at 08:27.
DoviuX is offline
Send a message via Skype™ to DoviuX
 


Thread Tools
Display Modes

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 15:09.


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