View Single Post
Nue
Junior Member
Join Date: Sep 2013
Old 03-16-2019 , 08:12   Re: [CSGO] Bonemerging particles on model(Position on Model Random)
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
https://forums.alliedmods.net/showthread.php?p=2580534

you can check how its done in the above plugin
https://www.youtube.com/watch?v=EbiK...ature=youtu.be
This is the result of paranting burning_character particle using that code

Code:
#include <cstrike>
#include <sdktools>
#include <clientprefs>

int MyParticle[MAXPLAYERS+1];

public OnPluginStart()
{
	HookEvent("player_spawn", Auras_PlayerSpawn);
	HookEvent("player_death", Auras_PlayerDeath);
	HookEvent("player_team", Auras_PlayerTeam);
	RegConsoleCmd("autobuy", ParticleStart);
}

public Action:ParticleStart(id, Arguments)
{
	RemoveParticlesFromPlayer(id);
	AddParticlesToPlayer(id);
}

public OnMapStart()
{
	loringlib_PrecacheEffect ( "ParticleEffect" );
	PrecacheGeneric ( "particles/burning_fx.pcf", true );
	loringlib_PrecacheParticleName ( "burning_character" );
}

stock void loringlib_PrecacheEffect ( const char[] effPath ) {
    static int table = INVALID_STRING_TABLE;
    if ( table == INVALID_STRING_TABLE )
        table = FindStringTable ( "EffectDispatch" );
        
    bool lockTable = LockStringTables ( false );
    AddToStringTable ( table, effPath );
    LockStringTables ( lockTable );
}

stock void loringlib_PrecacheParticleName ( const char[] effPath ) {
    static int table = INVALID_STRING_TABLE;
    if ( table == INVALID_STRING_TABLE )
        table = FindStringTable ( "ParticleEffectNames" );
        
    bool lockTable = LockStringTables ( false );
    AddToStringTable ( table, effPath );
    LockStringTables ( lockTable );
}

public Action:Auras_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(!client || !IsClientInGame(client) || !IsPlayerAlive(client) || !(2<=GetClientTeam(client)<=3))
		return Plugin_Continue;
	
	//If they had one equipped but didn't die, kill it
	RemoveParticlesFromPlayer(client);
	
	AddParticlesToPlayer(client);
	//float nulls[3];
	//AttachParticle(client, "burning_character", nulls);
	return Plugin_Continue;
}

public Action:Auras_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(!client || !IsClientInGame(client))
		return Plugin_Continue;
	
	//Kill the particle system when the player dies
	RemoveParticlesFromPlayer(client);

	return Plugin_Continue;
}

public Action:Auras_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(!client || !IsClientInGame(client))
		return Plugin_Continue;
	
	//Kill the particle system when the player dies
	RemoveParticlesFromPlayer(client);

	return Plugin_Continue;
}

public void RemoveParticlesFromPlayer(int iClient)
{
	if(MyParticle[iClient] == INVALID_ENT_REFERENCE || !IsEntParticleSystem(MyParticle[iClient]))
		return;
	
	AcceptEntityInput(MyParticle[iClient], "Kill");
}

stock bool IsEntParticleSystem(int iEntity)
{
	if (IsValidEdict(iEntity))
	{
		char sBuffer[128];
		GetEdictClassname(iEntity, sBuffer, sizeof(sBuffer));
		if (StrEqual(sBuffer, "info_particle_system", false))
		{
			return true;
		}
	}
	return false;
}

public void AddParticlesToPlayer(int iClient)
{
	int iEntity = CreateEntityByName("info_particle_system");
	MyParticle[iClient] = iEntity;
	if (IsValidEdict(iEntity) && (iClient > 0))
	{
		if (IsPlayerAlive(iClient))
		{
			// Get players current position
			new Float:vPosition[3];
			GetEntPropVector(iClient, Prop_Send, "m_vecOrigin", vPosition);
			
			// Move particle to player
			TeleportEntity(iEntity, vPosition, NULL_VECTOR, NULL_VECTOR);
			
			// Set entity name
			DispatchKeyValue(iEntity, "targetname", "particle");
			
			// Get player entity name
			decl String:szParentName[64];
			GetEntPropString(iClient, Prop_Data, "m_iName", szParentName, sizeof(szParentName));
			
			// Set the effect name
			DispatchKeyValue(iEntity, "effect_name", "burning_character");
			
			// Spawn the particle
			DispatchSpawn(iEntity);
			
			// Target the particle
			SetVariantString("!activator");
			
			// Set particle parent name
			DispatchKeyValue(iEntity, "parentname", szParentName);
			
			// Set client to parent of particle
			AcceptEntityInput(iEntity, "SetParent", iClient, iEntity, 0);
			
			// Activate the entity (starts animation)
			ActivateEntity(iEntity);
			AcceptEntityInput(iEntity, "Start");
			
			// Attach to parent model
			SetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity", iClient);
			
			SetFlags(iEntity);
		}
	}
}

public void SetFlags(int iEdict) 
{ 
    if (GetEdictFlags(iEdict) & FL_EDICT_ALWAYS) 
    { 
        SetEdictFlags(iEdict, (GetEdictFlags(iEdict) ^ FL_EDICT_ALWAYS)); 
    } 
}

public PrecacheParticle(const String:path[])
{
	if(!FileExists(path, true, NULL_STRING))
	{
		//PrintToServer("\nParticle file \'%s\' not found.", path);
		//return;
	}

	PrecacheGeneric(path, true);
}
Nue is offline