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

set_task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-01-2016 , 11:07   set_task
Reply With Quote #1

Something that i'm still not fully familiar with is set_task.

I'm currently creating an AIO plugin which will contain several tasks. This means, that every task should have a different id. To do this, you could define tasknames each with a different value.

The only thing i don't know is, when should i distract id with the task id?

I'll give you some examples.

I'm really not willing to use godmode as spawn protection. What i wanna do is set a task when the player spawns and call Ham_TakeDamage.

Within Ham_TakeDamage, i wanna check if that task exists, if it does, block the damage.

PHP Code:
#define PROTECTTASK 1996 
PHP Code:
RegisterHam(Ham_Spawn"player""FwPlayerSpawnPost"1)
RegisterHam(Ham_TakeDamage"player""FwPlayerTakeDamagePre"0
PHP Code:
public FwPlayerSpawnPost(id) {
    if(!
get_pcvar_num(pCvarPlugin) || !get_pcvar_num(pCvarSpawnProtection)) {
        return 
PLUGIN_HANDLED
    
}
    
    new 
Float:fProtectTime get_pcvar_float(pCvarSpawnProtectionTime)
    
    
FwPlayerTakeDamagePre(id)
    
set_task(fProtectTime"StopSpawnProtection"id PROTECTTASK)
}

public 
FwPlayerTakeDamagePre(id) {
    if(!
get_pcvar_num(pCvarPlugin) || !get_pcvar_num(pCvarSpawnProtection)) {
        return 
PLUGIN_HANDLED
    
}
    
    if(
task_exists(id PROTECTTASK)) {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

public 
StopSpawnProtection(id) {
    
id id PROTECTTASK // Is this what i should do?

__________________

Last edited by Napoleon_be; 09-01-2016 at 11:11.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 09-01-2016 , 11:11   Re: set_task
Reply With Quote #2

PHP Code:
public StopSpawnProtection(taskid
{
    new 
id taskid PROTECTTASK

I'm not sure if this is what you wanted to ask.
__________________

Last edited by gabuch2; 09-01-2016 at 11:13.
gabuch2 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-01-2016 , 11:12   Re: set_task
Reply With Quote #3

Compiler will throw error since id isn't declared
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 09-01-2016 , 11:13   Re: set_task
Reply With Quote #4

Forgot "new"

edited it
__________________

Last edited by gabuch2; 09-01-2016 at 11:13.
gabuch2 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-01-2016 , 11:14   Re: set_task
Reply With Quote #5

Thanks, that's the only thing? Further i don't know what i should do within that function since i don't need to do anything except for that. It will always throw a warning that id is never used.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 09-01-2016 , 11:27   Re: set_task
Reply With Quote #6

Well, with the way you wanted to provide protection there's not really anything else to do, maybe displaying a message to the player that its spawn protection is no longer active?

client_print(id, ... etc etc
__________________

Last edited by gabuch2; 09-01-2016 at 11:28.
gabuch2 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-01-2016 , 11:48   Re: set_task
Reply With Quote #7

After all, you don't need a task. Simply use get_gametime()
About the substract thing, you set the taskid to id + PROTECTTASK. If in task callback you want to do something with the player index, you can obtain it by substracting -PROTECTTASK, so you get only id. If you don't need the player index in that task, then don't add id to PROTECTTASK and use only that as task index.

PHP Code:
public something(id)
{
     
set_task(..., ..., SomeRandomNumber id)
}

public ...(
TaskIndex)
{
    new 
id TaskIndex SomeRandomNumber

That's basically: SomeRandomNumber + id - SomeRandomNumber = id.
__________________

Last edited by HamletEagle; 09-01-2016 at 11:53.
HamletEagle is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 09-01-2016 , 11:57   Re: set_task
Reply With Quote #8

Code:
public StopSpawnProtection(id) {}

Return values for ham forwards are:
Code:
HAM_IGNORED  /**< Calls target function, returns normal value */ HAM_HANDLED  /**< Tells the module you did something, still calls target function and returns normal value */ HAM_OVERRIDE    /**< Still calls the target function, but returns whatever is set with SetHamReturn*() */ HAM_SUPERCEDE   /**< Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */
PartialCloning is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-02-2016 , 03:55   Re: set_task
Reply With Quote #9

Quote:
Originally Posted by Shattered Heart Lynx View Post
Well, with the way you wanted to provide protection there's not really anything else to do, maybe displaying a message to the player that its spawn protection is no longer active?

client_print(id, ... etc etc
Quote:
Originally Posted by HamletEagle View Post
After all, you don't need a task. Simply use get_gametime()
About the substract thing, you set the taskid to id + PROTECTTASK. If in task callback you want to do something with the player index, you can obtain it by substracting -PROTECTTASK, so you get only id. If you don't need the player index in that task, then don't add id to PROTECTTASK and use only that as task index.

PHP Code:
public something(id)
{
     
set_task(..., ..., SomeRandomNumber id)
}

public ...(
TaskIndex)
{
    new 
id TaskIndex SomeRandomNumber

That's basically: SomeRandomNumber + id - SomeRandomNumber = id.
Quote:
Originally Posted by PartialCloning View Post
Code:
public StopSpawnProtection(id) {}


Return values for ham forwards are:
Code:
HAM_IGNORED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;/**< Calls target function, returns normal value */ HAM_HANDLED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;/**< Tells the module you did something, still calls target function and returns normal value */ HAM_OVERRIDE&nbsp;&nbsp;&nbsp;&nbsp;/**< Still calls the target function, but returns whatever is set with SetHamReturn*() */ HAM_SUPERCEDE&nbsp;&nbsp;&nbsp;&nbsp;/**< Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */
@Shattered Heart Lynx, that's probably the only thing i could do yes.

@HamletEagle, I'm not really familiar with get_gametime(), although thanks for the explanation, got me further.

@PartialCloning, thanks for reminding, i always forget that >.<
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 09-02-2016 , 06:15   Re: set_task
Reply With Quote #10

It should look something like this, I think:

PHP Code:
new Float:SafeTime[33
PHP Code:
RegisterHam(Ham_Spawn"player""FwPlayerSpawnPost"1)
RegisterHam(Ham_TakeDamage"player""FwPlayerTakeDamagePre"0
PHP Code:
public FwPlayerSpawnPost(id) {
    if(
get_pcvar_num(pCvarPlugin) && get_pcvar_num(pCvarSpawnProtection))
        
SafeTime[id] = get_gametime() + get_pcvar_float(pCvarSpawnProtectionTime)

    return 
HAM_IGNORED 
}

public 
FwPlayerTakeDamagePre(idinflictorattackerFloat:damagedmgbits) {
    if(
get_pcvar_num(pCvarPlugin) && get_pcvar_num(pCvarSpawnProtection) && SafeTime[id] >= get_gametime())
        return 
HAM_SUPERCEDE
    
    
return HAM_IGNORED

Returning HAM_SUPERCEDE on Ham_TakeDamage causes damage to not happen (there's multiple ways to ignore damage with Ham_TakeDamage).
__________________
Bad_Bud 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 07:41.


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