Raised This Month: $ Target: $400
 0% 

Precaching models


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mettyou
Junior Member
Join Date: Apr 2008
Old 06-03-2010 , 06:05   Precaching models
Reply With Quote #1

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 ?
mettyou is offline
Kryzu
Senior Member
Join Date: Feb 2009
Old 06-03-2010 , 15:42   Re: Precaching models
Reply With Quote #2

First of all:

PHP Code:
precache_model(yourdir); 
__________________
Kryzu is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-03-2010 , 15:54   Re: Precaching models
Reply With Quote #3

Quote:
Originally Posted by Kryzu View Post
First of all:

PHP Code:
precache_model(yourdir); 
Why?
__________________
hleV is offline
Kryzu
Senior Member
Join Date: Feb 2009
Old 06-03-2010 , 16:00   Re: Precaching models
Reply With Quote #4

Don't have to include engine...
__________________
Kryzu is offline
Kryzu
Senior Member
Join Date: Feb 2009
Old 06-04-2010 , 04:52   Re: Precaching models
Reply With Quote #5

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"
__________________

Last edited by Kryzu; 06-04-2010 at 04:54.
Kryzu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-04-2010 , 06:48   Re: Precaching models
Reply With Quote #6

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.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-04-2010 at 06:51.
ConnorMcLeod is offline
mettyou
Junior Member
Join Date: Apr 2008
Old 06-04-2010 , 14:34   Re: Precaching models
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
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 ).
mettyou is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-04-2010 , 16:58   Re: Precaching models
Reply With Quote #8

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
mettyou
Junior Member
Join Date: Apr 2008
Old 06-04-2010 , 14:31   Re: Precaching models
Reply With Quote #9

Quote:
Originally Posted by Kryzu View Post
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 is offline
Kryzu
Senior Member
Join Date: Feb 2009
Old 06-05-2010 , 06:41   Re: Precaching models
Reply With Quote #10

Quote:
Originally Posted by mettyou View Post
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...
__________________
Kryzu 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 05:17.


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