Raised This Month: $51 Target: $400
 12% 

Weapon Icon Display


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Fun Stuff       
zenix
Member
Join Date: Mar 2007
Old 04-05-2007 , 17:27   Weapon Icon Display
Reply With Quote #1

Weapon Icon Display - display your current weapon as an icon in your hud!

~Weapon Icon Display~

I don't know of any use of this in a game or something, but I saw it in GunGame and thought it was cool, so I opened it up, found that it was mostly just related code and really couldn't just take the 1 function that does it and put it into another file. So, I just pretty much made this from scratch.

Modules
#include <amxmodx>

Cvars
amx_show_weapon_icon - Show the icon?
Commands
amx_weapon_icon - Command toggle wrapper for amx_show_weapon_icon

Known Bugs/Glitches
  • MUST COMPILE USING AMX MOD X STUDIO!!!
  • Gernade sprites are scewing up - flashbang is showing part of HE, Smoke is HE gernade, sigh...

Thanks/Credits
  • SAMURAI16 - For his awsome User Icon Status tutorial
  • XxAvalanchexX - For writing GunGame which gave me this idea
  • pizzahut - use CurWeapon event instead of PlayerPreThink
  • Deviance - use get_players()

Todos
  • Move the icon next to the time remaining (like in GunGame) - Maybe, maybe not. You can not change the color of the icon when it's next to the time display [ATTEMPTING]
  • Add support for other mods/special weapons (like a rocket launcher or jetpack) [UNKNOWN]

Notes
I put this mod as Counter Strike only as I don't know if the weapon icons/id's are the same between most of the mods. CZ, maybe, but I have not tested it yet.
1st plugin!
Due to how the plugin ensures that each user has his/her own icon and keeps status of each one seperatly, players may experience a momentary delay of 1-3 secs before the icon changes to reflect their current weapon. The more players, the more likely and longer this effect. This may also happen with a rapid change of guns (ie picking up/dropping until finding desired one on an fy_ map)

Changelog
Code:
/**
* Changelog
*
* version 0.1
*	- Intial Release
*
* version 0.2
* 	- Fixed intial blank display of status
*	- Fixed on/off bug
* version 0.3
*	- Added suggestion: Use else/if
*	- Added suggestion: use get_players() instead of hardcoded 32
*	- Added suggestion: Changed register_forward() to register_event("CurWeapon"...)
*	- Added attempt to remove icon on death (remove_weapon_icon)
* version 0.4
*	- Completley added get_players() (whoops :| )
*	- Fixed crashing bug
*	- 2nd related bug - crashed CS upon death FIXED
*	- Finally posted some screenys :)
*	- Reverted icon_origin to a normal variable and set it to {0,0,0}
* version 0.5 (now == 5.0 KB! ha ha ha)
*	- Added "is_user_ok()" function
*	- Added "add_weapon_icon()" function
*	- Added "remove_weapon_icon()" function
*	- Changed use of direct manipulation of cvar "amx_show_weapon_icon" to use of a pcvar instead
*	- Attempt at removal of icon upon player's death #2 (with combo of attempt 1)
*	- No more fakemeta depedency! (for sure)
* version 0.5c
*	- Removed add_weapon_icon() function, caused the icon to continue the stay after gun change and simply add the icon to the display
*	- Modified color to a lighter green, request for a different color started
* version 0.6
*	- Added color changing icon to represent how much ammo is left
*	- Weapon icon now is removed upon death & replaced when user spawns (for sure)
* version 1.0 (Finally! w00t)
*	- Approved it! AWESOME! Thanks Hawk552!
*	- Change color back to green (sorry about the purple)
*	- Added notes to file with possible ideas
*/
Screenshots
1st - In the buy zone, in cs_italy and just started the map. Glock anyone?
2nd - Just bought a TMP and moved out of the buy zone
Attached Thumbnails
Click image for larger version

Name:	at_beginning2.PNG
Views:	9041
Size:	18.6 KB
ID:	15148   Click image for larger version

Name:	changed_to_tmp2.PNG
Views:	7974
Size:	7.2 KB
ID:	15149  
Attached Files
File Type: sma Get Plugin or Get Source (weapon_icon.sma - 14336 views - 6.8 KB)
__________________
My Current Plugins:
Weapon Icon Display

Last edited by Zenith77; 09-28-2007 at 19:12. Reason: updated to 1.0
zenix is offline
Liquidz
Senior Member
Join Date: Jan 2006
Location: Toronto, Canada
Old 04-05-2007 , 18:12   Re: Weapon Icon display
Reply With Quote #2

screen shots?
__________________

Liquidz is offline
Send a message via MSN to Liquidz
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 04-05-2007 , 18:22   Re: Weapon Icon display
Reply With Quote #3

Code:
    if (equali(toggle, "1")) {         status = "enabled"     }     if (equali(toggle, "0")) {         status = "disabled"     }     if (equali(toggle, "")) {         console_print(id, "Usage: amx_weapon_icon <1/0> - Toggles wether or not showing the user's current weapon as an icon")         console_print(id, "Weapon Icon is currently %s", status)         return PLUGIN_HANDLED     }
You should use else if here.

