Im using the on walk event and - if <context.old_location.xyz> != <context.new_location.xyz> to check if the player is moving, though I find the above if statement to be wayyyy too sensitive. I've tried subtracting them, taking the absolute and then rounding but then it complains that context.old_location.xyz is not a valid decimal. Also tried just rounding both but same issue. Any alternatives/workarounds to this?
#(JustinS) Check for movement?
106 messages · Page 1 of 1 (latest)
(JustinS) Check for movement?
Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
!t distance
Cannot Specify Searched Tag
Multiple possible tags: <LocationTag.distance[<location>]>, <MaterialTag.distance>, <EntityTag.fall_distance>, <LocationTag.tree_distance>, <WorldTag.view_distance>, <server.view_distance>, <NPCTag.distance_margin>, <LocationTag.distance_squared[<location>]>, <LocationTag.distance[<location>].vertical>, <LocationTag.distance[<location>].horizontal>, <WorldTag.simulation_distance>, <NPCTag.path_distance_margin>, <WorldTag.no_tick_view_distance>, <LocationTag.points_between[<location>].distance[<#.#>]>, <WorldTag.border_warning_distance>, <LocationTag.distance[<location>].vertical.multiworld>, <LocationTag.distance[<location>].horizontal.multiworld>, <NPCTag.sentinel.guard_distance_minimum>.
!t LocationTag.distance[<location>]
Returns the distance between 2 locations.
Group
math
Returns
ElementTag(Decimal)
Do you want to check for every movement, or just when they walk to a different location?
That event fires very often
I mean that's only 20 times a second * the amount of players
every movement
yeahh thats kinda bad
Im trying to allow players to heal themselves but only when they stand still
!e player steps on block
Group
Player
**WARNING**
This event may fire very rapidly.
Event Lines
player steps on block player steps on <material>
Triggers
when a player steps onto a specific block material.
Has Player
Always. - this adds switches flagged:<flag name> + permission:<node>, in addition to the <player> link.
Context
<context.location> returns a LocationTag of the block the player is stepping on.
<context.previous_location> returns a LocationTag of where the player was before stepping onto the block.
<context.new_location> returns a LocationTag of where the player is now.
Has Known Location
True - this adds switches in:<area> + location_flagged:<flag name>.
Cancellable
True - this adds <context.cancelled> and determines cancelled + cancelled:false.
Ill need the standing still component for multiple things in the future probably
they cant jump either
pretty much the same but fires quite less often
!e jumps
I guess I have to add a seperate event for jumping then?
how exactly
You run a command, wait a few seconds, get healed if you didn't move ?
flag the player when theyre walking. The heal script is on a repeat 8 times (keeps adding a little bit of health) and when you move (it keeps checking the flag) it stops
ah so being immobile naturally heals
if you run the heal command
yeah
it only goes on for 8 times
then theres a cooldown
Ill give this a try
wait
now i don't understand
please explain what should happen step by step (overall mechanism you're aiming for)
Theres a special tool that allows the player to heal themselves but only when theyre standing still. When they right click it, it heals them for 8 seconds (every second it adds a little health). If they move, the healing process stops
ok so the trigger is a right click event with a specific item in hand
use this as the trigger, not the player walking event
thats what Im doing
ye but you don't have to flag the player and check for movement or whatever
keep the logic withing that right click event
then how do I check if theyre moving?
Heres what I have rn:
player_movement_detection:
type: world
events:
after player steps on block:
- flag player walking:true
- wait 0.2s
- flag player walking:false
force_heal:
type: task
script:
- ratelimit <player> 12s
- itemcooldown diamond duration:12
- cast slow <player> amplifier:1 duration:8s no_clear no_icon hide_particles
- repeat <duration[8s].in_seconds> from:0:
- if <player.flag[walking]>:
- cast slow remove <player>
- stop
- define target <player.eye_location.ray_trace_target[ignore=<player>;range=8]||null>
- if <[target]> != null && (<[target].is_player> || <[target].is_mob> || <[target].is_npc>):
- define target <player>
- heal <player> 1
- narrate "healing target: <[target].name>"
- wait 1s```
<duration[8s].in_seconds>
😂
for your information this is writing 8 with extra steps
yeah idk I saw that in a different post lol
i like the extra readability tho
I thought it was weird
but it worked
I can just remove the inseconds part right? The s behind the 8 takes care of that
literaly replace by - repeat 8 from:0:
also don't need the from:0 if the loop index is never checked
but anyways, that's not really a logical approach
pseudo code (this is not a script you can copy)
on player right clicks with my item:
- define location player.location
- repeat 8: # because you said it must repeat 8 times
# note that putting the `wait` first means they must be imobile for a second before getting the first healing
# might want to put that to the end for an instant initial healing
- wait 1s # add whatever delay you want between each healing
- define new_location player.location
- if location.distance[new_location] > 0.5: # or whichever threshold you feel is "imobile enough"
- narrate "Don't move if you want to get healed"
- stop
- do things # at this point you know the user didn't move
hmm yeah thats pretty smart
now if you want to ensure the player didn't jump, or didn't do some action you want to prohibit while healing, you could do something like this:
on player right clicks with my item:
- define location player.location
+ - flag player is_healing
- repeat 8: # because you said it must repeat 8 times
# note that putting the `wait` first means they must be imobile for a second before getting the first healing
# might want to put that to the end for an instant initial healing
- wait 1s # add whatever delay you want between each healing
- define new_location player.location
+ - if !player.has_flag[is_healing]:
+ - narrate "You did something that stopped you from healing"
+ - stop
- if location.distance[new_location] > 0.5: # or whichever threshold you feel is "imobile enough"
- narrate "Don't move if you want to get healed"
- stop
- do things # at this point you know the user didn't move
# this or any other event you'd like to listen to
+ on player jumps flagged:is_healing:
+ - flag player is_healing:!
Ill change it to that, though I just found out about another (little) issue: whenever Im looking at a mob, it still thinks I want to heal myself. Whenever I look at another entity during the healing it should heal them instead. So somethings going wrong here? There's no errors. I changed the if to all the '!''s because that prevents me from putting more code in an if statement
- define target <player.eye_location.ray_trace_target[ignore=<player>;range=8;raysize=0.15]||null>
- if <[target]> == null || !<[target].is_player> || !<[target].is_mob> || !<[target].is_npc>:
- define target <player>
- heal <player> 1
- narrate "healing target: <[target].name>"```
Hmm the playerloc variable isnt working?
[19:11:13 INFO]: ERROR in script 'force_heal' in queue 'FORCE_HEAL_3405_ReferenceCourier' while executing command 'IF' in file '\scripts\Forcepowers.dsc' on line '92' with player 'JustinS_2006'!
Error Message: Tag <player.location.distance[playerLoc]> is invalid!
[19:11:13 INFO]: Additional Error Info: Unfilled or unrecognized sub-tag(s) 'distance[playerLoc]' for tag <player.location.distance[playerLoc]>!
[19:11:13 INFO]: Additional Error Info: The returned value from initial tag fragment 'player.location' was: 'l@300.50541147525314, 63, -616.2464319769457, -3.715579, 155.362732, world'.```
- define playerLoc <player.location
- if !<player.flag[healing]> || <player.location.distance[playerLoc]> > 0.5:
... ```
Help us help you by pasting your script to https://paste.denizenscript.com/New/Script and linking it back here.
The formatting is weird
you don't have to, i was just curious if this is exactly what you had
Because there are 2 things wrong
- define playerLoc <player.location this was wrongly pased, you're missing a > in your message
main reason I asked for a paste
also
<player.location.distance[playerLoc]>
playerLoc is just plain text
<[playerLoc]> is a definition that will return the value you defined
huh which line is that?
in the paste it shows that > at the end
so <player.location.distance[<[playerLoc]>]>
yes, in your message it doesnt
.
ah
Great, that doesnt throw an error anymore, thanks. Im still having the issue of it not healing the player if theyre not looking at another entity though
Should I make a seperate thread for that? I feel like this one already contains most context
See the chat
[target].name should be my name
Couldn't you just use the player as a fallback?
wdym
!t if_null
If the object is null (or the tag errors), this will return the input object.
If the object isn't null, the input won't be parsed, and the original object will be returned.
For example, "<player.if_null[<npc>]>" will return the player if there is a player, and otherwise will return the NPC.
This functions as a fallback - meaning, if the tag up to this point errors, that error will be hidden.
Returns
ObjectTag
If your ray target is null, fallback to the player casting
eg. <player.eye_location.ray_trace_target[ignore=<player>;range=8;raysize=0.3]||<player>>
instead of <player.eye_location.ray_trace_target[ignore=<player>;range=8;raysize=0.3]||null>