View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2016 , 08:11   Re: [HL] Weapon Spawn Effects
Reply With Quote #3

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(AllocatedStringsclassname))
          {
              
      Offset engfunc(EngFunc_AllocStringclassname)
              
      TrieSetCell(AllocatedStringsclassnameOffset)
          }
          else 
          {
              
      TrieGetCell(AllocatedStringsclassnameOffset)
          }
          
          new 
      ghost engfunc(EngFunc_CreateNamedEntityOffset
      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.
__________________

Last edited by HamletEagle; 04-22-2016 at 08:13.
HamletEagle is offline