Raised This Month: $ Target: $400
 0% 

Help with a simple script.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Davidos
Senior Member
Join Date: Feb 2005
Old 12-01-2007 , 17:38   Help with a simple script.
Reply With Quote #1

Code:
/*AMXMODX script, made out of pure randomeness*/ #include <amxmodx> #include <engine> #include <fun> public plugin_init() {     register_plugin("Realregen","1.0","Dave")     register_event("ResetHUD", "HealthOn", "be") } public HealthOn(id) {     set_task(10.0,"Heal",id,"",0,"b")     return PLUGIN_CONTINUE } public Heal(id) {     if(!is_user_alive(id))     {         return PLUGIN_HANDLED     }     new health = get_user_health(id)     if(health>=100)     {         return PLUGIN_HANDLED     }     new speed = get_speed(id)     if(speed>=250)     {         new newhealths = health + 1         set_user_health(id,newhealths)         return PLUGIN_HANDLED     }     if(speed>25 && speed<250)     {         new newhealthm = health + 2         set_user_health(id,newhealthm)         return PLUGIN_HANDLED     }     else     {         new newhealthf = health + 3         set_user_health(id,newhealthf)         return PLUGIN_HANDLED     }     return PLUGIN_HANDLED }

This plugin is made so a certain user gets the set ammount of HP every 10 seconds, depending on movement speed etc. etc.

The problem is, for some reason, when a user dies and respawns, the HP will regain 'TWICE' the speed.

For example,
User 1 gets hit, he receives a regeneration bonus of 3 hp per 10 seconds for standing still (resting)

User 1 dies even with the health regen.

User 1 respawns, plays some more and gets hit again...
He receives a regeneration bonus of 3 hp per 5 seconds for standing still, and 3 hp more after another 5 seconds.

Anyone know how to fix the problem? I tried adding a bool function, but as usual it freaked out on me -.-;

Thanks in advance,
Dave


On a side note, this has no rush at all. I know how to do it so it actually works, but I wanna try stuff this way.
__________________
Roar.

Last edited by Davidos; 12-01-2007 at 18:42.
Davidos is offline
aznbeau1121g
Member
Join Date: Jan 2006
Old 12-01-2007 , 20:52   Re: Help with a simple script.
Reply With Quote #2

i'm not a good scripter so i can't really help u but i can give suggestion this might help, not sure if it works, change it alittle

Code:
new bool:g_heal
Code:
register_event("EventDeath", "Event_Death", "a")
register_event("EventAlive", Event_Alive", "ab")
Code:
public Event_Death(id)
{
     g_heal[id] = false
     }
     PLUGIN_CONTINUE
}
public Event_Alive(id)
{
     g_heal[id] = true
     }
     PLUGIN_CONTINUE
}
aznbeau1121g is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 12-02-2007 , 00:12   Re: Help with a simple script.
Reply With Quote #3

The reason why is that ResetHUD is called 2 times after user respawn (approx in 1 sec interval).

You can either do this:

Code:
public HealthOn(id) {     if (!task_exists(id)) set_task(10.0,"Heal",id,"",0,"b")     return PLUGIN_CONTINUE }

or set your healing task from client_connect / client_putinserver, not from respawn event.

UPDATE: You can also remove task on death event:

Code:
public plugin_init()   {     // blah blah     register_event("DeathMsg", "on_shit_happens", "a");     // more blah blah   } public on_shit_happens()   {     new id = read_data(2);     remove_task(id);   }

... but I would use 2. solution.
__________________

Last edited by alien; 12-02-2007 at 00:15.
alien is offline
Send a message via ICQ to alien
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-02-2007 , 05:05   Re: Help with a simple script.
Reply With Quote #4

Code:
public HealthOn(id) {     if( ! task_exixts(id) )         set_task(10.0, "Heal", id, _, _, "b") }
ConnorMcLeod is offline
Davidos
Senior Member
Join Date: Feb 2005
Old 12-02-2007 , 08:34   Re: Help with a simple script.
Reply With Quote #5

Like I said, I wanted to try it with register event.
I already knew how to do it in other ways.
No problem anyway.

[The plugin has been finished.]
__________________
Roar.

Last edited by Davidos; 12-02-2007 at 11:26.
Davidos is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-02-2007 , 08:39   Re: Help with a simple script.
Reply With Quote #6

Quote:
Originally Posted by Davidos View Post
The problem is, for some reason, when a user dies and respawns, the HP will regain 'TWICE' the speed.
[...]
Anyone know how to fix the problem?
ConnorMcLeod is offline
Davidos
Senior Member
Join Date: Feb 2005
Old 12-02-2007 , 08:46   Re: Help with a simple script.
Reply With Quote #7

What, do you want me to make a second thread for one plugin? >.>;

Quote:
Originally Posted by title
Help with a simple script.
So there. >d
__________________
Roar.

Last edited by Davidos; 12-02-2007 at 09:32.
Davidos 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 11:07.


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