AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   about percentage (https://forums.alliedmods.net/showthread.php?t=188255)

fearmelfice 06-24-2012 07:56

about percentage
 
help me, i want to make a hud message which announce me when the clip is 50% and 10%
but i dont know what script i must write?

thanks, sorry if my english bad

Liverwiz 06-24-2012 14:22

Re: about percentage
 
I give you concept and links to function wikis you will need. But you're gonna have to write the code yourself. or go to the request section.

CreateHudSyncObj() http://www.amxmodx.org/funcwiki.php?go=func&id=1064
new weapon = cs_get_user_weapon(id) http://www.amxmodx.org/funcwiki.php?go=func&id=738
http://www.amxmodx.org/funcwiki.php?go=func&id=207
new Float:percent = (cs_get_weapon_ammo(id) / clipSize[weapon]) * 100 //This will get % of clip left
if(percent == 50 || percent == 10)
show_hudmessage(id, "Your clip is at ^%%d!", percent)
http://www.amxmodx.org/funcwiki.php?go=func&id=29

NOTE: clipSize you'll have to write yourself. It'll be an array of the clip size of that weapon. i.e. CSW_M4A1 = 30, CSW_FAMAS = 25, CSW_M249 = 100 etc etc
PHP Code:

new clip clipSize[CSW_M4A1]    //clip will then equal 30 

put it all in a weapon fire hook. so it gets run after each shot. (not sure what you'd want to use for that)

Know what? I actually think i'll have fun writing this. So i might even do it for you, if you need. But i don't have time today. So if you're willing to wait untill tomorrow or something, PM me and i'll get it for you when i can. Otherwise, if you can't write it (it should be real simple) just post in request.

hornet 06-24-2012 18:13

Re: about percentage
 
Quote:

Originally Posted by Liverwiz (Post 1735270)
show_hudmessage(id, "Your clip is at ^%%d!", percent)

This won't work. That will display:

PHP Code:

Your clip is at %d

%% Means that the second % will be used as an unformatted character in the string.

Use:

PHP Code:

show_hudmessage(id"Your clip is at %%%d!"percent

And best way to hook weapon fire is http://forums.alliedmods.net/showthread.php?t=54887

YamiKaitou 06-24-2012 18:19

Re: about percentage
 
Quote:

Originally Posted by hornet (Post 1735387)
Use:
PHP Code:

show_hudmessage(id"Your clip is at %%%d!"percent


Better
PHP Code:

show_hudmessage(id"Your clip is at %d%%!"percent


hornet 06-24-2012 18:32

Re: about percentage
 
Quote:

Originally Posted by YamiKaitou (Post 1735390)
Better
PHP Code:

show_hudmessage(id"Your clip is at %d%%!"percent


Is that by opinion or American standard? Haha :p I though % symbols usually come before the number ( regardless of pronounciation ) :D

YamiKaitou 06-24-2012 19:08

Re: about percentage
 
Quote:

Originally Posted by hornet (Post 1735403)
Is that by opinion or American standard? Haha :p I though % symbols usually come before the number ( regardless of pronounciation ) :D

Well, his original post had it behind the number, so you would think he would want it displayed that way regardless of how different countries display it

fearmelfice 06-24-2012 19:08

Re: about percentage
 
ummm... i will try it by myself first, but if i'm failed, i will go to request section :D

ok thanks to you all :)

hornet 06-24-2012 19:57

Re: about percentage
 
Quote:

Originally Posted by YamiKaitou (Post 1735424)
Well, his original post had it behind the number, so you would think he would want it displayed that way regardless of how different countries display it

I see :)



Also, fearmelfice, I forgot to mention, use floatround() rather than defining percent as a float.

fearmelfice 06-24-2012 20:03

Re: about percentage
 
okay hornet

fysiks 06-24-2012 21:16

Re: about percentage
 
Quote:

Originally Posted by Liverwiz (Post 1735270)
new Float:percent = (cs_get_weapon_ammo(id) / clipSize[weapon]) * 100 //This will get % of clip left
if(percent == 50 || percent == 10)

You are performing integer division which will give you an integer (0 in this case). Also, you can never use the comparison operator (==) with floating point numbers.


All times are GMT -4. The time now is 06:13.

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