Public feed #887222

Mine

public text v1 · immutable
Raw Edit
·published 2008-02-01 04:50 UTC
rendered paste body

--If the Arena has yet to be created put anything in here that should happen when it is created.
if (g_arena == nil) then
	g_arena = nil
	g_player = nil
	g_bGameRunning = false
	g_bGameRestarting = false
	g_cHumanKills = 0
	g_cZombieKills = 0
	g_cZombies = 0
	g_cHumans = 0
	g_cCompletedTurrets = 0
	g_cCompletedWalls = 0
	g_vHumanSilverVendor = nil
	g_vZombieClassVendor = nil
	g_vZombieSilverVendor = nil
	g_qFortSlots = {['wall1'] = nil, ['wall2'] = nil, ['wall3'] = nil, ['wall4'] = nil, ['turret1'] = nil, ['turret2'] = nil, ['powergenerator'] = nil}
	g_qFortQuests = {['turrets'] = false, ['powergenerator'] = false, ['walls'] = false}
	g_oPlayers = { }
	g_goPlayers = { }
	g_tBlankPlayer = {['Silver'] = 0, ['Achievments'] = {'none'}, ['Zombie Kills'] = 0, ['Human Kills'] = 0}
	dofile('TSF.lua')
end


--Create our arena.
function Arena_OnCreate(arena)
	g_arena = arena
	math.randomseed(os.time())
end

function Player_OnJoin(plyr)
	plyr:message('%Welcome to Zombie Mod v0.1')
	--load players
	if (g_goPlayers[plyr.m_name] == nil) then
		g_goPlayers[plyr.m_name] = {['Zombie Kills'] = 0}
	end
	if (g_bGameRunning == false and g_arena:numPlaying() >= 2) then
		startGame()
	end
	if (g_bGameRunning == false) then
		plyr:message('*(Current Game Status: None)')
	elseif (g_bGameRunning == true) then
		plyr:message('*(Current Game Status: Running)')
		plyr:message('*Zombies = ' .. g_cZombies .. ', Humans ' .. g_cHumans)
	else
		g_arena:message('Fatal Error, Player on join')
	end
end

function Msg_OnCommand(plyr, command, payload, recipient, msg_type) -- player, string, string, string, integer
	
	if (plyr:getPermissionLevel() == 3) then
		if (command == '?reloadscript') then
			plyr:message('Reloading Script')
			dofile('zombiemod.lua')
			plyr:message('Script Reloaded')
			return
		elseif (command == '?reloadtsf') then
			plyr:message('Reloading TSF')
			dofile('TSF.lua')
			plyr:message('TSF Reloaded')
			return
		elseif (command == '?whereami') then
			plyr:message('Gathering information on your location.')
			local coords = plyr:coords()
			plyr:message('X= ' .. coords.x .. ' Y= ' .. coords.y .. ' Rotation= ' .. coords.rotation)
			plyr:message('You are in '..location(coords.x, coords.y))
			return
		elseif (command == "?place") then
			plyr:message('Placing '..payload..' at current location')
			local TSF = io.open('place.txt', "a+")
			local coords = plyr:coords()
			TSF:write(''..payload..' '..coords.x..', '..coords.y)
			TSF:close()
			return
		elseif (command == '?turretbuild') then
			local player = g_arena:getPlayer(''..payload..'')
			if (player ~= nil) then
				player:inventory_modify('Gun Barrel', 1)
				player:inventory_modify('Box of Shells', 2)
				player:inventory_modify('Power Cord', 1)
			else
				plyr:message('invalid player')
			end
			return
		elseif (command == '?wallbuild') then
			local player = g_arena:getPlayer(''..payload..'')
			if (player ~= nil) then
				player:inventory_modify('Concrete Slab', 3)
				player:inventory_modify('Concrete Holder', 2)
			else
				plyr:message('invalid player')
			end
			return
		elseif (command == '?powerbuild') then
			local player = g_arena:getPlayer(''..payload..'')
			if (player ~= nil) then
				player:inventory_modify('Power Cord', 2)
				player:inventory_modify('Broken Generator', 1)
				player:inventory_modify('Jug of Gas', 1)
			else
				plyr:message('invalid player')
			end
			return
		end
	end

end

function location(x, y)
	--1300 x 1300 blocks...
	local letter
	local number
	
	local alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
	local numbers = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'}
	letter = alphabet[math.ceil(x / 1300)]
	number = numbers[math.ceil(y / 1300)]
	
	local coords = ''..letter..''..number..''
	return coords
end

