Function That Returns True If Player Is Moving?

Language: JP EN DE FR
2010-09-08
New Items
users online
Forum » Windower » Support » Function that returns true if player is moving?
Function that returns true if player is moving?
Offline
Posts: 428
By Selindrile 2016-06-11 20:27:03
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-11 20:38:56
Link | Quote | Reply
 
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.
[+]
Offline
Posts: 428
By Selindrile 2016-06-11 21:48:41
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-11 22:05:19
Link | Quote | Reply
 
Code
if moving then


It will also call your self_command function with the phrase "started to move!" or "stopped moving!" when you start or stop moving.
Offline
Posts: 428
By Selindrile 2016-06-11 22:07:58
Link | Quote | Reply
 
Yeah, that's exactly what I was thinking, awesome, thanks so much!
 Lakshmi.Byrth
VIP
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-11 22:15:54
Link | Quote | Reply
 
np, hopefully it works! I have not tried it or even verified that it will load.
Offline
Posts: 428
By Selindrile 2016-06-11 22:52:19
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-11 23:28:01
Link | Quote | Reply
 
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.
Offline
Posts: 428
By Selindrile 2016-06-11 23:34:08
Link | Quote | Reply
 
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.
Offline
Posts: 428
By Selindrile 2016-06-11 23:47:32
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-11 23:53:19
Link | Quote | Reply
 
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!
Offline
Posts: 428
By Selindrile 2016-06-11 23:57:46
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-12 00:20:41
Link | Quote | Reply
 
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.
Offline
Posts: 428
By Selindrile 2016-06-12 00:24:08
Link | Quote | Reply
 
I appreciate all the help even if it doesn't work, and I missed that too.
Offline
Posts: 428
By Selindrile 2016-06-12 00:26:42
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-12 00:31:12
Link | Quote | Reply
 
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
Offline
Server: Fenrir
Game: FFXI
user: Minjo
Posts: 199
By Fenrir.Caiir 2016-06-12 00:31:39
Link | Quote | Reply
 
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
Offline
Server: Fenrir
Game: FFXI
user: Minjo
Posts: 199
By Fenrir.Caiir 2016-06-12 00:32:06
Link | Quote | Reply
 
Curses, foiled a golem
Offline
Posts: 428
By Selindrile 2016-06-12 00:33:49
Link | Quote | Reply
 
Ah, I totally get why that was boolean now, derp, thanks.
Offline
Posts: 428
By Selindrile 2016-06-12 01:17:35
Link | Quote | Reply
 
Removing the >1 on the end ended up working fine for me, thanks a ton to both of you!
Offline
Posts: 428
By Selindrile 2016-06-12 06:43:55
Link | Quote | Reply
 
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
Offline
Server: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2016-06-12 07:27:13
Link | Quote | Reply
 
I updated the code posts to reflect that.
[+]
Log in to post.