Raised This Month: $ Target: $400
 0% 

id + any_defined_value in set_task()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 06-24-2012 , 11:00   id + any_defined_value in set_task()
Reply With Quote #1

OK, I'm sick of this, it made me confused.
I read in some codes and tutorials (especially Exolent's tutorial about enums):
Code:
// Top #define WhatEver 49162 public anything(id) {     set_task(0.1, "fw_fw", id + WhatEver) } public fw_fw(bla) {     id = bla - WhatEver     // Code ... }
Why do they sum the index of the player (id) with the define (WhatEver) if they, eventually, will get the same player id, and they never re-use the define.

It's just confusing!!!!
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-24-2012 , 11:10   Re: id + any_defined_value in set_task()
Reply With Quote #2

PHP Code:
set_task(0.1"fw_fw"id
This is enough, then you use

public function(id)

where id = playerid from 1 to 32

Last edited by DjOptimuS; 06-24-2012 at 11:11.
DjOptimuS is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-24-2012 , 11:14   Re: id + any_defined_value in set_task()
Reply With Quote #3

The id (3rd param.) in set_task() has to be unique, so you cannot have (actually can have, but using player IDs (1-32) in set_tasks() may turn out to be a bad idea) two or more simultaneous tasks with the same id.

Defines are usually used in cases when a plugin has several set_task() functions which are related to players (but not only). When set_task() executes a function it is possible to get player's id.

Last edited by t3hNox; 06-24-2012 at 11:21. Reason: corrected myself
t3hNox is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 06-24-2012 , 11:25   Re: id + any_defined_value in set_task()
Reply With Quote #4

Quote:
Originally Posted by t3hNox View Post
Defines are usually used in cases when a plugin has several set_task() functions which are related to players (but not only). When set_task() executes a function it is possible to get player's id.
If you can provide some examples to that, it'd be nice.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 06-24-2012 at 11:26.
pokemonmaster is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-24-2012 , 11:39   Re: id + any_defined_value in set_task()
Reply With Quote #5

i use that all the time and i remove the task when player disconnected if the task is with B flag and i never had any problems, you can set a random constant + playerid if you don't like

new const task = 32784;

and set task with the id + task
DjOptimuS is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-24-2012 , 11:42   Re: id + any_defined_value in set_task()
Reply With Quote #6

EDIT: This example I've used is misleading and is likely to fail. See post #9.

A player might have several tasks running which require their player index when ready. For example, a weapon pickup delay for both primary and secondary weapons, therefore you need 2 task identifiers, incase a player picks up a secondary weapon before his delay has expired for his primary weapon ( or vice versa ):
Code:
#define TASK_PRIMARY      1001 #define TASK_SECONDARY    1002

You add the identifier to their player index:
Code:
set_task( 5.0, "GetPrimary", id + TASK_PRIMARY ); set_task( 5.0, "GetSecondary", id + TASK_SECONDARY );

And then deduct the identifier to retain the player index once again:
Code:
public GetPrimary( id ) {     id -= TASK_PRIMARY; } public GetSecondary( id ) {     id -= TASK_SECONDARY; }

Hope that helps.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 06-24-2012 at 19:51.
hornet is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-24-2012 , 16:46   Re: id + any_defined_value in set_task()
Reply With Quote #7

Basically if you want to remove (or change) a task, you need to provide its ID. It gets problematic when you have several tasks with same ID and want to remove/change a certain task.
hleV is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 06-24-2012 , 17:22   Re: id + any_defined_value in set_task()
Reply With Quote #8

Ahhhhh, now I understood it.

Thanks all!
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-24-2012 , 19:10   Re: id + any_defined_value in set_task()
Reply With Quote #9

Quote:
Originally Posted by hornet View Post
Code:
#define TASK_PRIMARY      1001 #define TASK_SECONDARY    1002
You should space them with the max players available (ie. 1001, 1033, 1065, etc.)

Usually you will see authors use an enum to do this:
Code:
enum += 32
{
   TASK_ONE = 1001,
   TASK_TWO,
   TASK_THREE,
   //etc.
}
If you used your examples, primary task for id 2 (1001+2) would have the same task id as secondary task for id 1 (1002+1). This would only be problematic if you need to check, change, or remove tasks though.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-24-2012 , 19:19   Re: id + any_defined_value in set_task()
Reply With Quote #10

Quote:
Originally Posted by Emp` View Post
You should space them with the max players available (ie. 1001, 1033, 1065, etc.)

Usually you will see authors use an enum to do this:
Code:
enum += 32
{
   TASK_ONE = 1001,
   TASK_TWO,
   TASK_THREE,
   //etc.
}
If you used your examples, primary task for id 2 (1001+2) would have the same task id as secondary task for id 1 (1002+1). This would only be problematic if you need to check, change, or remove tasks though.
Oh, I never actually thought of that. Somehow I survived without functional errors in my concept so far.
Thanks
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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 09:24.


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