villager defender.sk

Created by Mich

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

#villager defender
options:
	logo: &l&a[&eDefiende la villa&a]&l&9

function vdScoreboard(player: player):
	while {vd game} is true:
		set title of {_player}'s scoreboard to "{@logo}"
		set line 6 of {_player}'s scoreboard to "&9&lPlayers: &r&a%{_player}%"
		set line 5 of {_player}'s scoreboard to "&9&lZombie kills: &r&a%{vd zombies kills::%{_player}%}% "
		set line 4 of {_player}'s scoreboard to "&9&lMoney: &r&a%{vd money::%{_player}%}%"
		set line 3 of {_player}'s scoreboard to "&9&lZombies: &r&a%{vd zombies alive}%"
		set line 2 of {_player}'s scoreboard to "&9&lVillagers: &r&a%{vd villagers alive}%"
		set line 1 of {_player}'s scoreboard to "&9&lRound: &r&a%{vd round}%"
		wait 1 second

function vdPathFind(zombie: entity):
	set {_target} to a random element out of {vd villagers::*}
	add {_zombie} to {vd zombie target::*}
	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 {vd villagers::*}
		wait a tick

function vd():
	if {vd game} is not set:
		set {vd villagers alive} to 0
		set {vd zombies alive} to 0
		set {vd round} to 1
		message "{@logo} The round 1 starts in 20 seconds" to {vd players::*}
		set {vd game} to true
		vdSpawn()
	else:
		delete {vd zombie target::*}
		message "{@logo} The round %{vd round}% starts in 20 seconds" to {vd players::*}
		vdSpawn()
	
function vdSpawn():
	wait 15 seconds
	message "{@logo} The round %{vd round}% start in 5 seconds" to {vd players::*}
	wait 5 seconds
	set {vd villagers alive} to {vd max villagers}
	set {vd zombies alive} to {vd min zombies}
	vdSpawnVillagers()
	vdSpawnZombies()

function vdSpawnVillagers():
	loop {vd max villagers} times:
		set {_vspawn} to a random element out of {vd villagers spawn::*}
		spawn a villager at {_vspawn}'s location
		add last spawned entity to {vd villagers::*}
		vdVida(last spawned entity)
		wait a tick

function vdSpawnZombies():
	loop {vd min zombies} times:
		set {_zspawn} to a random element out of {vd zombies spawn::*}
		spawn a zombie at {_zspawn}'s location
		add last spawned entity to {vd zombies::*}
		vdZombie(last spawned entity)
		vdVida(last spawned entity)
		wait a tick

function vdGameOver():
	delete {vd respawn::*}
	delete {vd zombie target::*}
	delete {vd zombies kills::*}
	teleport {vd players::*} to {vd loc::lobby}
	clear {vd players::*}'s scoreboard
	delete {vd armor::*}
	wait a tick
	kill {vd zombies::*}
	kill {vd villagers::*}
	delete {vd players::*}
	delete {vd zombies alive}
	delete {vd villagers alive}
	set {vd max players} to 1
	set {vd max villagers} to 6
	set {vd min zombies} to 4
	delete {vd round}
	delete {vd sword::*}
	delete {vd money::*}
	delete {vd players}
	wait 5 seconds
	delete {vd game}

function vdZombie(zombie: entity):
	#chances para equipar al zombie
	chance of 15%:
		give a random element out of {vd weapons::*} to {_zombie}
	chance of 15%:
		equip {_zombie} with a random element out of {vd armors::*}
		equip {_zombie} with a random element out of {vd armors::*}
		equip {_zombie} with a random element out of {vd armors::*}
		equip {_zombie} with a random element out of {vd armors::*}
	chance of 30%:
		vdPathFind({_zombie})

function vdEquipPlayer(player: player):
	set slot 0 of {_player} to 8 apples
	set slot 1 of {_player} to 1 wood sword
	set slot 2 of {_player} to 1 grey dye named "&aBow slot"
	set slot 3 of {_player} to 1 grey dye named "&aBlocks slot"
	set slot 4 of {_player} to 1 emerald named "&aShop"
	set slot 8 of {_player} to 1 grey dye named "&aArrows slot"
	set {vd zombies kills::%{_player}%} to 0
	wait 1 second
	vdScoreboard({_player})

