AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Setting player models (https://forums.alliedmods.net/showthread.php?t=106085)

VMAN 10-11-2009 14:07

Setting player models
 
Can someone please take a look at this and tell my why nothing happens?

I have the folders in the correct places. Tried it with bots on listen server and no effect. No errors in console either. No compile warnings, loads fine.

I'm going crazy trying to figure out why it's not working.

It is supposed to give all the CT's one model, and all the T's models depending on which class they chose. (each class is set to one model for testing purposes)

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>


public plugin_init() {
    
register_plugin("Player Models""1.0""vman");
    
    
register_event("HLTV""evRoundStart""a""1=0""2=0");
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1);
    
register_forward(FM_SetClientKeyValue"fwSetClientKeyValue");
    
register_forward(FM_ClientUserInfoChanged"fwClientUserInfoChanged");
}

public 
plugin_precache() {
    
precache_model("models/player/vcmdl_ctcz-1/vcmdl_ctcz-1.mdl");
    
precache_model("models/player/vcmdl_tcz-1/vcmdl_tcz-1.mdl");
}

#define MODELSET_TASK 100

new Float:g_roundstarttime;
new 
Float:g_models_targettime;

new 
bool:g_has_custom_model[33];
new 
g_player_model[33][32];

public 
client_putinserver(id) {
    
g_has_custom_model[id] = false;
}

public 
evRoundStart() {
    
g_roundstarttime get_gametime();
}

public 
fwHamPlayerSpawnPost(id) {
    if(
is_user_alive(id)) {
        if(
get_user_team(id) == 1) {
            if(
task_exists(id MODELSET_TASK)) {
                
remove_task(id MODELSET_TASK);
            }
            
            
//fm_reset_user_model(id);
            
            
new currentmodel[32];
            
fm_get_user_model(idcurrentmodelcharsmax(currentmodel));
            
            new 
terrmodel[32];
            
            if(
equal(currentmodel"terror")) {terrmodel "vcmdl_tcz-1";}
            else if(
equal(currentmodel"guerilla")) {terrmodel "vcmdl_tcz-1";}
            else if(
equal(currentmodel"leet")) {terrmodel "vcmdl_tcz-1";}
            else if(
equal(currentmodel"arctic")) {terrmodel "vcmdl_tcz-1";}
            else if(
equal(currentmodel"militia")) {terrmodel "vcmdl_tcz-1";}
            
            
copy(g_player_model[id], charsmax(g_player_model[]), terrmodel);
            
            if(!
equal(currentmodelg_player_model[id])) {
                if(
get_gametime() - g_roundstarttime 5.0) {
                    
set_task(2.5"fm_update_user_model"id MODELSET_TASK);
                }
                
                else {
                    
fm_update_user_model(id MODELSET_TASK);
                }
            }
        }
        
        else if(
get_user_team(id) == 2) {
            if(
task_exists(id MODELSET_TASK)) {
                
remove_task(id MODELSET_TASK);
            }
            
            
//fm_reset_user_model(id);
            
            
copy(g_player_model[id], charsmax(g_player_model[]), "vcmdl_ctcz-1");
            
            new 
currentmodel[32];
            
fm_get_user_model(idcurrentmodelcharsmax(currentmodel));
            
            if(!
equal(currentmodelg_player_model[id])) {
                if(
get_gametime() - g_roundstarttime 5.0) {
                    
set_task(2.5"fm_update_user_model"id MODELSET_TASK);
                }
                
                else {
                    
fm_update_user_model(id MODELSET_TASK);
                }
            }
        }
    }
}

public 
fwSetClientKeyValue(id, const infobuffer[], const key[]) {
    if(
g_has_custom_model[id] && equal(key"model")) {
        return 
FMRES_SUPERCEDE;
    }
    
    return 
FMRES_IGNORED;
}

public 
fwClientUserInfoChanged(id) {
    if(!
g_has_custom_model[id]) {
        return 
FMRES_IGNORED;
    }
    
    new 
currentmodel[32];
    
fm_get_user_model(idcurrentmodelcharsmax(currentmodel));
    
    if(!
equal(currentmodelg_player_model[id]) && !task_exists(id MODELSET_TASK)) {
        
fm_set_user_model(id MODELSET_TASK);
    }
    
    return 
FMRES_IGNORED;
}

public 
fm_update_user_model(taskid) {
    new 
Float:current_time;
    
current_time get_gametime();
    
    if(
current_time g_models_targettime >= 0.5) {
        
fm_set_user_model(taskid);
        
g_models_targettime current_time;
    }
    
    else {
        
set_task((g_models_targettime 0.5) - current_time"fm_set_user_model"taskid);
        
g_models_targettime g_models_targettime 0.5;
    }
}

stock fm_reset_user_model(id) {
    
dllfunc(DLLFunc_ClientUserInfoChangedidengfunc(EngFunc_GetInfoKeyBufferid));
    
g_has_custom_model[id] = false;
}

stock fm_get_user_model(idmodel[], len) {
    
engfunc(EngFunc_InfoKeyValueengfunc(EngFunc_GetInfoKeyBufferid), "model"modellen);
}

public 
fm_set_user_model(id) {
    
id -= MODELSET_TASK;
    
engfunc(EngFunc_SetClientKeyValueidengfunc(EngFunc_GetInfoKeyBufferid), "model"g_player_model[id]);
    
g_has_custom_model[id] = true;


This is based on this tutorial

shuttle_wave 10-23-2009 22:45

Re: Setting player models
 
I want plugin that just replace players model eg. Replace all ct with a guard model and replace all t with Prisoner model. Like that?? If u want pm me and ill make u one

xbatista 10-24-2009 02:30

Re: Setting player models
 
Just remove 'if get_user_team and if task exists( MODELSET_TASK) on the top', just remove task without any checks, put on the top of Player_Spawn.
Btw ,you didn't used the code correctly like in his code.

VMAN 10-24-2009 02:39

Re: Setting player models
 
shuttle, gtfo my thread

drumzplaya13 10-24-2009 04:05

Re: Setting player models
 
LOL at VMAN telling shuffle off. :D

I would try what xbatista said. if it works, I am going to use this plugin if you dont mind because I have been looking for something like this for a while.


All times are GMT -4. The time now is 22:41.

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