Error in my function I dont know how to fix

  • 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.

Mich

Active Member
Jul 15, 2020
148
6
18
23
Skript Version (do not put latest): Skript 2.4.1
Skript Author: Bensku
Minecraft Version: 1.12.2
Server Spigot 1.12.2

Code:
On load:
    set {M1911} to a Iron horse armor named "M1911"

Function guns(p: player, v: entity):
    if {_p} is holding {M1911}:
        if the distance between the {_p} and {_v} is less than 10:
            set {vida.%{_v}%} to {vida.%{_v}%} - 12.5
            message "12.5" to {_p}
            message "%{vida.%{_v}%}%" to {_p}
        else if the distance between the {_p} and {_v} is more than 10:
            set {vida.%{_v}%} to {vida.%{_v}%} - 6.25


on rightclick:
    player is holding {M1911}
    make the player shoot an snowball at speed 2
        
command /gun:
    trigger:
        give {M1911} to the player
on damage of a zombie:
    if {vida.%victim%} is set:
        damage was caused by lava, fire or burning
        cancel event
        stop
    if {vida.%victim%} is set:
        cancel event
        attacker is a player
        guns(attacker, victim)
        if {vida.%victim%} is less than or equal to 0:
            kill victim
command /test:
    trigger:
        spawn a zombie 1 meter above the player
        add 1 to {z_count}
        set {zombie::%{z_count}%} to last spawned entity
        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
 
Code:
On load:
    set {M1911} to a Iron horse armor named "M1911"
 
Function guns(p: player, v: entity):
    if {_p} is holding {M1911}:
        if the distance between the {_p} and {_v} is less than 10:
            set {vida.%{_v}%} to {vida.%{_v}%} - 12.5
            message "12.5" to {_p}
            message "%{vida.%{_v}%}%" to {_p}
    else if the distance between the {_p} and {_v} is more than 10:
        set {vida.%{_v}%} to {vida.%{_v}%} - 6.25
 
 
on rightclick:
    player is holding {M1911}
    make the player shoot an snowball at speed 2
     
command /gun:
    trigger:
        give {M1911} to the player
on damage of a zombie:
    if {vida.%victim%} is set:
        damage was caused by lava, fire or burning
        cancel event
        stop
    if {vida.%victim%} is set:
        cancel event
        attacker is a player
        guns(attacker, victim)
        if {vida.%victim%} is less than or equal to 0:
            kill victim
command /test:
    trigger:
        spawn a zombie 1 meter above the player
        add 1 to {z_count}
        set {zombie::%{z_count}%} to last spawned entity
        set {vida.%{zombie::%{z_count}%}%} to 100
 
Code:
On load:
    set {M1911} to a Iron horse armor named "M1911"
 
Function guns(p: player, v: entity):
    if {_p} is holding {M1911}:
        if the distance between the {_p} and {_v} is less than 10:
            set {vida.%{_v}%} to {vida.%{_v}%} - 12.5
            message "12.5" to {_p}
            message "%{vida.%{_v}%}%" to {_p}
    else if the distance between the {_p} and {_v} is more than 10:
        set {vida.%{_v}%} to {vida.%{_v}%} - 6.25
 
 
on rightclick:
    player is holding {M1911}
    make the player shoot an snowball at speed 2
    
command /gun:
    trigger:
        give {M1911} to the player
on damage of a zombie:
    if {vida.%victim%} is set:
        damage was caused by lava, fire or burning
        cancel event
        stop
    if {vida.%victim%} is set:
        cancel event
        attacker is a player
        guns(attacker, victim)
        if {vida.%victim%} is less than or equal to 0:
            kill victim
command /test:
    trigger:
        spawn a zombie 1 meter above the player
        add 1 to {z_count}
        set {zombie::%{z_count}%} to last spawned entity
        set {vida.%{zombie::%{z_count}%}%} to 100
Did you fix the code or something?
 
Status
Not open for further replies.