Author Topic: [Scripts] I need a script that detects when the player is standing still  (Read 458 times)

0 Members and 1 Guest are viewing this topic.

Rock

  • Elite Member
  • *****
  • Posts: 819
  • rock
  • Awards 3 years on site 1 year on site Was in the top 10 of the forum stats page as of 4/12/15 Former MotM winners
    • View Profile
    • Awards
  • Xbox: extremely thick
  • PSN: extremely moist
  • Steam: at your service
[Scripts] I need a script that detects when the player is standing still
« on: December 17, 2017, 09:12:37 PM »
I have a challenge map and I want a script that teleports the player out of the challenge area if they stop moving.  How can I do this?
hi

WhereThatWallAt

  • Jr. Member
  • **
  • Posts: 27
    • View Profile
    • Awards
  • PSN: WhereThatWallAt
  • Steam: WhereThatWallAt
Re: I need a script that detects when the player is standing still
« Reply #1 on: December 18, 2017, 11:54:53 PM »
See post below for finished script xD
« Last Edit: December 20, 2017, 02:09:56 PM by WhereThatWallAt »
I found the wall.

Dryym

  • Supreme Member
  • *****
  • Posts: 4334
  • What's yours is mine. ~TM's Resident Master Thief~
  • Awards Members who have unlocked the robotic avatar Awarded to exemplary forum members 2 years on site 3 years on site Site art contributions/TPs in-game/Contest winners 1 year on site
    • View Profile
    • Awards
  • Xbox: dryym
Re: I need a script that detects when the player is standing still
« Reply #2 on: December 19, 2017, 10:44:50 AM »
Script foo
{
    While(var n < 5(or whatever number you want)
     {
          Save player coords to variables here.
          Wait(amount of time)
          Save new coords to second set of variables
          If(coords = new coords)
              n++;
      }
     Teleport here
}
End script.


Sent from my iPhone using Tapatalk

That's not how the TM script syntax works.


Var [x] [y] [z]
Var [ox] = [x]
Var [oy] = [y]
Var [oz] = [z] //The X,Y,Z values of the last iteration of the loop.

Var [x] = [prel:x]
Var [y] = [prel:y]
Var [z] = [prel:z] //The player's current X,Y,Z coords.

If
  IsVar [x] [=] [ox]
  IsVar [y] [=] [oy]
  IsVar [z] [=] [oz]
Then
  Teleport [player] [COORDS HERE]
EndIf
Loop [30000]


This checks if you have been standing on the same block for 30 seconds. If so, It teleports you to whatever place you make it teleport you to.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

WhereThatWallAt

  • Jr. Member
  • **
  • Posts: 27
    • View Profile
    • Awards
  • PSN: WhereThatWallAt
  • Steam: WhereThatWallAt
Re: I need a script that detects when the player is standing still
« Reply #3 on: December 20, 2017, 01:32:12 PM »
That’s because it wasn’t made with TM syntax it’s called pseudo-code and is a common practice. Considering I did not have access to the game at the time. I wrote it in Pseudo Ja*va syntax because it’s what I know. It essentially shows the method in which it can be done and is not meant to be used as a copy paste.

NOTE: Was not aware there was not a while function, so that's MB. Will edit appropriately.
« Last Edit: December 20, 2017, 02:08:59 PM by WhereThatWallAt »
I found the wall.

cY Agent 115

  • Sr. Member
  • ****
  • Posts: 364
  • Death to trolls on the forums
  • Awards 2 years on site 1 year on site
    • View Profile
    • Awards
  • Xbox: cY Agent 115
  • Steam: cY Agent 115
Re: I need a script that detects when the player is standing still
« Reply #4 on: December 21, 2017, 01:22:51 AM »
The program used to make the first your attempt @WhereThatWallAt isn't the best for TM scripting. Simply imputing into notepad or a normal text format is completely fine.

What's even better (source from MrMarooca) is that you can literally highlight, ctrl+c then ctrl+v from notepad (or any source with the same format) straight into the script editor and it will just place it in as is.

For instance:

If
Player HasInventory [Goldpieces] [100] [<]
Then
Notify [Local] [60,60,60] [You have insufficient funds]
If
Player HasInventory [Goldpieces] [100] [=>]
Then
Inventory [Goldpieces] [Take] [100]
Inventory [Wood Pickaxe] [add] [1]

That whole script will look like that if you copy and paste into TM, cool eh?

KryptoniteKS

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
    • Awards
  • Steam: RelinquishedFire
Re: I need a script that detects when the player is standing still
« Reply #5 on: December 31, 2017, 12:27:55 AM »
Var
  • [y] [z]

Var [ox] = [x]
Var [oy] = [y]
Var [oz] = [z] //The X,Y,Z values of the last iteration of the loop.

Var [x] = [prel:x]
Var [y] = [prel:y]
Var [z] = [prel:z] //The player's current X,Y,Z coords.

If
  IsVar [x] [=] [ox]
  IsVar [y] [=] [oy]
  IsVar [z] [=] [oz]
Then
  Teleport [player] [COORDS HERE]
EndIf
Loop [30000]
After looking at this, I realized there was a typo because it didn't really make sense to me so I tried the script myself. I'm fairly new to scripting so I figured this was a learning moment for me. Just looking at this taught me a lot so thanks Dryym but I will paste the improved script below. This script unfortunately did not work at all because by saying If [ox] =
  • , you are saying if [ox] equals the queried position of the player, which would always return true because [ox] =
  • as stated in the script. To fix this, I added a wait timer (1 second) between querying the players position and his position exactly one second after that. This fixed the problem.

Var [x] = [prel:x]
Var [y] = [prel:y]
Var [z] = [prel:z] //Player's current position at the start of the script
Wait [1000]
Var [ox] = [prel:x]
Var [oy] = [prel:y]
Var [oz] = [prel:z] //Player's current position after 1 second has passed

If
  IsVar [x] = [ox]
  IsVar [y] = [oy]
  IsVar [z] = [oz]
Then
Teleport [actor] [x,y,z]
EndIf
Loop [1000]

It wouldn't let me copy and paste my script unfortunately so I made this one by simply typing it in chat so I don't know if it will copy over correctly, but this is what it should look like. Every second the script will loop so it will always be running and checking if the player is moving or not. If they stop moving for one second, they will teleport to the chosen coords. Obviously you can change the timer to like [500] for half a second or even [250] for a fourth of a second, but any lower is not recommended because it isn't safe to say the player can move a single coordinate in the time that a fourth of a second passes.
Also, I know this post is a little old, but I just wanted to post this so others viewing can have a script to look at for their parkour maps.
I didn't mean to throw you under the bus Dryym, i know you're a great scripter from seeing your posts, but I just wanted to get a working script in this article.
Edit: I don't know why it is doing this, but for every little square you see in the text, it is [ x ] without the spaces. Not sure why this happens.