function vdVida(entity: entity):
	set {_vida} to health of {_entity}
	set {_x1} to 0#Vida minima
	set {_x3} to 10#Vida maxima
	set {_y1} to 0#% minimo
	set {_y3} to 100#% maximo
	set {_calculate1} to ({_vida} - {_x1})
	set {_calculate2} to ({_y3} - {_y1})
	set {_calculate3} to ({_calculate1} * {_calculate2})
	set {_calculate4} to ({_x3} - {_x1})
	set {_calculate5} to ({_calculate3} / {_calculate4})
	set {_y2} to ({_calculate5} + {_y1})
	if {_y2} is more than 75:
		set the name of {_entity} to "&9Health: &a%{_y2}%%%"
	else if {_y2} is more than 50:
		set the name of {_entity} to "&9Health: &e%{_y2}%%%"
	else if {_y2} is more than 25:
		set the name of {_entity} to "&9Health: &c%{_y2}%%%"
	else:
		set the name of {_entity} to "&9Health: &4%{_y2}%%%"

on load:
	set {vd max players} to 1
	set {vd max villagers} to 6
	set {vd min zombies} to 4
	set {vd players} to 0
	
on unload:
	vdGameOver()

command /vd [<text>] [<text>]:
	executable by: players
	permission: vd.use
	trigger:
		if arg 1 is "set":
			player has permission "vd.admin"
			if arg 2 is "spawn":
				set {vd loc::spawn} to the player's location 
				message "{@logo} Spawn set at your location."
			else if arg 2 is "lobby":
				player has permission "vd.admin"
				set {vd loc::lobby} to the player's location
				message "{@logo} Lobby set at your location."
			else if arg 2 is "vspawn":
				player has permission "vd.admin"
				set {_vspawn} to the player's location
				add {_vspawn} to {vd villagers spawn::*}
				message "{@logo} Villager spawn set at your location."
			else if arg 2 is "zspawn":
				player has permission "vd.admin"
				set {_vspawn} to the player's location
				add {_vspawn} to {vd zombies spawn::*}
				message "{@logo} Zombie spawn set at your location."
			else:
				message "{@logo} The arguments are vspawn, zspawn, spawn and lobby."
		else if arg 1 is "remove":
			player has permission "vd.admin"
			if arg 2 is "vspawn":
				delete {vd villagers spawn::*}
				message "{@logo} Villagers spawns removed."
			else if arg 2 is "zspawn":
				player has permission "vd.admin"
				delete {vd zombies spawn::*}
				message "{@logo} Zombies spawns removed."
			else:
				message "{@logo} The arguments are zspawn and vspawn."
		else if arg 1 is "add":
			player has permission "vd.admin"
			if arg 2 is "armor":
				add player's held item to {vd armors::*}
				message "{@logo} you added held item."
				message "&e%{vd armors::*}%"
			else if arg 2 is "wepon":
				add player's held item to {vd wepons::*}
				message "{@logo} you added held item."
				message "&e%{vd weapons::*}%"
			else:
				message "{@logo} The arguments are armor and wepon."
		else if arg 1 is "join":
			if {vd game} is not set:
				add player to {vd players::*}
				set {vd money::%player%} to 0
				add 1 to {vd players}
				message "{@logo} %player% Join the game." to {vd players::*}
				teleport the player to {vd loc::spawn}
				wait 1 second 
				vdEquipPlayer(player)
				vd()
		else:
			message "{@logo} /vd join"
			player has permission "vd.admin"
			message "{@logo} /vd set spawn"
			message "{@logo} /vd set lobby"
			message "{@logo} /vd set vspawn"
			message "{@logo} /vd set zspawn"
			message "{@logo} /vd remove vspawn"
			message "{@logo} /vd remove zspawn"
			
on leave:
	loop {vd players::*}:
		if player is loop-value:
			remove loop-value from {vd players::*}
			remove 1 from {vd players}
			if {vd players} is equal to 0:
				vdGameOver()

on death of a zombie:
	loop {vd zombies::*}:
		if victim is loop-value:
			delete drops
			if {vd game} exists:
				set {vd zombies alive} to {vd zombies alive} - 1
				if {vd zombies alive} is equal to 0:
					message "{@logo} Round competed!" to {vd players::*}
					set {vd round} to {vd round} + 1
					set {_integer} to a random integer between 1 and 3
					set {vd min zombies} to {vd min zombies} + {_integer}
					set {vd zombies alive} to {vd min zombies}
					delete {vd game}
					wait a tick
					kill {vd villagers::*}
					wait a tick
					set {vd game} to true
					vd()

on death of a villager:
	loop {vd villagers::*}:
		if victim is loop-value-1:
			if {vd game} exists:
				set {vd villagers alive} to {vd villagers alive} - 1
				if {vd villagers alive} is equal to 0:
					message "{@logo} All villagers died game over!." to {vd players::*}
					vdGameOver()
					loop {vd players::*}:
						teleport loop-value-2 to {survival loc %loop-value-2%}
				else:
					message "{@logo} A villager die!! Villagers left %{vd villagers alive}%." to {vd players::*}

