Raised This Month: $ Target: $400
 0% 

player model problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drumzplaya13
Senior Member
Join Date: Feb 2008
Location: TEXAS
Old 10-25-2009 , 05:48   player model problems
Reply With Quote #1

I didnt make this plugin, I do though find it useful and I AM using it on my server. There is a problem with it though and I was wondering if someone could help me out with it. The models precache fine, they run the first round. CT model work. Sometimes the CT skin gets on a T, also the T models go back to default once the round ends, instead of using the T player model I specified in it. Can someone help me with the problem, here is the code.


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/player1/player1.mdl");
    precache_model("models/player/player2/player2.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(id, currentmodel, charsmax(currentmodel));
            
            new terrmodel[32];
            
            if(equal(currentmodel, "terror")) {terrmodel = "player1";}
            else if(equal(currentmodel, "guerilla")) {terrmodel = "player1";}
            else if(equal(currentmodel, "leet")) {terrmodel = "player1";}
            else if(equal(currentmodel, "arctic")) {terrmodel = "player1";}
            else if(equal(currentmodel, "militia")) {terrmodel = "player1";}
            
            copy(g_player_model[id], charsmax(g_player_model[]), terrmodel);
            
            if(!equal(currentmodel, g_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[]), "player2");
            
            new currentmodel[32];
            fm_get_user_model(id, currentmodel, charsmax(currentmodel));
            
            if(!equal(currentmodel, g_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(id, currentmodel, charsmax(currentmodel));
    
    if(!equal(currentmodel, g_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_ClientUserInfoChanged, id, engfunc(EngFunc_GetInfoKeyBuffer, id));
    g_has_custom_model[id] = false;
}

stock fm_get_user_model(id, model[], len) {
    engfunc(EngFunc_InfoKeyValue, engfunc(EngFunc_GetInfoKeyBuffer, id), "model", model, len);
}

public fm_set_user_model(id) {
    id -= MODELSET_TASK;
    engfunc(EngFunc_SetClientKeyValue, id, engfunc(EngFunc_GetInfoKeyBuffer, id), "model", g_player_model[id]);
    g_has_custom_model[id] = true;
}
__________________
Think Positive - Stay Positive

Last edited by drumzplaya13; 10-25-2009 at 05:55.
drumzplaya13 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-25-2009 , 05:57   Re: player model problems
Reply With Quote #2

Try to use this method instead.
__________________
Arkshine is offline
drumzplaya13
Senior Member
Join Date: Feb 2008
Location: TEXAS
Old 10-26-2009 , 01:13   Re: player model problems
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
Try to use this method instead.
I used his plugin, it works but there is a problem. When someone switches from CT to T, they still have the CT models. I need it so if they get switched by the server to the opposite team, the newly found T will have the specified T model instead of the CT model.

Here is the .sma and here is my .ini file...

Code:
/*    Formatright © 2009, ConnorMcLeod

    Players Models 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.

    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 Players Models; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <cstrike>
#include <fakemeta>

#pragma semicolon 1

#define VERSION "1.2.1"

#define SetUserModeled(%1)        g_bModeled |= 1<<(%1 & 31)
#define SetUserNotModeled(%1)        g_bModeled &= ~( 1<<(%1 & 31) )
#define IsUserModeled(%1)        ( g_bModeled &  1<<(%1 & 31) )

#define SetUserConnected(%1)        g_bConnected |= 1<<(%1 & 31)
#define SetUserNotConnected(%1)        g_bConnected &= ~( 1<<(%1 & 31) )
#define IsUserConnected(%1)        ( g_bConnected &  1<<(%1 & 31) )

#define MAX_MODEL_LENGTH    16
#define MAX_AUTHID_LENGTH 25

#define MAX_PLAYERS    32

#define ClCorpse_ModelName 1
#define ClCorpse_PlayerID 12

#define g_ulModelIndexPlayer 491

new const g_szDefaultModels[][] = {"", "urban", "terror", "leet", "arctic", "gsg9", 
                    "gign", "sas", "guerilla", "vip", "militia", "spetsnaz" };

new const MODEL[] = "model";
new g_bModeled;
new g_szCurrentModel[MAX_PLAYERS+1][MAX_MODEL_LENGTH];

new Trie:g_tTeamModels[2];
new Trie:g_tModelIndexes;

new g_szNewModels[12][MAX_MODEL_LENGTH];

new g_szAuthid[MAX_PLAYERS+1][MAX_AUTHID_LENGTH];
new g_bPersonalModel[MAX_PLAYERS+1];

new g_bConnected;

public plugin_init()
{
    register_plugin("Players Models", VERSION, "ConnorMcLeod");

    register_forward(FM_SetClientKeyValue, "SetClientKeyValue");
    register_message(get_user_msgid("ClCorpse"), "Message_ClCorpse");
}

public plugin_precache()
{
    new szConfigFile[128];
    get_localinfo("amxx_configsdir", szConfigFile, charsmax(szConfigFile));
    format(szConfigFile, charsmax(szConfigFile), "%s/players_models.ini", szConfigFile);

    new iFile = fopen(szConfigFile, "rt");
    if( iFile )
    {
        new Trie:tDefaultModels = TrieCreate();
        for(new i=1; i<sizeof(g_szDefaultModels); i++)
        {
            TrieSetCell(tDefaultModels, g_szDefaultModels[i], i);
        }

        g_tModelIndexes = TrieCreate();

        g_tTeamModels[0] = TrieCreate();
        g_tTeamModels[1] = TrieCreate();

        new szDatas[70], szRest[40], szKey[MAX_AUTHID_LENGTH], szModel1[MAX_MODEL_LENGTH], szModel2[MAX_MODEL_LENGTH], iVal;
        while( !feof(iFile) )
        {
            fgets(iFile, szDatas, charsmax(szDatas));
            trim(szDatas);
            if(!szDatas[0] || szDatas[0] == ';' || szDatas[0] == '#' || (szDatas[0] == '/' && szDatas[1] == '/'))
            {
                continue;
            }

            strbreak(szDatas, szKey, charsmax(szKey), szRest, charsmax(szRest));

            if( TrieGetCell(tDefaultModels, szKey, iVal) )
            {
                parse(szRest, szModel1, charsmax(szModel1));
                if( szModel1[0] && PrecachePlayerModel(szModel1) )
                {
                    formatex(g_szNewModels[iVal], MAX_MODEL_LENGTH-1, szModel1);
                }
            }
            else if( equal(szKey, "STEAM_", 6) || equal(szKey, "BOT") )
            {
                parse(szRest, szModel1, charsmax(szModel1), szModel2, charsmax(szModel2));
                if( szModel1[0] && PrecachePlayerModel(szModel1) )
                {
                    TrieSetString(g_tTeamModels[1], szKey, szModel1);
                }
                if( szModel2[0] && PrecachePlayerModel(szModel2) )
                {
                    TrieSetString(g_tTeamModels[0], szKey, szModel2);
                }
            }
        }
        TrieDestroy(tDefaultModels);
        fclose( iFile );
    }
}

PrecachePlayerModel( const szModel[] )
{
    if( TrieKeyExists(g_tModelIndexes, szModel) )
    {
        return 1;
    }

    new szFileToPrecache[64];
    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%s.mdl", szModel, szModel);
    if( !file_exists( szFileToPrecache ) )
    {
        return 0;
    }

    TrieSetCell(g_tModelIndexes, szModel, precache_model(szFileToPrecache));

    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%st.mdl", szModel, szModel);
    if( file_exists( szFileToPrecache ) )
    {
        precache_model(szFileToPrecache);
        return 1;
    }
    formatex(szFileToPrecache, charsmax(szFileToPrecache), "models/player/%s/%sT.mdl", szModel, szModel);
    if( file_exists( szFileToPrecache ) )
    {
        precache_model(szFileToPrecache);
        return 1;
    }

    return 1;
}

public plugin_end()
{
    TrieDestroy(g_tTeamModels[0]);
    TrieDestroy(g_tTeamModels[1]);
    TrieDestroy(g_tModelIndexes);
}

public client_authorized( id )
{
    get_user_authid(id, g_szAuthid[id], MAX_AUTHID_LENGTH-1);

    for(new i=1; i<=2; i++)
    {
        if( TrieKeyExists(g_tTeamModels[2-i], g_szAuthid[id]) )
        {
            g_bPersonalModel[id] |= i;
        }
        else
        {
            g_bPersonalModel[id] &= ~i;
        }
    }
}

public client_putinserver(id)
{
    if( !is_user_hltv(id) )
    {
        SetUserConnected(id);
    }
}

public client_disconnect(id)
{
    g_bPersonalModel[id] = 0;
    SetUserNotModeled(id);
    SetUserNotConnected(id);
}

public SetClientKeyValue(id, const szInfoBuffer[], const szKey[], const szValue[])
{
    if( equal(szKey, MODEL) && IsUserConnected(id) )
    {
        new iInternalModel;
        new iTeam = _:cs_get_user_team(id, iInternalModel);
        if( 1 <= iTeam <= 2 )
        {
            new szSupposedModel[MAX_MODEL_LENGTH];

            if( g_bPersonalModel[id] & iTeam )
            {
                TrieGetString(g_tTeamModels[2-iTeam], g_szAuthid[id], szSupposedModel, charsmax(szSupposedModel));
            }
            else
            {
                formatex(szSupposedModel, charsmax(szSupposedModel), g_szNewModels[iInternalModel]);
            }

            if( szSupposedModel[0] )
            {
                if(    !IsUserModeled(id)
                ||    !equal(g_szCurrentModel[id], szSupposedModel)
                ||    !equal(szValue, szSupposedModel)    )
                {
                    formatex(g_szCurrentModel[id], MAX_MODEL_LENGTH-1, szSupposedModel);
                    SetUserModeled(id);
                    set_user_info(id, MODEL, szSupposedModel);
                    new iModelIndex;
                    TrieGetCell(g_tModelIndexes, szSupposedModel, iModelIndex);
                    set_pev(id, pev_modelindex, iModelIndex);
                    set_pdata_int(id, g_ulModelIndexPlayer, iModelIndex);
                    return FMRES_SUPERCEDE;
                }
            }

            if( IsUserModeled(id) )
            {
                SetUserNotModeled(id);
                g_szCurrentModel[id][0] = 0;
            }
        }
    }
    return FMRES_IGNORED;
}

public Message_ClCorpse()
{
    new id = get_msg_arg_int(ClCorpse_PlayerID);
    if( IsUserModeled(id) )
    {
        set_msg_arg_string(ClCorpse_ModelName, g_szCurrentModel[id]);
    }
}
.ini file:

Code:
; replace default skins
;"defaultname" "newname"

; set skin according to steamid
;"STEAM_0:1:23456789" "terrorist_model" "ct_model"
;"BOT" "bot_te_model" "bot_ct_model"

"terror" "Prisoner"
"guerilla" "Prisoner"
"arctic" "Prisoner"
"militia" "Prisoner"
"urban" "Guard"
"gign" "Guard"
"gsg9" "Guard"
"sas" "Guard"

"STEAM_0:0:xxx484xx" "Prisoner" "Admin"

"STEAM_0:1:x46xxx" "Prisoner" "Admin"

"STEAM_0:1:x460xx" "Prisoner" "Admin"

"STEAM_0:1:x93xxxxx" "Prisoner" "Admin"

"STEAM_0:0:xx992xxx" "Prisoner" "Admin"

"STEAM_0:1:xx951xx" "Prisoner" "Admin"

"STEAM_0:0:xx2xxxx" "Prisoner" "Admin"

"STEAM_0:1:xx12xxx" "Prisoner" "Admin"
Any suggestions?
__________________
Think Positive - Stay Positive

Last edited by drumzplaya13; 10-26-2009 at 01:16.
drumzplaya13 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-26-2009 , 02:15   Re: player model problems
Reply With Quote #4

Quote:
Originally Posted by drumzplaya13 View Post
Any suggestions?
Read the whole thread about the plugin would have driven you to that post : http://forums.alliedmods.net/showthr...434#post966434

Also, if you want support about that plugin, don't post anywhere but on the plugin thread.


Should be fixed in v1.3.0
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 11-03-2009 at 04:43.
ConnorMcLeod is offline
drumzplaya13
Senior Member
Join Date: Feb 2008
Location: TEXAS
Old 10-26-2009 , 02:39   Re: player model problems
Reply With Quote #5

Yes I know it leads me to that thread, Ive been using your plugin for 2 days now on my new server, and I was quoting him. Sorry, I will reply in your original plugin thread Conner. Usually when I do that for most plugins, no one seems to answer anymore but since I know your alive I will.
__________________
Think Positive - Stay Positive

Last edited by drumzplaya13; 10-26-2009 at 02:53.
drumzplaya13 is offline
drumzplaya13
Senior Member
Join Date: Feb 2008
Location: TEXAS
Old 10-25-2009 , 06:00   Re: player model problems
Reply With Quote #6

so with that plugin I guess I can set all default T and CT models to that plus give custom skins to other people. I will try and figure it out. Thank you for the suggestion.
__________________
Think Positive - Stay Positive
drumzplaya13 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 17:47.


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