Solved Creating Custom Gravity

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

GOLDEN_KE_LA

Member
Jun 12, 2017
10
0
0
Skript Version: Skript 2.2
Skript Author: Bensku
Minecraft Version: 1.8.8

Full Code:
code_language.skript:
on rightclick:
    if player is holding far music disc named "&6Gravity Staff":
        loop all living entities excludes player in radius 15 of player:
            push all living entities 0.5 meter in front of player at speed -0.5
            #particle from affected entities to player

I was trying to make a gravity staff that attracts all living entities to 0.5 block in front of the player using it (So the user can hit them easily). But it did not work out for me. I also wanted to add magicCrit particles forming a line from all victims to the player (user), which is moving towards the player (user) with the same speed the player moves towards the player (user). Can someone please help me with it? Thanks a lot.
 
Skript Version: Skript 2.2
Skript Author: Bensku
Minecraft Version: 1.8.8

Full Code:
code_language.skript:
on rightclick:
    if player is holding far music disc named "&6Gravity Staff":
        loop all living entities excludes player in radius 15 of player:
            push all living entities 0.5 meter in front of player at speed -0.5
            #particle from affected entities to player

I was trying to make a gravity staff that attracts all living entities to 0.5 block in front of the player using it (So the user can hit them easily). But it did not work out for me. I also wanted to add magicCrit particles forming a line from all victims to the player (user), which is moving towards the player (user) with the same speed the player moves towards the player (user). Can someone please help me with it? Thanks a lot.
I don't have time to help with the pushing stuff right now, but you can use my SexyShapes script/api to do the line part.
 
As far as I know, nothing like "push all living entities 0.5 meter in front of player at speed -0.5" exists. The push format is:
(push|thrust) %entities% %direction% [(at|with) (speed|velocity|force) %number%]

So you would want something like this:

code_language.skript:
on rightclick:
    if player is holding far music disc named "&6Gravity Staff":
        loop all living entities in radius 15 of player:
            if loop-value is not player:
                 push loop-value backwards at speed 0.5

However, this gets complicated because you wouldn't always want to push the entity backwards. Depending on the way it's facing you would need to push it different ways. Then you would need make a while loop and continuously push it in that direction until it's 0.5 blocks from the player, but if the player moves or the entity turns and is facing a different direction you would need to recalculate which direction to push it.
 
@Donut the following:
code_language.skript:
%number% [meter[s]] in[ ]front [of] %entities%
is an expression (the direction one). So what he did should work.
 
Here you go. I had made a similar system as to what you're requesting years ago. I just modified it to current Skript standards. This does what you need aswell as using my perfected gravity system. basically I tested this wait tick and push combo to be as perfect as it can be back in the day. It's very similar to ProdigyGadget's gravity gadget which can be viewed in this video (At 1:18)


Here is the coding

code_language.skript:
on rightclick with obsidian:
    player is holding obsidian named "&5&lAnti-gravity"
    cancel event
    if block at location 2 meters above player is air:
        set {_loc} to location of block 2 meters above player
        set block at {_loc} to obsidian
        loop 300 times:
            loop players in radius 10 around {_loc}:
                if ground state of loop-player is true:
                    push loop-player upwards at speed 0.14
                set {_locs::*} to line from loop-player to {_loc} with density 3
                play 1 crit at {_locs::*}
                #optional wait 1 tick here because of Skript lag from particles
            wait 2 ticks
        set block at {_loc} to air
    else:
        message "&cYou must place the gravity staff at a clear location."
Using Bensku's edit, Skellett and BioSphere
 
Last edited by a moderator:
@LimeGlass That's sweet but I don't think it helps @GOLDEN_KE_LA because he wants the living entities around the player to be drawn towards them.

Scratch what I said in my previous post, I found the effect golden_ke_la needs: "push the loop-value in the direction of the player at speed -0.5"

So the script would look something like this:
code_language.skript:
on rightclick:
    if player is holding far music disc named "&6Gravity Staff":
        loop living entities in radius 15 around player:
            if loop-value is not player:
                push the loop-value in the direction of the player at speed -0.5

You'll have to make it continuously push the loop-value towards the player until they're 0.5 blocks from the player.
 
@LimeGlass That's sweet but I don't think it helps @GOLDEN_KE_LA because he wants the living entities around the player to be drawn towards them.

Scratch what I said in my previous post, I found the effect golden_ke_la needs: "push the loop-value in the direction of the player at speed -0.5"

So the script would look something like this:
code_language.skript:
on rightclick:
    if player is holding far music disc named "&6Gravity Staff":
        loop living entities in radius 15 around player:
            if loop-value is not player:
                push the loop-value in the direction of the player at speed -0.5

You'll have to make it continuously push the loop-value towards the player until they're 0.5 blocks from the player.

Thanks for your answer, but unfortunately, I have tried that before. It draws to player to the opposite direction where YOU are looking. if im looking at a 45 degree angle facing down, The entities will move to 45 degrees upwards and backwards.
 
Thanks for your answer, but unfortunately, I have tried that before. It draws to player to the opposite direction where YOU are looking. if im looking at a 45 degree angle facing down, The entities will move to 45 degrees upwards and backwards.
use this function to get the opposite direction. Needs Skellett and SkQuery

code_language.skript:
function getOppositeDirection(d: direction) :: direction:
    set {_s} to "%{_d}%"
    loop {_s} split at "and":
        if {_direction} is not set:
            set {_direction} to "%numbers in loop-value%" parsed as number
            set {_final} to loop-value
        else if "%the numbers in loop-value%" parsed as number > {_direction}:
            set {_direction} to "%numbers in loop-value%" parsed as number
            set {_final} to loop-value
    if {_final} contains "north":
        return north
    else if {_final} contains "east":
        return east
    else if {_final} contains "south":
        return south
    else if {_final} contains "west":
        return west
Or use this coding which is simpler

code_language.skript:
on rightclick with stone:
    if name of player's tool is "&6Gravity Staff":
        loop living entities in radius 15 around player:
            if loop-entity is not player:
                push loop-entity (direction from loop-entity to player) at speed 0.5
 
Status
Not open for further replies.