Forums » Community Projects

Turbo Lock - Auto Shut Down plugin

12»
May 15, 2008 Logoffskies link
It's annoying when your turbo shuts off, but your bind stays on "ON" mode. If you tell your guy to turbo, this plugin rapidly checks to see if your energy suddenly starts increasing. In such a situation, it turns off, because you probably ran out of energy, and the game forced you to stop turboing. Since it tweaks with your wgaf.cfg, it has options to reinstall all the aliases it uses, uninstall any aliases, or "deinstall", which involves writing it to be the same as Eldrad's original bind. Credit to Eldrad for the original bind which I shamelessly edited.

Megaupload

MyntX=Timer();declare("ttog",{...});function reinstallttog() gkinterface.GKProcessCommand("alias mt '+turbo 0';alias -t 'mt';alias +t '+turbo; alias -t mt';alias acti 'Activate';alias ttog 'ttog1';alias ttog5 '+turbo 0;ttog4';alias ttog6 'Activate; ttog2';alias ttog0 ' ';alias ttog2 'ttog5; alias ttog ttog1; alias acti Activate; alias -t mt; alias mt ttog5; echo Turbo OFF';alias ttog1 'ttog3;+turbo; alias ttog ttog2; alias acti ttog6; alias -t ttog0; alias mt ttog2; echo Turbo ON'") end;reinstallttog();function deinstallttog() gkinterface.GKProcessCommand("alias ttog1 '+turbo; alias ttog ttog2; alias acti ttog6; alias -t ttog0; alias mt ttog2; echo Turbo ON';alias ttog2 '+turbo 0; alias ttog ttog1; alias acti Activate; alias -t mt; alias mt ttog2; echo Turbo OFF';") end;function uninstallttog() gkinterface.GKProcessCommand("alias ttog ' ';alias ttog1 ' ';alias ttog2 ' ';alias ttog5 ' ';alias ttog6 ' ';alias ttog0 ' ';alias +t ' ';alias -t ' ';alias mt ' ';alias acti ' '") end;function TurboOn() if ttog[1]~=nil then MyntX:SetTimeout(50, function() TurboOn() end); if ttog[2]<GetActiveShipEnergy() then gkinterface.GKProcessCommand("ttog2") end end;ttog[2]=GetActiveShipEnergy() end;RegisterUserCommand("ttog3", function() ttog[1]=1;ttog[2]=GetActiveShipEnergy();TurboOn() end);function ttoghelp() print("reinstallttog - Rewrites your binds for automatic shut off.");print("deinstallttog - Returns your binds to the default turbo lock settings.");print("uninstallttog - Removes all binds used for turbo lock.");print("+t - Normal Turbo.");print("ttog - Toggle turbo lock.");print("acti - Activate. Default key is enter.") end;RegisterUserCommand("ttog4", function() ttog[1]=nil end);RegisterUserCommand("reinstallttog", function() reinstallttog() end);RegisterUserCommand("deinstallttog", function() deinstallttog() end);RegisterUserCommand("uninstallttog", function() uninstallttog() end);RegisterUserCommand("ttoghelp", function() ttoghelp() end);print("autottog v1.1 - type /ttoghelp for a list of commands. Original bind by Eldrad.")
May 15, 2008 slime73 link
Newlines for the win.
May 19, 2008 Logoffskies link
What for? So you can reverse engineer it? I already told you precisely how it works;If you have any suggestions and you can't deal with semicolons, let me know and I'll make a v1.1.
May 19, 2008 slime73 link
So I can actually understand it and maybe help you improve it? :p

Also, your link is broke.
May 19, 2008 maq link
Heh, 'reverse engineer', more like to rewrite sanely :D
May 19, 2008 PsyRa link
Looks like something I would see on the daily WTF.

http://thedailywtf.com/
May 22, 2008 Logoffskies link
declare("ttog",{...})

