Plenty Lua Codes and Questions

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
So, the following days are crucial to my first release, and so I'll be asking a few questions. Sorry about that in advance, here it goes the first:

1Q - Hair of the Dog.
Solved! Thanks bc1 and JFD. :)

Code:
function VenomResourceScarce(player, pMyUnit)
	if (pMyUnit ~= nil) and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
		local player = Players[playerID];
		local pMyUnit = Unit:GetOwner();
		local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat
		local iModifier = pMyUnit:GetStrategicResourceCombatPenalty()
		if pMyUnit == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
			if (iModifier == 2) then
				pUnit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (GameInfo.Units[pUnit:GetUnitType()].Combat) *100))
			elseif (iModifier == 1) then
				pUnit:SetBaseCombatStrength(iStrength + math.floor(0.15 * (GameInfo.Units[pUnit:GetUnitType()].Combat) *100))
			end
		end
	end
end

This code is supposed to make my units immune to the -15% Combat strength from not having the required Strategic Resource. My question is: What trigger do I set it to?
I assume that if I make it PlayerDoTurn it'll increase the unit's strength each turn, ad infinitum, which isn't the idea here.
So I went to see the Events and saw something about CombatSim, but I'm not sure how to work with it, nor if it is the right trigger.

Thoughts?

====================

2Q - Are you afraid of the Dark?
Solved! Thanks Machiavelli24 and bc1. :)

Code:
print('Venom Fear on Worker is on')
function VenomFearWorker(playerID, pMyUnit, pPlayer)
	if (pMyUnit ~= nil) and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
		local pPlayer = Players[playerID];
		local iMyPlayer = pMyUnit:GetOwner();
		local iTotalUnhappiness = pPlayer:GetUnhappiness();
		local iTotalHappiness = pPlayer:Gethappiness()
		
		if (pMyUnit:GetUnitAIType() == GameInfoTypes["UNIT_WORKER"]) then
			if (pMyUnit:IsStackedGreatGeneral()) then
				pMyUnit:workRate(250)
				Player.SetHappiness((iTotalHappiness - iTotalUnhappiness) - 1)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(VenomFearWorker)

This is supposed to increase the worker's Work Rate by 2,5 times while a Great General UU is stacked, but also increases the total Unhappiness by 1.
The problem is that it gets into a loop, eternally increasing the Unhappiness and I don't believe it's wearing off after the worker and the GG go separate ways.

Tips?

====================

3Q - Get Away from Me!

Ok, this one is probably a bit messy but I believe it can be done.
I don't know how to use 'pairs' but I've seen some uses in mods and believe this is an UA that probably needs that. Here is what I have so far:

Code:
function SinisterCitadelPush(playerID, CityID, iHex)
	local player = Players[playerID]
	local pcap = player:GetCapitalCity()
	if (player:IsEverAlive()) and player:isNotMinor then
		if (pcap:IsHasBuilding(GameInfoTypes["BUILDING_SPIDERPALACE"])) then -- must have the Spider palace (so any Spider civ is ok)
			local plot = pcap:Plot()
			local iHex = ToHexFromGrid( Vector2(plot:GetX(), plot:GetY()) )  -- check all adjacent plots
			for Units in iHex do
				for Units, in pairs do -- ??
					-- check if unit is from a player at war
					-- if it is, check the ring before that one (absolutely no idea)
						-- move every unit capable of moving
						if Unit:HasMoved
							return
						else
							damage
						end
					end
				end
			end
		end
	end
end
(it theoretically has one extra 'end' because the last 'if' has the comment '--' before it)
 
A few things to remember:

function VenomResourceScarce(playerID, pMyUnit)
local player = Players[playerID];

Parameters need to be consistent.

And there are often better methods of retrieving data (always check the wiki first):

local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat vs. unit.GetBaseCombatStrength()

As bc1 said, you'd be better off using a promotion to negate the penalty.

Code:
function VenomResourceScarce(playerID)
local player = Players[playerID]
if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
for unit in player:units() do [COLOR="Red"]-- cycling through all the player's units[/COLOR]
if unit:GetStrategicResourceCombatPenalty() > 0 then [COLOR="Red"]-- if any unit has a strategic combat penalty[/COLOR]
if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET"]) then [COLOR="Red"]-- if the unit doesn't already have the mitigating promotion[/COLOR]
  unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET"], true) [COLOR="Red"]-- give them it[/COLOR]
end
else
if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET"]) then [COLOR="Red"]-- if the unit has the mitigating promotion, but no longer has a strategic resource penalty[/COLOR]
  unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET"], false) [COLOR="Red"]-- remove it[/COLOR]
end
end
end
end
GameEvents.PlayerDoTurn.Add(VenomResourceScarce)
 
It seems so easy when you guys do it. :P

So, this would give them a bonus (as per the Promotion) but doesn't care how much the penalty was, right? I mean, if it gets to -3 (need 3 iron, per example) the promotion would still kick in, great, BUT the Combat strength modifier must be different from -1 and -2, in order to avoid a bonus Combat strength when at -1.

Code:
function VenomResourceScarce(playerID)
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
		for unit in player:units() do -- cycling through all the player's units
			if unit:GetStrategicResourceCombatPenalty() == 1 then -- if any unit has a strategic combat penalty
				if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"]) then -- if the unit doesn't already have the mitigating promotion
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"], true) -- give them it
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], false) 
				end
			elseif unit:GetStrategicResourceCombatPenalty() == 2 then
				if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"]) then -- if the unit doesn't already have the mitigating promotion
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], true) -- give them it
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"], false) 
				end
			else
				if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"]) or unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"]) then -- if the unit has the mitigating promotion, but no longer has a strategic resource penalty
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"], false) -- remove it
					unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], false)
				end
			end
		end
	end
end

Would this work?
 
GetStrategicResourceCombatPenalty() returns the value of the penalty, I expect. So it'd be more like:

Code:
if unit:GetStrategicResourceCombatPenalty() >= 45 then 
     if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"]) then -- if the unit doesn't already have the mitigating promotion
	unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"], true) -- give them it
     end
