Raised This Month: $ Target: $400
 0% 

Solved merge tasks (?)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-11-2021 , 22:02   Re: merge tasks (?)
Reply With Quote #3

Quote:
Originally Posted by kww View Post
is there some simple way to merge multiple tasks into one?
i want to merge three tasks and have one callable function instead of three that i have
here is nothing complex, but i just wonder if it possible
I don't see any good reason to do such a thing based on this code but yes, it's possible (note that Napoleon's implementation is flawed, see below). Can you not just give the grenade immediately (i.e. without the set_task)? I give a grenade to the user in grenade_throw() in my Day of Defeat plugin and it works flawlessly.

Quote:
Originally Posted by Napoleon_be View Post
untested

PHP Code:
#include <amxmodx>
#include <fun>
#include <csx>

new g_wid;

public 
plugin_init()
    
register_plugin("infinite_grenades""latest""kww")

public 
grenade_throw(idgidwid) {
    
g_wid wid;
    
set_task(0.1"giveGrenade"id);
}

public 
giveGrenade(id)
{
    switch(
g_wid)
    {
        case 
CSW_HEGRENADEgive_item(id"weapon_hegrenade");
        case 
CSW_FLASHBANGgive_item(id"weapon_flashbang");
        case 
CSW_SMOKEGRENADEgive_item(id"weapon_smokegrenade");
    }

You cannot put wid into a global variable and guarantee that it won't have changed by the time it is used by the called function (this is called a "race condition"). You would need to pass it as an additional argument of the task to guarantee that the function will execute with the correct data.
__________________

Last edited by fysiks; 06-11-2021 at 22:07.
fysiks is offline
 



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 02:31.


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