AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hold execution for specific time (https://forums.alliedmods.net/showthread.php?t=183451)

Liverwiz 04-21-2012 23:03

Hold execution for specific time
 
I'm trying to pause the execution of my program for a few seconds every once in a while. I remember it using the set_task function....but as the night grows later everything seems a bit more cryptic.

How would i pause execution of my program for, say, 0.5 seconds, then continue on with the execution?

fysiks 04-22-2012 02:43

Re: Hold execution for specific time
 
You can't literally "pause the execution" of your plugin. set_task() is what you would use to execute a function after a certain amount of time. You will have to be more specific to get better answers. Explain exactly what you are trying to do. Also, if you have code, then show your code.

Liverwiz 04-22-2012 12:40

Re: Hold execution for specific time
 
My code:
PHP Code:

    new iSsCount 5
    
new params[1]; params[0] = id
    set_task
(0.3"ssTask"0params1"a"iSsCount

i made this post before figured the above code out. That is what i put, and so far it compiled fine, just have yet to test it. I know that's sub par code concepts, but its the easiest way of doing it for right now. Later i'll be fixing it up to be less retarded. I just wanted everything easily editable. at the top of my function. Few minutes i'll edit and report.

[EDIT] it works!! apparently i CAN figure things out.....anyone looking for answers in this thread...please note:

PHP Code:

 new params[] = {id

WILL NOT work in this case. something about it needing to be a constant expression. i'd assume it doesn't trust the programmer to be able to NOT change a variable and care that it'll be wrong later after it passes the value. but i'm sure someone with a little more experience could add to that, if they care enough.

fysiks 04-22-2012 14:20

Re: Hold execution for specific time
 
Use it like this:

PHP Code:

set_task(0.3"ssTask",id, .flags="a", .repeat=iSsCount)


public 
ssTask(id)
{
    
// stuff here



Liverwiz 04-22-2012 15:19

Re: Hold execution for specific time
 
so the id parameter in the set_task is the user's id?

say i wanted to send another argument to the ssTask function, would i put that in the parameters[] argument?

PHP Code:

new sz_command[] = "+jump"
set_task(0.3"ssTask"idsz_command"a"iSsCount)

public 
ssTask(idsz_command[])
    
client_cmd(idsz_command

or what is that "parameters" argument there for?

and, to get a better understanding, the '.' before 'flags' and 'repeat' do what?

fysiks 04-22-2012 15:27

Re: Hold execution for specific time
 
Quote:

Originally Posted by Liverwiz (Post 1694621)
so the id parameter in the set_task is the user's id?

Not necessarily but it can be and often is. Third parameter of set_task() is the task id but if you are only having one task per person you can use "id" as the task id.

Quote:

Originally Posted by Liverwiz (Post 1694621)
say i wanted to send another argument to the ssTask function, would i put that in the parameters[] argument?

Yes.

Quote:

Originally Posted by Liverwiz (Post 1694621)
PHP Code:

new sz_command[] = "+jump"
set_task(0.3"ssTask"idsz_command"a"iSsCount)

public 
ssTask(idsz_command[])
    
client_cmd(idsz_command

or what is that "parameters" argument there for?

I believe you need to do it like this:

PHP Code:

    new sz_command[6] = "+jump"
    
set_task(0.3"ssTask"idsz_commandsizeof(sz_command), "a"iSsCount)

public 
ssTask(sz_command[], id)  // this needs to be like this iirc.
{
    
client_cmd(idsz_command)



Quote:

Originally Posted by Liverwiz (Post 1694621)
and, to get a better understanding, the '.' before 'flags' and 'repeat' do what?

They allow you to submit parameters to the function out of order and skip others as long as the ones you skip have default values.

Liverwiz 04-22-2012 16:36

Re: Hold execution for specific time
 
Quote:

Originally Posted by fysiks (Post 1694625)
PHP Code:

    new sz_command[6] = "+jump"
    
set_task(0.3"ssTask"idsz_commandsizeof(sz_command), "a"iSsCount)

public 
ssTask(sz_command[], id)  // this needs to be like this iirc.
{
    
client_cmd(idsz_command)



THANKS! i put that in and it compiled correctly. I'll test it when i can get a chance.


Quote:

Originally Posted by fysiks (Post 1694625)
They allow you to submit parameters to the function out of order and skip others as long as the ones you skip have default values.

neato, does this work for any function? including one of the functions within my code, or is that just for amxx stock functions?

fysiks 04-22-2012 16:48

Re: Hold execution for specific time
 
Quote:

Originally Posted by Liverwiz (Post 1694673)
neato, does this work for any function? including one of the functions within my code, or is that just for amxx stock functions?

I think it's a Pawn thing so I would imagine it would work for your custom functions too. Try it out.

Liverwiz 04-22-2012 17:26

Re: Hold execution for specific time
 
didn't work when i tried to compile it. my code.....

PHP Code:

public plugin_init()
{
        
register_plugin("YourMom""Eats""Vegitables")
    
makeObject("ben", .steamID[]="halla"5, .weaponIndx=24)
}
public 
makeObject(name[], nameIndxsteamID[], steamIDIndxweapon[], weaponIndx)
{
    new 
tallest
    
if(nameIndx steamIDIndx && nameIndx weaponIndx)
        
tallest nameIndx
    
else if(steamIDIndx nameIndx && steamIDIndx weaponIndx)
        
tallest steamIDIndx
    
else if(weaponIndx steamIDIndx && weaponIndx nameIndx)
        
tallest weaponIndx
    
else
        
tallest 1
    
new object[3][++tallest]
    
    
object[0] = name[]
    
object[1] = steamID[]
    
object[2] = weapon[]
    return 
object


threw errors all on the isntantiation line..
Code:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : error 001: expected token: "=", but found "["
C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : warning 215: expression has no effect
C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : warning 215: expression has no effect
C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Brandon\My Documents\Downloads\pstudio-0.8.3\temp745.sma(63) : fatal error 107: too many error messages on one line

Compilation aborted.
4 Errors.
Could not locate output file C:\Documents and Settings\Brandon\My Documents\AMXX scripts\liver_sixteenK.amx (compile failed).

Compilation Time: 0.63 sec

i'd say there's some special headers that need to go on the function, or code within it to make that happen. possible variable declarations? who kows....

P.S. i'm aware that code wouldn't run properly, but it would be runtime errors if executed, not compilation errors as it shows here.

fysiks 04-23-2012 00:37

Re: Hold execution for specific time
 
  • Any argument that you leave out must have a default value assigned (I mentioned this above).
  • The 5 can't just be in the middle of nowhere. Once you use the .arg method there is no longer order associated with the following arguments.
  • Public functions can't have default values. Make it local.
  • You can't dynamically size arrays like that. You must used constants. There are dynamic arrays but they wouldn't help here since you are sizing for string lengths.


All times are GMT -4. The time now is 07:42.

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