function reinstallttog() gkinterface.GKProcessCommand("alias mt '+turbo 0';alias -t 'mt';alias +t '+turbo; alias -t mt';alias acti 'Activate';alias ttog 'ttog1';alias ttog5 '+turbo 0;ttog4';alias ttog6 'Activate; ttog2';alias ttog0 ' ';alias ttog2 'ttog5; alias ttog ttog1; alias acti Activate; alias -t mt; alias mt ttog5; echo Turbo OFF';alias ttog1 'ttog3;+turbo; alias ttog ttog2; alias acti ttog6; alias -t ttog0; alias mt ttog2; echo Turbo ON'") end

reinstallttog()

function deinstallttog() gkinterface.GKProcessCommand("alias ttog1 '+turbo; alias ttog ttog2; alias acti ttog6; alias -t ttog0; alias mt ttog2; echo Turbo ON';alias ttog2 '+turbo 0; alias ttog ttog1; alias acti Activate; alias -t mt; alias mt ttog2; echo Turbo OFF';") end

function uninstallttog() gkinterface.GKProcessCommand("alias ttog ' ';alias ttog1 ' ';alias ttog2 ' ';alias ttog5 ' ';alias ttog6 ' ';alias ttog0 ' ';alias +t ' ';alias -t ' ';alias mt ' ';alias acti ' '") end

function TurboOn() if ttog[1]~=nil then MyntX:SetTimeout(50, function() TurboOn() end); if ttog[2]<GetActiveShipEnergy() then gkinterface.GKProcessCommand("ttog2") end end;ttog[2]=GetActiveShipEnergy() end

RegisterUserCommand("ttog3", function() ttog[1]=1;ttog[2]=GetActiveShipEnergy();TurboOn() end)

function ttoghelp() print("reinstallttog - Rewrites your binds for automatic shut off.");print("deinstallttog - Returns your binds to the default turbo lock settings.");print("uninstallttog - Removes all binds used for turbo lock.");print("+t - Normal Turbo.");print("ttog - Toggle turbo lock.");print("acti - Activate. Default key is enter.") end

RegisterUserCommand("ttog4", function() ttog[1]=nil end)

RegisterUserCommand("reinstallttog", function() reinstallttog() end)

RegisterUserCommand("deinstallttog", function() deinstallttog() end)

RegisterUserCommand("uninstallttog", function() uninstallttog() end)

RegisterUserCommand("ttoghelp", function() ttoghelp() end);print("autottog v1.0 - type /ttoghelp for a list of commands. Original bind by Eldrad.")
May 22, 2008 maq link
Heh, slowly breaking?
Few more days and you'll add all the newlines? :D
Or even *gasp* indent? ;)
May 23, 2008 MSKanaka link
I think it's worth asking what the point is of making a plugin that does nothing but gkinterface.GKProcessCommand. It's not worth the effort -- if all you're going to do is use GKProcessCommand without actually using Lua for anything important you would be just as well off sticking with the alias/bind syntax built into VO.
May 23, 2008 blacknet link
RegisterUserCommand("uninstallttog", function() uninstallttog() end)

This is insane. If you are going to call a function from a function and provide no other code then just assign it to the 2nd function to begin with and not use needless and wasteful constructs.

gkinterface.GKProcessCommand("alias mt '+turbo 0';alias -t 'mt';alias +t '+turbo; alias -t mt';alias acti 'Activate';alias ttog 'ttog1';alias ttog5 '+turbo 0;ttog4';alias ttog6 'Activate; ttog2';alias ttog0 ' ';alias ttog2 'ttog5; alias ttog ttog1; alias acti Activate; alias -t mt; alias mt ttog5; echo Turbo OFF';alias ttog1 'ttog3;+turbo; alias ttog ttog2; alias acti ttog6; alias -t ttog0; alias mt ttog2; echo Turbo ON'")

