Raised This Month: $ Target: $400
 0% 

How to make a delay?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RelaxMazteR
Member
Join Date: Jul 2009
Location: Sweden
Old 07-21-2011 , 15:17   How to make a delay?
Reply With Quote #1

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.
RelaxMazteR is offline
Honors
Member
Join Date: Jul 2011
Old 07-21-2011 , 15:36   Re: How to make a delay?
Reply With Quote #2

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.
Honors is offline
plowed
Senior Member
Join Date: Oct 2010
Location: germany
Old 07-21-2011 , 15:52   Re: How to make a delay?
Reply With Quote #3

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. 
    



Last edited by plowed; 07-21-2011 at 15:54.
plowed is offline
Honors
Member
Join Date: Jul 2011
Old 07-21-2011 , 17:59   Re: How to make a delay?
Reply With Quote #4

Quote:
Originally Posted by plowed View Post
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.
Honors is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-21-2011 , 18:37   Re: How to make a delay?
Reply With Quote #5

[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 View Post
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).
__________________

Last edited by fysiks; 07-21-2011 at 22:16.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-21-2011 , 21:37   Re: How to make a delay?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
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 );

__________________

Last edited by Bugsy; 07-21-2011 at 23:02.
Bugsy 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 08:58.


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