elseif unit:GetStrategicResourceCombatPenalty() >= 30 then
      if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"]) then
	unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], true)
      end
      if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"]) then
          unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"], false)
      end
elseif unit:GetStrategicResourceCombatPenalty() >= 15 then
     if not unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"]) then
	unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"], true)
      end
      if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"]) then
          unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"], false)
      end
      if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"]) then
          unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], false)
      end
else
    if unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"]) or unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"]) or unit:HasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"]) then 
	unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET1"], false)
	unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET2"], false)
        unit:SetHasPromotion(GameInfoTypes["PROMOTION_BANE_STRATEGIC_PENALTY_OFFSET3"], false)
    end
end

It's very convoluted, but I think would get the job done.
 
No, I got it. As I said, this is one easily done in .xml since it's merely strength pump, but I have other promotions in mind that can't be emulated via the pre-determined FireAxis tables like one that gives a bonus to Combat strength against a certain type of enemy that can only be chosen after you lose a city, since it will search for the certain enemy with iNewOwner.

This is the code, just in case:

Code:
function HirumaCityLost(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, bConquest)
	local newOwner = Players[iNewOwner]
	local oldOwner = Players[iOldOwner]
	local leaderType = GameInfo.Leaders[oldOnwer:GetLeaderType()].Type
	if newOwner ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and oldOwner == GameInfoTypes["CIVILIZATION_HIRUMA"] then
		local plot = Map.GetPlot(iCityX, iCityY)
		local capital = ioldOwner:GetCapitalCity()
		local random = Map.Rand(1) + 1
		if random == 1 then
			local iStrength = unit.GetBaseCombatStrength() --Thanks for the tip, JFD
			local iUnitID = GameInfo.Units.UNIT_JADEHAND.ID
			unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (unit.GetBaseCombatStrength()) *100))
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY1"])
		elseif random == 2 then
			local iUnitID = GameInfo.Units.UNIT_CRABERSERKER.ID
			unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY2"])
		else
			print('Something is wrong. It returned neither 1 nor 2, but " .. random .. " instead.')
		end
	end
end

The idea is that after someone conquers one of your cities, you get either of your UU in your Capital, with a promotion (in this case, it'll give Combat Strength bonus against the Conqueror), and in Jade Hand's case, it'll also boost his strength by 30%.
 
In this regard, you couldn't use a promotion to achieve the effect, you're right. Though you'd still want one to inform the effect to the player.

Code:
function HirumaCityLost(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, bConquest)
	local newOwner = Players[iNewOwner]
	local oldOwner = Players[iOldOwner]
	if newOwner ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and oldOwner == GameInfoTypes["CIVILIZATION_HIRUMA"] then
		local plot = Map.GetPlot(iCityX, iCityY)
		local capital = oldOwner :GetCapitalCity()
		local random = Map.Rand(1) + 1
               if random == 1 then
			local iStrength = unit.GetBaseCombatStrength()
			local unit = oldOwner:InitUnit (GameInfoTypes["UNIT_JADEHAND"] , capital:GetX(), capital:GetY() ) -- [COLOR="Red"]pPlayer doesn't exist, mostly because there are two players involved in this event. Oldowner is the one you want. Not putting local in front of unit makes that variable a global. Globals should be used as little as possible, as they demand more from the game to run. For unit above, that is already localized; just in a different place.[/COLOR]
                        unit:JumpToNearestValidPlot()
			unit:SetBaseCombatStrength(iStrength + math.floor(0.30 *(unit.GetBaseCombatStrength()) *100))	
                        unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"], true) [COLOR="Red"]-- You wouldn't need two different promotions, as they're just there for aesthetic and informative purposes.[/COLOR]
		elseif random == 2 then
			local unit = oldOwner:InitUnit (GameInfoTypes["UNIT_CRABERSERKER"], capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
		        unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"], true)
		else
			print('Something is wrong. It returned neither 1 nor 2, but " .. random .. " instead.')
		end
	end
end

Still, you're getting the idea. I'm glad that you try to write out the code first -- it's the only way you'll really learn lua.

What I tend to do with localizing is to only make a variable things that I'm going to use at least more than once. For instance, you need the player's capital four times (capital:GetX() and capital:GetY(), for each random), so I would localize this. However, you only need the know the unit you're creating once, so I just put a direct reference to that where's its needed.

All that said, the bonus against the Conqueror is beyond me.
 
Ah, that was a pretty bad move on my part, making two distinct Promotions.
I thought of something, but I believe it'll lag slower computers though:
I give them the Promotion, which will have no effect on itself, but check everyturn for units with that Promotion and give them a bonus against the old owner via some kind of global variable, instead of local (if that's a thing, maybe I'm just talking out of my *** here).

Thank you very much! I have a few more codes I'm working on, but they are working for the time being, mostly due to this forum's modders. :D
 
Wouldn't it just be easier to give the civilization unique units for every resource using unit where the unique unit was identical but didn't require resources?

The main difference would be that the player wouldn't need the resource to build the unit, but that restriction can be replicated with a "can build" check.

12 of one, ((4!)%10)*3 of the other.
 
Ok, here is the whole code now, I'm confident it works after reading about variables here.

Code:
function HirumaCityLost(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, bConquest)
	local newOwner = Players[iNewOwner]
	local oldOwner = Players[iOldOwner]
	local leaderType = GameInfo.Leaders[oldOnwer:GetLeaderType()].Type
	if newOwner ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and oldOwner == GameInfoTypes["CIVILIZATION_HIRUMA"] then
		local plot = Map.GetPlot(iCityX, iCityY)
		local capital = ioldOwner:GetCapitalCity()
		local random = Map.Rand(1) + 1
		if random == 1 then
			local iStrength = unit.GetBaseCombatStrength() --Thanks for the tip, JFD
			local iUnitID = GameInfo.Units.UNIT_JADEHAND.ID
			unit = oldOwner:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (unit.GetBaseCombatStrength()) *100))
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"])
		elseif random == 2 then
			local iUnitID = GameInfo.Units.UNIT_CRABERSERKER.ID
			unit = oldOwner:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"])
		else
			print('Something is wrong. It returned neither 1 nor 2, but " .. random .. " instead.')
		end
		BornOutOfNecessitySetEnemy()
		end
	end