??WHY?? Lua offers many diverse ways to reach the same goals with out having to pass everything to gki.
May 23, 2008 firsm link
it's obfuscated lua! leave it the way it is!
May 23, 2008 SuperMegaMynt link
First of, thankyou all for your excellent commments and questions about my (yes MY mwahahaha!) lil' plugin.

To maq, I don't understand new lines, or indenting or any of that crap. What I do understand is scripting, i.e. do this, then this then this etc. Thus. Additionally, I'm loathe to include copious 'wasteful constructs', as so elegantly described by our resident Lua expert, blacknet.

Miharu, that is an superb question. I'm sorry that I don't have an answer, as a plugin that strictly used methods which could be duplicated by binding could of course be more simply done with a bind. I fail to see how that is related to this plugin however, which utilizes the mighty power of Lua to GetActiveShipEnergy() and the more accurate timer.

blacknet, you might note that "uninstalltog" is not a function, as opposed to uninstalltog(). "uninstalltog" is a string, that when input calls the function by the same name, which does Lua stuff. Thus, the purpose is to do Lua stuff with slash commands, which would be explained to you in not so many words if you ran it up, noticed the "type /ttoghelp for a list of commands" on your chat log, and went ahead and followed those directions.

As for the drawn out gkinterface block I used, I'm interested in how I could attain that same goal, but am skeptical that you actually know what you're talking about when you thought that stuff inside quotes denoted functions. Please prove me wrong.

firsm; obfuscated it may be, but it is solid. (Again, please prove me wrong via trying it, and reporting bugs, feedback and that sort of thing.)
May 23, 2008 maq link
oh, there's nothing to understand. It's just to make it easier to read and all.
Personally i don't care how you write your plugins.
If you got it to do what you wanted to, that's fine.
May 23, 2008 slime73 link
local function stuff(unused, blah)
  if not blah then print("you suck") return end
  local cmd = blah[1]:lower()
  if cmd == "stop" then
    stopfunc()
  elseif cmd == "go" then
    startfunc()
  else
    print("you suck")
  end
end

RegisterUserCommand("blah", stuff)
May 23, 2008 SuperMegaMynt link
I would really like to understand it though, because it limits my ability to read other people's work. Basically, I get that ; = new line. What does the indenting represent? Is it just there for style, or does it have some effect on the mechanics? As I try and decipher slime's incredibly witty insult, I see that it might be either/or. I can't decide because I don't know what that script does.

If you could explain things with an operationlist mind set, that would be a large help.
May 23, 2008 slime73 link
It's about 100000000000x easier to understand the code and insert/delete things.

By the way, that code makes 2 commands: /blah go and /blah stop.
May 24, 2008 maq link
ok assuming you aren't playing stupid and hoping answering won't make me look stupid:

newline is just enter in the code, it's not equivalent to ;
in fact lua doesn't require using ;'s. (or newlines for that matter, but it's much easier to read the code with them.)
so generally you put one command per line. sometimes more, like slimes first 'if'.

as for indent it's putting tabs or spaces in front of some parts of the code, generally the ones that are inside other statements.
it also makes it much easier to read, as you can easily see for example what is inside a function and where it ends.

and no it doesn't directly affect how it'll run, tho it'll make it easier to find errors so, you might say it does affect things indirectly.
May 24, 2008 MSKanaka link
Long story short -- if you want help on your code from other people, you need to make it so that they can read it. Most people who you ask to help will not spend their time wading through a single block of prose-like code trying to piece it out, nor are they normally going to go to the effort of copypasting the code and adding linebreaks on their own. If you want help, you need to make an effort to make your code accessible to those you want help from.
May 24, 2008 SuperMegaMynt link
Thankyou maq.

And I hope new users aren't intimidated by insane coding style; I've used this exact plugin since day one, and have had no errors, or heard of any thus far. I assure you that if Miharu, slime or anybody else can't read it, the computer and I, at least, are just dandy on the issue. ;)
May 24, 2008 maq link
Heh, they can read it, prolly.
They just can't be arsed to ;P