1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error in my function I dont know how to fix

Discussion in 'Skript' started by Mich, Jul 16, 2020.

Thread Status:
Not open for further replies.
  1. Mich

    Mich Active Member

    Joined:
    Jul 15, 2020
    Messages:
    145
    Likes Received:
    5
    Skript Version (do not put latest): Skript 2.4.1
    Skript Author: Bensku
    Minecraft Version: 1.12.2
    Server Spigot 1.12.2

    Code (Text):
    1. On load:
    2.     set {M1911} to a Iron horse armor named "M1911"
    3.  
    4. Function guns(p: player, v: entity):
    5.     if {_p} is holding {M1911}:
    6.         if the distance between the {_p} and {_v} is less than 10:
    7.             set {vida.%{_v}%} to {vida.%{_v}%} - 12.5
    8.             message "12.5" to {_p}
    9.             message "%{vida.%{_v}%}%" to {_p}
    10.         else if the distance between the {_p} and {_v} is more than 10:
    11.             set {vida.%{_v}%} to {vida.%{_v}%} - 6.25
    12.  
    13.  
    14. on rightclick:
    15.     player is holding {M1911}
    16.     make the player shoot an snowball at speed 2
    17.        
    18. command /gun:
    19.     trigger:
    20.         give {M1911} to the player
    21. on damage of a zombie:
    22.     if {vida.%victim%} is set:
    23.         damage was caused by lava, fire or burning
    24.         cancel event
    25.         stop
    26.     if {vida.%victim%} is set:
    27.         cancel event
    28.         attacker is a player
    29.         guns(attacker, victim)
    30.         if {vida.%victim%} is less than or equal to 0:
    31.             kill victim
    32. command /test:
    33.     trigger:
    34.         spawn a zombie 1 meter above the player
    35.         add 1 to {z_count}
    36.         set {zombie::%{z_count}%} to last spawned entity
    37.         set {vida.%{zombie::%{z_count}%}%} to 100

    Variables cannot be used here. (zombies.sk, line 8: if the distance between the {_p} and {_v} is less than 10:')
    [18:47:23 ERROR]: 'else if' has to be placed just after another 'if' or 'else if' section (zombies.sk, line 12: else if the distance between the {_p} and {_v} is more than 10:')

    How I try to fix the code

    I did everything else widout the function and it was working great, but doing this widout a function it will be messy and will take more time
     
  2. Deku

    Deku Member

    Joined:
    Jul 12, 2020
    Messages:
    36
    Likes Received:
    0
    Code (Text):
    1. On load:
    2.     set {M1911} to a Iron horse armor named "M1911"
    3.  
    4. Function guns(p: player, v: entity):
    5.     if {_p} is holding {M1911}:
    6.         if the distance between the {_p} and {_v} is less than 10:
    7.             set {vida.%{_v}%} to {vida.%{_v}%} - 12.5
    8.             message "12.5" to {_p}
    9.             message "%{vida.%{_v}%}%" to {_p}
    10.     else if the distance between the {_p} and {_v} is more than 10:
    11.         set {vida.%{_v}%} to {vida.%{_v}%} - 6.25
    12.  
    13.  
    14. on rightclick:
    15.     player is holding {M1911}
    16.     make the player shoot an snowball at speed 2
    17.      
    18. command /gun:
    19.     trigger:
    20.         give {M1911} to the player
    21. on damage of a zombie:
    22.     if {vida.%victim%} is set:
    23.         damage was caused by lava, fire or burning
    24.         cancel event
    25.         stop
    26.     if {vida.%victim%} is set:
    27.         cancel event
    28.         attacker is a player
    29.         guns(attacker, victim)
    30.         if {vida.%victim%} is less than or equal to 0:
    31.             kill victim
    32. command /test:
    33.     trigger:
    34.         spawn a zombie 1 meter above the player
    35.         add 1 to {z_count}
    36.         set {zombie::%{z_count}%} to last spawned entity
    37.         set {vida.%{zombie::%{z_count}%}%} to 100
     
  3. Mich

    Mich Active Member

    Joined:
    Jul 15, 2020
    Messages:
    145
    Likes Received:
    5
    Did you fix the code or something?
     
Thread Status:
Not open for further replies.

Share This Page

Loading...