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

[TF2] Random shutdown server when creating landmine


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oplkill
Member
Join Date: Aug 2015
Old 07-26-2017 , 07:50   [TF2] Random shutdown server when creating landmine
Reply With Quote #1

Hi, i created code, which creating landmine at the point which will detonate if enemy player trigger it(walk near landmine). Its working good, landmines creating and detonates, but sometimes randomly server shutdown when i creating new landmine or some of them detonate, without any error message...
I dont know where is the memory leak or something which shutdown server.

PHP Code:
new Float:l_mineHealth 200.0;
new 
String:MODEL_MINE_RED[STRING_MAXLEN];
new 
String:MODEL_MINE_BLUE[STRING_MAXLEN];
new 
Float:l_mineDistance 100.0;
new 
Float:l_mineDamage 300.0;
new 
Float:l_mineRadiusDmg 100.0;

new 
String:SOUND_MINE_CREATE[STRING_MAXLEN];
new 
String:SOUND_MINE_CATCH[STRING_MAXLEN];

new 
Handle:g_hMines INVALID_HANDLE;
new 
Handle:g_hMinesTimer INVALID_HANDLE;

enum l_eMine
{
    
Float:lm_iHealth,
    
lm_iEntity,
    
lm_iTeam,
    
Float:lm_fPos0,
    
Float:lm_fPos1,
    
Float:lm_fPos2,
    
lm_iOwner,
    
bool:lm_bExist,
};

new 
g_MineData[l_eMine];

void OnMapStart_mine()
{
    
PrecacheSound(SOUND_MINE_CREATE);
    
PrecacheModel(MODEL_MINE_RED);
    
PrecacheModel(MODEL_MINE_BLUE);
    
PrecacheModel(SOUND_MINE_CATCH);
    
    
OnRoundStarted_mine();
}

void OnRoundStarted_mine()
{
    if(
g_hMinesTimer != INVALID_HANDLE)
        
KillTimer(g_hMinesTimer);
    
g_hMinesTimer INVALID_HANDLE;
    
    if(
g_hMines != INVALID_HANDLE)
        if(
GetArraySize(g_hMines) > 0)
        {
            for(
int b GetArraySize(g_hMines)-1>= 0b--)
            {
                
GetArrayArray(g_hMinesbg_MineDatasizeof(g_MineData));
                
                if(!
g_MineData[lm_bExist])
                    continue;
                
                if(
g_MineData[lm_iEntity] > MaxClients)
                {
                    
SDKUnhook(g_MineData[lm_iEntity], SDKHook_OnTakeDamageOnTakeDamage_mine);
                    
RemoveEdict(g_MineData[lm_iEntity]);
                    
//AcceptEntityInput(iData[l_iEntity], "Kill");
                
}
            }
        }

    
delete g_hMines;
    
g_hMines CreateArray(l_eMine);
}

public 
Action:PlayerVoice_mine(client)
{
    new 
Float:flPos[3];
    if(
GetClientLookPosition(clientflPos))
    {
        if(
true/*CanBuildAtPosMineTrap(flPos)*/)
        {
            new 
iMine SpawnMine(clientflPos);
            if(
iMine == -1)
            {
                
EmitSoundToClient(clientSOUND_NOPE);
                return 
Plugin_Handled;
            }
            
EmitSoundToAll(SOUND_MINE_CREATEclient);
            
            return 
Plugin_Handled;
        }
    }
    
    
EmitSoundToClient(clientSOUND_NOPE);
    return 
Plugin_Handled;
}

