[CSGO]Using generic precache for custom particles

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

[CSGO]Using generic precache for custom particles

Postby VinciT » Sun Aug 30, 2015 9:41 pm

I'm having some trouble precaching and using custom particles with the following code:

Syntax: Select all

blue_fire = Generic('particles/blue_flame_test.pcf', True)

@ClientCommand('+lookatweapon')
def test_particle(player_info, command):
player = PlayerEntity(index_from_playerinfo(player_info))
particle = make_particle(player.origin, 'blue_flame_c', 3)
particle.set_parent(player, -1)

def make_particle(location, particle_name, duration):
particle = Entity(create_entity('info_particle_system'))
particle.effect_name = particle_name
particle.origin = location
particle.set_property_int('m_iEffectIndex', string_tables.ParticleEffectNames.add_string(particle_name))
particle.call_input('Start')
tick_delays.delay(duration, particle.remove)
return particle

The code above gives me no errors, and yet nothing happens. There are no particles. The .pcf file contains blue_flame, blue_flame_b, blue_flame_c, blue_flame_d, and blue_flame_e.
I came across thisSourceMod plugin which uses PrecacheGeneric() to change the burning particles. So I tried using the same method in Source.Python, but to no avail. What am I doing wrong?
Attachments
blue_flame_test.zip
(4.79 KiB) Downloaded 419 times
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Aug 30, 2015 10:13 pm

Does your "test_particle" callback actually get called?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Sun Aug 30, 2015 10:22 pm

Yeah, I've added print() to it before to make sure it actually gets called. The first time I use it, there's like a tiny 'freeze-up', as if something is about to happen, but nothing does.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Mon Aug 31, 2015 7:17 am

Are you sure the particle is actually working for csgo? Some time ago I did some testing with particles and tried to use pcf files from other games in csgo, or csgo's pcf files in other games.
Csgo's particle editor is utter bullshit, but it couldn't load the particles in the file. It looked like the different engine versions differentiated in using the particles.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Aug 31, 2015 12:47 pm

Doing a quick search, I noticed that there is no entity data that uses effect_name. The example I am sure you got that from was from an older version of SP. We must have not added effect_name when we updated the entities structure. I'll look into that here in a few and get it implemented.

*Edit: done
https://github.com/Source-Python-Dev-Team/Source.Python/commit/058e4a49a20bd6d2146dec749c88bdc4b7c8716f
https://github.com/Source-Python-Dev-Team/Source.Python/commit/57f70ca1bd4a7092fda50440edcb7af2bf3fec1b


These changes also mean you can change 2 other lines:

Syntax: Select all

particle.set_property_int('m_iEffectIndex', string_tables.ParticleEffectNames.add_string(particle_name))
particle.call_input('Start')

can now be:

Syntax: Select all

particle.effect_index = string_tables.ParticleEffectNames.add_string(particle_name)
particle.start()



*Edit2: I also forgot to mention that this line:

Syntax: Select all

particle = Entity(create_entity('info_particle_system'))

can just be:

Syntax: Select all

particle = Entity.create('info_particle_system')
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Wed Sep 02, 2015 12:04 am

satoon, that's awesome! The particles are still not showing though. Maybe I messed up while making the particles.

stonedegg wrote:Are you sure the particle is actually working for csgo? Some time ago I did some testing with particles and tried to use pcf files from other games in csgo, or csgo's pcf files in other games.
Csgo's particle editor is utter bullshit, but it couldn't load the particles in the file. It looked like the different engine versions differentiated in using the particles.

I think you can use the Alien Swarm particle editor to make particles for CSGO, or at least that's what I did.
I just extracted the .pcf files and the particle materials with GCFScape, placed them in the Alien Swarm directories and all of the particles worked just fine in the editor.

The particles I made are just recolored versions of just a few fire/flame particles.

Edit: I found thispiece of code on the SourceMod forums for testing custom particles. And it worked. My custom particles spawned. Here's the code:

Syntax: Select all

#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
RegAdminCmd("sm_pt",parttest,ADMFLAG_ROOT);
}
public OnMapStart()
{
AddFileToDownloadsTable("particles/blue_flame_test.pcf"); // Download to client,or it will not work
PrecacheGeneric("particles/blue_flame_test.pcf",true); //Precache Any pcf(particle file)
}

