#Pushback on barrier touch

1 messages · Page 1 of 1 (latest)

twin iron
#

I want to make a skript so that if a player touches a barrier in certain worlds, they get pushed back like 2-3 blocks. Almost like a bounce. Here is what I have so far:

on move:
  player's world is "Duels" or player's world is "spawn"
  block at player's location is barrier
  push player backwards at speed 1 for 2 ticks```

However I feel like this is SUPER inefficient since like its checking every time they move any other ways?
#

Also side question right now I have this Skript

on projectile hit:
  event-projectile is an ender pearl
  shooter's world is "Duels"
  set {_location} to event-location
  loop blocks in radius 5 around event-location:
    loop-block is barrier
    cancel event
    delete event-projectile
    send action bar "&cʏᴏᴜ ᴄᴀɴɴᴏᴛ ᴘᴇᴀʀʟ ɪɴᴛᴏ ʙᴀʀʀɪᴇʀs" to shooter
    stop

on projectile hit:
  event-projectile is an ender pearl
  shooter's world is "spawn"
  set {_location} to event-location
  loop blocks in radius 5 around event-location:
    loop-block is barrier
    cancel event
    delete event-projectile
    send action bar "&cʏᴏᴜ ᴄᴀɴɴᴏᴛ ᴘᴇᴀʀʟ ɪɴᴛᴏ ʙᴀʀʀɪᴇʀs" to shooter
    stop```
#

I have to repeat the Skript to account for another world

#

how can I make it work for both worlds?

stable dirge
#

shooter's world is "this" or "that"

compact sable
# twin iron I want to make a skript so that if a player touches a barrier in certain worlds,...

block at player's location is the block where their legs are so this probably wouldnt work anyway, also yeah if this "on move" is the one that checks 20 times per second with lots of players this probably become laggy. instead, you can make a region in and above the barrier blocks and use on region enter event to trigger your pushback code
or on move on barrier block but personally i'd prefer the region one

#

also you can make region flags that stop enderpearls so just use that instead

twin iron
compact sable
#

there are definitely other ways but can I ask why you can't do it with regions?

twin iron
#

Wait no not 28 regions, it’s 56 regions

#

I can’t make that

#

😂

twin iron
stable dirge
compact sable
#

I mean you can make 56 regions it is still easier

I'm at work but I'll get back to this at some point

stable dirge
twin iron
#

Ok so I have barriers around an arena

#

U can’t escape

#

Even if u tried

#

But I still want for if u touch any of the barriers

#

For there to be pushback

#

Like a forcefield

#

Yk?

stable dirge
#

you could also create fake worldborders which will do the trick, I believe SkBee has that feature

twin iron
#

That’s it

#

But it needs to be good for preformance

compact sable
#

Are the arenas square cause you can do one big region over it all then one small region in the arena area, that way it will be way less work

#

I have to say any other way apart from regions will be crappy or janky imo

twin iron
#

need it per barrier block

#

u touch a barrier block

#

u bounce 5 back

willow willow
#

do you want the server to lag more or less

twin iron
#

but I cannot do the region thing

#

lmao

willow willow
#

welp you're stuck with on any movement 🤷

twin iron
#

like my spawn is 1 region

#

cant I make it so if u touch the edge u bounce back>

willow willow
#

you can check when you leave a region

twin iron
#

ur just on the outside

#

lmao

willow willow
#

so shrink the region by 1 block in all directions

#

or just deal with it

#

¯_(ツ)_/¯

twin iron
#

then what would the code be?

twin iron
#

it

#

so whats the bounceback code

willow willow
#

when you exit a region, push the player (direction from player to location of CENTER_OF_REGION) at speed X

willow willow
#

i have better things to do

twin iron
#

java dev

#

not skript dev

willow willow
#

if you know how to code in one language, you understand how the process of coding works.

willow willow
#

all coding languages use documentation

twin iron
#

and lang

#

are very different

willow willow
#

all coding languages return errors

twin iron
#

than java

willow willow
#

all coding languages cite examples for learning

willow willow
twin iron
# willow willow the indentation tells you when its wrong, and is basically written in barebones ...
        if {teleport_countdown} is not set:
                set {teleport_countdown} to 180

                  if size of all players in region "rtpportal" > 1:
                while {teleport_countdown} > 0:
                        loop all players in region "rtpportal"
                        set {_random_biome} to random element out of {"forest", "desert", "plains", "jungle"}
                        send title "&cTeleporting in %{teleport_timer}% seconds to %{_random_biome}%" to loop-player with fade in 0 stay 20 fade out 0
                        wait 1 second
                        subtract 1 from {teleport_countdown}

                  loop all players in region "rtpportal":
                teleport loop-player to location(random integer between -10000 and 10000, 80, random integer between -10000 and 10000, world "world")

                delete {teleport_countdown}
                else
                send "&cNot enough players in the region to initiate teleportation!" to player```
#

Heres a code im working on

#

everytime I fix 1 indenation

#

3 more pop up

#

its unfixable

#

plz explainn to me how ot fix this lmao

#

@willow willow ?

#

like whats wrong with this?

willow willow
#

stop double indenting it

#

you're putting two tabs where there should be one

#

and then other times you're putting half a tab

#

or just forgetting to make a section operate at all

twin iron
#

can u indent it for me?

#

or tell me whats wrong

willow willow
#

😐

twin iron
#

like should it be like this

willow willow
#

else -> else:

#

then fix your indentation

twin iron
#
        if {teleport_countdown} is not set:
                set {teleport_countdown} to 180

                  if size of all players in region "rtpportal" > 1:
                while {teleport_countdown} > 0:
                        loop all players in region "rtpportal"
                        set {_random_biome} to random element out of {"forest", "desert", "plains", "jungle"}
                        send title "&cTeleporting in %{teleport_timer}% seconds to %{_random_biome}%" to loop-player with fade in 0 stay 20 fade out 0
                        wait 1 second
                        subtract 1 from {teleport_countdown}

                  loop all players in region "rtpportal":
                teleport loop-player to location(random integer between -10000 and 10000, 80, random integer between -10000 and 10000, world "world")

                delete {teleport_countdown}
                else:
                send "&cNot enough players in the region to initiate teleportation!" to player```
