Page 1 of 1
Looking For a Command help..
Posted: Fri Aug 26, 2011 8:46 pm
by Pranjal1234
OK so this is the issue i want the player to stop at the way point but it to still attack the mobs and a range that can be set..
I tried using player:rest(600) but it just stands there and doesn't attack near by moobs
Also i saw a post with this guy talking about a scanning type functions where it cld scan around for mobs from that waypoint for a certain amt of time.
Thanks For Read , Any Comment is Accepted

Re: Looking For a Command help..
Posted: Fri Aug 26, 2011 9:02 pm
by lisa
Something like this will probably do what you want.
Code: Select all
<!-- # 1 --><waypoint x="4810" z="-1888" y="107">
repeat
player:clearTarget();
player:target(player:findEnemy())
if player:haveTarget() then
player:fight();
end
until not player:haveTarget()
</waypoint>
Obviously the waypoint coords arn't the ones you want, just did that to show where the code goes.
Re: Looking For a Command help..
Posted: Fri Aug 26, 2011 9:06 pm
by Pranjal1234
Could i put a time for that so that it stands at that waypoint and if some mob comes close it will attack it and will go back to the same waypoint untill the time is up?
Thanks For The Response

Re: Looking For a Command help..
Posted: Fri Aug 26, 2011 9:36 pm
by lisa
until not player:haveTarget()
the until ends the loop, so you can make the until what ever you want.
Code: Select all
<!-- # 1 --><waypoint x="4810" z="-1888" y="107">
starttime = os.time()
repeat
player:clearTarget();
player:target(player:findEnemy())
if player:haveTarget() then
player:fight();
end
until os.time() - starttime >= 60 -- so will stay at waypoint for 60 seconds.
</waypoint>
Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 10:58 am
by kanta
If this is something you are going to do many times through your waypoint file you could make it into a userfunction so any changes you make to the base coding only needs to be changed once and not have to search through and change many instances of it.
Open a text editor (such as notepad or whatever editor you use) and put the following code in:
Code: Select all
function KillWhileWaiting(timetowait)
starttime = os.time()
repeat
player:clearTarget();
player:target(player:findEnemy())
if player:haveTarget() then
player:fight();
end
until os.time() - starttime >= timetowait
end
Save this in the "rom\userfunctions" folder as something like "userfunction_KillWhileWaiting.lua". In your waypoint file you would use this like:
Code: Select all
<!-- # 5 --><waypoint x="-7308" z="45008" y="620">
KillWhileWaiting(30)
</waypoint>
The number in the () will tell the bot how long you want to wait. It can be any value, where the value is the number of seconds you want to wait.
Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 8:05 pm
by lisa
of course a good idea to do that =)
If I could add a suguestion, make a default value for the waittime.
Code: Select all
function KillWhileWaiting(timetowait)
timetowait = timetowait or 60 --sets to 60 if no value for timetowait
starttime = os.time()
repeat
player:clearTarget();
player:target(player:findEnemy())
if player:haveTarget() then
player:fight();
end
until os.time() - starttime >= timetowait
end
Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 10:08 pm
by kanta
Cool, I'd forgotten how to add a default value. I think I'm actually gonna keep this one

Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 10:32 pm
by rock5
I would also suggest checking localizations. 'starttime' in particular could very easily be used elsewhere. So to avoid conflict use
Code: Select all
function KillWhileWaiting(timetowait)
local timetowait = timetowait or 60 --sets to 60 if no value for timetowait
local starttime = os.time()
repeat
player:clearTarget();
player:target(player:findEnemy())
if player:haveTarget() then
player:fight();
end
until os.time() - starttime >= timetowait
end
Of course you don't have to indent like this but I just have a pet peeve about indents.

Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 11:24 pm
by kanta
I thought about the local thing but wasn't sure if it would be necessary.... Kinda avoided asking about it because I thought it would be a noob question

Re: Looking For a Command help..
Posted: Sat Aug 27, 2011 11:53 pm
by lisa
Yeah when I test code I generally have it as local first and if it doesn't work then I remove the local.
I obviously hadn't tested this code

Re: Looking For a Command help..
Posted: Sun Aug 28, 2011 4:35 am
by rock5
You should always use 'local' unless you want the variable to be global or it was already declared 'local' earlier.
Just because not declaring it local doesn't cause any problems, is no excuse for not declaring it. It may well cause problems in the future if someone else unwittingly uses the same global variable.
Re: Looking For a Command help..
Posted: Sun Aug 28, 2011 11:51 am
by lisa
seems using this type of code
Code: Select all
something = something or somethingelse
doesn't work if done as local
Been testing some code for party heals and have this
Code: Select all
_firsttimes = _firsttimes or false
if _firsttimes == false then
cprintf(cli.yellow,"Party member "..i.." has the name of ")
cprintf(cli.red, GetPartyMemberName(i).."\n")
_firsttimes = true
end
If I do
Code: Select all
local _firsttimes = _firsttimes or false
it doesn't work and always says it is false
--=== Update ===--
Actually minor correction, it does work but you can't change the value with
_firsttimes = true, so if it is going to be that value without alteration then it works just fine. If you want to be able to change it later then you will probably have to make it not local.
In the end I gave up trying to make it a local, in my case anyway.
Code: Select all
if _firsttimes == nil then -- post party names when bot started
if GetPartyMemberName(i) ~= nil then
cprintf(cli.yellow,"Party member "..i.." has the name of ")
cprintf(cli.red, GetPartyMemberName(i).."\n")
_firsttimes = true
end
end
So I have a global which i only use just once and never use anywhere else, can't think of how else to do it. This code is within a loop and I only want the prints done the first time code us done.
Re: Looking For a Command help..
Posted: Sun Aug 28, 2011 8:32 pm
by rock5
Actually I think that's working as intended. Using 'local' would initialise the value. If you want to check it again at a later time, it would have to be global I think. In most cases 'something = something or somrthingelse' would assume a global variable.
Re: Looking For a Command help..
Posted: Tue Aug 30, 2011 6:23 pm
by SpiralV
let me note something, whenever the time in which a value changes is needed, then a global is necessary. Thats a simple rule that I do often use.
the reason is simple the time can only be found if the current value is compared with the previous which must be stored permanently.
Re: Looking For a Command help..
Posted: Wed Aug 31, 2011 12:37 am
by Administrator
I think the problem is that false is, well, false, so in the or statement, it is ignored (as it needs to be true to be returned).
Re: Looking For a Command help..
Posted: Wed Aug 31, 2011 1:35 am
by lisa
Administrator wrote:I think the problem is that false is, well, false, so in the or statement, it is ignored (as it needs to be true to be returned).
lol that just makes to much sense =)