Raised This Month: $128 Target: $400
 32% 

Efficient way of precaching models and sounds?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
Old 02-21-2021 , 15:41   Efficient way of precaching models and sounds?
Reply With Quote #1

Hello, what's the best way to precache this models and sounds.

Code example:
PHP Code:
headshot precache_model("sprites/headshot.spr")
        
knife_kill precache_model("sprites/knife_kill.spr")
        
grenade_kill precache_model("sprites/grenade_kill.spr")
        
one_kill precache_model("sprites/1_kill.spr")
        
two_kill precache_model("sprites/2_kill.spr")
        
three_kill precache_model("sprites/3_kill.spr")
        
four_kill precache_model("sprites/4_kill.spr")
        
five_kill precache_model("sprites/5_kill.spr")
        
six_kill precache_model("sprites/6_kill.spr")
        
seven_kill precache_model("sprites/7_kill.spr")
        
eight_kill precache_model("sprites/8_kill.spr")
        
more_than_eight_kill precache_model("sprites/more_than_8_kill.spr")
        
normal_kill precache_model("sprites/normal_kill.spr")
    
precache_sound("misc/headshot.wav")
        
precache_sound("misc/knife_kill.wav")
        
precache_sound("misc/grenade_kill.wav")
        
precache_sound("misc/wallshot.wav")
        
precache_sound("misc/1_kill.wav")
        
precache_sound("misc/2_kill.wav")
        
precache_sound("misc/3_kill.wav")
        
precache_sound("misc/4_kill.wav")
        
precache_sound("misc/5_kill.wav")
        
precache_sound("misc/6_kill.wav")
        
precache_sound("misc/7_kill.wav")
        
precache_sound("misc/8_kill.wav")
        
precache_sound("misc/firstblood.wav")
        
precache_sound("misc/last_kill.wav")
        
precache_sound("misc/unstoppable.wav"
__________________
My Steam:


Last edited by nG_getwreck; 02-21-2021 at 15:41.
nG_getwreck is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-21-2021 , 16:47   Re: Efficient way of precaching models and sounds?
Reply With Quote #2

That's perfectly fine. What are you trying to optimize? Why do you think this is inefficient?
__________________
HamletEagle is offline
lexzor
Senior Member
Join Date: Nov 2020
Old 02-21-2021 , 16:50   Re: Efficient way of precaching models and sounds?
Reply With Quote #3

PHP Code:
new playerskins[][] = 
{
    
"sias",
    
"fbi",
    
"swat_bombson",
    
"st6_blueberries",
    
"isis",
    
"alqaeda",
    
"pro_loudmouth",
    
"pro_miamy"
}

public 
plugin_precache()
{
    static 
playermodels[256]
    
    for (new 
0sizeof(playerskins); i++)
    {    
        
formatex(playermodelscharsmax(playermodels), "models/player/%s/%s.mdl"playerskins[i], playerskins[i])    
        
precache_model(playermodels)    
    } 
    

here you have an example of how i precache some models.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-21-2021 , 17:16   Re: Efficient way of precaching models and sounds?
Reply With Quote #4

The only thing that needs "optimizing" here is using "precache_generic" for files that are used client-side, e.g. I'm assuming all the sounds there.

If the sound is played with "client_cmd spk" instead of "emit_sound", use "precache_generic". This way you save up precious resource space.

PS: you need to add "sound/" in the path when doing this.

@lexzor - not really a good way because it can crash the server if the model has a T.mdl file.

Code:
precache_player_model(szModel[]) {     static szFile[128]     formatex(szFile, charsmax(szFile), "models/player/%s/%s.mdl", szModel, szModel)     precache_generic(szFile)     replace(szFile, charsmax(szFile), ".mdl", "T.mdl")         if(file_exists(szFile))     {         precache_generic(szFile)     } }
__________________

Last edited by OciXCrom; 02-21-2021 at 17:17.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
lexzor
Senior Member
Join Date: Nov 2020
Old 02-22-2021 , 04:23   Re: Efficient way of precaching models and sounds?
Reply With Quote #5

I did not go into this detail because it was not the case in my plugin or in the subject of the topic. I assumed he just wanted a method that wasn't so hardcoded
lexzor is offline
Reply


Thread Tools
Display Modes

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 08:33.


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