View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-14-2014 , 10:20   Re: stop effect mistake
Reply With Quote #2

Don't use a global variable for effect. Instead, pass its entity index as part of the timer. Like this:

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public Plugin:myinfo =  {
    
name "effect particle",
    
author "Skuzy",
    
description " ",
    
version " ",
    
url " "
}
 
public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weaponFloat:damageForce[3], Float:damagePosition[3])
{

    new 
particle CreateEntityByName("info_particle_system");
    
    new 
Float:Origine[3];
    
GetEntPropVector(victimProp_Send"m_vecOrigin"Origine);

    
TeleportEntity(particleOrigineNULL_VECTORNULL_VECTOR);
    
DispatchKeyValue(particle"effect_name""water_splash_02_animated");
    
DispatchKeyValue(particle"targetname""particle");
    
DispatchSpawn(particle);
    
ActivateEntity(particle);
    
AcceptEntityInput(particle"Start");
    
CreateTimer(1.0,stop_effectEntIndexToEntRef(particle));
}

public 
Action:stop_effect(Handle:timerany:particleRef)
{
    new 
particle EntRefToEntIndex(particleRef);
    if (
particle MaxClients)
    {
        
stop(particle);
    }
}

stop(particle)
{
    
AcceptEntityInput(particle"Stop");
    
AcceptEntityInput(particle"Kill");

The particle is being passed as a reference here in case the entity is removed before the timer is called.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-14-2014 at 10:22.
Powerlord is offline