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

How to kill an entity without "KillHierarchy"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 05-16-2020 , 01:03   How to kill an entity without "KillHierarchy"
Reply With Quote #1

Just trying to kill an ent with a command

I need to trace where the player is looking at... so i tried this from a plugin:
PHP Code:
Handle:TraceRay(client)
{
    new 
Float:startent[3], Float:angle[3], Float:end[3];
    
GetClientEyePosition(clientstartent);
    
GetClientEyeAngles(clientangle);
    
GetAngleVectors(angleendNULL_VECTORNULL_VECTOR);
    
NormalizeVector(endend);

    
startent[0] += end[0] * 10.0;
    
startent[1] += end[1] * 10.0;
    
startent[2] += end[2] * 10.0;

    
end[0] = startent[0] + end[0] * 80.0;
    
end[1] = startent[1] + end[1] * 80.0;
    
end[2] = startent[2] + end[2] * 80.0;
    
    return 
TR_TraceRayFilterEx(startentendCONTENTS_SOLIDRayType_EndPointFilterPlayers);

And now i tried to make the player look the ent so he can pick it up...
PHP Code:
public Action:Cmd_RemoveMines(clientargc)
{
    if(!
b_allow_pickup || IsFakeClient(client) || !IsPlayerAlive(client))
        return 
Plugin_Handled;

    new 
Handle:trace TraceRay(client);
    
    
decl Float:end[3];
    if (
TR_DidHit(trace) && TR_GetEntityIndex(trace) < 1)
    {
        
TR_GetEndPosition(endtrace);
        
CloseHandle(trace);

        new 
= -1;
        while ((
FindEntityByClassname(i"prop_physics_override")) != -&& GetClientByLasermine(i) == client)
            
PickupLasermine(clienticlient);
    }
    return 
Plugin_Handled;

Its kinda working because he just needs to be close to the mine and he can pick it up, not need to be looking at it annnnnd here comes the problem, when he pick 1 mine (PickupLasermine) it took it all and not just the ent he has in the front

So im trying editing the PickupLasermine thing and seems to KillHierarchy removes all the entities parents in the map, so idk what to use to kill the ent he is looking at.
PHP Code:
PickupLasermine(clientlasermineowner)
{
    if (
i_clients_amount[client] >= && i_clients_amount[client] == AddClientLasermines(client))
    {
        return;
    }
    
    new 
Action:result Forward_OnPrePickup(clientlasermineowner);
    
    switch (
result)
    {
        case 
Plugin_HandledPlugin_Stop :
        {
            return;
        }
    }
    
//I know KillHierarchy doesn't work for what i am trying to do.
    //AcceptEntityInput(lasermine, "KillHierarchy");
    
OnEntityDestroyed(int lasermine);
    if (
i_clients_amount[client] >= 0)
        
PrintHintText(client"%t""Mines"i_clients_amount[client]);
    else
        
PrintHintText(client"%t""Infinity mines");
    
EmitSoundToClient(clientSND_BUYMINE);
    
    
Forward_OnPostPickup(clientlasermineowner);

HALP
__________________
Elitcky is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-16-2020 , 03:25   Re: How to kill an entity without "KillHierarchy"
Reply With Quote #2

...
AcceptEntityInput(lasermine, "Kill"); ??

*edit
I'm guessing.
__________________
Do not Private Message @me

Last edited by Bacardi; 05-16-2020 at 03:26.
Bacardi is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 05-16-2020 , 03:55   Re: How to kill an entity without "KillHierarchy"
Reply With Quote #3

No sir
I tried it to (Forgot to say in the thread), didn't work, it takes all of the entities, i think its more a problem about checking 1 ent from the owner, idk how to check just 1 ent, because it check all the ents of the owner, and if the function goes continue, it take all of them
__________________
Elitcky is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-16-2020 , 06:45   Re: How to kill an entity without "KillHierarchy"
Reply With Quote #4

If you need to pickup mines that are close to player you can just get two vectors (Player's origin and mine's origin) and check GetVectorDistance <= REQUIRED_DISTANCE_TO_PICKUP. And after that just use RemoveEntity.

EDIT: Also, if you want to pickup mine that player is looking at, first you can use GetClientAimTarget( client, false ) (after that check if returned index is player's mine) and then you can do same what i said above. And you dont need to use any loops if you want to pickup only one mine each time.

Example:
Code:
int iTarget = GetClientAimTarget( client, false );
if ( iTarget != -1 && IsLasermine( iTarget ) && GetClientByLasermine( iTarget ) == client ) {
	float vecTargetPos[ 3 ], vecPlayerPos[ 3 ];
	GetClientAbsOrigin( client, vecPlayerPos );
	GetEntPropVector( iTarget, Prop_Send, "m_vecOrigin", vecTargetPos );
	if ( GetVectorDistance( vecPlayerPos, vecTargetPos ) <= REQUIRED_DISTANCE_TO_PICKUP ) {
		// Your code on mine pickup
		RemoveEntity( iTarget );
	}
}
__________________

Last edited by MAGNAT2645; 05-16-2020 at 06:59. Reason: Added an example
MAGNAT2645 is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 05-16-2020 , 12:22   Re: How to kill an entity without "KillHierarchy"
Reply With Quote #5

Well i tried this, but is not working, something im doing wrong, but can't figure it out what, i tried like 4 or 5 different ways to do that
PHP Code:
PickupLasermine(clientlasermineowner)
{
    if (
i_clients_amount[client] >= && i_clients_amount[client] == AddClientLasermines(client))
    {
        return;
    }
    
    new 
Action:result Forward_OnPrePickup(clientlasermineowner);
    
    switch (
result)
    {
        case 
Plugin_HandledPlugin_Stop :
        {
            return;
        }
    }
    
    
int iTarget GetClientAimTargetclientfalse );
    if ( 
iTarget != -&& IsEntityLasermineiTarget ) && GetClientByLasermineiTarget ) == client 
    {
        
float vecTargetPos], vecPlayerPos];
        
GetClientAbsOriginclientvecPlayerPos );
        
GetEntPropVectoriTargetProp_Send"m_vecOrigin"vecTargetPos );
        
/*if ( GetVectorDistance( vecPlayerPos, vecTargetPos ) <= 60.0 ) {
            // Your code on mine pickup
            RemoveEntity( lasermine );
        */
        
RemoveEntityiTarget );
        
//AcceptEntityInput(lasermine, "KillHierarchy");
    
}

    if (
i_clients_amount[client] >= 0)
        
PrintHintText(client"%t""Mines"i_clients_amount[client]);
    else
        
PrintHintText(client"%t""Infinity mines");
    
EmitSoundToClient(clientSND_BUYMINE);
    
    
Forward_OnPostPickup(clientlasermineowner);

__________________
Elitcky 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:49.


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