Raised This Month: $ Target: $400
 0% 

set task disable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-09-2022 , 15:35   Re: set task disable
Reply With Quote #1

Why do you have all of this repetitive code?

PHP Code:
set_task(35.0"give_health"player)
set_task(70.0"give_health"player)
set_task(105.0"give_health"player)
set_task(140.0"give_health"player)
set_task(175.0"give_health"player)
set_task(210.0"give_health"player)
set_task(250.0"give_health"player)
set_task(280.0"give_health"player)
set_task(315.0"give_health"player)
set_task(350.0"give_health"player)
set_task(385.0"give_health"player)
set_task(430.0"give_health"player)
set_task(455.0"give_health"player)
set_task(490.0"give_health"player)
set_task(525.0"give_health"player
Creating tasks is an expensive operation.
Tasks can be assigned custom flags to make them work differently, e.g. make them repeat X times or until you stop them.

https://amxx-bg.info/api/amxmodx/set_task

All of the above code can be replaced with a repeating task:

Code:
set_task(40.0, "give_health", player, + TASK_GIVE_HEALTH .flags = "b")

Or one that is repeated X times:

Code:
set_task(40.0, "give_health", player, + TASK_GIVE_HEALTH .flags = "a", .repeat = 15)

Then simply stop it if you need it to:

Code:
remove_task(player + TASK_GIVE_HEALTH)

You should always avoid repetitive lines of code in your plugin.
__________________

Last edited by OciXCrom; 01-09-2022 at 15:36.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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:41.


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