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

Solved pass data to set_task function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Watermelonnable
Member
Join Date: Feb 2017
Old 12-08-2019 , 15:43   pass data to set_task function
Reply With Quote #1

So I want to delay a function inside an event and I'm going to use set_task for this. The problem is that the function delayed needs to be given a player ID which I have in the "set_task" scope but I don't know how to pass it. Any help here, please?

Thus far, this is what I've tried:

PHP Code:
public cswa_damage(weapon_idvictimattackerFloat:damage)
{
    if (
get_weapon_edict(weapon_idREPL_CSWA_ITEMID) == g_iItemID) {
        static 
name[2][32];
        new 
callbackData[1];
        
callbackData[0] = victim;
        
get_user_name(victimname[1], charsmax(name[]));
        
set_task(4.0"KillPlayer"name[1], callbackData);
    }
}

public 
KillPlayer(id)
{
    if (
is_user_alive(id)) {
        
user_kill(id);
    }


Last edited by Watermelonnable; 12-10-2019 at 07:29.
Watermelonnable is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 12-08-2019 , 16:00   Re: pass data to set_task function
Reply With Quote #2

https://www.amxmodx.org/api/amxmodx/set_task

you dont need all this, you can simply do:
PHP Code:
public cswa_damage(weapon_idvictimattackerFloat:damage)
{
    if(
get_weapon_edict(weapon_idREPL_CSWA_ITEMID) == g_iItemID)
    {
        
set_task(4.0"KillPlayer"victim);
    }
}

public 
KillPlayer(id)
{
    if(
is_user_alive(id))
    {
        
user_kill(id);
    }

ZaX is offline
Old 12-08-2019, 16:08
DjSoftero
This message has been deleted by DjSoftero.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-08-2019 , 16:10   Re: pass data to set_task function
Reply With Quote #3

You can also pass more data if needed.
PHP Code:
new MoreData];
MoreData] = 123;
MoreData] = 456;
MoreData] = 789;
    
set_task1.0 "Func" id MoreData sizeofMoreData ) );


public 
Func( const MoreData] , id )
{
    
server_print"id=%d MoreData[0]=%d MoreData[1]=%d MoreData[2]=%d" id MoreData] , MoreData] , MoreData] );

__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-08-2019 , 16:15   Re: pass data to set_task function
Reply With Quote #4

@DjSoftero, you would always use sizeof() in set_task() since you are not formatting/manipulating a string. charsmax() returns sizeof() - 1, so using charsmax() on an array sized to 1 would be 0, meaning no data is passed. Your code is wrong and will cause confusion.
__________________

Last edited by Bugsy; 12-08-2019 at 16:16.
Bugsy is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 12-08-2019 , 16:23   Re: pass data to set_task function
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
@DjSoftero, you would always use sizeof() in set_task() since you are not formatting/manipulating a string. charsmax() returns sizeof() - 1, so using charsmax() on an array sized to 1 would be 0, meaning no data is passed. Your code is wrong and will cause confusion.
fair enough. lost my touch with it.
DjSoftero is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 12-08-2019 , 20:00   Re: pass data to set_task function
Reply With Quote #6

little offtopic but @Bugsy, is it possible to pass parameter(s) with register_clcmd ?

if we lets say have

public test( id, bool: print )

to have smth like: register_clcmd( "say /test", test, 1 ) ?

thanks in advance!
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-08-2019 , 20:49   Re: pass data to set_task function
Reply With Quote #7

No, but it's still doable.
PHP Code:
register_clcmd"say" "SayFunc" );

public 
SayFuncid )
{
    new 
szArgs194 ] , szCmd32 ];
    
    
read_argsszArgs charsmaxszArgs ) );
    
remove_quotesszArgs );
    
argbreakszArgs szCmdcharsmaxszCmd ) , szArgs ,  charsmaxszArgs ) );
    
    if ( 
equaliszCmd "/test" ) )
    {
        
//szCmd = the command
        //szArgs = the text said after '/test'  eg. "/test 1234", szArgs would hold 1234
    
}

__________________
Bugsy is offline
Watermelonnable
Member
Join Date: Feb 2017
Old 12-09-2019 , 10:27   Re: pass data to set_task function
Reply With Quote #8

Thank you guys for your help. I understand it better now The plugin compiled fine, I'm gonna test it now.
Watermelonnable is offline
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 08:21.


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