AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with a simple script. (https://forums.alliedmods.net/showthread.php?t=63854)

Davidos 12-01-2007 17:38

Help with a simple script.
 
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.

aznbeau1121g 12-01-2007 20:52

Re: Help with a simple script.
 
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
}


alien 12-02-2007 00:12

Re: Help with a simple script.
 
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.

ConnorMcLeod 12-02-2007 05:05

Re: Help with a simple script.
 
Code:
public HealthOn(id) {     if( ! task_exixts(id) )         set_task(10.0, "Heal", id, _, _, "b") }

Davidos 12-02-2007 08:34

Re: Help with a simple script.
 
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.]

ConnorMcLeod 12-02-2007 08:39

Re: Help with a simple script.
 
Quote:

Originally Posted by Davidos (Post 558956)
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?


Davidos 12-02-2007 08:46

Re: Help with a simple script.
 
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


All times are GMT -4. The time now is 11:07.

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