How to make delays... in RunConsoleCommand

I haven’t touched LUA in a while, but in a ball, this is what I’m trying to do.


function Blargh()
	RunConsoleCommand("slot2")
	RunConsoleCommand("+attack")
	RunConsoleCommand("-attack")
	RunConsoleCommand("+attack2")
	RunConsoleCommand("-attack2")
	RunConsoleCommand("+use")
	RunConsoleCommand("-use")
	RunConsoleCommand("slot1")
	RunConsoleCommand("slot1")
	RunConsoleCommand("slot1")
	RunConsoleCommand("+attack")
	RunConsoleCommand("-attack")
	RunConsoleCommand("+attack")
end


The commands don’t really execute in order from what it seems, so I believe I need to have a few second delay between all of them.

What can I do to accomplish this?

Please note, this function will be using a timer to cycle itself over and over

What will the delay of the timer be? There’s a few ways of doing this and it really depends on how often the function will be running.

Every 12 minutes.

The commands need 1-2ms delays

This goes in the Questions subforum

[LUA]
timer.Simple(720, function()
timer.Simple(0.002, RunConsoleCommand, “slot2”)
timer.Simple(0.004, RunConsoleCommand, “+attack”)
//And so on
end)
[/LUA]

Now say if I wanted to make this a toggleable console function i.e (script_activated 1/0), how would I do that?

Use **[G.CreateConVar

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.CreateConVar)** to create a console variable and read from it using **[G.GetConVarNumber

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.GetConVarNumber)**:

[lua]CreateConVar(“script_activated”, “1”)[/lua]

and then inside the function, use:

[lua]if !tobool(GetConVarNumber(“script_activated”)) then return end[/lua]



CreateClientConVar("script_enabled", 0)
function Blargh()
        if GetConVarNumber("script_enabled") <= 0 then return end
	timer.Simple(0.3, RunConsoleCommand "slot2")
	timer.Simple(0.8, RunConsoleCommand "+attack")
	timer.Simple(1.3, RunConsoleCommand "-attack")
	timer.Simple(1.8, RunConsoleCommand, "+attack2")
	timer.Simple(2.3, RunConsoleCommand, "-attack2")
	timer.Simple(2.8, RunConsoleCommand, "+use")
	timer.Simple(3.3, RunConsoleCommand, "-use")
	timer.Simple(3.8, RunConsoleCommand, "slot1")
	timer.Simple(4.3, RunConsoleCommand, "slot1")
	timer.Simple(4.8, RunConsoleCommand, "slot1")
	timer.Simple(5.3, RunConsoleCommand, "+attack")
	timer.Simple(5.8, RunConsoleCommand, "-attack")
	timer.Simple(6.3, RunConsoleCommand, "+attack")
end
timer.Simple(720, Blargh)

Would this work?

Yep should do, just remember though that CreateClientConVar accepts two other arguments, one of which you may find useful.

[lua]
local enabled = CreateClientConVar(“checking_enabled”, “0”. true, false);

timer.Create(“every_12_mins”, 720, 0, function()
if( enabled:GetInt() >= 1 ) then
timer.Simple(0.3, RunConsoleCommand “slot2”);
timer.Simple(0.8, RunConsoleCommand “+attack”);
timer.Simple(1.3, RunConsoleCommand “-attack”);
timer.Simple(1.8, RunConsoleCommand, “+attack2”);
timer.Simple(2.3, RunConsoleCommand, “-attack2”);
timer.Simple(2.8, RunConsoleCommand, “+use”);
timer.Simple(3.3, RunConsoleCommand, “-use”);
timer.Simple(3.8, RunConsoleCommand, “slot1”);
timer.Simple(4.3, RunConsoleCommand, “slot1”);
timer.Simple(4.8, RunConsoleCommand, “slot1”);
timer.Simple(5.3, RunConsoleCommand, “+attack”);
timer.Simple(5.8, RunConsoleCommand, “-attack”);
timer.Simple(6.3, RunConsoleCommand, “+attack”);
else
return;
end
end)
[/lua]

This is a sorry attempt at bypassing an anti-AFK by the way (more then likely). Also, use timer.Create timer.Simple just loops once and ends.

A lot of AFK scripts are now using Keypress, so yeah, this won’t work for shit.

Exactly, a good anti-AFK will check for spoofed client input aswell.

stonna is right

Oh, and there should be a comma after the “0”, in case you just copied and pasted the code.

[lua]local enabled = CreateClientConVar(“checking_enabled”, “0”, true, false)[/lua]

oops, sorry for the typo.

It is not an Anti-AFK script, as you probably should be able to tell by the commands being executed.

Thanks for the input anyway (:

[editline]22nd October 2011[/editline]

It keeps saying that the timer is trying to execute a nil value D=

Edit: I found out that I missed the first 3 commas after RunCC, failure.