AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved merge tasks (?) (https://forums.alliedmods.net/showthread.php?t=332971)

kww 06-11-2021 10:47

merge tasks (?)
 
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"


Napoleon_be 06-11-2021 12:16

Re: merge tasks (?)
 
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");
    }



fysiks 06-11-2021 22:02

Re: merge tasks (?)
 
Quote:

Originally Posted by kww (Post 2749513)
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 (Post 2749522)
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.

kww 06-12-2021 03:11

Re: merge tasks (?)
 
Quote:

Originally Posted by fysiks (Post 2749550)
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

Natsheh 06-12-2021 18:28

Re: merge tasks (?)
 
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);



Napoleon_be 06-13-2021 17:21

Re: merge tasks (?)
 
Quote:

Originally Posted by Natsheh (Post 2749588)
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.


All times are GMT -4. The time now is 02:31.

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