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

Solved Precache models


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
brokuka
Junior Member
Join Date: Sep 2018
Old 09-02-2018 , 13:31   Precache models
Reply With Quote #1

Hi guys. Can someone help me ?
FATAL ERROR (shutting down): SV_ModelIndex: model models/player//.mdl not precached
Code:
public jbe_player_models_read_file(szIniFile[])
{
    new const szListEqual[][] = {"PRISONER", "GUARD", "CHIEF", "FOOTBALLER", "GIRL", "OWNER"};
    
    new szBuffer[128], szText[34], iLine, iLen, iNum;
    while(read_file(szIniFile, iLine++, szBuffer, charsmax(szBuffer), iLen))
    {
        if(!iLen || szBuffer[0] == ';' || szBuffer[0] == EOS) continue;
        strtok(szBuffer, szText, charsmax(szText), szBuffer, charsmax(szBuffer), '=');
        trim(szText);
        trim(szBuffer);
        for(iNum = 0; iNum < sizeof(g_iArrayPlayerModel); iNum++)
        {
            if(equal(szText, szListEqual[iNum])) 
            { 
                formatex(g_iArrayPlayerModel[iNum], 63, szBuffer);      
                engfunc(EngFunc_PrecacheModel, g_iArrayPlayerModel[iNum]);
                break;
            }
        }
    }
}
Code:
public plugin_precache()
{
jbe_player_models_read_file(DIRECTORY_PLAYER_MODEL_INI);
}
Code:
#define DIRECTORY_PLAYER_MODEL_INI     "addons/amxmodx/configs/BG_JBE/ini/player_models.ini"
Ini file:
Code:
PRISONER "models\player\sas\sas.mdl" and etc like this

Last edited by brokuka; 09-04-2018 at 18:01.
brokuka is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 09-02-2018 , 14:08   Re: Precache models
Reply With Quote #2

Omg such a poor code, Up.
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
brokuka
Junior Member
Join Date: Sep 2018
Old 09-02-2018 , 14:23   Re: Precache models
Reply With Quote #3

Quote:
Originally Posted by Ghosted View Post
Omg such a poor code, Up.
I'm beginner in coder
brokuka is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-02-2018 , 17:02   Re: Precache models
Reply With Quote #4

Check my jailbreak mod (jailbreak_main.sma) or any other Models plugin.


Here is a stock for file reading with a format.
PHP Code:

