AlliedModders

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

mettyou 06-03-2010 06:05

Precaching models
 
how to precache models using cvar ? i have a config file myconfig.cfg and exec it to server in this file some cvars and model cvar but plugin doesn't work

myconfig.cfg
cvar_mymodel = "someModel"

amxx sample:
PHP Code:

public plugin_init() 
{
    
mymodel register_cvar("cvar_mymodel""someModel")
}

public 
plugin_cfg()
{
    static 
cfgdir[32]
    
get_configsdir(cfgdircharsmax(cfgdir))
    
server_cmd("exec %s/myconfig.cfg"cfgdir)
}


public 
plugin_precache()
{
    static 
modelname[128]
    new 
MODEL[20]
    
get_pcvar_string(mymodelMODELcharsmaxMODEL ));
    
    
formatex(modelname127"models/player/%s/%s.mdl"MODELMODEL)
    
engfunc(EngFunc_PrecacheModelmodelname)


this is true ? :grrr:

Kryzu 06-03-2010 15:42

Re: Precaching models
 
First of all:

PHP Code:

precache_model(yourdir); 


hleV 06-03-2010 15:54

Re: Precaching models
 
Quote:

Originally Posted by Kryzu (Post 1199062)
First of all:

PHP Code:

precache_model(yourdir); 


Why?

Kryzu 06-03-2010 16:00

Re: Precaching models
 
Don't have to include engine...

Kryzu 06-04-2010 04:52

Re: Precaching models
 
Not tested, should work

PHP Code:

#include <amxmodx>

new szModelDir[64];

public 
plugin_init() {
    
register_plugin("Model precache""0.1""Kryzu")
    
    new 
g_pModelDir register_cvar("cvar_mymodel""someModel")
    new 
szModel[12]; //I have no idea how much chars there can be

    
get_pcvar_string(g_pModelDirszModelcharsmax(szModel))
    
formatex(szModelDirsizeof(szModelDir) -1"models/%s/%s.mdl"szModelszModel);
}
public 
plugin_precache(){
    
precache_model(szModelDir);


Your cvar example:
cvar_mymodel "vip"

ConnorMcLeod 06-04-2010 06:48

Re: Precaching models
 
Even if fakemeta is already included for other reasons, use precache_model, precache_generic and precache_sound.
Optimization is trivially trivial for this specific example, but it's better to have good habits.
Read this : http://forums.alliedmods.net/showthread.php?t=88792

IMO cvars are not appropriated when precache is involved, because once precache is passed you can't do nothing anymore, so a .cfg or .ini file read during precache should be better.

mettyou 06-04-2010 14:31

Re: Precaching models
 
Quote:

Originally Posted by Kryzu (Post 1199420)
Not tested, should work

PHP Code:

#include <amxmodx>

new szModelDir[64];

public 
plugin_init() {
    
register_plugin("Model precache""0.1""Kryzu")
    
    new 
g_pModelDir register_cvar("cvar_mymodel""someModel")
    new 
szModel[12]; //I have no idea how much chars there can be

    
get_pcvar_string(g_pModelDirszModelcharsmax(szModel))
    
formatex(szModelDirsizeof(szModelDir) -1"models/%s/%s.mdl"szModelszModel);
}
public 
plugin_precache(){
    
precache_model(szModelDir);


Your cvar example:
cvar_mymodel "vip"


this is same with my and should not work. Compiler doesn't give an error but in the game models doesn't show on the players.

mettyou 06-04-2010 14:34

Re: Precaching models
 
Quote:

Originally Posted by ConnorMcLeod (Post 1199460)
Even if fakemeta is already included for other reasons, use precache_model, precache_generic and precache_sound.
Optimization is trivially trivial for this specific example, but it's better to have good habits.
Read this : http://forums.alliedmods.net/showthread.php?t=88792

IMO cvars are not appropriated when precache is involved, because once precache is passed you can't do nothing anymore, so a .cfg or .ini file read during precache should be better.


this is good idea. I will try ( read a file in precache ).

ConnorMcLeod 06-04-2010 16:58

Re: Precaching models
 
Anyway, the problem on your plugin is that plugin_precache is fired BEFORE plugin_init, so do all stuff in plugin_precache and it's fine.

Kryzu 06-05-2010 06:41

Re: Precaching models
 
Quote:

Originally Posted by mettyou (Post 1199707)
this is same with my and should not work. Compiler doesn't give an error but in the game models doesn't show on the players.

Well this plugin doesn't SET models. It only precaches them, as you asked...
Do like Connor said if not working...


All times are GMT -4. The time now is 05:17.

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