on damage of a player:
	attacker is a player
	loop {vd players::*}:
		if victim is loop-value:
			cancel event 

on damage of a zombie:
	loop {vd zombies::*}:
		if loop-value is victim:
			vdVida(victim)

on damage of a villager:
	if attacker is a player:
		loop {vd players::*}:
			if attacker is loop-value:
				cancel event 
	else:
		vdVida(victim)
		
on death of a zombie:
	attacker is a player
	loop {vd zombies::*}:
		if victim is loop-value:
			set {vd money::%attacker%} to {vd money::%attacker%} + 4
			set {vd zombies kills::%attacker%} to {vd zombies kills::%attacker%} + 1
			send title "&a+4" to attacker for 2.5 seconds
			wait 2.5 seconds
			reset the title

on death of a player:
	loop {vd players::*}:
		if victim is loop-value:
		delete {vd sword::%loop-value%}
		delete {vd armor::%loop-value%}
		#force event-player to respawn
		delete drops
		subtract 1 from {vd players}
		if {vd players} is equal to 0:
			vdGameOver()
			exit loop
		else:
			set {vd respawn::%loop-value%} to 15
			message "{@logo} %loop-value% will come back in 15 seconds." to {vd players::*}
			while {vd players} is not equal to 0:
				wait 1 second
				set {vd respawn::%loop-value%} to {vd respawn::%loop-value%} - 1
				if {vd players} is equal to 0:
					vdGameOver()
					teleport loop-value to {vd loc::lobby}
					exit loop
				if {vd respawn::%loop-value%} is equal to 0:
					teleport loop-value to {vd loc::spawn}
					vdEquipPlayer(loop-value)
					message "%loop-player% Is back!" to {vd players::*}
					exit loop
				

on respawn:
	loop {vd players::*}:
		if event-player is loop-value:
			if {vd players} is more than 0:
				teleport loop-value to {vd loc::lobby}
			if {vd respawn::%loop-value%} is equal to 0:
				delete {vd respawn::%loop-value%}
				teleport loop-value to {vd loc::spawn}
				vdEquipPlayer(loop-value)
				add 1 to {vd players}
			else:
				teleport loop-value to {survival loc %loop-value%}

on droping:
	loop {vd players::*}:
		if loop-value is player:
			cancel event

on place:
	loop {vd players::*}:
		if loop-value is player:
			set {_blockloc} to location of event-block
			add {_blockloc} to {vd blocks::*}
			wait 1 minute
			set event-block to air
			remove {_blockloc} from {vd blocks::*}

on unload:
	loop {vd blocks::*}:
		set block at location at loop-value to air
		remove loop-value from {vd blocks::*}
		wait a tick

on break:
	loop {vd players::*}:
		if loop-value is player:
			cancel event

on inventory click:
	loop {vd players::*}:
		if loop-value is player:
			cancel event

#arreglar armadura y espada
on arm swing:
	loop {vd players::*}:
		if loop-value is player:
			repair tool of player
			repair helmet of player
			repair chestplate of player
			repair leggings of player
			repair boots of player

on rightclick holding a emerald:
	name of tool of player is "&aShop"
	set {_gui} to a new chest inventory with 3 row with name "{@logo}"
	set slot 0 of {_gui} to 8 apples with lore "&9&lCost: &c8$"
	set slot 2 of {_gui} to a bow with lore "&9&lCost: &c10$"
	set slot 3 of {_gui} to 64 oak wood planks with lore "&9&lCost: &c80 || &9&aThis block last 1 minute in the floor."
	set slot 8 of {_gui} to 64 arrows with lore "&9&lCost: &c32$"
	set slot 9 of {_gui} to 8 steak with lore "&9&lCost: &c24$"
	if {vd sword::%player%} is not set:
		set slot 1 of {_gui} to a stone sword named "&l&9Upgrade sword." with lore "&9&lCost: &c10$"
	else if {vd sword::%player%} is "stone":
		set slot 1 of {_gui} to a iron sword named "&l&9Upgrade sword." with lore "&9&lCost: &c25"
	else if {vd sword::%player%} is "iron":
		set slot 1 of {_gui} to a diamond sword named "&l&9upgrade sword." with lore "&9&lCost: &c60"
	else if {vd sword::%player%} is "diamond":
		set slot 1 of {_gui} to a diamond sword of sharpness 2 named "&l&9Enchant your sword." with lore "&9&lCost: &c100"
	else if {vd sword::%player%} is "max":
		set slot 1 of {_gui} to a bedrock named "&l&9Sword at maximum."
	if {vd armor::%player%} is not set:
		set slot 4 of {_gui} to a gold helmet named "&l&9Buy armor." with lore "&9&lCost: &c5"
	else if {vd armor::%player%} is "iron":
		set slot 4 of {_gui} to a iron helmet named "&l&9Upgrade armor." with lore "&9&lCost: &c20"
	else if {vd armor::%player%} is "iron2":
		set slot 4 of {_gui} to a iron helmet of protection 1 named "&l&9Upgrade armor." with lore "&9&lCost: &c20"
	else if {vd armor::%player%} is "max":
		set slot 4 of {_gui} to a bedrock named "&l&9Armour at maximum"
	open {_gui} to player


