|
Function that returns true if player is moving?
By Selindrile 2016-06-11 20:27:03
I've asked a couple times in the Gearswap thread but never got an answer, figured making a new post might make someone see it.
Anyone got a relatively easy way to determine if a player is moving for gearswap? I'm basically looking for a function that returns true if the player is moving.
Mostly looking to make it swap gear to movement+ gear when moving, but wouldn't mind having it for other checks too.
I tried to copy HealBot's isMoving() function but, tbh don't fully understand that implementation and couldn't get it to work in gearswap. I'm sure it's because I'm not copying something over right. :/
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-11 20:38:56
Code mov = {counter=0}
if player and player.index and windower.ffxi.get_mob_by_index(player.index) then
mov.x = windower.ffxi.get_mob_by_index(player.index).x
mov.y = windower.ffxi.get_mob_by_index(player.index).y
mov.z = windower.ffxi.get_mob_by_index(player.index).z
end
moving = false
windower.raw_register_event('prerender',function()
mov.counter = mov.counter + 1;
if mov.counter>15 then
local pl = windower.ffxi.get_mob_by_index(player.index)
if pl and pl.x and mov.x then
local movement = math.sqrt( (pl.x-mov.x)^2 + (pl.y-mov.y)^2 + (pl.z-mov.z)^2 ) > 0.1
if movement and not moving then
send_command('gs c started to move!')
moving = true
elseif not movement and moving then
send_command('gs c stopped moving!')
moving = false
end
end
if pl and pl.x then
mov.x = pl.x
mov.y = pl.y
mov.z = pl.z
end
mov.counter = 0
end
end)
Something like this.
[+]
By Selindrile 2016-06-11 21:48:41
Thank you so much!
So I can use if moving == 'True' for other checks, and use those gs c to equip movement gear, right? At least if I'm following it.
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-11 22:05:19
It will also call your self_command function with the phrase "started to move!" or "stopped moving!" when you start or stop moving.
By Selindrile 2016-06-11 22:07:58
Yeah, that's exactly what I was thinking, awesome, thanks so much!
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-11 22:15:54
np, hopefully it works! I have not tried it or even verified that it will load.
By Selindrile 2016-06-11 22:52:19
Loads, but doesn't seem to be working, trying to pinpoint where it fails, could easily be on my end.
Some info for you if you're interested in continuing, it seems like after loading:
if dist > 1 and not moving then
elseif dist < 1 and moving then
don't ever seem to be true
(Random guess, do I need to require maths? I thought that was already included somewhere in gearswap's libs, but I may be wrong)
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-11 23:28:01
It's probably that my x doesn't match the x of get_player(). Try changing all the X, Y, and Zs to the uppercase form.
By Selindrile 2016-06-11 23:34:08
I realized you were using mov to only check every 15 prerender ticks, derped there, did a replace all in selection for .x .y and .z for .X .Y and .Z
looks like if pl and pl.X and mov.X then
is always false
I had missed that if statement when I was trying to see which ones were working, so don't know if dist is properly calculating yet, since the if before that is never true it seems.
By Selindrile 2016-06-11 23:47:32
Looking at the wiki, the function windower.ffxi.get_player()
doesn't actually seem to return an x y and z in it's table.
but then again, I tried returning everything to lowercase and this, and it still didn't seem to be doing anything
Code if windower.ffxi.get_mob_by_target('me') then
mov.x = windower.ffxi.get_mob_by_target('me').x
mov.y = windower.ffxi.get_mob_by_target('me').y
mov.z = windower.ffxi.get_mob_by_target('me').z
end
Ok, I had forgotten to change the
local pl = windower.ffxi.get_player()
to
local pl = windower.ffxi.get_mob_by_target('me')
When I do I get an error: attempt to compare number with boolean
on the following line
if dist > 1 and not moving then
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-11 23:53:19
Code mov = {counter=0}
if player and player.index and windower.ffxi.get_mob_by_index(player.index) then
mov.x = windower.ffxi.get_mob_by_index(player.index).x
mov.y = windower.ffxi.get_mob_by_index(player.index).y
mov.z = windower.ffxi.get_mob_by_index(player.index).z
end
moving = false
windower.raw_register_event('prerender',function()
mov.counter = mov.counter + 1;
if mov.counter>15 then
local pl = windower.ffxi.get_mob_by_index(player.index)
if pl and pl.x and mov.x then
local movement = math.sqrt( (pl.x-mov.x)^2 + (pl.y-mov.y)^2 + (pl.z-mov.z)^2 ) > 0.1
if movement and not moving then
send_command('gs c started to move!')
moving = true
elseif not movement and moving then
send_command('gs c stopped moving!')
moving = false
end
end
if pl and pl.x then
mov.x = pl.x
mov.y = pl.y
mov.z = pl.z
end
mov.counter = 0
end
end)
Another attempt!
By Selindrile 2016-06-11 23:57:46
local pl = windower.get_mob_by_index(player.index)
Attempt to call field 'get_mob_by_index' (a nil value)
Which seems weird cuz
mov.x = windower.ffxi.get_mob_by_index(player.index).x is above that in the code, and not giving an error?
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-12 00:20:41
windower.ffxi.get_mob_by_index
Sorry, it's getting late. This will probably be my last post tonight. I fixed the above code with that change.
By Selindrile 2016-06-12 00:24:08
I appreciate all the help even if it doesn't work, and I missed that too.
By Selindrile 2016-06-12 00:26:42
Well, unfortunately, if you see this tomorrow or whenever.
if dist > 1 and not moving then
gives: attempt to compare number with boolean, so somehow dist is ending up as true or false?
Same issue when I tried using windower.ffxi.get_mob_by_target('me')
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-12 00:31:12
Edited the code again. I had >1 after the distance calculation as a result of splicing together various ways to do this. Now I'm really gone!
Fenrir.Caiir
VIP
Server: Fenrir
Game: FFXI
Posts: 199
By Fenrir.Caiir 2016-06-12 00:31:39
Change it to
"if dist and not moving then"
or change
dist = math.sqrt( (pl.x-mov.x)^2 + (pl.y-mov.y)^2 + (pl.z-mov.z)^2 ) > 1
to
dist = math.sqrt( (pl.x-mov.x)^2 + (pl.y-mov.y)^2 + (pl.z-mov.z)^2 )
Fenrir.Caiir
VIP
Server: Fenrir
Game: FFXI
Posts: 199
By Fenrir.Caiir 2016-06-12 00:32:06
Curses, foiled a golem
By Selindrile 2016-06-12 00:33:49
Ah, I totally get why that was boolean now, derp, thanks.
By Selindrile 2016-06-12 01:17:35
Removing the >1 on the end ended up working fine for me, thanks a ton to both of you!
By Selindrile 2016-06-12 06:43:55
To anyone thinking of using this, I highly reccomend using <.1 instead of <1 for checking dist, especially if you use uncapped framerate, otherwise moving slowly can cause a lot of false-stops, other than that, working pretty great.
Lakshmi.Byrth
VIP
Server: Lakshmi
Game: FFXI
Posts: 6,327
By Lakshmi.Byrth 2016-06-12 07:27:13
I updated the code posts to reflect that.
[+]
I've asked a couple times in the Gearswap thread but never got an answer, figured making a new post might make someone see it.
Anyone got a relatively easy way to determine if a player is moving for gearswap? I'm basically looking for a function that returns true if the player is moving.
Mostly looking to make it swap gear to movement+ gear when moving, but wouldn't mind having it for other checks too.
I tried to copy HealBot's isMoving() function but, tbh don't fully understand that implementation and couldn't get it to work in gearswap. I'm sure it's because I'm not copying something over right. :/
|
|