All pastes #2972931 Raw Edit

Mine

public unlisted text v1 · immutable
#2972931 ·published 2015-04-15 08:32 UTC
rendered paste body
-- Based on mikade's Highlander
--------------------------------

-- Shopplander

-- Made by eldiablo

--------------------------------


HedgewarsScriptLoad("/Scripts/Locale.lua")
HedgewarsScriptLoad("/Scripts/Tracker.lua")


local atkArray = 	{
				amBazooka, amRCPlane, amBallgun, amDynamite, amCake, amHellishBomb, amBee, amMortar, amDrill, amGrenade, amClusterBomb, amMolotov, amSineGun, amWatermelon, amShotgun, amFirePunch, amWhip, amBaseballBat, amFlamethrower,  amMine, amSMine
					}

local utilArray = 	{  amBlowTorch, amExtraDamage, amIceGun, amBirdy, amLandGun, amPickHammer, amGirder, amPortalGun, amLaserSight, amLowGravity, amRubber, }

local wepArray = 	{}

local currHog
local lastHog
local started = false
local switchStage = 0

local lastWep = amNothing
local shotsFired = 0

function CheckForWeaponSwap()
	if GetCurAmmoType() ~= lastWep then
		shotsFired = 0
	end
	lastWep = GetCurAmmoType()
end

function onSlot()
	CheckForWeaponSwap()
end

function onSetWeapon()
	CheckForWeaponSwap()
end

function onHogAttack()
	CheckForWeaponSwap()
	shotsFired = shotsFired + 1
end

function StartingSetUp(gear)

	for i = 1, #wepArray do	
		setGearValue(gear,wepArray[i],0)
	end
      
     setGearValue(gear,amKamikaze,100)
	setGearValue(gear,amRope,100)
	setGearValue(gear,amSkip,100)
     

	i = 1 + GetRandom(#atkArray)
	setGearValue(gear,atkArray[i],1)

      i = 1 + GetRandom(#utilArray)
	setGearValue(gear,utilArray[i],1)

	SetHealth(gear, 100)

end

--[[function SaveWeapons(gear)
-- er, this has no 0 check so presumably if you use a weapon then when it saves  you wont have it

	for i = 1, (#wepArray) do
		setGearValue(gear, wepArray[i], GetAmmoCount(gear, wepArray[i]) )
		 --AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
	end

end]]

function ConvertValues(gear)

	for i = 1, #wepArray do
		AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
	end

end

-- this is called when a hog dies
function TransferWeps(gear)

	if CurrentHedgehog ~= nil then

		for i = 1, #wepArray do
			val = getGearValue(gear,wepArray[i])
			if val ~= 0 then

				setGearValue(CurrentHedgehog, wepArray[i], val)

				-- if you are using multi-shot weapon, gimme one more
				if (GetCurAmmoType()  == wepArray[i]) and (shotsFired ~= 0) then
					AddAmmo(CurrentHedgehog, wepArray[i], val+1)
				-- assign ammo as per normal
				else
					AddAmmo(CurrentHedgehog, wepArray[i], val)
				end

			end
		end

	end

end

function onGameInit()
	GameFlags = bor(GameFlags,gfInfAttack + gfRandomOrder + gfPerHogAmmo)
	HealthCaseProb = 100
end

function onGameStart()

	ShowMission	(
				loc("SHOPPLANDER"),
				loc("Not all hogs are born smart."),

				"- " .. loc("Eliminate enemy hogs and take their weapons.") .. "|" ..
				"- " .. loc("Per-Hog Ammo") .. "|" ..
				"- " .. loc("Weapons reset.") .. "|" ..
				"- " .. loc("Unlimited Attacks&Rope") .. "|" ..
				"", 4, 4000
				)

	if MapHasBorder() == false then
       	for i, w in pairs(airWeapons) do
            table.insert(atkArray, w)
        end
	end

	for i, w in pairs(atkArray) do
        table.insert(wepArray, w)
	end

	for i, w in pairs(utilArray) do
        table.insert(wepArray, w)
	end

	table.insert(wepArray, amSkip)
	table.insert(wepArray, amRope)
     table.insert(wepArray, amKamikaze)

	runOnGears(StartingSetUp)
	runOnGears(ConvertValues)


end

function CheckForHogSwitch()

	if (CurrentHedgehog ~= nil) then

		currHog = CurrentHedgehog

		if currHog ~= lastHog then

			-- re-assign ammo to this guy, so that his entire ammo set will
			-- be visible during another player's turn
			if lastHog ~= nil then
				ConvertValues(lastHog)
			end

			-- give the new hog what he is supposed to have, too
			ConvertValues(CurrentHedgehog)

		end

		lastHog = currHog

	end

end

function onNewTurn()
	CheckForHogSwitch()
end

--function onGameTick20()
--CheckForHogSwitch()
-- if we use gfPerHogAmmo is this even needed? Err, well, weapons reset, so... yes?
-- orrrr, should we rather call the re-assignment of weapons onNewTurn()? probably not because
-- then you cant switch hogs... unless we add a thing in onSwitch or whatever
-- ye, that is probably better actually, but I'll add that when/if I add switch
--end

--[[function onHogHide(gear)
	-- waiting for Henek
end

function onHogRestore(gear)
	-- waiting for Henek
end]]

function onGearAdd(gear)

	--if GetGearType(gear) == gtSwitcher then
	--	SaveWeapons(CurrentHedgehog)
	--end

	if (GetGearType(gear) == gtHedgehog) then
		trackGear(gear)
	end

end

function onGearDelete(gear)

	if (GetGearType(gear) == gtHedgehog) then --or (GetGearType(gear) == gtResurrector) then
		TransferWeps(gear)
		trackDeletion(gear)
	end

end

function onAmmoStoreInit()
	-- no, you can't set your own ammo scheme
end