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_model( gszModel )
}
Sound:
PHP Code:
public plugin_precache()
{
precache_sound( gszSound )
}
Multiple files:
PHP Code:
public plugin_precache()
{
for ( new i = 0 ; i < sizeof( g_Models ) ; i++ )
precache_model( g_Models[ i ] );
}
Generic folders:
PHP Code:
public plugin_precache()
{
precache_generic( gszFolder )
}
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_model( id, "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_cmd( id, "spk sound.wav" )
If you have a subfolder for your sound, like "sounds/subfolder/sound.wav", you just use:
PHP Code:
client_cmd( id, "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
__________________