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

Entity not being created


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-03-2021 , 12:48   Entity not being created
Reply With Quote #1

Hey

I am trying to create an entity on the floor where a player dies (with a custom model) and detect whether someone touches it.

I have the following code:
PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <multicolors>

char entitymdl[] = "models/weapons/spirtmodels/entityspawn.mdl";

#pragma newdecls required

public Plugin myinfo 
{
    
name "[SpirT] Spawn entity on player death",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
HookEvent("player_death"OnPlayerDeath);
}

public 
Action OnPlayerDeath(Event event, const char[] namebool dontBroadCast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if(
client == attacker || attacker == || !attacker)
    {
        return 
Plugin_Continue;
    }
    
    
PrintToChatAll("Detected attacker %N and victim %N"attackerclient);
    
SpawnEntity(client);
    return 
Plugin_Handled;
}

void SpawnEntity(int client)
{
    
int coin;
    
    if((
coin CreateEntityByName("prop_dynamic")) != -1)
    {
        
PrintToChatAll("Entity is valid");
        
float position[3];
        
GetClientEyePosition(clientposition);
        
TeleportEntity(coinpositionNULL_VECTORNULL_VECTOR);
        
PrintToChatAll("Entity teleported to victim position %f"position);
        
        
DispatchKeyValue(coin"model"entitymdl);
        
PrintToChatAll("Coin model was set to %s"entitymdl);
        
DispatchKeyValue(coin"massScale""8.0");
        
DispatchKeyValue(coin"physicsmode""2");
        
DispatchSpawn(coin);
        
        
SetEntProp(coinProp_Send"m_usSolidFlags"8);
        
SetEntProp(coinProp_Send"m_CollisionGroup"11);
        
        
SDKHook(coinSDKHook_StartTouchOnTouchEntity);
    }
}

public 
Action OnTouchEntity(int entityint client)
{
    
PrintToChatAll("Touch hook started");
    
char model[128];
    
model[0] = '\0';
    
    
GetEntPropString(entityProp_Data"m_ModelName"modelsizeof(model));
    
    if (
client && client <= MaxClients && IsPlayerAlive(client) && StrEqual(modelentitymdl))
    {
        
StartDeleting(entityclient);
    }
}

void StartDeleting(int entityint client)
{
    if(
IsValidEntity(entity))
    {
        
AcceptEntityInput(entity"Kill");
        
PrintToChatAll("%N just picked up the item"client);
        
SDKUnhook(entitySDKHook_StartTouchOnTouchCoin);
    }

So, with this source that I have provided, it sends the message as creating the entity and deleting it at the same time. So, how can I keep the entity on the player position and only delete it once someone touches it?

Regards,
SpirT.
__________________

Last edited by SpirT; 04-05-2021 at 04:10. Reason: Using the timer fixed it.
SpirT is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 04-03-2021 , 14:09   Re: Entity not being created
Reply With Quote #2

Your code looks ok.

I think is missing a debug to detect what is touching the entity, probably with that info you can understand what is happening

Otherwise, try waiting for a frame (or create a timer to test) before spawning the entity.
Maybe it is touching the death player itself (even with the IsPlayerAlive(client))

Also doesn't make much sense comparing the model in the OnTouchEntity check
__________________
Marttt is online now
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-03-2021 , 14:26   Re: Entity not being created
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Your code looks ok.

I think is missing a debug to detect what is touching the entity, probably with that info you can understand what is happening

Otherwise, try waiting for a frame (or create a timer to test) before spawning the entity.
Maybe it is touching the death player itself (even with the IsPlayerAlive(client))

Also doesn't make much sense comparing the model in the OnTouchEntity check
Thanks for your reply. I already tried to do some debugging. I also tried to kill the opponent in a far distance, but it still says that I have touched it!

With the timer do you mean creating it before deleting it?
__________________
SpirT is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 04-03-2021 , 14:48   Re: Entity not being created
Reply With Quote #4

by Timer I mean hooking "SDKHook(coin, SDKHook_StartTouch, OnTouchEntity);" inside the timer.
__________________
Marttt is online now
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 04-03-2021 , 16:00   Re: Entity not being created
Reply With Quote #5

Quote:
void SpawnEntity(int client)
{
int coin;

if((coin = CreateEntityByName("prop_dynamic")) != -1)
{
PrintToChatAll("Entity is valid");
float position[3];
GetClientEyePosition(client, position);
TeleportEntity(coin, position, NULL_VECTOR, NULL_VECTOR);
PrintToChatAll("Entity teleported to victim position %f", position);

DispatchKeyValue(coin, "model", entitymdl);
PrintToChatAll("Coin model was set to %s", entitymdl);
DispatchKeyValue(coin, "massScale", "8.0");
DispatchKeyValue(coin, "physicsmode", "2");
DispatchSpawn(coin);

SetEntProp(coin, Prop_Send, "m_usSolidFlags", ;
SetEntProp(coin, Prop_Send, "m_CollisionGroup", 11);
CreateTimer(1.0, CreateCoin,coin,TIMER_FLAG_NO_MAPCHANGE);
// SDKHook(coin, SDKHook_StartTouch, OnTouchEntity);
}
}

public Action CreateCoin(Handle timer, int coin)
{
SDKHook(coin, SDKHook_StartTouch, OnTouchEntity);
}

Something like this........
__________________
Waiting for HL3,Day of Defeat3 ,but will it ever come? So I'm gonna play COD WW2.>>>>SM_SKINCHOOSER<<<<
>>You need Models for DODS/CSS/CSGO , than click here!!!<<
andi67 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 04-03-2021 , 16:02   Re: Entity not being created
Reply With Quote #6

Put a delay in between player death and creating it, im guessing its hitting the dead player. Try a RequestFrame delay if that doesn't work then use a timer at 0.1 sec...that should work, if it does not then go to 0.2 etc. Or just do what Andi67 suggests.

Last edited by MasterMind420; 04-03-2021 at 16:03.
MasterMind420 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-03-2021 , 16:41   Re: Entity not being created
Reply With Quote #7

...depends, do custom model have physic model, so touch would activate ?
You can look from Hammer map editor, via model browser, check "render collision model" you should see red wireframes.
Or from Model Viewer, check physics model.

What I remember.
*edit Try different model ? ex: "models\weapons\w_eq_smokegrenade_dropped.mdl "

Last edited by Bacardi; 04-03-2021 at 16:42.
Bacardi is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-04-2021 , 05:35   Re: Entity not being created
Reply With Quote #8

Quote:
Originally Posted by Marttt View Post
by Timer I mean hooking "SDKHook(coin, SDKHook_StartTouch, OnTouchEntity);" inside the timer.
I tried that and it worked. Also, the model path was wrong, but even though it worked!

I'll give a try to andi67 source.
__________________
SpirT is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-05-2021 , 04:12   Re: Entity not being created
Reply With Quote #9

Andi67's code worked perfectly, I changed also the timer from 1.0 to 0.5 and it works great! I just have another question. With these settings, the model spawns @ player death position, but I'd like it to fall to the floor, like if we would spawn any weapon in the air. Is that possible? (CS:GO)
__________________
SpirT is offline
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 04-05-2021 , 05:15   Re: Entity not being created
Reply With Quote #10

Change prop_dynamic to prop_physics.....
__________________
Waiting for HL3,Day of Defeat3 ,but will it ever come? So I'm gonna play COD WW2.>>>>SM_SKINCHOOSER<<<<
>>You need Models for DODS/CSS/CSGO , than click here!!!<<
andi67 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:52.


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