Raised This Month: $ Target: $400
 0% 

Entity is touched = server crash


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-15-2015 , 07:38   Entity is touched = server crash
Reply With Quote #1

What is problem, why crashing without any errors?!
PHP Code:
#define TASK_EXPLODE 1111

#define EXPLOSION_MAX_DAMAGE 100
#define EXPLOSION_RANGE 300
#define EXPLOSION_BLAST_RADIUS 250

new toucher_owner;
new 
Float:g_origin[3];

// It's called when the entity is touched
public mine_explosion(touchertouched)
{
    
toucher_owner entity_get_edict(toucherEV_ENT_owner);
    
        
// Only crashing if this check is passed!
    
if(cs_get_user_team(touched) != cs_get_user_team(toucher_owner))
    {
        
entity_get_vector(toucherEV_VEC_origing_origin);
    
        
set_task(0.5"explode"toucher TASK_EXPLODE);
    
        
emit_sound(toucherCHAN_AUTO"ambience/particle_suck1.wav"VOL_NORMATTN_NORM0PITCH_NORM);
    }
}

public 
explode(toucher)
{    
    
toucher -= TASK_EXPLODE;
    
    new 
Float:position[3];
    
position[0] = g_origin[0] + random_float(-100.0100.0);
    
position[1] = g_origin[1] + random_float(-100.0100.0);
    
position[2] = g_origin[2] + random_float(-50.050.0);

    
te_explosion(Float:g_originFloat:positionzerogxplode, (random_num(0,20) + 20), 12TE_EXPLFLAG_NONE);
    
te_smoke(Float:g_originFloat:positionsteam16010);
        
    new 
players[32], numi;
    
get_players(playersnum"a");

    new 
targetFloat:target_origin[3], Float:distancedamage;
    new 
multiplier = (EXPLOSION_MAX_DAMAGE EXPLOSION_MAX_DAMAGE) / EXPLOSION_RANGE;
    
    for(
i=0i<numi++)
    {
        
target players[i];
        
        
entity_get_vector(targetEV_VEC_origintarget_origin);

        
distance get_distance_f(g_origintarget_origin);
        
        if(
distance EXPLOSION_RANGE && cs_get_user_team(toucher_owner) != cs_get_user_team(target))
        {
            
damage = (EXPLOSION_RANGE floatround(distance)) * multiplier;
            
damage sqroot(damage);
            
            
ExecuteHamB(Ham_TakeDamagetargettouchertoucherdamageDMG_ALWAYSGIB);
            
            
remove_entity(toucher);
        }
    }
}

stock te_explosion(Float:origin[3], Float:position[3], spritescaleframerateflags)
{
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin);
    
write_byte(TE_EXPLOSION);
    
engfunc(EngFunc_WriteCoordposition[0]); // position.x
    
engfunc(EngFunc_WriteCoord ,position[1]); // position.y
    
engfunc(EngFunc_WriteCoordposition[2]); // position.z
    
write_short(sprite); // sprite index
    
write_byte(scale); // scale in 0.1's
    
write_byte(framerate); // framerate
    
write_byte(flags); // flags
    
message_end();
}

stock te_smoke(Float:origin[3], Float:position[3], spritescaleframerate)
{
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin);
    
write_byte(TE_SMOKE);
    
engfunc(EngFunc_WriteCoordposition[0]); // position.x
    
engfunc(EngFunc_WriteCoord ,position[1]); // position.y
    
engfunc(EngFunc_WriteCoordposition[2]); // position.z
    
write_short(sprite); // sprite index
    
write_byte(scale); // scale in 0.1's
    
write_byte(framerate); // framerate
    
message_end();


Last edited by KiLLeR.; 02-15-2015 at 07:38.
KiLLeR. is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 02-15-2015 , 07:54   Re: Entity is touched = server crash
Reply With Quote #2

touch is called every frame that the touch occurs. i would think spamming the emit_sound will crash the server, try commenting it out and test it
jimaway is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-15-2015 , 08:03   Re: Entity is touched = server crash
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
touch is called every frame that the touch occurs. i would think spamming the emit_sound will crash the server, try commenting it out and test it
Again crashing...
KiLLeR. is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 02-15-2015 , 08:37   Re: Entity is touched = server crash
Reply With Quote #4