public Action :p arttest(client, args)
{
decl String:info[100];
GetCmdArg(1, info, 100);
PrintToChatAll("Run");
new iExp = CreateEntityByName("info_particle_system");//Call custom particle(Use Particle tool -> CS:S or Dota2 -> [ -tools -nop4 ],open particle editor and u can find an particle name effect
DispatchKeyValue(iExp, "start_active", "1");
DispatchKeyValue(iExp, "effect_name", info); //info = String of name of an effect.
DispatchSpawn(iExp);
PrintToChatAll("Spawn:%d",iExp);
new Float:Pos[3];
GetLookPos(client,Pos);
PrintToChatAll("Pos:%f %f %f",Pos[0],Pos[1],Pos[2]);
TeleportEntity(iExp, Pos, NULL_VECTOR,NULL_VECTOR);
ActivateEntity(iExp);
return Plugin_Handled;
}

public bool:GetLookPos_Filter(ent, mask, any:client) return client != ent;
GetLookPos(client, Float :p os[3])
{
decl Float:EyePosition[3], Float:EyeAngles[3], Handle:h_trace;
GetClientEyePosition(client, EyePosition);
GetClientEyeAngles(client, EyeAngles);
h_trace = TR_TraceRayFilterEx(EyePosition, EyeAngles, MASK_SOLID, RayType_Infinite, GetLookPos_Filter, client);
TR_GetEndPosition(pos, h_trace);
CloseHandle(h_trace);
}

I'm just guessing here but, could the implementation of PrecacheGeneric() in Source.Python be different? Maybe something with the 'preload' part of the function?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Sep 02, 2015 12:23 am

Yeah, I tested it, as well, and it did not show. I also tried with the pcf files from the link you provided above, and they did not work either. I have no idea why or how to get them to work, unfortunately. If you or anyone else figures it out, please post how here.
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Wed Sep 02, 2015 12:41 am

I'm such an idiot. Instead of using the same arguments/properties for the info_particle_system as the guy did with the SourceMod code to see if I was missing something, I just blame the implementation.
The particles work with Source.Python as well. All I needed to do was add particle.start_active = 1

I have one question though. While using SM to spawn the particles, there was no lag/freeze up the first time I spawn it, that's not the case with SP.
Now I'm pretty sure this has something to do with the preload part of the PrecacheGeneric() function. I tested it with SM just to be sure:

Syntax: Select all

//int PrecacheGeneric(const char[] generic, bool preload)
PrecacheGeneric("particles/blue_flame_test.pcf", true); //no lag/freezeup
PrecacheGeneric("particles/blue_flame_test.pcf", false); //same lag/freezeup as SP

Edit: Well damn.. I was wrong. The particles stayed precached on my client, so when I restarted the server without SM, I thought I had found what was the issue, but I was wrong.
When I restarted my game, the particles were gone. So all in all, I'm back to square one.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Sep 02, 2015 6:37 am

Btw. the preload argument is also available in SP:

Syntax: Select all

from engines.server import engine_server

engine_server.precache_generic(<string>, <preload>)
We should probably update our precache classes to include this argument as well.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Sep 02, 2015 12:40 pm

Good point. Done:
https://github.com/Source-Python-Dev-Team/Source.Python/commit/72297e8af5d613283f1b0a11f183e081c9b885c4


*Edit: does setting the "active" attribute after calling start (if you don't use start_active) work, as well? If not, we can always include the _ZN15CParticleSystem8ActivateEv virtual function. Though, obviously, the best way to handle it would be setting start_active.
Image
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Postby VinciT » Wed Sep 02, 2015 7:35 pm

Syntax: Select all

@Event('server_spawn')
def load_particles(game_event):
engine_server.precache_generic('particles/blue_flame_test.pcf', True)
When preloading is set to True, the particles work, if it's set to False, they don't.

Also, I forgot to mention, the blue_flame_test.pcf particles need a controlpoint, otherwise they'll go straight to the center/origin of the map.
I've attached another particle system, blue_fire_test.pcf which is a recolored version of the cs_office.pcf

Code: Select all

blue_office_child_flame01b
blue_office_child_flame02b
blue_office_child_flame03b
blue_office_fire
blue_office_smoke
These particles don't need any controlpoints.
One more thing, if a client is downloading the particles for the first time, they won't see the particles until they reconnect. This happened both with SM and SP.
Attachments
blue_fire_test.zip
(5.38 KiB) Downloaded 429 times

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 36 guests