AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Randomizing player models with correct hitboxes (https://forums.alliedmods.net/showthread.php?t=140968)

Mini_Midget 10-18-2010 08:00

Randomizing player models with correct hitboxes
 
I'm having problems trying to read from my .ini file and to set the correct model hitboxes or not.
So far it is reading from the file and precaching the correct files and setting it randomly on spawn.
But what I'm having problems with is setting it to either use the model hitboxes or the default CS hitboxes.
The reason why I'm doing this is because I have models that are not normal size (such as headcrabs) and some which are.

The .ini file looks like this.
Code:

;Put your list of custom models here and 0 or 1 after it to decide if the
;model should use the default CS model hitboxes or the custom model hitboxes

;The line below would load the model and use the custom_model_default hitboxes rather than the default CS ones
;custom_model_hitboxes 1

;The line below would low the custom model but use the default CS model hitboxes
;custom_model_default 0


;zombie_swarm 1
zombie_original 1
;dotd_classic 1
;dotd_torso 0
headcrab 1

PHP Code:

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

new const OFFSET_MODELINDEX 491
new const OFFSET_LINUX 5

#define TASKID_MODEL        3810


new model_name[256][256];
new 
model_index[256];
new 
model_index_bool[256];
new 
models_count;

new 
g_CurrentModel[33][32];
// new g_ModelIndex[sizeof g_ZombiePlayerModels];
new g_DefaultModelIndex;
new 
boolb_Model[33];


new 
Floatg_flCounter;

public 
plugin_init() 
{
    
register_plugin("PLUGIN""VERSION""AUTHOR")
    
RegisterHam(Ham_Spawn"player""bacon_Spawn_Post"1)
    
register_forward(FM_SetClientKeyValue,        "fw_SetClientKeyValue")
    
register_forward(FM_ClientUserInfoChanged,    "fw_ClientUserInfoChanged")
    
register_logevent("Round_End"    2,    "1=Round_End")

}

public 
plugin_precache()
{
    
precache_ParseINI;
    
    for(new 
models_count i++)
    {
        new 
ZombieModel[256]
        
format(ZombieModelcharsmax(ZombieModel), "models/player/%s/%s.mdl"model_name[i], model_name[i]);
        if(
file_exists(ZombieModel))
        {
            
model_index[i] = precache_model(ZombieModel);
            
log_amx("%s precached!!!"model_name[i]);
        }
        else
            
log_amx("%s does not exist!! Fail."model_name[i]);
            
    }
    
g_DefaultModelIndex precache_model("models/player.mdl");

}

public 
precache_ParseINI()
{
    static 
configs_dir[256], file_name[256], zswarm_dir[256];
    
    
get_configsdir(configs_dirsizeof configs_dir 1);
    
    
formatex(zswarm_dirsizeof zswarm_dir 1,"%s/Zombie_Swarm",configs_dir);
    
formatex(file_namesizeof file_name 1"%s/zswarm_models.ini",zswarm_dir);
        
    
    if(!
dir_exists(zswarm_dir))
        
mkdir(zswarm_dir);
    
    if(!
file_exists(file_name))
        
write_file(file_name,"");
    
    static 
iLineiLengthfile_text[256];
    
    static 
file_model_name[256];
    static 
file_model_index
    
    
static ZombieModel[256];
    static 
zombie_index_bool[256];
    while(
read_file(file_nameiLine++, file_textsizeof file_text 1iLength))
    {
        if((
file_text[0]== ';') || !iLength)
            continue;
        
        
//zombie_swarm 1
        
parse(file_textfile_model_namecharsmax(file_model_name), file_model_index1);
                                
        
ZombieModel file_model_name;
        
log_amx("Parse %s. Success!!!"ZombieModel);
        
zombie_index_bool[models_count] = file_model_index;
        
        
format(model_name[models_count], charsmax(model_name), "%s"ZombieModel);
        
format(model_index_bool[models_count], 1"%s"zombie_index_bool);
        
models_count++;
    }
}

public 
Round_End()     g_flCounter 0.0

public bacon_Spawn_Post(id)
{
    if (!
is_user_alive(id))
        return

    static 
CsTeamsteam team cs_get_user_team(id)
    new 
currentmodel[32];

    if (
team == CS_TEAM_CT// CT
    
{
        
copy(g_CurrentModel[id], charsmax(g_CurrentModel[]), model_name[random(models_count)]);

        
fm_get_user_model(idcurrentmodelcharsmax(currentmodel) );

        if(!
equal(currentmodelg_CurrentModel[id]) && !b_Model[id])
        {
            
set_task(0.5 g_flCounter"Task_Model"id TASKID_MODEL);
            
g_flCounter += 0.1;
        }
    }
}

public 
fw_SetClientKeyValue(idinfobufferkey[], value[])
{
    if (
b_Model[id] && equal(key"model"))
        return 
FMRES_SUPERCEDE

    
return FMRES_IGNORED
}

public 
fw_ClientUserInfoChanged(idinfobuffer)
{
    if (!
b_Model[id])
        return 
FMRES_IGNORED

    
new currentmodel[32];
    
fm_get_user_model(idcurrentmodelcharsmax(currentmodel) );

    if(!
equal(currentmodelg_CurrentModel[id]))
        
fm_set_user_model(idg_CurrentModel[id])

    return 
FMRES_IGNORED
}

public 
Task_Model(task)
{
    new 
id task TASKID_MODEL

    fm_set_user_model
(idg_CurrentModel[id])
    
client_print(idprint_chat"CHANGING MODEL");
}

stock fm_set_user_model(playermodelname[])
{
    
engfunc(EngFunc_SetClientKeyValueplayerengfunc(EngFunc_GetInfoKeyBufferplayer), "model"modelname)
    for(new 
sizeof model_name i++)
    {
        if(!
equal(modelnamemodel_name[i]))
            
set_pdata_int(playerOFFSET_MODELINDEXg_DefaultModelIndexOFFSET_LINUX)
        
        if(
model_index_bool[i])
        {
            
set_pdata_int(playerOFFSET_MODELINDEXmodel_index[i], OFFSET_LINUX)
        }
    }

    
b_Model[player] = true
}

stock fm_get_user_model(playermodel[], len)
{
    
engfunc(EngFunc_InfoKeyValueengfunc(EngFunc_GetInfoKeyBufferplayer), "model"modellen)



Mini_Midget 11-16-2010 02:53

Re: Randomizing player models with correct hitboxes
 
Bump

Emp` 11-16-2010 17:49

Re: Randomizing player models with correct hitboxes
 
file_model_index should be a string. The parse native separates a string into other strings based on spaces/quotations.

You should create file_model_index as a string:
Code:

    static file_model_index[2]
(Note that this is assuming that the second string will be "1" or "0", you might want to increase the string size just to be safe)

You then need to change how you save the "model index":
Code:

zombie_index_bool[models_count] = str_to_num(file_model_index);
Additionally, because precache_ParseINI is only called once, you should not be creating static variables within the function. This should only be done when the function is called many times.


All times are GMT -4. The time now is 10:16.

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