As @jimaway has already mentioned, the touch is called each frame while the entities are in contact. So I guess that setting a task each frame will cause the server to crash. So I'd guess to check if the task already exist and then set it.
PHP Code:
if(!task_exists(toucher TASK_EXPLODE))
  
set_task(0.5"explode"toucher TASK_EXPLODE
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 02-15-2015 , 13:15   Re: Entity is touched = server crash
Reply With Quote #5

Make sure to check is_user_connected(index), this is important.

PHP Code:
public mine_explosion(touchertouched)
{
    if(
is_valid_ent(toucher) && is_user_connected(touched))
    {
        
toucher_owner entity_get_edict(toucherEV_ENT_owner);
        if(
is_user_connected(toucher_owner))
        {
            
// Only crashing if this check is passed!
            
if(cs_get_user_team(touched) != cs_get_user_team(toucher_owner))
            {
                
//#define SOLID_NOT 0 // No interaction with other objects
                //if instant explode then you can set EV_INT_solid to SOLID_NOT, to prevent touch again
                
entity_set_int(toucherEV_INT_solidSOLID_NOT)
                
entity_get_vector(toucherEV_VEC_origing_origin);
                
set_task(0.5"explode"toucher TASK_EXPLODE);
                
emit_sound(toucherCHAN_AUTO"ambience/particle_suck1.wav"VOL_NORMATTN_NORM0PITCH_NORM);
            }
        }
    }

also set_task is not good to use here, you can use "entity_set_float(ent, EV_FL_nextthink, get_gametime()+0.5)"
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 02-15-2015 at 13:18.
yokomo is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 02-16-2015 , 01:03   Re: Entity is touched = server crash
Reply With Quote #6

this is a blind shot but this plugin is a tripmine, right?
isn't the mine supposed to explode, and be removed, and not the player?

set_task(0.5, "explode", toucher + TASK_EXPLODE);
->>
set_task(0.5, "explode", touched + TASK_EXPLODE);


just asking because idk the behavior of removing player entity but my common sense tells me it's not a good idea
remove_entity(toucher);
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 02-16-2015 , 05:45   Re: Entity is touched = server crash
Reply With Quote #7

Quote:
Originally Posted by aron9forever View Post
this is a blind shot but this plugin is a tripmine, right?
isn't the mine supposed to explode, and be removed, and not the player?

set_task(0.5, "explode", toucher + TASK_EXPLODE);
->>
set_task(0.5, "explode", touched + TASK_EXPLODE);


just asking because idk the behavior of removing player entity but my common sense tells me it's not a good idea
remove_entity(toucher);
As far as I can see from the code, the 'toucher' id is the one of the mine entity. Otherwise it makes no sense and should be changed, but if it's so, there shouldn't be a problem.
__________________

Last edited by Flick3rR; 02-16-2015 at 05:45.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-16-2015 , 13:22   Re: Entity is touched = server crash
Reply With Quote #8

When trying to remove a player entity the server will crash.
__________________
HamletEagle is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 02-16-2015 , 13:30   Re: Entity is touched = server crash
Reply With Quote #9

I guess the indexes of the player and the entity should be replace with one another. I mean, just change them with the another one. F*ckin english, killing me...
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-21-2015 , 09:22   Re: Entity is touched = server crash
Reply With Quote #10

Working fine.
PHP Code:
public mine_explosion(touchertouched)
{
    if(!
is_valid_ent(toucher) && !is_user_connected(touched))
        return;

    
toucher_owner entity_get_edict(toucherEV_ENT_owner);
    
    
// Only crashing if this check is passed!
    
if(cs_get_user_team(touched) != cs_get_user_team(toucher_owner))
    {
        
entity_get_vector(toucherEV_VEC_origing_origin);
        
        if(
task_exist(toucher TASK_EXPLODE))
        {
            
set_task(0.5"explode"toucher TASK_EXPLODE);
        }
    }

But now i have another problem.
PHP Code:
set_user_health(targetget_user_health(target) - damage); // work!
ExecuteHamB(Ham_TakeDamagetargettouchertoucherdamageDMG_ALWAYSGIB); // doesn't work! (there are no errors, just don't take damage) 
I prefer to use Ham_TakeDamage instead of set_user_health.

Last edited by KiLLeR.; 02-21-2015 at 09:42.
KiLLeR. 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 21:42.


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