stock int SpawnMine(builderFloat:Position[3])
{
    new 
pEnt =    CreateEntityByName("prop_dynamic");        
    if (
pEnt == -1
    { 
        
LogMessage("Mine failed to create."); 
        return -
1;
    }
    
    
int iTeam GetClientTeam(builder);
    
g_MineData[lm_iTeam] = iTeam;
    
g_MineData[lm_iEntity] = pEnt;
    
g_MineData[lm_iHealth] = l_mineHealth;
    
g_MineData[lm_fPos0] = Position[0];
    
g_MineData[lm_fPos1] = Position[1];
    
g_MineData[lm_fPos2] = Position[2];
    
g_MineData[lm_iOwner] = builder;
    
g_MineData[lm_bExist] = true;
    
PushArrayArray(g_hMinesg_MineDatasizeof(g_MineData));
    
    if(
iTeam == TFTeam_Red)
        
DispatchKeyValue(pEnt"model"MODEL_MINE_RED);
    else
        
DispatchKeyValue(pEnt"model"MODEL_MINE_BLUE);
    
    
SDKHook(pEntSDKHook_OnTakeDamageOnTakeDamage_mine);
    
    
DispatchSpawn(pEnt);
    
TeleportEntity(pEntPositionNULL_VECTORNULL_VECTOR);    
    
    if(
g_hMinesTimer == INVALID_HANDLE)
    {
        
g_hMinesTimer CreateTimer(0.25Timer_mine0TIMER_REPEAT);
    }
    
    return 
pEnt;
}

public 
Action:Timer_mine(Handle:hTimerany:data)
{
    if(
GetArraySize(g_hMines) > 0)
    {
        for(
int b GetArraySize(g_hMines)-1>= 0b--)
        {
            
GetArrayArray(g_hMinesbg_MineDatasizeof(g_MineData));
            if(!
g_MineData[lm_bExist])
            {    
                
RemoveFromArray(g_hMinesb);
                continue;
            }
            
            for(new 
i=1i<=MaxClientsi++)
            {
                if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) != g_MineData[lm_iTeam])
                {
                    if(!
TF2_IsPlayerInCondition(iTFCond_Ubercharged))
                    {
                        new 
Float:flPos2[3];
                        
GetClientAbsOrigin(iflPos2);
                        new 
Float:flPos1[3];  
                        
flPos1[0] = g_MineData[lm_fPos0];
                        
flPos1[1] = g_MineData[lm_fPos1];
                        
flPos1[2] = g_MineData[lm_fPos2];
                        new 
Float:flDistance GetVectorDistance(flPos1flPos2);
                        if(
flDistance <= l_mineDistance)
                        {
                            if(!
IsClientInGame(g_MineData[lm_iOwner]))
                                
g_MineData[lm_iOwner] = 0;
                            new 
ent g_MineData[lm_iEntity];
                            
                            for(new 
c=1c<=MaxClientsc++)
                            {
                                if(
IsClientInGame(c) && IsPlayerAlive(c) && GetClientTeam(c) != g_MineData[lm_iTeam])
                                {
                                    if(!
TF2_IsPlayerInCondition(cTFCond_Ubercharged))
                                    {
                                        
GetClientAbsOrigin(cflPos2);
                                        
                                        
flDistance GetVectorDistance(flPos1flPos2);
                                        if(
flDistance l_mineRadiusDmg)
                                        {
                                            
SDKHooks_TakeDamage(c0g_MineData[lm_iOwner], l_mineDamageDMG_PREVENT_PHYSICS_FORCE|DMG_CRUSH|DMG_ALWAYSGIB|DMG_BLAST);
                                        }
                                    }
                                }
                            }
                            
int iExplosion CreateParticleAtEntity(ent"explosion");
                            if(
iExplosion MaxClients)
                            {
                                
KillEntityDelay(iExplosion);
                            }
                            
                            if(
ent MaxClients)
                            {
                                
SDKUnhook(entSDKHook_OnTakeDamageOnTakeDamage_mine);
                                
RemoveEdict(ent);
                                
//AcceptEntityInput(ent, "Kill");
                            
}
                            
//iData[l_bExist] = false;
                            //SetArrayArray(g_hMines, b, iData, sizeof(iData));
                            
RemoveFromArray(g_hMinesb);
                            break;
        }}}}}
        
        return 
Plugin_Continue;
    }
    
    
g_hMinesTimer INVALID_HANDLE;
    return 
Plugin_Stop;
}

