AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   [HL] Weapon Spawn Effects (https://forums.alliedmods.net/showthread.php?t=185124)

GordonFreeman (RU) 05-12-2012 23:42

[HL] Weapon Spawn Effects
 
2 Attachment(s)

Description:
Just see head image. Plugin makes glow effect on place of pickuped weapon and remove it when this weapon respawns. This effect you can see in the Half-Life Mod - Scientist Slaughterhouse.
Cvars:
ws_render <0..5> [1] - render type
ws_renderfx <0..20> [19] - render fx
ws_renderamt <0.0..255.0> [20.0] - glow amount
ws_color <0..255> <0..255> <0..255> [random] - glow color ([random]) - random *LOL*

Kuma77 09-28-2014 21:08

Re: [HL] Weapon Spawn Effects
 
Nice job

HamletEagle 04-22-2016 08:11

Re: [HL] Weapon Spawn Effects
 
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.

KORD_12.7 04-22-2016 08:36

Re: [HL] Weapon Spawn Effects
 
Spoiler

GordonFreeman (RU) 05-02-2016 01:00

Re: [HL] Weapon Spawn Effects
 
Updated. Rewritted to engine module.
Still no support for weaponmod :p

Quote:

Originally Posted by HamletEagle (Post 2413131)
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.

Its true that i need call such functions like TrieDestroy, ArrayDestroy, SQL_FreeHandle and etc. in plugin_end ? I supposed that AMXX already freeing this on mapchange.

HamletEagle 05-02-2016 13:01

Re: [HL] Weapon Spawn Effects
 
Quote:

Its true that i need call such functions like TrieDestroy, ArrayDestroy, SQL_FreeHandle and etc. in plugin_end ? I supposed that AMXX already freeing this on mapchange.
This is what I said, you should clean all handles. AMXX is freeing them, but Arkshine said it could fail, so it's better to make sure.

In fw_Respawn and fw_Think I don't see that you checked if entity is valid. Also this: 4.In get_rendercolor, s[3][6] should be declared in else{ }.

Else it looks okay. So waiting to fix this minor things.

Arkshine 05-02-2016 16:10

Re: [HL] Weapon Spawn Effects
 
I never said It could fail. 1.8.2/trie, due to design, you can waste memory. Not a big deal. For this kind of API, this is just a good practice/safer to free memory in the plugin as soon you don't need the handle anymore.

GordonFreeman (RU) 05-03-2016 03:39

Re: [HL] Weapon Spawn Effects
 
Updated.
Quote:

Originally Posted by HamletEagle (Post 2416022)
fw_Think I don't see that you checked if entity is valid.

There is already check for remove_entity in fw_Think and i don't think is_valid_ent needed for TrieGetCell.
Code:
public fw_Think(ent){     new dnum[5],ghost     num_to_str(ent,dnum,charsmax(dnum))         TrieGetCell(g_owners,dnum,ghost)         if(ghost)     {         TrieDeleteKey(g_owners,dnum)                 if(is_valid_ent(ghost))         {             remove_entity(ghost)         }     } }

HamletEagle 05-03-2016 14:22

Re: [HL] Weapon Spawn Effects
 
Looks ok. Approved.


All times are GMT -4. The time now is 03:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.