AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Loading incorrect model. (string is concatenating?) (https://forums.alliedmods.net/showthread.php?t=305975)

gabuch2 03-11-2018 11:07

Loading incorrect model. (string is concatenating?)
 
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?

jimaway 03-11-2018 11:53

Re: Loading incorrect model. (string is concatenating?)
 
most likely problem with the part of code where you set oldVModel[id]

gabuch2 03-11-2018 14:16

Re: Loading incorrect model. (string is concatenating?)
 
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.

Bugsy 03-11-2018 14:40

Re: Loading incorrect model. (string is concatenating?)
 
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 


NiHiLaNTh 03-11-2018 15:50

Re: Loading incorrect model. (string is concatenating?)
 
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.

gabuch2 03-11-2018 20:31

Re: Loading incorrect model. (string is concatenating?)
 
Quote:

Originally Posted by NiHiLaNTh (Post 2582566)
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.


All times are GMT -4. The time now is 18:03.

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