Action:OnTakeDamage_mine(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weaponFloat:damageForce[3], Float:damagePosition[3], damagecustom)
{
    
int id FindValueInArray(g_hMinesvictimlm_iEntity);
    if (
id == -1)
        return 
Plugin_Continue;
    
    
GetArrayArray(g_hMinesidg_MineDatasizeof(g_MineData));
    
g_MineData[lm_iHealth] -= damage;
    if(
g_MineData[lm_iHealth] <= 0.0)
    {
        
SDKUnhook(victimSDKHook_OnTakeDamageOnTakeDamage_mine);
        
RemoveEdict(victim);
        
g_MineData[lm_bExist] = false;
        
//RemoveFromArray(g_hMines, id);
    
}
    
    
SetArrayArray(g_hMinesidg_MineDatasizeof(g_MineData));
    
    return 
Plugin_Changed;

oplkill is offline
oplkill
Member
Join Date: Aug 2015
Old 08-14-2017 , 09:54   Re: [TF2] Random shutdown server when creating landmine
Reply With Quote #2

i rewrited some code and maked it hook at OnTouch, but function OnStartTouch_perk_trap never calling, whatever anybody touching that entity.

PHP Code:
new Float:l_trapHealth 200.0;
new 
String:MODEL_TRAP_RED[STRING_PERK_MAXLEN];
new 
String:MODEL_TRAP_BLUE[STRING_PERK_MAXLEN];
new 
l_trapCount 1;
new 
Float:l_trapDistance 100.0;
new 
Float:l_trapTime 10.0;

new 
String:SOUND_TRAP_CREATE[STRING_PERK_MAXLEN];
new 
String:SOUND_TRAP_CATCH[STRING_PERK_MAXLEN];

new 
Handle:g_hTraps INVALID_HANDLE;
new 
Handle:g_hTrapsTimer INVALID_HANDLE;

enum l_eTrap
{
    
Float:lt_iHealth,
    
lt_iEntity,
    
lt_iTeam,
    
Float:lt_fPos0,
    
Float:lt_fPos1,
    
Float:lt_fPos2,
    
lt_iOwner,
    
bool:lt_bExist,
};

new 
g_TrapData[l_eTrap];

public 
Action:PlayerVoice_perk_trap(client)
{
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   2"client);
    new 
Float:flPos[3];
    if(
GetClientLookPosition(clientflPos))
    {
        
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   3"client);
        new 
iTrap SpawnTrap(clientflPos);
        
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   4"client);
        if(
iTrap == -1)
        {
            
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   5"client);
            
EmitSoundToClient(clientSOUND_NOPE);
            return 
Plugin_Handled;
        }
        
EmitSoundToAll(SOUND_TRAP_CREATEclient);
        
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   6"client);
        
        return 
Plugin_Handled;
    }
    
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   9"client);
    
EmitSoundToClient(clientSOUND_NOPE);
    return 
Plugin_Handled;
}

stock int SpawnTrap(builderFloat:Position[3])
{
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   10"builder);
    new 
pEnt =    CreateEntityByName("prop_dynamic");        
    if (
pEnt == -1
    { 
        
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   11"builder);
        
LogMessage("Trap failed to create."); 
        return -
1;
    }
    
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   12"builder);
    
int iTeam GetClientTeam(builder);
    
g_TrapData[lt_iTeam] = iTeam;
    
g_TrapData[lt_iEntity] = pEnt;
    
g_TrapData[lt_iHealth] = l_trapHealth;
    
g_TrapData[lt_fPos0] = Position[0];
    
g_TrapData[lt_fPos1] = Position[1];
    
g_TrapData[lt_fPos2] = Position[2];
    
g_TrapData[lt_iOwner] = builder;
    
g_TrapData[lt_bExist] = true;
    
PushArrayArray(g_hTrapsg_TrapDatasizeof(g_TrapData));
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   13"builder);
    
    if(
iTeam == TFTeam_Red)
        
DispatchKeyValue(pEnt"model"MODEL_TRAP_RED);
    else
        
DispatchKeyValue(pEnt"model"MODEL_TRAP_BLUE);
    
    
DispatchSpawn(pEnt);
    
TeleportEntity(pEntPositionNULL_VECTORNULL_VECTOR);    
    
LogToFile(DebugFile"[ roll TRAP ] Id = %d.   15"builder);
    
SDKHook(pEntSDKHook_StartTouchOnStartTouch_perk_trap);
    
    return 
pEnt;
}

public 
Action:OnStartTouch_perk_trap(entityother)
{    
    
LogToFile(DebugFile"[ roll TRAP ]  TOUCH  88  %d  %d"entityother);
    if(
IsValidClient(other) && IsPlayerAlive(other))
    {
        
LogToFile(DebugFile"[ roll TRAP ]    99   %d"other);
        
int id FindValueInArray(g_hTrapsentitylt_iEntity);
        if (
id == -1)
        {
            if(
entity MaxClients)
            {
                
SDKUnhook(entitySDKHook_StartTouchOnStartTouch_perk_trap);
                
RemoveEdict(entity);
            }
            return 
Plugin_Stop;
        }
        
LogToFile(DebugFile"[ roll TRAP ]    100");
        
GetArrayArray(g_hTrapsidg_TrapDatasizeof(g_TrapData));
        if(!
TF2_IsPlayerInCondition(otherTFCond_Ubercharged) && !HasGodmode(other) && GetClientTeam(other) != g_TrapData[lt_iTeam])
        {
            
LogToFile(DebugFile"[ roll TRAP ]    22");
            if(!
IsClientInGame(g_TrapData[lt_iOwner]))
                
g_TrapData[lt_iOwner] = 0;
            
EmitSoundToAll(SOUND_TRAP_CATCHother);
            
CatchPlayerNoMove(otherl_trapTime);
            
TF2_StunPlayer(otherl_trapTime1.00TF_STUNFLAG_BONKSTUCKg_TrapData[lt_iOwner]);
            
            if(
entity MaxClients)
            {
                
LogToFile(DebugFile"[ roll TRAP ]    23");
                
SDKUnhook(entitySDKHook_StartTouchOnStartTouch_perk_trap);
                
RemoveEdict(entity);
            }
            
LogToFile(DebugFile"[ roll TRAP ]    24");
            
RemoveFromArray(g_hTrapsid);
            
            return 
Plugin_Stop;
        }
    }
    
    return 
Plugin_Stop;

oplkill 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 08:37.


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