AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   id + any_defined_value in set_task() (https://forums.alliedmods.net/showthread.php?t=188267)

pokemonmaster 06-24-2012 11:00

id + any_defined_value in set_task()
 
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!!!!

DjOptimuS 06-24-2012 11:10

Re: id + any_defined_value in set_task()
 
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

t3hNox 06-24-2012 11:14

Re: id + any_defined_value in set_task()
 
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.

pokemonmaster 06-24-2012 11:25

Re: id + any_defined_value in set_task()
 
Quote:

Originally Posted by t3hNox (Post 1735175)
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. :mrgreen:

DjOptimuS 06-24-2012 11:39

Re: id + any_defined_value in set_task()
 
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

hornet 06-24-2012 11:42

Re: id + any_defined_value in set_task()
 
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.

hleV 06-24-2012 16:46

Re: id + any_defined_value in set_task()
 
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.

pokemonmaster 06-24-2012 17:22

Re: id + any_defined_value in set_task()
 
Ahhhhh, now I understood it.

Thanks all! :up:

Emp` 06-24-2012 19:10

Re: id + any_defined_value in set_task()
 
Quote:

Originally Posted by hornet (Post 1735197)
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.

hornet 06-24-2012 19:19

Re: id + any_defined_value in set_task()
 
Quote:

Originally Posted by Emp` (Post 1735428)
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 :)


All times are GMT -4. The time now is 06:15.

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