Fighting Zombie

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

MrVlamis

Member
Apr 27, 2022
11
0
1
19
Hey, I wanted to do a little project and I would like to have e.g. 2 zombies fight against each other e.g. the zombie of team red only attacks the zombies of blue and not his own. now I wanted to ask you if something like this would be feasible
 
This will spawn the 2 types of zombies
Code:
command /spawnzombie <text>:
  permission: op
  trigger:
    if arg-1 = "red":
      spawn 1 zombie at player
      equip last spawned zombie with a leather helmet
      dye last spawned zombie's helmet rgb(255, 0, 0)
      set the display name of the last spawned zombie to "&4Red Zombie"
    else if arg-1 = "blue":
      spawn 1 zombie at player
      equip last spawned zombie with a leather helmet
      dye last spawned zombie's helmet rgb(0, 0, 255)
      set the display name of the last spawned zombie to "&1Blue Zombie"

to make them fight you need to set the nearest zombie of the opposite team (check the name for that) to the zombie's target
https://skripthub.net/docs/?id=933
 
This will spawn the 2 types of zombies
Code:
command /spawnzombie <text>:
  permission: op
  trigger:
    if arg-1 = "red":
      spawn 1 zombie at player
      equip last spawned zombie with a leather helmet
      dye last spawned zombie's helmet rgb(255, 0, 0)
      set the display name of the last spawned zombie to "&4Red Zombie"
    else if arg-1 = "blue":
      spawn 1 zombie at player
      equip last spawned zombie with a leather helmet
      dye last spawned zombie's helmet rgb(0, 0, 255)
      set the display name of the last spawned zombie to "&1Blue Zombie"

to make them fight you need to set the nearest zombie of the opposite team (check the name for that) to the zombie's target
https://skripthub.net/docs/?id=933

and how i can do that?
 
Hey, I wanted to do a little project and I would like to have e.g. 2 zombies fight against each other e.g. the zombie of team red only attacks the zombies of blue and not his own. now I wanted to ask you if something like this would be feasible
You need sk bee for path find
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
[doublepost=1651703070,1651628612][/doublepost]
You need sk bee for path find
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
I tested the code and it works but the zombies attack is too fast so I modify the code and now they attack each other every second and not every tick you can add more time if you want to just change wait 1 second for example wait 3 seconds.
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                wait 1 second
                PathFind({_zombie}, "red")
                exit loop
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                wait 1 second
                PathFind({_zombie}, "blue")
                exit loop
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
[doublepost=1651703520][/doublepost]
You need sk bee for path find
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
[doublepost=1651703070,1651628612][/doublepost]
I tested the code and it works but the zombies attack is too fast so I modify the code and now they attack each other every second and not every tick you can add more time if you want to just change wait 1 second for example wait 3 seconds.
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                wait 1 second
                PathFind({_zombie}, "red")
                exit loop
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                wait 1 second
                PathFind({_zombie}, "blue")
                exit loop
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
now I added a small push backwards and upwards and it looks way better
Code:
function PathFind(zombie: entity, team: string):
    if {_team} is "red":
        set {_target} to a random element out of {blue team zombie::*}
        add {_zombie} to {red team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {blue team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                push {_target} upwards with force 0.5
                push {_target} backwards with force 0.5
                wait 1 second
                PathFind({_zombie}, "red")
                exit loop
            wait a tick
    if {_team} is "blue":
        set {_target} to a random element out of {red team zombie::*}
        add {_zombie} to {blue team zombie::*}
        while {_zombie} is alive:
            set path target with speed 1.2 of {_zombie} to {_target}
            if {_target} is not alive:
                set {_target} to a random element out of {red team zombie::*}
            if distance between {_zombie} and {_target} is less than or equal to 1:
                damage {_target} by 1 heart
                push {_target} upwards with force 0.5
                push {_target} backwards with force 0.5
                wait 1 second
                PathFind({_zombie}, "blue")
                exit loop
            wait a tick

on unload:
    kill {red team zombie::*}#kill all red team zombies
    kill {blue team zombie::*}
    delete {red team zombie::*}#clear the variable
    delete {blue team zombie::*}

command /spawnzombie <text>:
    permission: op
    trigger:
        if arg-1 = "red":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(255, 0, 0)
            set the display name of the last spawned zombie to "&4Red Zombie"
            PathFind(last spawned entity, "red")
        else if arg-1 = "blue":
            spawn 1 zombie at player
            equip last spawned zombie with a leather helmet
            dye last spawned zombie's helmet rgb(0, 0, 255)
            set the display name of the last spawned zombie to "&1Blue Zombie"
            PathFind(last spawned entity, "blue")
 
Status
Not open for further replies.