Raised This Month: $ Target: $400
 0% 

[Help] with easy condition


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
avril-lavigne
Banned
Join Date: Apr 2009
Old 05-08-2011 , 00:29   [Help] with easy condition
Reply With Quote #1

Hi, here is cheap_suit regeneration Health function
I add armour. but it has a bug.
when your hp / ap = 200 and enemy hits you. your hp and ap immediately goes to 200. ( should be 10 each 2 secs )


Code:
public Task_HealthRegen(id) 
{  
	if(!is_user_alive(id) || !is_user_connected(id) || !g_HPRegen[id] || !g_HPRegen[id]) 
	{
		if(task_exists(id)) {
			remove_task(id)
		}
		return PLUGIN_CONTINUE
	}
	
	new iHealth = get_user_health(id)
           new iArmor = get_user_armor(id)
	if(iHealth < 200 || iArmor < 200)  // dont know may be && ?
       
	{
		message_begin(MSG_ONE, get_user_msgid("ScreenFade"), { 0, 0, 0 }, id)
		write_short(1<<10) 
		write_short(1<<10)
		write_short(1<<12) 
		write_byte(0) 
		write_byte(0)
		write_byte(255)
		write_byte(50)
		message_end()
		client_cmd(id,"speak shopmenu3/wearoff.wav")
		iHealth += RegenPoints
                       iArmor += RegenPoints
		set_user_health(id, iHealth) 
                set_user_armor(id, iArmor)
// here		if(get_user_health(id) > 200 || get_user_armor(id) > 200) {
		set_user_health(id, 200)
                        set_user_armor(id, 200)
		}           

	}
	return PLUGIN_CONTINUE
}
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-08-2011 , 00:32   Re: [Help] with easy condition
Reply With Quote #2

Instead you can just use the min native:
Code:
set_user_health( id, min( iHealth, 200 ) )
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-08-2011 , 00:37   Re: [Help] with easy condition
Reply With Quote #3

I believe that you need to separate this into two separate if statements:

PHP Code:
        if(get_user_health(id) > 200 || get_user_armor(id) > 200)
        {
            
set_user_health(id200)
            
set_user_armor(id200)
        } 
EDIT: Guess I should refresh before replying . Emp's solution would completely replace this if statement.
__________________

Last edited by fysiks; 05-08-2011 at 00:40.
fysiks is offline
avril-lavigne
Banned
Join Date: Apr 2009
Old 05-08-2011 , 01:59   Re: [Help] with easy condition
Reply With Quote #4

thanks , one time I did so, than deleted. will try again
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
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:21.


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