Raised This Month: $ Target: $400
 0% 

Entity not being created


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 13:33.


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