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[] name, bool dontBroadCast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if(client == attacker || attacker == 0 || !attacker)
{
return Plugin_Continue;
}
PrintToChatAll("Detected attacker %N and victim %N", attacker, client);
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(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", 8);
SetEntProp(coin, Prop_Send, "m_CollisionGroup", 11);
SDKHook(coin, SDKHook_StartTouch, OnTouchEntity);
}
}
public Action OnTouchEntity(int entity, int client)
{
PrintToChatAll("Touch hook started");
char model[128];
model[0] = '\0';
GetEntPropString(entity, Prop_Data, "m_ModelName", model, sizeof(model));
if (client > 0 && client <= MaxClients && IsPlayerAlive(client) && StrEqual(model, entitymdl))
{
StartDeleting(entity, client);
}
}
void StartDeleting(int entity, int client)
{
if(IsValidEntity(entity))
{
AcceptEntityInput(entity, "Kill");
PrintToChatAll("%N just picked up the item", client);
SDKUnhook(entity, SDKHook_StartTouch, OnTouchCoin);
}
}
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.
__________________