#

whats wrong with the indentation thp

#

o

#

like where is there an error

twin iron
#

like I need examples

willow willow
#

literally the entire code

twin iron
#

is this good?

#

also what IDE is that?

willow willow
#

conditions using :'s require indentation afterwards

#

same as events

#
  if player's tool is a diamond sword:
    broadcast "e"```
twin iron
#

so this?

willow willow
twin iron
#

ah

willow willow
#

loop needs a :

#

loop and while need indent

twin iron
#

this lmao?

#

Ah yes

willow willow
#

run it and it'll tell you the last thing thats wrong with it

twin iron
#

getting this error tho

willow willow
#

nice

twin iron
#

wats wrong

#

lmao

willow willow
#

surprised the parser didn't flag it

#

what are you else:ing

twin iron
#

the if statement?

willow willow
#

no you are elseing nothing

twin iron
#

ah

#

I see

#

like java

#

in that sense

willow willow
twin iron
#

yes did it

#

already

twin iron
#

WHAT IS WRONG

#

LMAO

willow willow
#

it doesn't understand the if statement, so it disregards it

#

because it disregards it, its pretending the if statement is not there

#

with no if statement, it reads the else: without an if statement before it

twin iron
#

so whats wrong with the if statement

willow willow
#

idk if you can gauge the amount of players in a region bc i never care to use regions for anything

#

just loop all players, check if they're within the region, then if they are, add 1 to a local variable

#

then use that local variable instead of the size of all players in region...

twin iron
#
    if {teleport_countdown} is not set:
        set {teleport_countdown} to 180

        if size of all players in region "rtpportal" > 1:
            while {teleport_countdown} > 0:
                loop all players in region "rtpportal":
                    set {_random_biome} to random element out of {"forest", "desert", "plains", "jungle"}
                    send title "&cTeleporting in %{teleport_timer}% seconds to %{_random_biome}%" to loop-player with fade in 0 stay 20 fade out 0
                    wait 1 second
                    subtract 1 from {teleport_countdown}

                    loop all players in region "rtpportal":
                        teleport loop-player to location(random integer between -10000 and 10000, 80, random integer between -10000 and 10000, world "world")

                    delete {teleport_countdown}
        else:
            send "&cNot enough players in the region to initiate teleportation!" to player


on enter of region "rtpportal":
    if {teleport_countdown} is not set:
        set {teleport_countdown} to 180
        
        set {_player_count} to 0
        
        loop all players:
            if loop-player is in region "rtpportal":
                add 1 to {_player_count}

        if {_player_count} > 1:
            while {teleport_countdown} > 0:
                loop all players in region "rtpportal":
                    set {_random_biome} to random element out of {"forest", "desert", "plains", "jungle"}
                    send title "&cTeleporting in %{teleport_countdown}% seconds to %{_random_biome}%" to loop-player with fade in 0 stay 20 fade out 0
                    wait 1 second
                    subtract 1 from {teleport_countdown}
            loop all players in region "rtpportal":
                teleport loop-player to location(random integer between -10000 and 10000, 80, random integer between -10000 and 10000, world "world")
                
            delete {teleport_countdown}
        else:
            send "&cNot enough players in the region to initiate teleportation!" to player
#

This @willow willow

#

?

compact sable
#

😬

twin iron
compact sable
#

spoon time

#

so your original issue is the one i will help you fix, i have no fkin clue what the code you sent is for because it isnt what you asked originally and its obviously quite broken

compact sable
#
  set {center-of-region} to location(0, 100, 0, world "Duels")
  set {region-name} to "region"
  set {lag-reducer-minimum-distance-from-center-of-region-check} to 10

on join:
  wait 2 ticks
  while player is online:
    wait 3 ticks
    if "%region at player%" contains {region-name}:
      if distance between player and {center-of-region} > {lag-reducer-minimum-distance-from-center-of-region-check}:
        loop all blocks in radius 1.5 of player where [input's y coord < player's y coord]:
          if {_a} = true:
            stop loop
          if loop-block = barrier block:
            set {_a} to true
        if {_a} = true:
          add 1 to {_b}
          set {_v} to normalized vector from player to {center-of-region}
          set player's velocity to {_v}
        if {_b} = 3:
          delete {_a}
          delete {_b}

on projectile hit:
  shooter is a player
  if event-block = barrier block:
    if shooter's world = "Duels" or "spawn":
      if event-entity = ender pearl:
        cancel event
        give shooter ender pearl
        send "&4You can't ender pearl there" to shooter```
#

try this untested code, may or may not work. give it a go and modify it to how you want it - don't forget to change the variable settings to exactly what they should be

compact sable