on inventory click:
	if name of event-inventory is "{@logo}":
		if index of event-slot = 0:
			cancel event
			if {vd money::%player%} is more than or equal to 8:
				set slot 0 of the player to 8 apples
				set {vd money::%player%} to {vd money::%player%} - 8
			else:
				message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		else if index of event-slot = 1:
			if {vd sword::%player%} is not set:
				if {vd money::%player%} is more than or equal to 10:
					set {vd sword::%player%} to "stone"
					set {vd money::%player%} to {vd money::%player%} - 10
					set slot 1 of the player to stone sword
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
			else if {vd sword::%player%} is "stone":
				if {vd money::%player%} is more than or equal to 25:
					set {vd money::%player%} to {vd money::%player%} - 25
					set {vd sword::%player%} to "iron"
					set slot 1 of the player to iron sword
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
			else if {vd sword::%player%} is "iron":
				if {vd money::%player%} is more than or equal to 60:
					set {vd money::%player%} to {vd money::%player%} - 60
					set {vd sword::%player%} to "diamond"
					set slot 1 of the player to diamond sword 
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
			else if {vd sword::%player%} is "diamond":
				if {vd money::%player%} is more than or equal to 100:
					set {vd money::%player%} to {vd money::%player%} - 100
					set {vd sword::%player%} to "max"
					set slot 1 of the player to diamond sword of sharpness 2
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		else if index of event-slot = 2:
			if {vd money::%player%} is more than or equal to 10:
				subtract 10 from {vd money::%player%}
				set slot 2 of the player to bow
			else:
				message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		else if index of event-slot = 3:
			if {vd money::%player%} is more than or equal to 80:
				subtract 80 from {vd money::%player%}
				set slot 3 of the player to 64 oak wood planks
			else:
				message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		else if index of event-slot = 8:
			if {vd money::%player%} is more than or equal to 32:
				subtract 32 from {vd money::%player%}
				set slot 8 of the player to 64 arrows
			else:
				message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		else if index of event-slot = 4:
			if {vd armor::%player%} is not set:
				if {vd money::%player%} is more than or equal to 5:
					set {vd money::%player%} to {vd money::%player%} - 5
					set helmet of player to gold helmet
					set chestplate of player to gold chestplate
					set leggings of player to gold leggings
					set boots of player to gold boots
					set {vd armor::%player%} to "iron"
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
			else if {vd armor::%player%} is "iron":
				if {vd money::%player%} is more than or equal to 20:
					set helmet of player to iron helmet
					set chestplate of player to iron chestplate
					set leggings of player to iron leggings
					set boots of player to iron boots
					set {vd money::%player%} to {vd money::%player%} - 20
					set {vd armor::%player%} to "iron2"
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
			else if {vd armor::%player%} is "iron2":
				if {vd money::%player%} is more than or equal to 20:
					set helmet of player to iron helmet of protection 1
					set chestplate of player to iron chestplate of protection 1
					set leggings of player to iron leggings of protection 1
					set boots of player to iron boots of protection 1
					set {vd money::%player%} to {vd money::%player%} - 20
					set {vd armor::%player%} to "max"
				else:
					message "{@logo} Not enough money. Money: %{vd money::%player%}%"
		if index of event-slot is 9:
			if {vd money::%player%} is more than or equal to 24:
				set {vd money::%player%} to {vd money::%player%} - 24
				set slot 0 of the player to 8 steak
			else:
				message "{@logo} Not enough money. Money: %{vd money::%player%}%"
				
		close the player's inventory
command /vdmoney:
	executable by: players 
	permission: vd.use
	trigger:
		loop {vd players::*}:
			if loop-value is player:
				message "{@logo} Dinero: %{vd money::%player%}%"

on entity target:
	target is a player
	loop {vd zombie target::*}:
		if loop-value is event-entity:
			cancel event