Solved How can I prevent a loop from doing damage to the player with Skript

  • 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 comminuty!

    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.

Chickenman

Member
Jul 30, 2021
10
0
1
34
I am programming a plugin in Skript using SkRayFall (though I'm unsure that that's useful for this scenario, I should put it there anyway) and I have a program that's supposed to damage all entities in a 1 block radius while pushing the play forward. This works fine, although it damages the player, which I do not want. It produces no errors.

Code:
Code:
on right click:
   player is holding a goat horn named "§7Robotic Horn":
       #broadcast "test"
       if {globalcooldown.%player%} is 0:
           if {mana.%player%} > 14:
               remove 15 from {mana.%player%}
               set {globalcooldown.%player%} to 5
               push player forward at speed 3
               set {ram.%player%} to true
               wait 0.5 seconds
               set {ram.%player%} to false
       else:
           send "&cPlease wait %{globalcooldown.%player%}% seconds to use this again!" to player

Code:
every 1 tick:
    loop all players:
        if {ram.%loop-player%} is true:
            loop all entities in radius 1 around loop-player:
                if loop-entity-2 is not a player or villager or armor stand:
                    damage loop-entity-2 by 5

Is there a way I could do this? This should work, and I think it's something to do with the loop-entity-2 part, but I am unable to fix it.

UPDATE:

Fixed by changing the loop code to

Code:
every 1 tick:
   loop all players:
       if {ram::%loop-player%} is true:
           loop all entities in radius 1 around loop-player where [entity is not player]:
               if loop-entity-2 is not a player:
                   damage loop-entity-2 by 5
Not sure what part is redundant here, but something is. Thanks for the help!
 
Last edited:
Would this work?
Code:
every 1 tick:
    loop all players:
        if {ram.%loop-player%} is true:
            loop all entities in radius 1 around loop-player where [entity is not player]:
                damage loop-entity-2 by 5

By the way, may I ask why you would need to separate the part of the ability that deals damage from the rest of the ability and make it check every tick? Couldn't you just make that code run during the right click ability? It's a bit performance heavy to loop all players every tick.

Also, please replace {these.variables} with {list::variables}.

Peace!
 
By the way, may I ask why you would need to separate the part of the ability that deals damage from the rest of the ability and make it check every tick? Couldn't you just make that code run during the right click ability? It's a bit performance heavy to loop all players every tick.

Sorry for replying late, I did this because the player moves during the damage period and I don't know how to it better.

I tried this code and it didn't work.
 
Code:
#Original Right Click Ability
on right click:
   player is holding a goat horn named "§7Robotic Horn":
       if {globalcooldown.%player%} is 0:
           if {mana.%player%} > 14:
               remove 15 from {mana.%player%}
               set {globalcooldown.%player%} to 5
               push player forward at speed 3
               set {ram.%player%} to true
               wait 0.5 seconds
               set {ram.%player%} to false
       else:
           send "&cPlease wait %{globalcooldown.%player%}% seconds to use this again!" to player
#Activating The Damage System
on right click:
   player is holding a goat horn named "§7Robotic Horn":
       #While The Ability Is Active
       while {ram.%player%} is true:
           loop entities in radius 1 of player:
               #Making Sure It Isn't The Player
               loop-entity is not player
               #Only Damaging It Once So They Don't Take Like 7 Hearts Of Damage
               {dmg.%loop-entity%} is not false
               #Change The Damage Here If You Want
               damage loop-entity by 1 heart
               set {dmg.%loop-entity%} to false

Hey! This should work. Tell me if it doesn't. Feel free to change anything, and look at the little notes I put in.
 
Status
Not open for further replies.