Flexible offensive aliases
Re: Flexible offensive aliases
This being the case, how would you remake the original alias? Is there a better way then using the following?Heiko wrote:a = b or c means: if b is undefined i. e. b = nil, then a = c
At the time the original posting was written matches[3] would have been undefined if capture group #2 was empty.
Today, this behaviour has been changed. All capture groups in the regex will be defined and empty capture groups will contain an empty string i.e. "". When the original post was written a script like send( matches[3] ) would have caused a Lua error whenever capture group #2 was empty.sent the default value "hello" in case matches[3] was empty. That was the whole point of the expression. Today, it's meaningless in this respect. Today you can make good use for this sort of expression when initializing variables e.g.Code: Select all
t = "hello" send( matches[3] or t )
-> if c is undefined at the time this script is run, initialize it to 0 instead of causing a Lua runtime error.Code: Select all
b = c or 0
Code: Select all
if not matches[3]=="" then blah end
Re: Flexible offensive aliases
Today you can simply write
Code: Select all
send( "kick" .. matches[2] .. matches[3] )
Re: Flexible offensive aliases
What if it is not a choice between variables? For instance if I have a script that sets a variable (x) where if matches[5] exists then x=matches[5] and if it does not x=0.
Re: Flexible offensive aliases
I like, but don't understand. Could I get a quick recap for those that don't understand all this. And the exact code for this. I want to make use of it. I seriously need to take the time to learn to understand all this.
Re: Flexible offensive aliases
Hm... does 'For example, our alias "dd" will either kick the target when you just do "dd", or kick a rat when you "dd rat".' help?
Re: Flexible offensive aliases
naftali wrote:What if it is not a choice between variables? For instance if I have a script that sets a variable (x) where if matches[5] exists then x=matches[5] and if it does not x=0.
Now if you wanted to make it so that it set the variable to matches[5] if it exists AND is not an empty string without resorting to an if statement, it's slightly more complicated.
Re: Flexible offensive aliases
Code: Select all
function pChk(wildcard, default)
local result = default
if wildcard ~= "" then result = wildcard end
return result
end
x = pChk(matches[5], 0)
Re: Flexible offensive aliases
This might be a sad question to ask, but as a horrid programmer, and rather new to Lua, I cannot figure this out. Say I wanted to create an Alias for "strike <target> Neck" While I have issues with just using target already, is there a way to script it to be flexible?
Re: Flexible offensive aliases
You can easily script that, depending upon how flexible you want it to be.
So let's say that you have 2 variables: target and bodypart
target is the one you want to attack.
bodypart is say neck or head or whatever.
You can set up an alias to set either of them.
The code would look something like:
Notice that there is a space after strike, and another space in between target and bodypart in the quotes. That is necessary to prevent the output to be sent as "strike<target>Neck" rather than "strike <target> Neck" as the concat function (the two dots) doesn't add spaces so we have to add them manually in the script.
HTH
So let's say that you have 2 variables: target and bodypart
target is the one you want to attack.
bodypart is say neck or head or whatever.
You can set up an alias to set either of them.
The code would look something like:
Code: Select all
send("strike " .. target .. " " .. bodypart)
HTH