AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set_task question. (https://forums.alliedmods.net/showthread.php?t=208177)

Unkolix 02-10-2013 15:46

Set_task question.
 
I've seen Arkshines advice and I would like to ask if my code is correct. Arkshines post:
Quote:

Originally Posted by Arkshine (Post 996696)
Add a random number after id.
Code:
set_task(0.1,"event1",id + 85447,"",0,"b")

In your function, remove this number to get the id :

Code:
public event1 ( TaskID ) {      new id = TaskID - 85447; }

And to remove the task :

Code:
remove_task( id + 85447 );



Is this correct?
PHP Code:

public client_putinserver(id)
{
    if (!
task_exists(id 1)) set_task(30.0"PrintText"id 1//Checks if task already exist, if not print text set in public PrintText
    
if (!task_exists(id 2)) set_task(600.0"AuthorText"id 2//Checks if task already exist, if not print text set in public AuthorText



Torge 02-10-2013 16:28

Re: Set_task question.
 
One question: What does id + 1 ?

Unkolix 02-10-2013 16:59

Re: Set_task question.
 
It kinda makes the task an unique id, so when you check it or remove the task you won't remove all the tasks you've coded.

Torge 02-10-2013 17:03

Re: Set_task question.
 
Ok, thanks, code looks very pretty.

YamiKaitou 02-10-2013 17:41

Re: Set_task question.
 
When using a taskid, make them already 32 numbers apart

Bugsy 02-10-2013 17:50

Re: Set_task question.
 
Quote:

Originally Posted by YamiKaitou (Post 1891972)
When using a taskid, make them already 32 numbers apart

Yes this is important to keep task-id's unique. Make each type of task have a range that will not mix with any other type of task.

This could happen:

PHP Code:

public client_putinserver(id)
{
    if (!
task_exists(id 1)) set_task(30.0"PrintText"id 1//Checks if task already exist, if not print text set in public PrintText
    
if (!task_exists(id 2)) set_task(600.0"AuthorText"id 2//Checks if task already exist, if not print text set in public AuthorText


Player id 1 task-id set at ( id + 2 ) = 1 + 2 = [3]
Player id 2 task-id set at ( id + 1 ) = 2 + 1 = [3] <- Same task-id already exists for player 1.

Try something like:

PHP Code:

const TaskPrint 5000;
const 
TaskAuthor 5100;

public 
client_putinserver(id)
{
    if (!
task_exists(id TaskPrint)) set_task(30.0"PrintText"id TaskPrint//Checks if task already exist, if not print text set in public PrintText
    
if (!task_exists(id TaskAuthor)) set_task(600.0"AuthorText"id TaskAuthor//Checks if task already exist, if not print text set in public AuthorText



Unkolix 02-11-2013 00:17

Re: Set_task question.
 
Quote:

Originally Posted by Bugsy (Post 1891982)
Yes this is important to keep task-id's unique. Make each type of task have a range that will not mix with any other type of task.

This could happen:

PHP Code:

public client_putinserver(id)
{
    if (!
task_exists(id 1)) set_task(30.0"PrintText"id 1//Checks if task already exist, if not print text set in public PrintText
    
if (!task_exists(id 2)) set_task(600.0"AuthorText"id 2//Checks if task already exist, if not print text set in public AuthorText


Player id 1 task-id set at ( id + 2 ) = 1 + 2 = [3]
Player id 2 task-id set at ( id + 1 ) = 2 + 1 = [3] <- Same task-id already exists for player 1.

Try something like:

PHP Code:

const TaskPrint 5000;
const 
TaskAuthor 5100;

public 
client_putinserver(id)
{
    if (!
task_exists(id TaskPrint)) set_task(30.0"PrintText"id TaskPrint//Checks if task already exist, if not print text set in public PrintText
    
if (!task_exists(id TaskAuthor)) set_task(600.0"AuthorText"id TaskAuthor//Checks if task already exist, if not print text set in public AuthorText



Wow, thanks! I didn't knew that it can contain letters!

fysiks 02-11-2013 01:49

Re: Set_task question.
 
Quote:

Originally Posted by Unkolix (Post 1892125)
I didn't knew that it can contain letters!

What in the world does that mean? Bugsy didn't post anything about using "letters" anywhere.

Backstabnoob 02-11-2013 08:35

Re: Set_task question.
 
Quote:

Wow, thanks! I didn't knew that it can contain letters!
He's using a constant. At compile time, this effectively becomes:
Code:
if (!task_exists(id + 5000)) set_task(30.0, "PrintText", id + 5000) if (!task_exists(id + 5100)) set_task(600.0, "AuthorText", id + 5100)


All times are GMT -4. The time now is 20:35.

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