end
GameEvents.CityCaputreComplete.Add(HirumaCityLost)

This is the code, the only thing changed was the added line near the end to call the function that defines the Enemy who took the city (it will change if another enemy takes another city, but that's ok for now).

Code:
function(BornOutOfNecessitySetEnemy)
	EnemyVengeance = Players[iNewOwner]
end

This - I assume - will create the global variable 'EnemyVengeance' that will be called during combat in order to define if the enemy is the right one.

Code:
function BornOutOfNecessity(attackingPlayer, attackingUnit, defendingPlayer)
	local pAPlayer = Players[attackingPlayer];
	local pDPlayer = Players[defendingPlayer];
	local attackUnit = pAPlayer:GetUnitByID(attackingUnit)
	if attackUnit:HasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"]) then
		if pDPlayer == EnemyVengeance then
			attackingUnit:SetBaseCombatStrength(attackingUnit.GetBaseCombatStrength() + math.floor(0.40 * (attackingUnit.GetBaseCombatStrength()) *100))
		end
	end
end
Events.RunCombatSim.Add(BornOutOfNecessity)
This would be the combat bonus if the defending player is the last enemy that took a City from you.

I couldn't find any other Event, so I believe RunCombatSim would be the right one.


@Machiavelli24: Sorry man, I didn't get it. I'm pretty new in coding, all I know is by research and you guys. Talk noobish to me, please. :lol:
 
A quick note, you do not want to use "RunCombatSim". It is an event related to animation, not gameplay. It does not behave how a person would intuit from the name. For example, it won't trigger for fights that a player can't see.
--------
You're trying to make a civilization that doesn't suffer a strength penalty if they are short strategic resources (right?). It is much simpler to achieve this effect by making their units not require strategic resources than trying to add and remove a promotion that offsets the penalty. Adding and removing a promotion has timing issues because a player's quantity of strategic resources can change through out the turn (from say trade deals) and you can't really detect when those changes happen. Making units not require resources can be done with XML alone (or SQL for less copy-pasting).

How you would make units not require strategic resources:

For the civilization, give them a unique unit that replaces the swordsman. This unique unit should be identical to the swordsman in every way except that it does not require iron. Also make a unique unit for the longswordsman. Repeat this process for every unit that requires a strategic resource.
 
A quick note, you do not want to use "RunCombatSim". It is an event related to animation, not gameplay. It does not behave how a person would intuit from the name. For example, it won't trigger for fights that a player can't see.

Aw man. Really? This is a big downer for me. I had plenty of plans for the starting and ending of combats. :\
I'll take a look at other events and see what I can do to simulate that, if everything else fails.

You're trying to make a civilization that doesn't suffer a strength penalty if they are short strategic resources (right?). It is much simpler to achieve this effect by making their units not require strategic resources than trying to add and remove a promotion that offsets the penalty. Adding and removing a promotion has timing issues because a player's quantity of strategic resources can change through out the turn (from say trade deals) and you can't really detect when those changes happen. Making units not require resources can be done with XML alone (or SQL for less copy-pasting).

How you would make units not require strategic resources:

For the civilization, give them a unique unit that replaces the swordsman. This unique unit should be identical to the swordsman in every way except that it does not require iron. Also make a unique unit for the longswordsman. Repeat this process for every unit that requires a strategic resource.

Hmmm. I got it now! Yes, this is not only simpler but very elegant (K.I.S.S.). Although the UA specifically states the amount of Strategic Resources it can offset.
 
Lots of bugs to fix before this even has a chance to work...
Code:
function HirumaCityLost(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, bConquest)
	local newOwner = Players[iNewOwner]
	local oldOwner = Players[iOldOwner]
	local leaderType = GameInfo.Leaders[oldOnwer:GetLeaderType()].Type
	if newOwner ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and oldOwner == GameInfoTypes["CIVILIZATION_HIRUMA"] then
--trying to compare cdata pointer with civ ID ? won't work :lol: (2nd part of condition will always be false)
		local plot = Map.GetPlot(iCityX, iCityY)
		local capital = ioldOwner:GetCapitalCity()
--can't run a method from the ID, need to use the cdata pointer => oldOwner:GetCapitalCity()
		local random = Map.Rand(1) + 1
		if random == 1 then
--not sure Map.Rand(1) ever becomes equal to 0, at best this will very seldom occur
			local iStrength = unit.GetBaseCombatStrength() --Thanks for the tip, JFD
			local iUnitID = GameInfo.Units.UNIT_JADEHAND.ID
--use GameInfoTypes.UNIT_JADEHAND, it's a bit faster
			unit = oldOwner:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (unit.GetBaseCombatStrength()) *100))
-- .30*100 = 30 x :lol: well actually 31 since you're also adding iStrength
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"])
		elseif random == 2 then
--not sure Map.Rand(1) ever becomes equal to 1, at best this will very seldom occur
			local iUnitID = GameInfo.Units.UNIT_CRABERSERKER.ID
--use GameInfoTypes.UNIT_CRABERSERKER, it's a bit faster
			unit = oldOwner:InitUnit (iUnitID, capital:GetX(), capital:GetY() )
			unit:JumpToNearestValidPlot()
			unit:SetHasPromotion(GameInfoTypes["PROMOTION_BORN_OUT_OF_NECESSITY"])
		else
			print('Something is wrong. It returned neither 1 nor 2, but " .. random .. " instead.')
		end
		BornOutOfNecessitySetEnemy()
		end
	end
end
GameEvents.CityCaputreComplete.Add(HirumaCityLost)
 
Hey, thanks for taking the time to help me.

if newOwner ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and oldOwner == GameInfoTypes["CIVILIZATION_HIRUMA"] then
--trying to compare cdata pointer with civ ID ? won't work :lol: (2nd part of condition will always be false)
Why? And what should I use?
Ok, I guess I've got it:
Code:
	local newOwner = Players[iNewOwner]
	local oldOwner = Players[iOldOwner]
