AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make a delay? (https://forums.alliedmods.net/showthread.php?t=162681)

RelaxMazteR 07-21-2011 15:17

How to make a delay?
 
Hey! I want to know how I can make a delay for 2 seconds when calling a function. I has tried to make a task but I cant get it to work with my value.

PHP Code:

public handlemenu(idmenuitem){
    new 
szItem[33], _accesscallback;
    
menu_item_getinfo(menuitem_access""0szItem32callback);

    
load(id1szItem);
}

load(idnumber, const szConfigsName[])
{    
    new 
szPath[129];
    
format(szPath128"%s.test"szConfigsName);


NOTE! I has deleted some code so it will be easier to read!
Hope I have posted in the right forum.

Honors 07-21-2011 15:36

Re: How to make a delay?
 
Try to do a set_task with params id+1+szItem ?

Then you can do : id -= (1+szItem) ; szItem -= (id+1) ; number -= (id+szItem)

I don't know if that work.

plowed 07-21-2011 15:52

Re: How to make a delay?
 
I think you can do it here too http://forums.alliedmods.net/showthread.php?t=162085
look at fysiks last post

smth like this

PHP Code:

public function() 
    static 
iTimeCmdIsAllowed 
    
if( get_systime() > iTimeCmdIsAllowed 
    { 
        
//Your Code
    

    else 
    { 
        
// 10 seconds has not passed since command was last used. 
    




Honors 07-21-2011 17:59

Re: How to make a delay?
 
Quote:

Originally Posted by plowed (Post 1515537)
I think you can do it here too http://forums.alliedmods.net/showthread.php?t=162085
look at fysiks last post

smth like this

PHP Code:

public function() 
    static 
iTimeCmdIsAllowed 
    
if( get_systime() > iTimeCmdIsAllowed 
    { 
        
//Your Code
    

    else 
    { 
        
// 10 seconds has not passed since command was last used. 
    




I think you are wrong. He doesn't want to do that.

fysiks 07-21-2011 18:37

Re: How to make a delay?
 
[QUOTE=RelaxMazteR;1515523]Hey! I want to know how I can make a delay for 2 seconds when calling a function. I has tried to make a task but I cant get it to work with my value.

PHP Code:

// Code removed.  See Bugsy's code below.
// I made a couple errors. 

Quote:

Originally Posted by plowed (Post 1515537)
I think you can do it here too http://forums.alliedmods.net/showthread.php?t=162085
look at fysiks last post

Nope, he just wants to delay the task. The code I presented there is to see if a command is allowed (depending on how long ago the last usage was).

Bugsy 07-21-2011 21:37

Re: How to make a delay?
 
Quote:

Originally Posted by fysiks (Post 1515632)
Using set_task() is the correct action to do what you want. Try this:

PHP Code:

public handlemenu(idmenuitem)
{
    new 
szItem[33], _accesscallback;
    
menu_item_getinfo(menuitem_access""0szItem32callback);

    
load(id1szItem);
    
set_task(2.0"load"12345szItemstrlen(szItem)+1)

}

load(idszConfigsName[])
{
    new 
szPath[129];
    
format(szPath128"%s.test"szConfigsName);




Nope, he just wants to delay the task. The code I presented there is to see if a command is allowed (depending on how long ago the last usage was).

There are a few problems with that code.

1. Functions called by set_task() must be public.
2. The load() function params are in the wrong order. Data is passed first followed by task-id when called by set_task.
3. Use sizeof() instead of strlen(), and charsmax() instead of size - 1.
4. Use formatex() when you are not passing the destination string as a param.
5. If you need to pass multiple params through set_task(), you must pack them all into the same array. You needing only to pass a number and string is easy since you can use the first cell to store the number and the remainder for the string. You can pack a lot of different data if needed, though.
6. You are calling load() with 3 params while it only has 2 in the declaration.

Try this, let me know if you need any adjustments.
PHP Code:

public handlemenuid menu item )
{
    new 
szItem34 ] , _access callback;
    
menu_item_getinfomenu item _access "" szItem] , charsmaxszItem ) - callback );

    
//Passed as "number" to load function
    
szItem] = 2468;
    
copyszItem] , charsmaxszItem ) - "Test String" );
    
    
loadszItem ,  id );
    
set_task2.0 "load" 12345 szItem sizeofszItem ) );


public 
load( const szData34 ] , id )
{
    new 
szPath129 ] , iNumber;
    
    
iNumber szData];
    
formatexszPath charsmaxszPath ) , "%s.test" szData] );

    
//Check that the data made it correctly.
    
server_print"id=%d Number=%d String=%s Path=%s" id iNumber szData] , szPath );




All times are GMT -4. The time now is 01:09.

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