Raised This Month: $32 Target: $400
 8% 

Solved merge tasks (?)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-11-2021 , 10:47   merge tasks (?)
Reply With Quote #1

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

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

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

public 
grenade_throw(idgidwid) {
    switch(
wid) {
        case 
CSW_HEGRENADE:
            
set_task(0.1"call_he"id)
        case 
CSW_FLASHBANG:
            
set_task(0.1"call_fb"id)
        case 
CSW_SMOKEGRENADE:
            
set_task(0.1"call_sg"id)
    }
    
    return 
PLUGIN_CONTINUE
}

public 
call_he(idgive_item(id"weapon_hegrenade")
public 
call_fb(idgive_item(id"weapon_flashbang")
public 
call_sg(idgive_item(id"weapon_smokegrenade"

Last edited by kww; 06-12-2021 at 03:09.
kww is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-11-2021 , 12:16   Re: merge tasks (?)
Reply With Quote #2

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");
    }

__________________

Last edited by Napoleon_be; 06-11-2021 at 12:16.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-12-2021 , 03:11   Re: merge tasks (?)
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
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.
In cs 1.6 i tested it w/o tasks but it gave me only flashbangs. With tasks it works better, just as I wanted

old script: https://forums.alliedmods.net/showpo...98&postcount=1

Last edited by kww; 06-12-2021 at 03:12.
kww is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-12-2021 , 18:28   Re: merge tasks (?)
Reply With Quote #5

Instead of give_item you can use cs_set_user_bpammo

You can try this, look how simple is that.
PHP Code:
#include csx
#include cstrike

public grenade_throw(idgidwid)
{
    
cs_set_user_bpammo(idwid2);

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-12-2021 at 18:33.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-13-2021 , 17:21   Re: merge tasks (?)
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Instead of give_item you can use cs_set_user_bpammo

You can try this, look how simple is that.
PHP Code:
#include csx
#include cstrike

public grenade_throw(idgidwid)
{
    
cs_set_user_bpammo(idwid2);

if only u could see the facepalm on me right now.
__________________

Last edited by Napoleon_be; 06-13-2021 at 18:17.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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 00:11.


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