[B]	local newCiv = newOner:GetCivilizationType()
	local oldCiv = oldOwner:GetCivilizationType()[/B]
	local leaderType = GameInfo.Leaders[oldOnwer:GetLeaderType()].Type
	if [U]newCiv[/U] ~= GameInfoTypes["CIVILIZATION_HIRUMA"] and [U]oldCiv[/U] == GameInfoTypes["CIVILIZATION_HIRUMA"] then

elseif random == 2 then
--not sure Map.Rand(1) ever becomes equal to 1, at best this will very seldom occur
Hmmm, I'll make a quick test. Thanks for the heads up.
One of the tests is in the post below. You were right! :D


unit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (unit.GetBaseCombatStrength()) *100))
-- .30*100 = 30 x :lol: well actually 31 since you're also adding iStrength
It should be "unit:SetBaseCombatStrength(iStrength + math.floor(0.30 * (unit.GetBaseCombatStrength())))" then, I believe?
 
Just conducted a test with Map.Rand.

Code:
	local random = Map.Rand(1, "") + 1
	local randomZ = Map.Rand(1, "")
	local randomY = Map.Rand(0, "")
	local randomX = Map.Rand(2, "")

Using these Map.Rand variations I've got these results:
(it's pretty big)
Spoiler :
[149877.320] lala: RandomNumber = 1. From the Counting function
[149877.320] lala: RandomNumber = 0 From the CountingZ function
[149877.320] lala: RandomNumber = 0 From the CountingY function
[149877.320] lala: RandomNumber = 0 From the CountingX function
[149877.445] lala: RandomNumber = 1. From the Counting function
[149877.445] lala: RandomNumber = 0 From the CountingZ function
[149877.445] lala: RandomNumber = 0 From the CountingY function
[149877.445] lala: RandomNumber = 0 From the CountingX function
[149877.742] lala: RandomNumber = 1. From the Counting function
[149877.742] lala: RandomNumber = 0 From the CountingZ function
[149877.742] lala: RandomNumber = 0 From the CountingY function
[149877.742] lala: RandomNumber = 0 From the CountingX function
[149877.960] lala: RandomNumber = 1. From the Counting function
[149877.960] lala: RandomNumber = 0 From the CountingZ function
[149877.960] lala: RandomNumber = 0 From the CountingY function
[149877.960] lala: RandomNumber = 1 From the CountingX function
[149878.163] lala: RandomNumber = 1. From the Counting function
[149878.163] lala: RandomNumber = 0 From the CountingZ function
[149878.163] lala: RandomNumber = 0 From the CountingY function
[149878.163] lala: RandomNumber = 1 From the CountingX function
[149878.334] lala: RandomNumber = 1. From the Counting function
[149878.334] lala: RandomNumber = 0 From the CountingZ function
[149878.334] lala: RandomNumber = 0 From the CountingY function
[149878.334] lala: RandomNumber = 1 From the CountingX function
[149878.490] lala: RandomNumber = 1. From the Counting function
[149878.490] lala: RandomNumber = 0 From the CountingZ function
[149878.490] lala: RandomNumber = 0 From the CountingY function
[149878.490] lala: RandomNumber = 0 From the CountingX function
[149878.646] lala: RandomNumber = 1. From the Counting function
[149878.646] lala: RandomNumber = 0 From the CountingZ function
[149878.646] lala: RandomNumber = 0 From the CountingY function
[149878.646] lala: RandomNumber = 1 From the CountingX function
[149878.802] lala: RandomNumber = 1. From the Counting function
[149878.802] lala: RandomNumber = 0 From the CountingZ function
[149878.802] lala: RandomNumber = 0 From the CountingY function
[149878.802] lala: RandomNumber = 0 From the CountingX function
[149878.958] lala: RandomNumber = 1. From the Counting function
[149878.958] lala: RandomNumber = 0 From the CountingZ function
[149878.958] lala: RandomNumber = 0 From the CountingY function
[149878.958] lala: RandomNumber = 1 From the CountingX function
[149879.068] lala: RandomNumber = 1. From the Counting function
[149879.068] lala: RandomNumber = 0 From the CountingZ function
[149879.068] lala: RandomNumber = 0 From the CountingY function
[149879.068] lala: RandomNumber = 0 From the CountingX function
[149879.224] lala: RandomNumber = 1. From the Counting function
[149879.224] lala: RandomNumber = 0 From the CountingZ function
[149879.224] lala: RandomNumber = 0 From the CountingY function
[149879.224] lala: RandomNumber = 1 From the CountingX function
[149879.348] lala: RandomNumber = 1. From the Counting function
[149879.348] lala: RandomNumber = 0 From the CountingZ function
[149879.348] lala: RandomNumber = 0 From the CountingY function
[149879.348] lala: RandomNumber = 0 From the CountingX function
[149879.473] lala: RandomNumber = 1. From the Counting function
[149879.473] lala: RandomNumber = 0 From the CountingZ function
[149879.473] lala: RandomNumber = 0 From the CountingY function
[149879.473] lala: RandomNumber = 1 From the CountingX function
[149879.614] lala: RandomNumber = 1. From the Counting function
[149879.614] lala: RandomNumber = 0 From the CountingZ function
[149879.614] lala: RandomNumber = 0 From the CountingY function
[149879.614] lala: RandomNumber = 1 From the CountingX function
[149879.738] lala: RandomNumber = 1. From the Counting function
[149879.738] lala: RandomNumber = 0 From the CountingZ function
[149879.738] lala: RandomNumber = 0 From the CountingY function
[149879.738] lala: RandomNumber = 0 From the CountingX function
[149879.879] lala: RandomNumber = 1. From the Counting function
[149879.879] lala: RandomNumber = 0 From the CountingZ function
[149879.879] lala: RandomNumber = 0 From the CountingY function
[149879.879] lala: RandomNumber = 0 From the CountingX function
[149880.019] lala: RandomNumber = 1. From the Counting function
[149880.019] lala: RandomNumber = 0 From the CountingZ function
[149880.019] lala: RandomNumber = 0 From the CountingY function
[149880.019] lala: RandomNumber = 1 From the CountingX function
[149880.128] lala: RandomNumber = 1. From the Counting function
[149880.128] lala: RandomNumber = 0 From the CountingZ function
[149880.128] lala: RandomNumber = 0 From the CountingY function
[149880.128] lala: RandomNumber = 0 From the CountingX function
[149880.269] lala: RandomNumber = 1. From the Counting function
[149880.269] lala: RandomNumber = 0 From the CountingZ function
[149880.269] lala: RandomNumber = 0 From the CountingY function
[149880.269] lala: RandomNumber = 1 From the CountingX function
[149880.409] lala: RandomNumber = 1. From the Counting function
[149880.409] lala: RandomNumber = 0 From the CountingZ function
[149880.409] lala: RandomNumber = 0 From the CountingY function
[149880.409] lala: RandomNumber = 0 From the CountingX function
[149880.550] lala: RandomNumber = 1. From the Counting function
[149880.550] lala: RandomNumber = 0 From the CountingZ function
[149880.550] lala: RandomNumber = 0 From the CountingY function
[149880.550] lala: RandomNumber = 1 From the CountingX function
[149880.690] lala: RandomNumber = 1. From the Counting function
[149880.690] lala: RandomNumber = 0 From the CountingZ function
[149880.690] lala: RandomNumber = 0 From the CountingY function
[149880.690] lala: RandomNumber = 0 From the CountingX function
[149881.642] lala: RandomNumber = 1. From the Counting function
[149881.642] lala: RandomNumber = 0 From the CountingZ function
[149881.642] lala: RandomNumber = 0 From the CountingY function
[149881.642] lala: RandomNumber = 0 From the CountingX function
[149883.248] TurnProcessing: Hiding TurnProcessing
[150033.181] lala: RandomNumber = 1. From the Counting function
[150033.181] lala: RandomNumber = 0 From the CountingZ function
[150033.181] lala: RandomNumber = 0 From the CountingY function
[150033.181] lala: RandomNumber = 1 From the CountingX function
[150033.306] lala: RandomNumber = 1. From the Counting function
[150033.306] lala: RandomNumber = 0 From the CountingZ function
[150033.306] lala: RandomNumber = 0 From the CountingY function
[150033.306] lala: RandomNumber = 1 From the CountingX function
[150033.431] lala: RandomNumber = 1. From the Counting function
[150033.431] lala: RandomNumber = 0 From the CountingZ function
[150033.431] lala: RandomNumber = 0 From the CountingY function
[150033.431] lala: RandomNumber = 0 From the CountingX function
[150033.540] lala: RandomNumber = 1. From the Counting function
[150033.540] lala: RandomNumber = 0 From the CountingZ function
[150033.540] lala: RandomNumber = 0 From the CountingY function
[150033.540] lala: RandomNumber = 0 From the CountingX function
[150033.649] lala: RandomNumber = 1. From the Counting function
[150033.649] lala: RandomNumber = 0 From the CountingZ function
[150033.649] lala: RandomNumber = 0 From the CountingY function
[150033.649] lala: RandomNumber = 1 From the CountingX function
[150033.758] lala: RandomNumber = 1. From the Counting function
[150033.758] lala: RandomNumber = 0 From the CountingZ function
[150033.758] lala: RandomNumber = 0 From the CountingY function
[150033.758] lala: RandomNumber = 1 From the CountingX function
[150033.867] lala: RandomNumber = 1. From the Counting function
[150033.867] lala: RandomNumber = 0 From the CountingZ function
[150033.867] lala: RandomNumber = 0 From the CountingY function
[150033.867] lala: RandomNumber = 0 From the CountingX function
[150033.961] lala: RandomNumber = 1. From the Counting function
[150033.961] lala: RandomNumber = 0 From the CountingZ function
[150033.961] lala: RandomNumber = 0 From the CountingY function
[150033.961] lala: RandomNumber = 0 From the CountingX function
[150034.086] lala: RandomNumber = 1. From the Counting function
[150034.086] lala: RandomNumber = 0 From the CountingZ function
[150034.086] lala: RandomNumber = 0 From the CountingY function
[150034.086] lala: RandomNumber = 1 From the CountingX function
[150034.195] lala: RandomNumber = 1. From the Counting function
[150034.195] lala: RandomNumber = 0 From the CountingZ function
[150034.195] lala: RandomNumber = 0 From the CountingY function
[150034.195] lala: RandomNumber = 0 From the CountingX function
[150034.320] lala: RandomNumber = 1. From the Counting function
[150034.320] lala: RandomNumber = 0 From the CountingZ function
[150034.320] lala: RandomNumber = 0 From the CountingY function
[150034.320] lala: RandomNumber = 1 From the CountingX function
[150034.429] lala: RandomNumber = 1. From the Counting function
[150034.429] lala: RandomNumber = 0 From the CountingZ function
[150034.429] lala: RandomNumber = 0 From the CountingY function
[150034.429] lala: RandomNumber = 1 From the CountingX function
[150034.538] lala: RandomNumber = 1. From the Counting function
[150034.538] lala: RandomNumber = 0 From the CountingZ function
[150034.538] lala: RandomNumber = 0 From the CountingY function
[150034.538] lala: RandomNumber = 0 From the CountingX function
[150034.663] lala: RandomNumber = 1. From the Counting function
[150034.663] lala: RandomNumber = 0 From the CountingZ function
[150034.663] lala: RandomNumber = 0 From the CountingY function
[150034.663] lala: RandomNumber = 0 From the CountingX function
[150034.757] lala: RandomNumber = 1. From the Counting function
[150034.757] lala: RandomNumber = 0 From the CountingZ function
[150034.757] lala: RandomNumber = 0 From the CountingY function
[150034.757] lala: RandomNumber = 0 From the CountingX function
[150034.881] lala: RandomNumber = 1. From the Counting function
[150034.881] lala: RandomNumber = 0 From the CountingZ function
[150034.881] lala: RandomNumber = 0 From the CountingY function
[150034.881] lala: RandomNumber = 0 From the CountingX function
[150034.975] lala: RandomNumber = 1. From the Counting function
[150034.975] lala: RandomNumber = 0 From the CountingZ function
[150034.975] lala: RandomNumber = 0 From the CountingY function
[150034.975] lala: RandomNumber = 0 From the CountingX function
[150035.100] lala: RandomNumber = 1. From the Counting function
[150035.100] lala: RandomNumber = 0 From the CountingZ function
[150035.100] lala: RandomNumber = 0 From the CountingY function
[150035.100] lala: RandomNumber = 0 From the CountingX function
[150035.193] lala: RandomNumber = 1. From the Counting function
[150035.193] lala: RandomNumber = 0 From the CountingZ function
[150035.193] lala: RandomNumber = 0 From the CountingY function
[150035.193] lala: RandomNumber = 0 From the CountingX function
[150035.318] lala: RandomNumber = 1. From the Counting function
[150035.318] lala: RandomNumber = 0 From the CountingZ function
[150035.318] lala: RandomNumber = 0 From the CountingY function
[150035.318] lala: RandomNumber = 0 From the CountingX function
[150035.427] lala: RandomNumber = 1. From the Counting function
[150035.427] lala: RandomNumber = 0 From the CountingZ function
[150035.427] lala: RandomNumber = 0 From the CountingY function
[150035.427] lala: RandomNumber = 0 From the CountingX function
[150035.552] lala: RandomNumber = 1. From the Counting function
[150035.552] lala: RandomNumber = 0 From the CountingZ function
[150035.552] lala: RandomNumber = 0 From the CountingY function
[150035.552] lala: RandomNumber = 0 From the CountingX function
[150035.661] lala: RandomNumber = 1. From the Counting function
[150035.661] lala: RandomNumber = 0 From the CountingZ function
[150035.661] lala: RandomNumber = 0 From the CountingY function
[150035.661] lala: RandomNumber = 0 From the CountingX function
[150035.880] lala: RandomNumber = 1. From the Counting function
[150035.880] lala: RandomNumber = 0 From the CountingZ function
[150035.880] lala: RandomNumber = 0 From the CountingY function
[150035.880] lala: RandomNumber = 1 From the CountingX function
[150036.753] lala: RandomNumber = 1. From the Counting function
[150036.753] lala: RandomNumber = 0 From the CountingZ function
[150036.753] lala: RandomNumber = 0 From the CountingY function
[150036.753] lala: RandomNumber = 1 From the CountingX function
[150036.878] lala: RandomNumber = 1. From the Counting function
[150036.878] lala: RandomNumber = 0 From the CountingZ function
[150036.878] lala: RandomNumber = 0 From the CountingY function
[150036.878] lala: RandomNumber = 1 From the CountingX function
[150036.894] TurnProcessing: Hiding TurnProcessing
[150036.987] lala: RandomNumber = 1. From the Counting function
[150036.987] lala: RandomNumber = 0 From the CountingZ function
[150036.987] lala: RandomNumber = 0 From the CountingY function
[150036.987] lala: RandomNumber = 1 From the CountingX function
[150037.112] lala: RandomNumber = 1. From the Counting function
[150037.112] lala: RandomNumber = 0 From the CountingZ function
[150037.112] lala: RandomNumber = 0 From the CountingY function
[150037.112] lala: RandomNumber = 0 From the CountingX function
[150037.206] lala: RandomNumber = 1. From the Counting function
[150037.206] lala: RandomNumber = 0 From the CountingZ function
[150037.206] lala: RandomNumber = 0 From the CountingY function
[150037.206] lala: RandomNumber = 1 From the CountingX function
[150037.331] lala: RandomNumber = 1. From the Counting function
[150037.331] lala: RandomNumber = 0 From the CountingZ function
[150037.331] lala: RandomNumber = 0 From the CountingY function
[150037.331] lala: RandomNumber = 0 From the CountingX function
[150037.424] lala: RandomNumber = 1. From the Counting function
[150037.424] lala: RandomNumber = 0 From the CountingZ function
[150037.424] lala: RandomNumber = 0 From the CountingY function
[150037.424] lala: RandomNumber = 1 From the CountingX function
[150037.643] lala: RandomNumber = 1. From the Counting function
[150037.643] lala: RandomNumber = 0 From the CountingZ function
[150037.643] lala: RandomNumber = 0 From the CountingY function
[150037.643] lala: RandomNumber = 1 From the CountingX function
[150037.752] lala: RandomNumber = 1. From the Counting function
[150037.752] lala: RandomNumber = 0 From the CountingZ function
[150037.752] lala: RandomNumber = 0 From the CountingY function
[150037.752] lala: RandomNumber = 0 From the CountingX function
[150037.861] lala: RandomNumber = 1. From the Counting function
[150037.861] lala: RandomNumber = 0 From the CountingZ function
[150037.861] lala: RandomNumber = 0 From the CountingY function
[150037.861] lala: RandomNumber = 0 From the CountingX function
[150037.970] lala: RandomNumber = 1. From the Counting function
[150037.970] lala: RandomNumber = 0 From the CountingZ function
[150037.970] lala: RandomNumber = 0 From the CountingY function
[150037.970] lala: RandomNumber = 1 From the CountingX function
[150038.095] lala: RandomNumber = 1. From the Counting function
[150038.095] lala: RandomNumber = 0 From the CountingZ function
[150038.095] lala: RandomNumber = 0 From the CountingY function
[150038.095] lala: RandomNumber = 1 From the CountingX function
[150038.204] lala: RandomNumber = 1. From the Counting function
[150038.204] lala: RandomNumber = 0 From the CountingZ function
[150038.204] lala: RandomNumber = 0 From the CountingY function
[150038.204] lala: RandomNumber = 1 From the CountingX function
[150038.329] lala: RandomNumber = 1. From the Counting function
[150038.329] lala: RandomNumber = 0 From the CountingZ function
[150038.329] lala: RandomNumber = 0 From the CountingY function
[150038.329] lala: RandomNumber = 1 From the CountingX function
[150038.423] lala: RandomNumber = 1. From the Counting function
[150038.423] lala: RandomNumber = 0 From the CountingZ function
[150038.423] lala: RandomNumber = 0 From the CountingY function
[150038.423] lala: RandomNumber = 1 From the CountingX function
[150038.547] lala: RandomNumber = 1. From the Counting function
[150038.547] lala: RandomNumber = 0 From the CountingZ function
[150038.547] lala: RandomNumber = 0 From the CountingY function
[150038.547] lala: RandomNumber = 0 From the CountingX function
[150038.641] lala: RandomNumber = 1. From the Counting function
[150038.641] lala: RandomNumber = 0 From the CountingZ function
[150038.641] lala: RandomNumber = 0 From the CountingY function
[150038.641] lala: RandomNumber = 0 From the CountingX function
[150038.750] lala: RandomNumber = 1. From the Counting function
[150038.750] lala: RandomNumber = 0 From the CountingZ function
[150038.750] lala: RandomNumber = 0 From the CountingY function
[150038.750] lala: RandomNumber = 0 From the CountingX function
[150038.875] lala: RandomNumber = 1. From the Counting function
[150038.875] lala: RandomNumber = 0 From the CountingZ function
[150038.875] lala: RandomNumber = 0 From the CountingY function
[150038.875] lala: RandomNumber = 0 From the CountingX function
[150038.969] lala: RandomNumber = 1. From the Counting function
[150038.969] lala: RandomNumber = 0 From the CountingZ function
[150038.969] lala: RandomNumber = 0 From the CountingY function
[150038.969] lala: RandomNumber = 1 From the CountingX function
[150039.093] lala: RandomNumber = 1. From the Counting function
[150039.093] lala: RandomNumber = 0 From the CountingZ function
[150039.093] lala: RandomNumber = 0 From the CountingY function
[150039.093] lala: RandomNumber = 0 From the CountingX function
[150039.187] lala: RandomNumber = 1. From the Counting function
[150039.187] lala: RandomNumber = 0 From the CountingZ function
[150039.187] lala: RandomNumber = 0 From the CountingY function
[150039.187] lala: RandomNumber = 0 From the CountingX function
[150039.296] lala: RandomNumber = 1. From the Counting function
[150039.296] lala: RandomNumber = 0 From the CountingZ function
[150039.296] lala: RandomNumber = 0 From the CountingY function
[150039.312] lala: RandomNumber = 0 From the CountingX function
[150039.530] lala: RandomNumber = 1. From the Counting function
[150039.530] lala: RandomNumber = 0 From the CountingZ function
[150039.530] lala: RandomNumber = 0 From the CountingY function
[150039.530] lala: RandomNumber = 0 From the CountingX function
[150040.295] lala: RandomNumber = 1. From the Counting function
[150040.295] lala: RandomNumber = 0 From the CountingZ function
[150040.295] lala: RandomNumber = 0 From the CountingY function
[150040.295] lala: RandomNumber = 0 From the CountingX function
[150040.420] lala: RandomNumber = 1. From the Counting function
[150040.420] lala: RandomNumber = 0 From the CountingZ function
[150040.420] lala: RandomNumber = 0 From the CountingY function
[150040.420] lala: RandomNumber = 0 From the CountingX function
[150040.513] lala: RandomNumber = 1. From the Counting function
[150040.513] lala: RandomNumber = 0 From the CountingZ function
[150040.513] lala: RandomNumber = 0 From the CountingY function
[150040.513] lala: RandomNumber = 1 From the CountingX function
[150040.544] TurnProcessing: Hiding TurnProcessing
[150040.607] lala: RandomNumber = 1. From the Counting function
[150040.607] lala: RandomNumber = 0 From the CountingZ function
[150040.607] lala: RandomNumber = 0 From the CountingY function
[150040.607] lala: RandomNumber = 0 From the CountingX function
[150040.716] lala: RandomNumber = 1. From the Counting function
[150040.716] lala: RandomNumber = 0 From the CountingZ function
[150040.716] lala: RandomNumber = 0 From the CountingY function
[150040.716] lala: RandomNumber = 1 From the CountingX function
[150040.841] lala: RandomNumber = 1. From the Counting function
[150040.841] lala: RandomNumber = 0 From the CountingZ function
[150040.841] lala: RandomNumber = 0 From the CountingY function
[150040.841] lala: RandomNumber = 0 From the CountingX function
[150040.950] lala: RandomNumber = 1. From the Counting function
[150040.950] lala: RandomNumber = 0 From the CountingZ function
[150040.950] lala: RandomNumber = 0 From the CountingY function
[150040.950] lala: RandomNumber = 1 From the CountingX function
[150041.075] lala: RandomNumber = 1. From the Counting function
[150041.075] lala: RandomNumber = 0 From the CountingZ function
[150041.075] lala: RandomNumber = 0 From the CountingY function
[150041.075] lala: RandomNumber = 1 From the CountingX function
[150041.168] lala: RandomNumber = 1. From the Counting function
[150041.168] lala: RandomNumber = 0 From the CountingZ function
[150041.168] lala: RandomNumber = 0 From the CountingY function
[150041.168] lala: RandomNumber = 1 From the CountingX function
[150041.293] lala: RandomNumber = 1. From the Counting function
[150041.293] lala: RandomNumber = 0 From the CountingZ function
[150041.293] lala: RandomNumber = 0 From the CountingY function
[150041.293] lala: RandomNumber = 1 From the CountingX function
[150041.387] lala: RandomNumber = 1. From the Counting function
[150041.387] lala: RandomNumber = 0 From the CountingZ function
[150041.387] lala: RandomNumber = 0 From the CountingY function
[150041.387] lala: RandomNumber = 0 From the CountingX function
[150041.512] lala: RandomNumber = 1. From the Counting function
[150041.512] lala: RandomNumber = 0 From the CountingZ function
[150041.512] lala: RandomNumber = 0 From the CountingY function
[150041.512] lala: RandomNumber = 0 From the CountingX function
[150041.605] lala: RandomNumber = 1. From the Counting function
[150041.605] lala: RandomNumber = 0 From the CountingZ function
[150041.605] lala: RandomNumber = 0 From the CountingY function
[150041.605] lala: RandomNumber = 0 From the CountingX function
[150041.714] lala: RandomNumber = 1. From the Counting function
[150041.714] lala: RandomNumber = 0 From the CountingZ function
[150041.714] lala: RandomNumber = 0 From the CountingY function
[150041.714] lala: RandomNumber = 1 From the CountingX function
[150041.824] lala: RandomNumber = 1. From the Counting function
[150041.824] lala: RandomNumber = 0 From the CountingZ function
[150041.824] lala: RandomNumber = 0 From the CountingY function
[150041.824] lala: RandomNumber = 1 From the CountingX function
[150041.933] lala: RandomNumber = 1. From the Counting function
[150041.933] lala: RandomNumber = 0 From the CountingZ function
[150041.933] lala: RandomNumber = 0 From the CountingY function
[150041.933] lala: RandomNumber = 0 From the CountingX function
[150042.058] lala: RandomNumber = 1. From the Counting function
[150042.058] lala: RandomNumber = 0 From the CountingZ function
[150042.058] lala: RandomNumber = 0 From the CountingY function
[150042.058] lala: RandomNumber = 1 From the CountingX function
[150042.167] lala: RandomNumber = 1. From the Counting function
[150042.167] lala: RandomNumber = 0 From the CountingZ function
[150042.167] lala: RandomNumber = 0 From the CountingY function
[150042.167] lala: RandomNumber = 1 From the CountingX function
[150042.292] lala: RandomNumber = 1. From the Counting function
[150042.292] lala: RandomNumber = 0 From the CountingZ function
[150042.292] lala: RandomNumber = 0 From the CountingY function
[150042.292] lala: RandomNumber = 0 From the CountingX function
[150042.401] lala: RandomNumber = 1. From the Counting function
[150042.401] lala: RandomNumber = 0 From the CountingZ function
[150042.401] lala: RandomNumber = 0 From the CountingY function
[150042.401] lala: RandomNumber = 1 From the CountingX function
[150042.526] lala: RandomNumber = 1. From the Counting function
[150042.526] lala: RandomNumber = 0 From the CountingZ function
[150042.526] lala: RandomNumber = 0 From the CountingY function
[150042.526] lala: RandomNumber = 1 From the CountingX function
[150042.619] lala: RandomNumber = 1. From the Counting function
[150042.619] lala: RandomNumber = 0 From the CountingZ function
[150042.619] lala: RandomNumber = 0 From the CountingY function
[150042.619] lala: RandomNumber = 0 From the CountingX function
[150042.744] lala: RandomNumber = 1. From the Counting function
[150042.744] lala: RandomNumber = 0 From the CountingZ function
[150042.744] lala: RandomNumber = 0 From the CountingY function
[150042.744] lala: RandomNumber = 1 From the CountingX function
[150042.962] lala: RandomNumber = 1. From the Counting function
[150042.962] lala: RandomNumber = 0 From the CountingZ function
[150042.962] lala: RandomNumber = 0 From the CountingY function
[150042.962] lala: RandomNumber = 0 From the CountingX function
[150043.820] lala: RandomNumber = 1. From the Counting function
[150043.820] lala: RandomNumber = 0 From the CountingZ function
[150043.820] lala: RandomNumber = 0 From the CountingY function
[150043.820] lala: RandomNumber = 1 From the CountingX function
[150043.930] lala: RandomNumber = 1. From the Counting function
[150043.930] lala: RandomNumber = 0 From the CountingZ function
[150043.930] lala: RandomNumber = 0 From the CountingY function
[150043.930] lala: RandomNumber = 1 From the CountingX function


What I can conclude from it is, based on the premise you can't get a negative number from Map.Rand is:
  • 'random' will ALWAYS return 1, because the API will return a number between 0 and that in parenthesis - 1, resulting in 0; but, the variable has a "+1" attached to the end, resulting in 0 + 1.
  • 'randomZ' will ALWAYS return 0, from the same reason as the one above.
  • 'randomY' the same thing, always 0 since the maxValue in this case is 0.
  • 'randomX' will return either 0 or 1, because of the regular -1 the API itself always count in.

So yeah, you were right, I can't use (1) + 1 and expect anything other than 1, the second clause will never be true and UNIT_CRABERSERKER will never spawn.

(I had to shorten the spoilered list because it was way too big, but I believe what I could fit is enough)
 
I'll deal with the part of the CombatSim on the previous code later, probably in the next version instead of this one. I have a new question:

Code:
print('Venom Fear on Worker is on')
function VenomFearWorker(playerID, pMyUnit, pPlayer)
	if (pMyUnit ~= nil) and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ORDERVENOM"] then
		local pPlayer = Players[playerID];
		local iMyPlayer = pMyUnit:GetOwner();
		local iTotalUnhappiness = pPlayer:GetUnhappiness();
		local iTotalHappiness = pPlayer:Gethappiness()
		
		if (pMyUnit:GetUnitAIType() == GameInfoTypes["UNIT_WORKER"]) then
			if (pMyUnit:IsStackedGreatGeneral()) then
				pMyUnit:workRate(250)
				Player.SetHappiness((iTotalHappiness - iTotalUnhappiness) - 1)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(VenomFearWorker)

This is supposed to increase the worker's Work Rate by 2,5 times while a Great General UU is stacked, but also increase the total Unhappiness by 1.
The problem is that it gets into a loop, eternally increasing the Unhappiness and I don't believe it's wearing off after the worker and the GG go separate ways. I understand where the eternal looping goes wrong, I just can't figure out how to make it stop. I thought of making a variable to retain the old Happiness value and give it back later, but can't make it work properly.

Tips?
 
function VenomFearWorker(playerID, pMyUnit, pPlayer)
...
GameEvents.PlayerDoTurn.Add(VenomFearWorker)
One big problem is that you are using the wrong event. Functions added to the PlayerDoTurn event will be executed at the start of every player's (human, AI, major or minor). There will be only one argument, the ID of the player who's turn it is. There will be no "pMyUnit" or "pPlayer".

To achieve your desired effect you need to know when a unit moves (because it could be the unique unit stacking or unstacking with a worker). PlayerDoTurn does not trigger when a unit moves. It is not possible to achieve your desired effect with PlayerDoTurn.

GameEvents.UnitSetXY(PlayerID player, UnitID unit, int x, int y) triggers every time a unit moves and is the event you want to use.
 
Back
Top Bottom