function Player_OnUnspec(plyr)
	if (g_bGameRunning == true) then
		if (g_cHumans <= 5) then
			plyr:inventory_modify('Human', 1)
			plyr:unspec('Humans', 'Test')
			g_cHumans = g_cHumans + 1
		else
			plyr:inventory_modify('Zombie', 1)
			plyr:unspec('Zombies', 'Test')
			g_cZombies = g_cZombies + 1
		end
	elseif (g_bGameRunning == false) then
		plyr:inventory_modify('Human', 1)
		plyr:unspec('Humans', 'Test')
		g_cHumans = g_cHumans + 1
	else
		g_arena:message('Fatal Error no game found')
	end
	
	if (g_bGameRunning == false and g_bGameRestarting == false) then
		g_arena:message('New Game Starting in 1 Minute')
		g_bGameRestarting = true
		event_create(startGame, 60000, g_arena)
		event_create(checkTeams, -60000, g_arena)
	end
	return false
end

function Vehicle_OnProduce(vehicle, plyr, menuitem)
	local vid = vehicle:vehicletypeid()
	g_arena:message('using vid ' ..vid)
	if (vid == 403) then
		if (plyr:getTeam().m_name == 'Zombie') then
			if (menuitem == 0) then
				plyr:message('$This is the Zombie Class Trainer, as the zombies grown in numbers more and more classes will be unlocked.')
				plyr:message('$The following classes are listed by <zombie name> - <how many zombies there need to be to unlock>.')
				plyr:message('')
				plyr:message('$---------Zombie----------Health----------Speed------------------------Special Abilities(if any)----------')
				plyr:message('@----Normal Zombie---------150-------------50-------------------------------Stun--------------------------')
				plyr:message('!----Spider Zombie---------50--------------50-------------------------------Hard to Hit-------------------')
				plyr:message('@----Fast Zombie-----------100-------------65-------------------------------Leap--------------------------')
				plyr:message('!----Exploding Zombie------200-------------45-------------------------------Explode on Death--------------')
				plyr:message('@----Hybrid-Zombie---------100-------------55-------------------------------Can Use Basic Human Weapons---')
			elseif (menuitem == 1) then
				if (g_cZombies >= 0) then
					plyr:inventory_modify('Zombie', 1)
					plyr:message('You are now a Zombie')
				else
					g_arena:message('Not Enough Zombies')
				end
			elseif (menuitem == 2) then
				if (g_cZombies >= 5) then
					plyr:inventory_modfiy('Spider Zombie', 1)
					plyr:message('You are now a Spider Zombie')
				else
					g_arena:message('Not Enough Zombies')
				end
			elseif (menuitem == 3) then
				if (g_cZombies >= 10) then
					plyr:inventory_modify('Fast Zombie', 1)
					plyr:message('You are now a Fast Zombie')
				else
					g_arena:message('Not Enough Zombies')
				end
			elseif (menuitem == 4) then
				if (g_cZombies >= 15) then
					plyr:inventory_modify('Exploding Zombie', 1)
					plyr:message('You are now a Exploding Zombie')
				else
					g_arena:message('Not Enough Zombies')
				end
			elseif (menuitem == 5) then
				if (g_cZombies >= 20) then
					plyr:inventory_modify('Hybrid-Zombie', 1)
					plyr:message('You are a Hybrid Zombie')
				else
					g_arena:message('Not Enough Zombies')
				end
			end
		else
			g_arena:message('You are not a Zombie')
		end
	elseif (vid == 405 or vid == 406 or vid == 400 or vid == 401 or vid == 402 or vid == 404 or vid == 407) then
		fortQuests(vid, plyr, menuitem)
	end
	return false
end

function startGame()
	g_arena:message('%Starting a new game')
	g_bGameRunning = true
	if (vendorSpawn() == false) then
		g_arena:message('Error in VendorSpawn')
		return false
	end
	if (spawnFort() == false) then
		g_arena:message('Error in Spawn Fort')
		return false
	end
	if (foodSpawn() == false) then
		g_arena:message('Error in FoodSpawn')
		return false
	end
	if (chooseZombie() == false) then
		g_arena:message('Error in choosing Zombie')
		return false
	end
	for i=1, g_arena:numPlayers() do
		local player = g_arena:getPlayer(i)
		if (player ~= nil) then
			player:changeTeam('Humans', 'test')
			player:warp(5030, 4781, 10)
		end
	end
	return false
end

function vendorSpawn()
	--g_vHumanSilverVendor = g_arena:vehicle_create()
	g_vZombieClassVendor = g_arena:vehicle_create(403, 4843, 4981, 237)
	g_vZombieClassVendor:setFrequency(-1)
	--g_vZombieSilverVendor = g_arena:vehicle_create()
end

