View Single Post
Author Message
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 08-28-2010 , 21:43   How to successfully precache files
Reply With Quote #1

Precaching Files, Yay!

I've seen a lot of topics in the Scripting Help section where the creator talks about having problems with precaching. So here's a quicky.

First we want to create a constant to hold the place of the file.

Model:
PHP Code:
new const gszModel[] = "models/model.mdl"
Use this for sprites as well! But for sprites, you may want to define the sprites folder of course:
PHP Code:
new const gszSprite[] = "sprites/sprite.spr"
Note: If you want to set a PLAYER model, so that a player looks like that specific model, you have to create a subfolder with the name of the model, such as:
PHP Code:
new const gszModel[] = "models/player/model/model.mdl"
Sound:
PHP Code:
new const gszSound[] = "sound.wav"
And no, I don't know why you have to specify the models folder when creating a constant for a model, and you don't for sound.

Multiple files:
PHP Code:
new const g_Models[][] = 
{
    
"models/model1.mdl",
    
"models/model2.mdl",
    
"models/model3.mdl"

Generic folders:
PHP Code:
new const gszSprite[] = "folder" 
Next, we want to actually precache the file so that the players can successfully download it.

Model:
PHP Code:
public plugin_precache()
{
    
precache_modelgszModel )

Sound:
PHP Code:
public plugin_precache()
{
    
precache_soundgszSound )

Multiple files:
PHP Code:
public plugin_precache()
{
    for ( new 
sizeofg_Models ) ; i++ )
        
precache_modelg_Models] );

Generic folders:
PHP Code:
public plugin_precache()
{
    
precache_genericgszFolder )

Examples

Models
There are many ways you can set a player model, but here's a quicky so you shut up.

Using CSTRIKE! (YAY)
PHP Code:
cs_set_user_modelid"model" 
If you want to remove that players model, you'll need to reset it.
PHP Code:
cs_reset_user_model(id
Sounds

Playing sounds is fairly simple. You can use client_cmd and spk.

Such as:
PHP Code:
client_cmdid"spk sound.wav" 
If you have a subfolder for your sound, like "sounds/subfolder/sound.wav", you just use:
PHP Code:
client_cmdid"spk subfolder/sound.wav" 
Yes, there are other ways to play sounds, I am too lazy to give examples.

If you have any suggestions just tell me. I know this isn't a very complete tutorial but w/e
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.

Last edited by GXLZPGX; 11-30-2014 at 04:22.
GXLZPGX is offline