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

Check if model has been precached


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-10-2019 , 09:30   Check if model has been precached
Reply With Quote #1

Hi, I wonder how can I check if a model or modelindex has been precached without crashing the server? I'm using this function engfunc(EngFunc_ModelIndex, "models/player/blue/blue.mdl") to get modelindex, but the problem comes when the model hasn't been precached, the server crashs, I don't want that, help me.
rtxa is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 03-10-2019 , 09:33   Re: Check if model has been precached
Reply With Quote #2

Precache it in your plugin.

PHP Code:
public plugin_precache()
{
    
gModelIndex precache_model("models/player/blue/blue.mdl");


Last edited by PartialCloning; 03-10-2019 at 09:35.
PartialCloning is offline
eat1k
Senior Member
Join Date: Apr 2018
Old 03-10-2019 , 09:39   Re: Check if model has been precached
Reply With Quote #3

Quote:
Originally Posted by rtxa View Post
Hi, I wonder how can I check if a model or modelindex has been precached without crashing the server? I'm using this function engfunc(EngFunc_ModelIndex, "models/player/blue/blue.mdl") to get modelindex, but the problem comes when the model hasn't been precached, the server crashs, I don't want that, help me.
If you want to check if file exists to stop the plugin so use file_exists + set_fail_state.
__________________
eat1k is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-10-2019 , 10:48   Re: Check if model has been precached
Reply With Quote #4

Use boolean variable and check if the file exists

PHP Code:
new bFilePrecached false;
public 
plugin_precache()
{
    
    if(
file_exists("models/player/blue/blue.mdl"))
    {
       
precache_model("models/player/blue/blue.mdl");
       
bFilePrecached true;
    }


PlayerSpawned(id)
{
   if(
bFilePrecachedcs_set_player_model(id"blue"); 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-11-2019 , 00:20   Re: Check if model has been precached
Reply With Quote #5

Thanks for your answers, but what I mean is that I don't know if user has precached the model, so in my function, when you try to get modelindex of a model that has not ben precached, the server will crash, I don't want that, I want to make it foolproof, do you understand?
rtxa is offline
eat1k
Senior Member
Join Date: Apr 2018
Old 03-11-2019 , 02:28   Re: Check if model has been precached
Reply With Quote #6

So check in precache before getting the model index. If it doesn’t exist stop the plugin and nothing will crash.
__________________
eat1k is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-11-2019 , 04:28   Re: Check if model has been precached
Reply With Quote #7

PartialCloning already told you the solution you need to precache_model first before getting it's index model.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-11-2019 , 11:39   Re: Check if model has been precached
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
PartialCloning already told you the solution you need to precache_model first before getting it's index model.
precache_model will crash if not used inside plugin_precache() forward, so that's doesn't work for me, it has to be at any time (like after plugin has init).
Look, there is a function in cstrike.inc that is foolproof if I'm not wrong, cs_set_user_model(), in the @error description it says "... if modeindex is updated and the
provided model is not precached, an error will be thrown.", here is the source code of cs_set_user_model() where it starts to check if modelindex has been precached or not.

Last edited by rtxa; 03-11-2019 at 11:46.
rtxa is offline
Old 03-11-2019, 12:46
<VeCo>
This message has been deleted by <VeCo>.
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 03-11-2019 , 12:53   Re: Check if model has been precached
Reply With Quote #9

why don't you precache it normally though? the server should have all the needed models

try with EngFunc_PrecacheModel, it should work in plugin_init() and plugin_cfg()
__________________

Last edited by <VeCo>; 03-11-2019 at 13:55.
<VeCo> is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-11-2019 , 13:48   Re: Check if model has been precached
Reply With Quote #10

Quote:
/**
* Precaches a model file.
*
* @note Can only be used inside of the plugin_precache() forward.
*
* @param name Path to the model file
*
* @return Unique cache id of the model
* @error If called outside of the plugin_precache() forward, an error is
* thrown.
*/
native precache_model(const name[]);
Anyway, explain why you do not want to precache the model inside of plugin_precache forward and why you do not consider any of the above answers a solution.
__________________








CrazY. 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 22:16.


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