function spawnFort()
	--This is where we spawn the for parts.
	g_qFortSlots['turret1'] = g_arena:vehicle_create(406, 3756, 4684, 179)
	g_qFortSlots['turret1']:setFrequency(-1)
	g_qFortSlots['turret2'] = g_arena:vehicle_create(405, 5024, 3398, 179)
	g_qFortSlots['turret2']:setFrequency(-1)
	g_qFortSlots['wall1'] = g_arena:vehicle_create(400, 4572, 4766, 179)
	g_qFortSlots['wall1']:setFrequency(-1)
	g_qFortSlots['wall2'] = g_arena:vehicle_create(401, 4608, 4686, 179)
	g_qFortSlots['wall2']:setFrequency(-1)
	g_qFortSlots['wall3'] = g_arena:vehicle_create(402, 4956, 4294, 179)
	g_qFortSlots['wall3']:setFrequency(-1)
	g_qFortSlots['wall4'] = g_arena:vehicle_create(404, 5044, 4294, 179)
	g_qFortSlots['wall4']:setFrequency(-1)
	g_qFortSlots['powergenerator'] = g_arena:vehicle_create(407, 5212, 4948, 179)
	g_qFortSlots['powergenerator']:setFrequency(-1)
	return true
end

function foodSpawn()
	--This is going to be where we spawn the food
	local arena = g_arena
	arena:item_create("Food", 10, 727, 4745)
	arena:item_create("Food", 10, 1011, 3729)
	arena:item_create("Food", 10, 2083, 3845)
	arena:item_create("Food", 10, 2635, 3865)
	arena:item_create("Food", 10, 4487, 4901)
	arena:item_create("Food", 10, 4651, 4405)
	arena:item_create("Food", 10, 4555, 4061)
	arena:item_create("Food", 10, 5207, 3873)
	arena:item_create("Food", 10, 4719, 3229)
	arena:item_create("Food", 10, 4863, 2105)
	arena:item_create("Food", 10, 4463, 1777)
	arena:item_create("Food", 10, 5059, 1673)
	arena:item_create("Food", 10, 4735, 833)
	arena:item_create("Food", 10, 2335, 1573)
	arena:item_create("Food", 10, 2143, 3173)
	arena:item_create("Food", 10, 2863, 2309)
	arena:item_create("Food", 10, 2527, 3253)
	arena:item_create("Food", 10, 2541, 4509)
	arena:item_create("Food", 10, 3325, 4433)
	arena:item_create("Food", 10, 3449, 3993)
	arena:item_create("Food", 10, 3257, 3365)
	arena:item_create("Food", 10, 3837, 3093)
	arena:item_create("Food", 10, 3529, 2401)
	arena:item_create("Food", 10, 3237, 2057)
	arena:item_create("Food", 10, 3565, 1549)
	arena:item_create("Food", 10, 3065, 1973)
	arena:item_create("Food", 10, 2541, 1897)
	arena:item_create("Food", 10, 2493, 2825)
	arena:item_create("Food", 10, 2909, 2697)
	arena:item_create("Food", 10, 3341, 4928)
	arena:item_create("Food", 10, 4209, 4324)
	arena:item_create("Food", 10, 4617, 3720)
	arena:item_create("Food", 10, 4465, 2864)
	arena:item_create("Food", 10, 5181, 2860)
	arena:item_create("Food", 10, 5049, 2068)
	arena:item_create("Food", 10, 4765, 1424)
	arena:item_create("Food", 10, 1153, 3332)
	arena:item_create("Food", 10, 2041, 4512)
	arena:item_create("Food", 10, 2549, 4880)
	arena:item_create("Food", 10, 2289, 4880)
	return true
end

