Raised This Month: $66 Target: $400
 16% 

[HL] Weapon Spawn Effects


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Half-Life        Category:   Fun Stuff        Approver:   HamletEagle (32)
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 05-13-2012 , 00:42   [HL] Weapon Spawn Effects
Reply With Quote #1



Weapon Spawn Effects

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*
Attached Files
File Type: sma Get Plugin or Get Source (weapon_spawn.sma - 899 views - 3.0 KB)

Last edited by GordonFreeman (RU); 05-03-2016 at 04:44. Reason: Img link updated
GordonFreeman (RU) is offline
Kuma77
Senior Member
Join Date: Sep 2014
Location: Behind PC
Old 09-28-2014 , 22:08   Re: [HL] Weapon Spawn Effects
Reply With Quote #2

Nice job
__________________
SPACE TIME
Kuma77 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2016 , 09: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 09:13.
HamletEagle is online now
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 04-22-2016 , 09:36   Re: [HL] Weapon Spawn Effects
Reply With Quote #4

Spoiler
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 05-02-2016 , 02:00   Re: [HL] Weapon Spawn Effects
Reply With Quote #5

Updated. Rewritted to engine module.
Still no support for weaponmod :p

Quote:
Originally Posted by HamletEagle View Post
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.
__________________
The functional way is the right way
GordonFreeman (RU) is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-02-2016 , 14:01   Re: [HL] Weapon Spawn Effects
Reply With Quote #6

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.
__________________
HamletEagle is online now
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-02-2016 , 17:10   Re: [HL] Weapon Spawn Effects
Reply With Quote #7

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.
__________________

Last edited by Arkshine; 05-02-2016 at 17:16.
Arkshine is offline
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 05-03-2016 , 04:39   Re: [HL] Weapon Spawn Effects
Reply With Quote #8

Updated.
Quote:
Originally Posted by HamletEagle View Post
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)         }     } }
__________________
The functional way is the right way

Last edited by GordonFreeman (RU); 05-03-2016 at 04:44.
GordonFreeman (RU) is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-03-2016 , 15:22   Re: [HL] Weapon Spawn Effects
Reply With Quote #9

Looks ok. Approved.
__________________
HamletEagle is online now
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:47.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode