Apprentice Necromancer Needs Help!

Civitar

Adventurer
Joined
Mar 23, 2014
Messages
1,507
Location
Switzerland
How do I give a unit an action to create another unit? I'd like to give a Necromancer unit the ability to spawn a new Zombie or Skeleton unit adjacent to the Necromancer when you click a button in the unit's menu.
I saw that whoward69 has something similar (if not identical) in his Morindim Clans mod, but I'm not sure how that works.
 
I saw that whoward69 has something similar (if not identical) in his Morindim Clans mod, but I'm not sure how that works.
With a LOT of DLL modding to add Lua events and api methods to do the actual work
 
I was answering your observation "not sure how that works" (and not how to do what you want - which will involve modding UnitPanel.lua at the very least if you want a lua only solution.)
 
Whew! You had me really worried. No, I just want to place a unit on the map when I click a button in the unit menu. And a Lua only solution is very preferable.

I've got a Sorceress unit that can spawn a Skeleton on the map, using the UnitPanel lua and some mission code I got from ViceVirtuoso... want me to zip it up for you?

EDIT: Posted my code up here if you want to take a look. The relevant file would be EvilSpiritsMission.lua . It's currently set so that the Sorceress can summon a Skeleton when she's adjacent to a friendly city, but I'm planning to make it so that she can only do it when you have more than a certain amount of Faith, which then gets deducted from your Faith total. (In essence, allowing her to spend Faith to summon Skeletons.)
 
OK, but how do I make it so that a Necromancer Unit can spawn a Zombie unit at any time (not Skeletons since they are only buildable in cities where the more powerful Necromancers are found) at a cost of, say, 30 culture?
Code:
Could you post the Lua like this to save time please?
As always thanks very much.
 
OK, but how do I make it so that a Necromancer Unit can spawn a Zombie unit at any time (not Skeletons since they are only buildable in cities where the more powerful Necromancers are found) at a cost of, say, 30 culture?
Code:
Could you post the Lua like this to save time please?
As always thanks very much.

I can take a crack at coding it tonight -- I think it should be a fairly simple change to make. I just hope that there aren't any issues with GetJONSCulture and SetJONSCulture that I don't know about. I'd need to make sure it worked first, so I'll have to playtest it tonight before I post it.

As for spawning Zombies instead of Skeletons, you just need to change the spawned unit appropriately. I don't have any Zombies in my own mod, but I can at least point out what you'd need to do to include them instead. :D
 
I just hope that there aren't any issues with GetJONSCulture and SetJONSCulture that I don't know about.

Not an issue, but rather than doing

SetJONSCulture(GetJONSCulture() - 30)

you can just do

ChangeJONSCulture(-30)
 
Not an issue, but rather than doing

SetJONSCulture(GetJONSCulture() - 30)

you can just do

ChangeJONSCulture(-30)

Thanks whoward! I was checking the Civ V Lua reference quickly, so just checked to see if the Get and Set commands I might need existed. Forgot that Change was an easier way around it...

Anyways, this Lua code appears to work for the most part, although I'm still running into issues with the SetMoves command...

Code:
function CheckSorceressButtonValidity(pPlayer)
	local iCurrentCulture = pPlayer:GetJONSCulture()
		if (iCurrentCulture > 30) then
			return true;
		end
	return false;
end