function fortQuests(vid, plyr, menuitem)
	--This is where we manage fort quests
	if (plyr:getTeam().m_name == 'Zombie') then
		return
	end
	if (vid == 400 or vid == 401 or vid == 402 or vid == 404) then
		if (g_qFortQuests['turrets'] == true) then
			if (menuitem == 0) then
				plyr:message('This looks like a good place to build a wall however you will need 3 Concrete Slabs, and 2 Concrete Holders')
			elseif (menuitem == 1) then
				local slabs = plyr:inventory_find('Concrete Slab')
				local holders = plyr:inventory_find('Concrete Holder')
				if (slabs >= 3 and holders >= 2) then
					plyr:inventory_modify('Concrete Slab', -3)
					plyr:inventory_modify('Concrete Holder', -2)
					g_cCompletedWalls = g_cCompletedWalls + 1
					if (vid == 400) then
						local c = g_qFortSlots['wall1']:coords()
						g_qFortSlots['wall1']:destroy()
						g_qFortSlots['wall1'] = g_arena:vehicle_create(408, c.x, c.y, c.rotation)
					elseif (vid == 401) then
						local c = g_qFortSlots['wall2']:coords()
						g_qFortSlots['wall2']:destroy()
						g_qFortSlots['wall2'] = g_arena:vehicle_create(409, c.x, c.y, c.rotation)
					elseif (vid == 402) then
						local c = g_qFortSlots['wall3']:coords()
						g_qFortSlots['wall3']:destroy()
						g_qFortSlots['wall3'] = g_arena:vehicle_create(410, c.x, c.y, c.rotation)
					elseif (vid == 404) then
						local c = g_qFortSlots['wall4']:coords()
						g_qFortSlots['wall4']:destroy()
						g_qFortSlots['wall4'] = g_arena:vehicle_create(411, c.x, c.y, c.rotation)
					end
				else
					plyr:message('You do not have enough materials to construct this.')
				end
			end
		else
			plyr:message('You should probably worry about some turrets first.')
		end
	end
	
	if (vid == 406 or vid == 405) then
		if (menuitem == 0) then
			plyr:message('This is a good place to build a turret, but you will need 1 Gun Barrel, 2 Box of Shells and 1 Power Cord')
		elseif (menuitem == 1) then
			local barrels = plyr:inventory_find('Gun Barrel')
			local shells = plyr:inventory_find('Box of Shells')
			local cords = plyr:inventory_find('Power Cord')
			if (barrels >= 1 and shells >= 2 and cords >= 1) then
				plyr:inventory_modify('Gun Barrel', -1)
				plyr:inventory_modify('Box of Shells', -2)
				plyr:inventory_modify('Power Cord', -1)
				g_cCompletedTurrets = g_cCompletedTurrets + 1
				if (vid == 406) then
					local c = g_qFortSlots['turret1']:coords()
					g_qFortSlots['turret1']:destroy()
					g_qFortSlots['turret1'] = g_arena:vehicle_create(412, c.x, c.y, c.rotation)
				elseif (vid == 405) then
					local c = g_qFortSlots['turret2']:coords()
					g_qFortSlots['turret2']:destroy()
					g_qFortSlots['turret2'] = g_arena:vehicle_create(413, c.x, c.y, c.rotation)
				end
			else
				plyr:message('You do not have enough materials to construct this.')
			end
		end
	end
	
	if (vid == 407) then
		if (g_qFortQuests['walls'] == true) then
			if (menuitem == 0) then
				plyr:message('You could build a good Generator here, but you will need 1 Jug of Gas, 1 Broken Generator, and 2 Power Cords')
			elseif (menuitem == 1) then
				local gas = plyr:inventory_find('Jug of Gas')
				local cords = plyr:inventory_find('Power Cord')
				local generator = plyr:inventory_find('Broken Generator')
				if (gas >= 1 and cords >= 2 and generator >= 1) then
					plyr:inventory_modify('Jug of Gas', -1)
					plyr:inventory_modify('Power Cord', -2)
					plyr:inventory_modify('Broken Generator', -1)
					g_arena:message('Humans Win, new game in 1 minute.')
					g_bGameRunning = false
					g_bGameRestarting = true
					event_create(startGame, 60000, g_arena)
					local c = g_qFortSlots['powergenerator']:coords()
					g_qFortSlots['powergenerator']:destroy()
					g_qFortSlots['powergenerator'] = g_arena:vehicle_create(414, c.x, c.y, c.rotation)
				else
					plyr:message('You do not have eaough materials to construct this.')
				end
			end
		else
			plyr:message('You should probably worry about some walls first.')
		end
	end
	
	
	--Now lets check to see if any quests were finished
	if (g_cCompletedWalls == 4) then
		g_qFortQuests['walls'] = true
	elseif (g_cCompletedTurrets == 2) then
		g_qFortQuests['turrets'] = true
	end
end

function chooseZombie()
	local number = math.random(1, g_arena:numPlaying())
	player = g_arena:getPlayer(number)
	if (player:spectator() == false and player ~= nil) then
		player:changeTeam('Zombie', 'test')
		player:inventory_modify('Zombie', 1)
		g_cHumans = g_cHumans - 1
		g_cZombies = g_cZombies + 1
		player:warp(1, 1, 0)
	else
		chooseZombie()
	end
	return true
end

function checkTeams()
	local zombie = team_fromName(g_arena, 'Zombie')
	local human = team_fromName(g_arena, 'Humans')
	if (zombie:numPlaying() == 0) then
		chooseZombie()
	else
		g_cZombies = zombie:numPlaying()
	end
	
	if (human:numPlaying() == 0) then
		g_bGameRunning = false
		g_bGameRestarting = true
		g_arena:message('Zombies Win')
		event_create(startGame, 60000, g_arena)
	else
		g_cHumans = human:numPlaying()
	end
	return false
end

function Player_OnDeath(killer, victim)
	g_arena:message(victim..' was turned by '..killer)
	checkTeams()
end