1.Use
charsmax() everywhere to get a string array size, don't hardcode it.
2.In
fw_Respawn:
- Check if the entity is valid.
- engfunc(EngFunc_AllocString,classname) that is an expensive operation, you should do it only one time. Note that this remains in server memory even if you restart HLDS. You have two solutions:
- Alloc each classname in plugin_init, save the values in a trie by classname and retrieve them in fw_Respawn.
- Alloc in fw_Respawn and save the value in a trie. Then, check if you already allocated for the classname. Something like:
PHP Code:
new Offset
if(!TrieKeyExists(AllocatedStrings, classname))
{
Offset = engfunc(EngFunc_AllocString, classname)
TrieSetCell(AllocatedStrings, classname, Offset)
}
else
{
TrieGetCell(AllocatedStrings, classname, Offset)
}
new ghost = engfunc(EngFunc_CreateNamedEntity, Offset)
I would do it like this. That way, only needed strings will be allocated.
- set_pev(ghost,pev_nextthink,0.0) is set two times.
3.In
fw_Think check if the entity is valid.
4.In
get_rendercolor, instead of
float(random_num(10,255)) use
random_float(10.0,255.0).
s[3][6] should be declared in
else{ }.
5.Destroy the trie in
plugin_end. Even if AMXX should free all handles automatically, it may fail. Also, it is good practice to clean what you used.
__________________