I was browsing
SMLIB and found the following:
PHP Code:
/*
* Precaches the given particle system.
* It's best to call this OnMapStart().
* Code based on Rochellecrab's, thanks.
*
* @param particleSystem Name of the particle system to precache.
* @return Returns the particle system index, INVALID_STRING_INDEX on error.
*/
stock PrecacheParticleSystem(const String:particleSystem[])
{
static particleEffectNames = INVALID_STRING_TABLE;
if (particleEffectNames == INVALID_STRING_TABLE) {
if ((particleEffectNames = FindStringTable("ParticleEffectNames")) == INVALID_STRING_TABLE) {
return INVALID_STRING_INDEX;
}
}
new index = FindStringIndex2(particleEffectNames, particleSystem);
if (index == INVALID_STRING_INDEX) {
new numStrings = GetStringTableNumStrings(particleEffectNames);
if (numStrings >= GetStringTableMaxStrings(particleEffectNames)) {
return INVALID_STRING_INDEX;
}
AddToStringTable(particleEffectNames, particleSystem);
index = numStrings;
}
return index;
}
/*
* Rewrite of FindStringIndex, because in my tests
* FindStringIndex failed to work correctly.
* Searches for the index of a given string in a string table.
*
* @param tableidx A string table index.
* @param str String to find.
* @return String index if found, INVALID_STRING_INDEX otherwise.
*/
stock FindStringIndex2(tableidx, const String:str[])
{
decl String:buf[1024];
new numStrings = GetStringTableNumStrings(tableidx);
for (new i=0; i < numStrings; i++) {
ReadStringTable(tableidx, i, buf, sizeof(buf));
if (StrEqual(buf, str)) {
return i;
}
}
return INVALID_STRING_INDEX;
}
This is supposedly based on
this. I tested both methods, however nothing worked. The stock runs correctly because the index was getting printed in my tests.
Also, I'm not sure whether that matters, but the way I test it is with a tiny test map with a info_particle_system in the center, so I'm not invoking the particle via scripts.