Raised This Month: $12 Target: $400
 3% 

How to successfully precache files


Post New Thread Reply   
 
Thread Tools Display Modes
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
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 08-28-2010 , 21:45   Re: How to successfully precache files
Reply With Quote #2

Quote:
Originally Posted by GXLZPGX View Post
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/model/model.mdl"
PHP Code:
new const gszModel[] = "models/player/model/model.mdl"
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 08-28-2010 , 21:46   Re: How to successfully precache files
Reply With Quote #3

Quote:
Originally Posted by drekes View Post
PHP Code:
new const gszModel[] = "models/player/model/model.mdl"
Thanks, fixed.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
fezh
Veteran Member
Join Date: Dec 2008
Location: BANNED
Old 08-28-2010 , 22:28   Re: How to successfully precache files
Reply With Quote #4

I wonder why people spent their time creating the funcwiki
__________________
"There is no knowledge, that is not power"
fezh is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 08-28-2010 , 22:41   Re: How to successfully precache files
Reply With Quote #5

Quote:
Originally Posted by fezh View Post
I wonder why people spent their time creating the funcwiki
There are so many people that don't read the funcwiki it's not even funny.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 08-28-2010 , 22:54   Re: How to successfully precache files
Reply With Quote #6

Quote:
Originally Posted by GXLZPGX View Post
There are so many people that don't read the funcwiki it's not even funny.
and there are not many examples. so this tutorial will be helpful too.
but they should take a look on the funcwiki too.
platzpatrone is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-28-2010 , 22:58   Re: How to successfully precache files
Reply With Quote #7

Some of these tutorials need to be put on the wiki and the wiki should then be promoted more.
__________________
fysiks is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 08-28-2010 , 23:14   Re: How to successfully precache files
Reply With Quote #8

this is exactly what im thinking about
platzpatrone is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-29-2010 , 01:31   Re: How to successfully precache files
Reply With Quote #9

Quote:
Originally Posted by GXLZPGX View Post
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.
Because you precache models AND sprites with precache_model().

You should cover sprites too and also, cover model and sprite indexes... by saving the value returned by precache_*()
__________________
Hunter-Digital is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 08-29-2010 , 12:18   Re: How to successfully precache files
Reply With Quote #10

Add one thing: Explain why isn't needed to add "sound/" on a sound path while precaching.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS 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 06:37.


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