stock get_file_keyvalue
(const file[], const cata[], const key[], value[], len)
{
    static 
sFile[128], fp;
    
formatex(sFilecharsmax(sFile), "%s/%s"CONFIGS_DIRfile);
    
    
fp fopen(sFile"a+");
    
    if(!
fp)
    {
        
set_fail_state("Error opening the file!")
        return 
0;
    }
    
    static 
sBuffer[256], szCata[64], szKey[64], key_foundcata_foundlinebool:key_update;
    
key_found = -1;
    
cata_found = -1;
    
line = -1;
    
key_update false;
    
    while(!
feof(fp))
    {
        
line ++;
        
        
fgets(fpsBuffercharsmax(sBuffer));
        
trim(sBuffer);
        
        if(!
sBuffer[0] || strlen(sBuffer) <= || sBuffer[0] == ';' || (sBuffer[0] == '/' && sBuffer[1] == '/'))
            continue;
        
        if(
sBuffer[0] == '[' && cata_found == -&& contain(sBuffer[1], "]") > -1)
        {
            
copyc(szCatacharsmax(szCata), sBuffer[1], ']');
            
            if(
equali(szCatacata))
            {
                
cata_found line;
            }
            
            continue;
        }
        
        if(
cata_found > -&& key_found == -1)
        {
            
strtok(sBufferszKeycharsmax(szKey), sBuffercharsmax(sBuffer), '=')
            
trim(szKey);
            
trim(sBuffer);
            
remove_quotes(szKey);
            
remove_quotes(sBuffer);
            
            if(
equali(szKeykey))
            {
                
key_found line;
                
                if(!
sBuffer[0])
                {
                    
key_update true;
                    break;
                }
                
                
copy(valuelensBuffer)
                break;
            }
        }
    }
    
    if(
cata_found == -1)
    {
        
formatex(szCatacharsmax(szCata), "[%s]"cata)
        
fputc(fp'^n');
        
fputs(fpszCata);
        
fputc(fp'^n');
        
        
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
        
fputs(fpsBuffer);
        
fputc(fp'^n');
    }
    
    if((
key_found == -&& cata_found > -1) || key_update == true
    {
        static 
sFile2[128], fp2;
        
formatex(sFile2charsmax(sFile2), "%s/2_%s"CONFIGS_DIRfile);
        
        
fp2 fopen(sFile2"wt");
        
        if(!
fp2)
        {
            
set_fail_state("Error opening the file!")
            return 
0;
        }
        
        
line = -1;
        
fseek(fp0SEEK_SET);
        while((
fgets(fpsBuffercharsmax(sBuffer)) > 0))
        {
            
line ++;
            
trim(sBuffer);
            
            if(
key_update == true)
            {
                if(
key_found == line)
                {
                    
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
                }
            }
            else if(
cata_found == line)
            {
                
formatex(szCatacharsmax(szCata), "[%s]"cata)
                
fputs(fp2szCata);
                
fputc(fp2'^n');
                
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
            }
            
            
fputs(fp2sBuffer);
            
fputc(fp2'^n');
        }
        
fclose(fp);
        
fclose(fp2);
        
        
delete_file(sFile);
        if(!
rename_file(sFile2sFile,1)) delete_file(sFile2);
        
        return 
1;
    }
    
    
fclose(fp);
    return 
1;


Example getting class model, class name is rabbit which its the category.
PHP Code:

new def_model[32] = "terror";

public 
plugin_precache()
{
        

        
get_file_keyvalue("classes.ini""RABBIT""CLASS_MODEL"def_modelcharsmax(def_model)) 
        
// i didnt make def_model array constant because it will be overwritten if the key value has a value in the file.

        
new szString[64];
        
formatex(szStringcharsmax(szString), "models/player/%s/%s.mdl"def_modeldef_model)
        
precache_model(szString);

Example i wrote doesnt support models with T file.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-02-2018 at 17:35.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
brokuka
Junior Member
Join Date: Sep 2018
Old 09-02-2018 , 19:00   Re: Precache models
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
Check my jailbreak mod (jailbreak_main.sma) or any other Models plugin.


Here is a stock for file reading with a format.
PHP Code:

stock get_file_keyvalue
(const file[], const cata[], const key[], value[], len)
{
    static 
sFile[128], fp;
    
formatex(sFilecharsmax(sFile), "%s/%s"CONFIGS_DIRfile);
    
    
fp fopen(sFile"a+");
    
    if(!
fp)
    {
        
set_fail_state("Error opening the file!")
        return 
0;
    }
    
    static 
sBuffer[256], szCata[64], szKey[64], key_foundcata_foundlinebool:key_update;
    
key_found = -1;
    
cata_found = -1;
    
line = -1;
    
key_update false;
    
    while(!
feof(fp))
    {
        
line ++;
        
        
fgets(fpsBuffercharsmax(sBuffer));
        
trim(sBuffer);
        
        if(!
sBuffer[0] || strlen(sBuffer) <= || sBuffer[0] == ';' || (sBuffer[0] == '/' && sBuffer[1] == '/'))
            continue;
        
        if(
sBuffer[0] == '[' && cata_found == -&& contain(sBuffer[1], "]") > -1)
        {
            
copyc(szCatacharsmax(szCata), sBuffer[1], ']');
            
            if(
equali(szCatacata))
            {
                
cata_found line;
            }
            
            continue;
        }
        
        if(
cata_found > -&& key_found == -1)
        {
            
strtok(sBufferszKeycharsmax(szKey), sBuffercharsmax(sBuffer), '=')
            
trim(szKey);
            
trim(sBuffer);
            
remove_quotes(szKey);
            
remove_quotes(sBuffer);
            
            if(
equali(szKeykey))
            {
                
key_found line;
                
                if(!
sBuffer[0])
                {
                    
key_update true;
                    break;
                }
                
                
copy(valuelensBuffer)
                break;
            }
        }
    }
    
    if(
cata_found == -1)
    {
        
formatex(szCatacharsmax(szCata), "[%s]"cata)
        
fputc(fp'^n');
        
fputs(fpszCata);
        
fputc(fp'^n');
        
        
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
        
fputs(fpsBuffer);
        
fputc(fp'^n');
    }
    
    if((
key_found == -&& cata_found > -1) || key_update == true
    {
        static 
sFile2[128], fp2;
        
formatex(sFile2charsmax(sFile2), "%s/2_%s"CONFIGS_DIRfile);
        
        
fp2 fopen(sFile2"wt");
        
        if(!
fp2)
        {
            
set_fail_state("Error opening the file!")
            return 
0;
        }
        
        
line = -1;
        
fseek(fp0SEEK_SET);
        while((
fgets(fpsBuffercharsmax(sBuffer)) > 0))
        {
            
line ++;
            
trim(sBuffer);
            
            if(
key_update == true)
            {
                if(
key_found == line)
                {
                    
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
                }
            }
            else if(
cata_found == line)
            {
                
formatex(szCatacharsmax(szCata), "[%s]"cata)
                
fputs(fp2szCata);
                
fputc(fp2'^n');
                
formatex(sBuffercharsmax(sBuffer), "%s = ^"%s^""keyvalue)
            }
            
            
fputs(fp2sBuffer);
            
fputc(fp2'^n');
        }
        
fclose(fp);
        
fclose(fp2);
        
        
delete_file(sFile);
        if(!
rename_file(sFile2sFile,1)) delete_file(sFile2);
        
        return 
1;
    }
    
    
fclose(fp);
    return 
1;


Example getting class model, class name is rabbit which its the category.
PHP Code:

new def_model[32] = "terror";

public 
plugin_precache()
{
        

        
get_file_keyvalue("classes.ini""RABBIT""CLASS_MODEL"def_modelcharsmax(def_model)) 
        
// i didnt make def_model array constant because it will be overwritten if the key value has a value in the file.

        
new szString[64];
        
formatex(szStringcharsmax(szString), "models/player/%s/%s.mdl"def_modeldef_model)
        
precache_model(szString);

Example i wrote doesnt support models with T file.
Default code of jbe engine are this:
Code:
jbe_player_models_read_file(szCfgFile[])
{
	new szBuffer[128], iLine, iLen, i;
	while(read_file(szCfgFile, iLine++, szBuffer, charsmax(szBuffer), iLen))
	{
		if(!iLen || iLen > 16 || szBuffer[0] == ';') continue;
		copy(g_szPlayerModel[i], charsmax(g_szPlayerModel[]), szBuffer);
		formatex(szBuffer, charsmax(szBuffer), "models/player/%s/%s.mdl", g_szPlayerModel[i], g_szPlayerModel[i]);
		engfunc(EngFunc_PrecacheModel, szBuffer);
		if(++i >= sizeof(g_szPlayerModel)) break;
	}
}
Code:
files_precache()
{
	new szCfgDir[64], szCfgFile[128];
	get_localinfo("amxx_configsdir", szCfgDir, charsmax(szCfgDir));
	formatex(szCfgFile, charsmax(szCfgFile), "%s/jb_engine/player_models.ini", szCfgDir);
	switch(file_exists(szCfgFile))
	{
		case 0: log_to_file("%s/jb_engine/log_error.log", "File ^"%s^" not found!", szCfgDir, szCfgFile);
		case 1: jbe_player_models_read_file(szCfgFile);
	}
}
Ini file:
Code:
; prisoner
jbe_prisoner

; guard
sas

; chief
jbe_chief

; footballer
jbe_footballer
And i just make code little for me easy But it's gonna make error. I make this way for sounds too(but they work perfect).

Last edited by brokuka; 09-02-2018 at 19:03.
brokuka is offline
brokuka
Junior Member
Join Date: Sep 2018
Old 09-03-2018 , 14:33   Re: Precache models
Reply With Quote #6

Up. Can someone help me ?
brokuka is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 09-03-2018 , 17:08   Re: Precache models
Reply With Quote #7

https://forums.alliedmods.net/misc.php?do=showrules
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-04-2018 , 08:07   Re: Precache models
Reply With Quote #8

Just debug your code and you'll see where your mistake is. Print out the model in the console before precaching it so you can see what you're actually trying to precache.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-04-2018 , 15:21   Re: Precache models
Reply With Quote #9

Check amx_settings_api.
__________________








CrazY. is offline
brokuka
Junior Member
Join Date: Sep 2018
Old 09-04-2018 , 15:50   Re: Precache models
Reply With Quote #10

Thanks for helping, i solve it =)
brokuka is offline
Reply



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 18:52.


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