Raised This Month: $32 Target: $400
 8% 

Solved Errors in plugin with datapack


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ozrich
AlliedModders Donor
Join Date: Oct 2015
Old 04-25-2019 , 07:02   Errors in plugin with datapack
Reply With Quote #1

Hi all, firstly, I'm new to SM scripting and don't understand alot, so apologies. I have a plugin that heals a player using a medpack. I'm getting a handle error for deleting a handle but it not existing and also Invalid memory access. However, I think they're both related. It's the same Function.

PHP Code:
L 04/25/2019 18:45:51: [SMException reportedInvalid data pack handle 1e300234 (error 3).
L 04/25/2019 18:45:51: [SMBlamingozrespawn4.3.smx
L 04
/25/2019 18:45:51: [SMCall stack trace:
L 04/25/2019 18:45:51: [SM]   [0DataPack.Reset
L 04
/25/2019 18:45:51: [SM]   [1Line 6106D:\Libraries\Insurgency Development\Sourcemod\WIP\scripting\ozrespawn4.3.sp::Filter_ClientSelf
L 04
/25/2019 18:45:51: [SM]   [3TR_TraceRayFilterEx
L 04
/25/2019 18:45:51: [SM]   [4Line 6078D:\Libraries\Insurgency Development\Sourcemod\WIP\scripting\ozrespawn4.3.sp::Healthkit 
PHP Code:
L 04/25/2019 18:45:51: [SMException reportedInvalid memory access
L 04
/25/2019 18:45:51: [SMBlamingozrespawn4.3.smx
L 04
/25/2019 18:45:51: [SMCall stack trace:
L 04/25/2019 18:45:51: [SM]   [1Line 6077D:\Libraries\Insurgency Development\Sourcemod\WIP\scripting\ozrespawn4.3.sp::Healthkit 
The Healthkit function is below:

PHP Code:
public Action Healthkit(Handle timerHandle hDatapack)
{
    
ResetPack(hDatapack);
    
int entity ReadPackCell(hDatapack);
    
float fEndTime ReadPackFloat(hDatapack);
    
float fGameTime GetGameTime();
    if (
entity && IsValidEntity(entity) && fGameTime <= fEndTime)
    {
        
float fOrigin[3];
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fOrigin);
        if (
g_fLastHeight[entity] == -9999.0)
        {
            
g_fLastHeight[entity] = 0.0;
            
EmitSoundToAll("Lua_sounds/healthkit_healing.wav"entitySNDCHAN_STATIC__0.7);
        }
        
//fOrigin[2] += 16.0;
        
fOrigin[2] += 1.0;
        
//TE_SetupBeamRingPoint(beamPos, 1.0, Revive_Indicator_Radius, g_iBeaconBeam, g_iBeaconHalo, 0, 15, 5.0, 3.0, 5.0, {255, 0, 0, 255}, 1, (FBEAM_FADEIN, FBEAM_FADEOUT));
        
TE_SetupBeamRingPoint(fOrigin15.0Healthkit_Radius*0.55g_iBeaconBeamg_iBeaconHalo051.01.02.0, {0204100255},1,0);
        
// // //TE_SetupBeamRingPoint(fOrigin, 5.0, Healthkit_Radius*1.95, g_iBeaconBeam, g_iBeaconHalo, 0, 30, 5.0, 3.0, 5.0, {0, 255, 0, 255}, 1, (FBEAM_FADEOUT));
        //TE_SetupBeamRingPoint(fOrigin, 10.0, Healthkit_Radius*1.95, g_iBeaconBeam, g_iBeaconHalo, 0, 30, 0.6, 3.0, 0.0, {0, 204, 102, 255}, 3, 0);
        
TE_SendToAll();
        
fOrigin[2] -= 16.0;
        if (
fOrigin[2] != g_fLastHeight[entity])
        {
            
g_fLastHeight[entity] = fOrigin[2];
        }
        else
        {
            
float fAng[3];
            
GetEntPropVector(entityProp_Send"m_angRotation"fAng);
            if (
fAng[1] > 89.0 || fAng[1] < -89.0)
                
fAng[1] = 90.0;
            if (
fAng[2] > 89.0 || fAng[2] < -89.0)
            {
                
fAng[2] = 0.0;
                
fOrigin[2] -= 6.0;
                
TeleportEntity(entityfOriginfAngview_as<float>({0.00.00.0}));
                
fOrigin[2] += 6.0;
                
EmitSoundToAll("ui/sfx/cl_click.wav"entitySNDCHAN_STATIC__1.0);
            }
        }
        for (
int iPlayer 1;iPlayer <= MaxClients;iPlayer++)
        {
            if (
IsClientInGame(iPlayer) && IsPlayerAlive(iPlayer) && GetClientTeam(iPlayer) == 2)
            {
                
float fPlayerOrigin[3];
                
GetClientEyePosition(iPlayerfPlayerOrigin);
                if (
GetVectorDistance(fPlayerOriginfOrigin) <= Healthkit_Radius)
                {
                    
DataPack hData CreateDataPack();
                    
WritePackCell(hDataentity);
                    
WritePackCell(hDataiPlayer);
                    
fOrigin[2] += 32.0;
                    
Handle trace TR_TraceRayFilterEx(fPlayerOriginfOriginMASK_SOLIDRayType_EndPointFilter_ClientSelfhData);
                    if (!
TR_DidHit(trace))
                    {
                        
int iMaxHealth GetEntProp(iPlayerProp_Data"m_iMaxHealth");
                        
int iHealth GetEntProp(iPlayerProp_Data"m_iHealth");
                        if (
iMaxHealth iHealth)
                        {
                            
iHealth += GetRandomInt(Healthkit_Healing_Per_Tick_MinHealthkit_Healing_Per_Tick_Max);
                            if (
iHealth >= iMaxHealth)
                            {
                                
EmitSoundToAll("Lua_sounds/healthkit_complete.wav"iPlayerSNDCHAN_STATIC__1.0);
                                
iHealth iMaxHealth;
                                
//PrintToChat(iPlayer, "\x05竊긌ua \x01@ \x03You are completely healed!");
                                
PrintCenterText(iPlayer"Healed !\n\n \n %d %%\n \n \n \n \n \n \n \n"iMaxHealth);
                            }
                            else 
PrintCenterText(iPlayer"Healing...\n\n \n   %d %%\n \n \n \n \n \n \n \n"iHealth);
                            
SetEntProp(iPlayerProp_Data"m_iHealth"iHealth);
                        }
                    }
                }
            }
        }
    }

The Filter_Clientself function which is actually deleting the handles is below:

PHP Code:
public bool Filter_ClientSelf(int entityint contentsMaskany data
{
    
DataPack dp data;
    
dp.Reset();
    
int client dp.ReadCell();
    
int player dp.ReadCell();
    
delete dp;
    return (
entity != client && entity != player);

Is delete dp; doing the same as dp.Reset(); ?

Thanks for any help! The sp is attached in case you need more info.
Attached Files
File Type: sp Get Plugin or Get Source (ozrespawn4.3.sp - 64 views - 227.1 KB)
__________________

Last edited by ozrich; 04-26-2019 at 01:18.
ozrich is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-25-2019 , 08:12   Re: Errors in plugin with datapack
Reply With Quote #2

So, if it's SM scripting, why is it posted in the AMXX section?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
ozrich
AlliedModders Donor
Join Date: Oct 2015
Old 04-25-2019 , 08:47   Re: Errors in plugin with datapack
Reply With Quote #3

My bad, waiting for mod to move it.
__________________
ozrich is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-25-2019 , 13:06   Re: Errors in plugin with datapack
Reply With Quote #4

The filter is called many times, but you're deleting it on the first call, move the delete out of the filter to after the TR_TraceRayFilterEx call.
__________________
asherkin is offline
ozrich
AlliedModders Donor
Join Date: Oct 2015
Old 04-25-2019 , 13:15   Re: Errors in plugin with datapack
Reply With Quote #5

Thanks Asherkin.

I moved "delete dp;" to after "Handle trace = TR_TraceRayFilterEx(fPlayerOrigin, fOrigin, MASK_SOLID, RayType_EndPoint, Filter_ClientSelf, hData);" and received the errors:

PHP Code:
D:\Libraries\Insurgency Development\Sourcemod\WIP\scripting\ozrespawn4.3.sp(6099) : error 017undefined symbol "dp"
D:\Libraries\Insurgency Development\Sourcemod\WIP\scripting\ozrespawn4.3.sp(6099) : error 115cannot use deletetype ::ft:dp:353996:353996 has no destructor 
Which makes sense because dp is defined in the filter function. I understand using datapack inside a filter isn't supported. Is there a better way of doing this? Could I define dp in the function that calls the filter function too?
__________________
ozrich is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 04-25-2019 , 15:17   Re: Errors in plugin with datapack
Reply With Quote #6

Youre passing hData into the call. Not dp.
PHP Code:
delete hData
Also why would a DataPack inside a filter not be supported?
__________________
Timocop is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 04-25-2019 , 23:31   Re: Errors in plugin with datapack
Reply With Quote #7

Not sure what you mean timocop, although annoying theres nothing stopping you from using a different variable name.

You shouldnt use a datapack in a filter because you're adding more things to execute for little information. Either store it in a global variable or do the sane thing and just check if the hit index is equal to the client being targeted.

Edit: stupid mobile

Last edited by Mitchell; 04-26-2019 at 02:03.
Mitchell is offline
ozrich
AlliedModders Donor
Join Date: Oct 2015
Old 04-26-2019 , 01:18   Re: Errors in plugin with datapack
Reply With Quote #8

Thanks Timocop.

Mitchell, thanks for the info. I'm still new, so probably couldn't do it, but I'll have this for reference.

It's not causing any issues so far and it works.
__________________
ozrich is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 04-26-2019 , 02:02   Re: Errors in plugin with datapack
Reply With Quote #9

@Mitchell Sorry i was pretty tired yesterday haha. My english isnt the best when im tired

Quote:
Originally Posted by Mitchell View Post
Not sure what you mean timocop, although annoying theres nothing stopping you from using a different variable name.
My post was just an addition to @asherkin post. @ozrich was just c&p "delete dp;" after the trace call like you said which didnt work because he is passing the data with a different variable name into the trace function.
PHP Code:
Handle trace TR_TraceRayFilterEx(fPlayerOriginfOriginMASK_SOLIDRayType_EndPointFilter_ClientSelf, >>hData<<); 
So he should use "delete hData;" instead after the trace call.

Quote:
Originally Posted by Mitchell View Post
You shouldnt use a datapack in a filter because you're adding more things to execute for little information. Either store it in a global variable or do the sane thing and just check if the hit index is equal to the client being targeted.
Youre totaly right. Thats bad practice performance wise yes, but that doesnt mean its not supported. Which he said.
But the only problem youll have with global variables when using them as packs is function recursively (when functions are executed twice in the same stack frame).
A pain to debug...
Since @ozrich is a beginner i think he should use the safe but slow method (for now)
__________________

Last edited by Timocop; 04-26-2019 at 02:05. Reason: I meant asherkin, whats wrong with me
Timocop is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 04-26-2019 , 02:04   Re: Errors in plugin with datapack
Reply With Quote #10

I get that you're new and probably don't understand the terms im using, but what i said you pretty much already have the code for in the top post. The datapack would be more advanced then anything ive mentioned.
For an example g_fLastHeight is a global array
Mitchell 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 11:16.


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