Code:
for (i=0; i<32; i++) {
This is a bad way of looping thu all players, a better way is to use get_players(), like

Code:
new players[32], num, players get_players(players, num) for(new i = 0; i < num; i++) {     player = players[i]         // ...

Else this is a good idea
Deviance is offline
pizzahut
Senior Member
Join Date: Oct 2004
Old 04-05-2007 , 18:54   Re: Weapon Icon display
Reply With Quote #4

I wonder if this can be done without redrawing the HUD icon all time, to keep the CPU load at a minimum. Perhaps hooking some events would work, like those related to HUD or weapons.
__________________
My AMXX plugins (content date 2007-03-29, link check 2017-04-26)

Plugins for the Royston Vasey TFC server - These are UNSUPPORTED, except those which have been published at AMX Mod X.

Last edited by pizzahut; 04-05-2007 at 19:29.
pizzahut is offline
Liquidz
Senior Member
Join Date: Jan 2006
Location: Toronto, Canada
Old 04-05-2007 , 19:29   Re: Weapon Icon display
Reply With Quote #5

huh? lol
__________________

Liquidz is offline
Send a message via MSN to Liquidz
pizzahut
Senior Member
Join Date: Oct 2004
Old 04-05-2007 , 19:56   Re: Weapon Icon display
Reply With Quote #6

Suggestion

Replace these lines:

Code:
register_forward(FM_PlayerPreThink,"fw_prethink"); public fw_prethink(id) { if(!pev(id,pev_button) && equali(cvar_value, "1"))

with:

Code:
register_event ("CurWeapon", "update_icon", "ab") public update_icon(id) { if(equal(cvar_value, "1"))
__________________
My AMXX plugins (content date 2007-03-29, link check 2017-04-26)

Plugins for the Royston Vasey TFC server - These are UNSUPPORTED, except those which have been published at AMX Mod X.

Last edited by pizzahut; 04-05-2007 at 20:08.
pizzahut is offline
zenix
Member
Join Date: Mar 2007
Old 04-05-2007 , 20:24   Re: Weapon Icon display
Reply With Quote #7

Quote:
Originally Posted by pizzahut View Post
Suggestion

Replace these lines:

Code:
register_forward(FM_PlayerPreThink,"fw_prethink"); public fw_prethink(id) { if(!pev(id,pev_button) && equali(cvar_value, "1"))

with:

Code:
register_event ("CurWeapon", "update_icon", "ab") public update_icon(id) { if(equal(cvar_value, "1"))
Done. Thanks +Karma

Quote:
Originally Posted by Deviance View Post
Code:
    if (equali(toggle, "1")) {         status = "enabled"     }     if (equali(toggle, "0")) {         status = "disabled"     }     if (equali(toggle, "")) {         console_print(id, "Usage: amx_weapon_icon <1/0> - Toggles wether or not showing the user's current weapon as an icon")         console_print(id, "Weapon Icon is currently %s", status)         return PLUGIN_HANDLED     }
You should use else if here.

Code:
for (i=0; i<32; i++) {
This is a bad way of looping thu all players, a better way is to use get_players(), like

Code:
new players[32], num, players get_players(players, num) for(new i = 0; i < num; i++) {     player = players[i]         // ...

Else this is a good idea


Done as well. Thanks for the compilment! +Karma

Changelog to 0.3 (I'll bump it up to 1.0 once it gets approved)
Code:
* version 0.3
*	- Added suggestion: Use else/if
*	- Added suggestion: use get_players() instead of hardcoded 32
*	- Added suggestion: Changed register_forward() to register_event("CurWeapon"...)
*	- Added attempt to remove icon on death (remove_weapon_icon)
__________________
My Current Plugins:
Weapon Icon Display

Last edited by zenix; 04-05-2007 at 20:52.
zenix is offline
Old 04-05-2007, 20:45
zenix
This message has been deleted by zenix. Reason: Sorry for the scare...I have a virus on comp... :|
pizzahut
Senior Member
Join Date: Oct 2004
Old 04-05-2007 , 21:09   Re: Weapon Icon display
Reply With Quote #8

Does it crash immediately when you start a game? Works fine for me, though I only tested it on a listen server without bots and without other players.
__________________
My AMXX plugins (content date 2007-03-29, link check 2017-04-26)

Plugins for the Royston Vasey TFC server - These are UNSUPPORTED, except those which have been published at AMX Mod X.
pizzahut is offline
Da_sk8rboy
Veteran Member
Join Date: Jul 2006
Old 04-05-2007 , 23:18   Re: Weapon Icon display
Reply With Quote #9

Quote:
Originally Posted by Liquidz View Post
screen shots?
__________________
i stop around here and there.
Da_sk8rboy is offline
No0n3
Junior Member
Join Date: Mar 2007
Location: Latvia
Old 04-06-2007 , 03:27   Re: Weapon Icon display
Reply With Quote #10

I can't compile it WHY?!!!!
Code:

Code:
  Version 0.2
 Welcome to the AMX Mod X 1.76-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Error: Argument type mismatch (argument 3) on line 47
Error: Argument type mismatch (argument 3) on line 90
Error: Argument type mismatch (argument 3) on line 129

3 Errors.
Could not locate output file C:\Games\counter-strike\cstrike\addons\amxmodx\plugins\weapon_icon_0.2.amx (compile failed).
Code:
 Version 0.3 
Welcome to the AMX Mod X 1.76-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Error: Argument type mismatch (argument 3) on line 47
Error: Argument type mismatch (argument 3) on line 90
Error: Argument type mismatch (argument 3) on line 129

3 Errors.
Could not locate output file C:\Games\counter-strike\cstrike\addons\amxmodx\plugins\weapon_icon.amx (compile failed).
__________________




Last edited by No0n3; 04-06-2007 at 03:35.
No0n3 is offline
Send a message via Skype™ to No0n3
Old 04-06-2007, 03:45
SAMURAI16
This message has been deleted by SAMURAI16. Reason: ops
Reply



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:41.


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