Raised This Month: $75 Target: $400
 18% 

Loading incorrect model. (string is concatenating?)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gabe Iggy
Veteran Member
Join Date: Mar 2011
Location: Chile
Old 03-11-2018 , 11:07   Loading incorrect model. (string is concatenating?)
Reply With Quote #1

Hello, I'm creating a custom ironsights plugin, however, in some rare cases server is crashing because it's loading an invalid model. I checked the console and it appears the model string is concatenating instead of replacing itself as you can see here.
Code:
FATAL ERROR (shutting down): SV_ModelIndex: model models/motv/2017_contrabandista/models/motv/2017_contrabandista/opfor/v_aug.mdl not precached
Here's the full code.

Code:
/* Mod Template generated by Pawn Studio */ #include <amxmodx> #include <amxmisc> #include <fakemeta> #include <hamsandwich> #include <engine> #define PLUGIN  "Gabe Iggy" #define VERSION "1.0" #define AUTHOR  "Sven Co-op Scopes" #define SNIPER_SCOPE "models/motv/scope_sniper.mdl" #define IRONSIGHTS_SCOPE "models/motv/scp_battler.mdl" #define NINEMMAR_SCOPE "models/scp_9mmar.mdl" #define MAXPLAYERS get_maxplayers() #define TASK_ID 2478756 /* Initialization */ new oldVModel[128][32]; new userReady[32] = 1; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);         register_event("SetFOV", "zoomingIn", "be");     new event = create_entity("weapon_aug");     RegisterHamFromEntity(Ham_Weapon_RetireWeapon, event, "zoomOut", 1); //hack for AS weapons     RegisterHam(Ham_Weapon_RetireWeapon, "weapon_crossbow", "zoomOut", 1);     RegisterHam(Ham_Weapon_RetireWeapon, "weapon_sniperrifle", "zoomOut", 1);     RegisterHam(Ham_Weapon_RetireWeapon, "weapon_9mmar", "zoomOut", 1);     RegisterHamFromEntity(Ham_Item_Holster, event, "zoomOut", 1);     RegisterHam(Ham_Item_Holster, "weapon_crossbow", "zoomOut", 1);     RegisterHam(Ham_Item_Holster, "weapon_sniperrifle", "zoomOut", 1);     RegisterHam(Ham_Item_Holster, "weapon_9mmar", "zoomOut", 1);     RegisterHamFromEntity(Ham_Item_Deploy, event, "deploy", 1);     RegisterHam(Ham_Item_Deploy, "weapon_crossbow", "deploy", 1);     RegisterHam(Ham_Item_Deploy, "weapon_sniperrifle", "deploy", 1);     RegisterHam(Ham_Item_Deploy, "weapon_9mmar", "deploy", 1);     remove_entity(event); } public plugin_precache() {     precache_model(SNIPER_SCOPE);     precache_model(IRONSIGHTS_SCOPE);     precache_model(NINEMMAR_SCOPE); } public deploy(weaponID) {     new id = get_pdata_ehandle(weaponID, 404, 16);     if(task_exists(id+TASK_ID))         remove_task(id+TASK_ID);     set_task(0.1, "funcRead", id+TASK_ID); } public zoomOut(weaponID) {     new id = get_pdata_ehandle(weaponID, 404, 16);     userReady[id] = 0;     set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, oldVModel[id])); } public funcRead(taskID) {     new id = taskID - TASK_ID;     userReady[id] = 1; } public zoomingIn(id) {     if(!task_exists(id+TASK_ID))     {         if(is_user_alive(id) && userReady[id])         {             new newFOV = read_data(1);                         if(newFOV != 0)                 pev(id, pev_viewmodel2, oldVModel[id], charsmax(oldVModel));                         switch(newFOV)             {                 case 20:                 {                     set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, SNIPER_SCOPE));                     return PLUGIN_CONTINUE;                 }                 case 40:                 {                     set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, NINEMMAR_SCOPE));                     return PLUGIN_CONTINUE;                 }                 case 41:                 {                     set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, IRONSIGHTS_SCOPE));                     return PLUGIN_CONTINUE;                 }                 case 0:                 {                     set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, oldVModel[id]));                     return PLUGIN_CONTINUE;                 }                 default:                 {                     return PLUGIN_HANDLED;                 }             }         }         else             return PLUGIN_HANDLED;     }     else         return PLUGIN_HANDLED;     return PLUGIN_HANDLED; }

What could be the cause of this?
__________________
Gabe Iggy is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-11-2018 , 11:53   Re: Loading incorrect model. (string is concatenating?)
Reply With Quote #2

most likely problem with the part of code where you set oldVModel[id]
jimaway is offline
Gabe Iggy
Veteran Member
Join Date: Mar 2011
Location: Chile
Old 03-11-2018 , 14:16   Re: Loading incorrect model. (string is concatenating?)
Reply With Quote #3

Yes but the question is why.

In all tests I've done this plugin works correctly but as soon as I put it in my working public server a crash happens randomly.
__________________
Gabe Iggy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-11-2018 , 14:40   Re: Loading incorrect model. (string is concatenating?)
Reply With Quote #4

I would take a look at every line where you reference oldVModel and verify you are using it consistently/correctly.

One thing I notice is you have it defined as new oldVModel[128][32] yet you are using the first index for the player id? If this is the case, it should be oldVModel[ MAXPLAYERS + 1 ][ MAXCHARS + 1 ] and then any time you set data to it, pass charsmax( oldVModel[] ) for max chars.

These two else's are not needed since the function terminates with a PLUGIN_HANDLED anyway.
PHP Code:
        else
            return 
PLUGIN_HANDLED;
    }
    else
        return 
PLUGIN_HANDLED;
    return 
PLUGIN_HANDLED;

You should try to use constants for offsets instead of putting in the integer value. It's difficult to quickly review\understand your code because I first need to search for what each offset is for.
PHP Code:
new id get_pdata_ehandle(weaponID40416); 
I would also try to do something cleaner to handle this:
PHP Code:
public deploy(weaponID)
{
    new 
id get_pdata_ehandle(weaponID40416);
    
    if(
task_exists(id+TASK_ID))
        
remove_task(id+TASK_ID);
        
    
set_task(0.1"funcRead"id+TASK_ID);
}

public 
funcRead(taskID)
{
    new 
id taskID TASK_ID;
    
userReady[id] = 1;

My guess is it is working in your tests when you are the only player but once various player id's are there your storage of data in oldVModel is not working as expected.

Add some lines to troubleshoot to confirm your code is working as expected.
PHP Code:
server_print"Setting model [%s] on player id [%d]" oldVModelid ] , id 
__________________

Last edited by Bugsy; 03-11-2018 at 14:44.
Bugsy is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 03-11-2018 , 15:50   Re: Loading incorrect model. (string is concatenating?)
Reply With Quote #5

You defined oldModel like this

Code:
new oldVModel[128][32];
but you use it like this:

Code:
set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, oldVModel[id]));
This is probably the source of your problems.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Gabe Iggy
Veteran Member
Join Date: Mar 2011
Location: Chile
Old 03-11-2018 , 20:31   Re: Loading incorrect model. (string is concatenating?)
Reply With Quote #6

Quote:
Originally Posted by NiHiLaNTh View Post
You defined oldModel like this

Code:
new oldVModel[128][32];
but you use it like this:

Code:
set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, oldVModel[id]));
This is probably the source of your problems.
Apparently this was the culprit.

I'll keep testing for a while before marking this thread as "Solved".

Thank you.
__________________
Gabe Iggy 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 08:46.


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