Traits with LUA. Need help

Kobazco

Chieftain
Joined
Mar 6, 2016
Messages
55
So I *ahem* borrowed some LUA from somebody else with a very similar trait that I want in my civ:

http://pastebin.com/d3VLWrJH

This SHOULD raise influence by 2 per turn when you have a pledge to protect a city state up to a maximum of 65. Nothing seems to work though. Any idea on what im doing wrong?
 
is any of your lua loading at all? read whoward's signature for file settings
 
This is a problem
Code:
influence=pMinorCiv:GetMinorCivFriendshipWithMajor(pPlayer)
because you are sending a pointer-object (pPlayer) and not a player ID#:

http://modiki.civfanatics.com/index.php?title=Player.GetMinorCivFriendshipWithMajor_(Civ5_API)

End result is this (line #25)
Code:
influence=pMinorCiv:GetMinorCivFriendshipWithMajor(pPlayer)
will either cause an error message in the lua log (and runtime failure of the code) or else it will set variable influence to "nil", which wil then cause an error on line number 26 because you are trying to compare a number against "nil".

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

It is also always better to supply the actual mod rather than a file or snippets of files from within it. There is no way for us to know if you have not also made one of the 'file-settings' mistakes in ModBuddy that gia referred to. The actual mod as it is in the game's MODS folder would allow us to verify that one way or the other.
 
Alright thanks for the info LeeS. I'll go ahead and upload my mod if you need it when I get home in like 7 hours
 
  1. As gia suspected, you've never told the game to do anything with file Lua/MarthTrait.lua
  2. You need to alter the code within file Lua/MarthTrait.lua to be as:
    Code:
    local iBonusPerTurn = 2		--To be tweaked by playtesting. Put here for easy changing.
    
    function raiseCityStateInfluence( player )
    	local pPlayer = Players[player]
    	if pPlayer:IsEverAlive() and pPlayer:IsAlive() then
    		print("Turn started for ",pPlayer:GetCivilizationShortDescription())
    		if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ALTEA"] then
    			local iTeam = pPlayer:GetTeam()
    			local pTeam = Teams[iTeam]
    			local atPeace = true
    			for iOtherTeam, pOtherTeam in pairs(Teams) do
    				if pTeam:IsAtWar(iOtherTeam) and iOtherTeam ~= 63 then 
    					atPeace = false
    				end	--Exclude 63 because that is Barbarians!
    			end
    			if (not atPeace) then 
    				print("--Archanea is at war. Influence will not be raised.") 
    			end
    			if atPeace then
    				print("--raising influence with protected city-states")
    				for iLoop = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
    					local pMinorCiv = Players[iLoop]
    					if pMinorCiv:IsEverAlive() and pMinorCiv:IsAlive() then
    						if pPlayer:IsProtectingMinor(iLoop) then
    							local influence = pMinorCiv:GetMinorCivFriendshipWithMajor([color="blue"]player[/color])
    							if influence < 65 then
    								print("--",pMinorCiv:GetCivilizationShortDescription())
    								pMinorCiv:ChangeMinorCivFriendshipWithMajor(player,iBonusPerTurn)
    							end
    						end
    					end
    				end
    			end
    		end 
    	end
    end
    [color="green"]GameEvents.PlayerDoTurn.Add(raiseCityStateInfluence)[/color]
    • See the blue highlight for the main needed change. You need to give the PlayerID# (player) in that method, and not the player pointer object (pPlayer)
    • Also note the movement of local variable influence to where it is really needed. You aren't using it anywhere outside that "if...then...end" sequence anyway.
    • The reason I added spaces in-between '=' signs, etc., is that it is easier for me to read what I am looking at.
    • In addition to not having the file set-up correctly within ModBuddy, you had no game event 'subscription' (shown in green highlight), so even if you did correctly set-up the file within ModBuddy, the code itself would not have done anything because the function was never given any instruction as to when it should operate.
  3. There is no guarrantee I did not miss something else wrt to your lua script. And I did not look at xml files or anything within them to see if there is anything incorrect within them or with the way they are set-up in ModBuddy.
 
Back
Top Bottom