local SorceressMissionButton = {
  Name = "SorceressMissionButton",
  Title = "Summon Skeleton",
  OrderPriority = 200,
  IconAtlas = "UNIT_ACTION_ATLAS_TH_EVIL_SPIRITS",
  PortraitIndex = 0,
  ToolTip = function(action, unit)
		local sTooltip;
		local pPlayer = Players[Game:GetActivePlayer()];
		local bIsValid = CheckSorceressButtonValidity(pPlayer);
		if bIsValid then
			sTooltip = "Summons a Skeleton"
		else
			sTooltip = "Can only be used when you have sufficient culture"
		end
		return sTooltip
  end, -- or a TXT_KEY_ or a function
  Condition = function(action, unit)
		if unit:GetMoves() <= 0 then
			return false
		end
		if unit:IsHasPromotion(GameInfoTypes.PROMOTION_SUMMON_ES_SKELETON) then
			return true
		else
			return false
		end
		--print(string.format("Condition %s called for unit %i for player %i", action.Name, unit:GetID(), unit:GetOwner()));
  end, -- or nil or a boolean, default is true
  Disabled = function(action, unit)
  		local pPlayer = Players[Game:GetActivePlayer()];
		local bIsValid = CheckSorceressButtonValidity(pPlayer);
		if bIsValid then
			return false
		end
		return true;
  end, -- or nil or a boolean, default is false
  Action = function(action, unit, eClick)
	if eClick == Mouse.eRClick then
		return
	end
    local pPlayer = Players[Game:GetActivePlayer()];

	print("Summoning a Skeleton.")

	if pPlayer:IsHuman() then
		pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "Summoning!" ,"One of your sorceresses summoned a skeleton!", -1, -1);
	end

	local iSkeletonUnitID = GameInfo.Units.UNIT_ES_SKELETON.ID
	skeleton = pPlayer:InitUnit (iSkeletonUnitID, unit:GetX(), unit:GetY() );
	skeleton:JumpToNearestValidPlot();
	unit:SetMoves(unit:GetMoves() - 1)
	unit:SetHasPromotion(GameInfoTypes.PROMOTION_SUMMON_ES_SKELETON, false)
	pPlayer:ChangeJONSCulture(-30);
  end,
}

LuaEvents.UnitPanelActionAddin(SorceressMissionButton)

It's based off of whoward's Modular UI and adapted by ViceVirtuoso for use in BNW. You'll need to include the UnitPanel.lua file with the mod.

My code still uses my Skeleton unit -- you'll just have to modify the promotions and units accordingly. :P
 
So, does it require BNW? And will it allow a unit that is not a sorceress to summon zombies if it has a promotion called Raise Dead or whatever?

whoward and/or ViceVirtuoso would be able to shed more light on whether or not it requires BNW -- I've got BNW on my computer, so I'll admit I haven't tested to see whether or not the code requires it.

As written, the code produces the button for any unit with the appropriate promotion and more than 0 moves. You could probably change the if statements in the Condition part of the code if you wanted to use other conditions. Tying it to a promotion does make it easier to hand out, though.
 
although I'm still running into issues with the SetMoves command...

You should use unit:ChangeMoves, but either way the problem is that you have to multiply by the Define "MOVE_DENOMINATOR". Your method doesn't work because it's only subtracting 1/60th of a move.
Code:
unit:ChangeMoves(-1 * GameDefines.MOVE_DENOMINATOR)
 
You'll want some AI too. The best way to do that is to state (in clear specific English) what an AI should do in your judgement, with all the various considerations listed by importance. Then translate that into pseudo code and then real code. It's very doable in Lua, but generally as much work as adding the action in the first place (more or less depending on how complicated the decision).
 
You'll want some AI too. The best way to do that is to state (in clear specific English) what an AI should do in your judgement, with all the various considerations listed by importance. Then translate that into pseudo code and then real code. It's very doable in Lua, but generally as much work as adding the action in the first place (more or less depending on how complicated the decision).

Yeah, that's one thing ViceVirtuoso pointed out to me -- the AI doesn't know the button is there, so it'll never use the function on its own.

For me, I was planning with my Sorceresses to just do a basic check at the start of the turn -- figure out what rate the AI is collecting faith/culture, determine how frequently they could spawn units if they wanted, and then just have them periodically generate them on their own. Or something. I haven't really had the chance to experiment with it yet, unfortunately...
 
So, does it require BNW? And will it allow a unit that is not a sorceress to summon zombies if it has a promotion called Raise Dead or whatever?

If you use the UnitPanel.lua found in my Madoka/Big Boss mods, then it will automatically work with either BNW or G&K. BNW-related fields in the UnitPanel will not load if only G&K is active.
 
What I'd like the WHFB AI to do (if it's not too complicated) is to generally only raise Zombies if it has enough culture and if it doesn't have much of other kinds of melee units. Because while Zombies are easy and inexpensive to raise and cost no maintenance (since culture is easy to come by in WH), they are laughably weak fighters. It should still keep some Zombies around for kicks though, basically to soften up enemies with a few throwaway Zombies before sending in skeleton warriors for the kill.
 
Back
Top Bottom