[HELP] Creating new LUA promotions

XK9Wolfe

Chieftain
Joined
Oct 15, 2015
Messages
12
Hey guys, I’ve been meaning to get into Lua modding for a while and figured the best way is to jump right in and start making stuff. Thing is, I’m just smashing rocks together; would anyone be willing to offer me some pointers here and there?

Have a look at this code and let me know what I’m doing wrong.
I’m trying to create a promotion that gives said unit XP at the start of every turn.

Spoiler :

Code:
-- Morbid Strength
-- Author: Titan
-- DateCreated: 8/27/2016 1:04:47 PM
--------------------------------------------------------------
function MorbidStrength(iPlayer)	 -- Create a function to call at the end of the turn
	local pPlayer = Players[iPlayer]	-- Create a local variable to state that the 'pointer Player' is the same as the 'index Player'
	if pPlayer:IsAlive() then -- Check to see if the indexed player is alive, and if he is then...
		for pUnit in pPlayer:Units() do -- for all 'pointer Units' in 'pointer Player's units do this action!
			if (pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_MORBID_STRENGTH"])) then -- First check to see if the 'pointer Units' have the required promotion, and if they do then
				pUnit:GiveExperience(15) -- give said unit 15 experience.
			end
	end
end
GameEvents.PlayerDoTurn.Add(MorbidStrength) -- Do this at the end of every turn.


I need feedback. Reading reference material just isn't cutting it for me and I'm left feeling more confused than when I started, so I really appreciate any help you guys have to offer.
 
Code:
-- Morbid Strength
-- Author: Titan
-- DateCreated: 8/27/2016 1:04:47 PM
--------------------------------------------------------------
function MorbidStrength(iPlayer)	 -- Create a function to call at the end of the turn
	local pPlayer = Players[iPlayer]	-- Create a local variable to state that the 'pointer Player' is the same as the 'index Player'
	if pPlayer:IsAlive() then -- Check to see if the indexed player is alive, and if he is then...
		for pUnit in pPlayer:Units() do -- for all 'pointer Units' in 'pointer Player's units do this action!
			if (pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_MORBID_STRENGTH"])) then -- First check to see if the 'pointer Units' have the required promotion, and if they do then
				pUnit:ChangeExperience(15) -- give said unit 15 experience.
			end
		[color="red"]end[/color]
	end
end
GameEvents.PlayerDoTurn.Add(MorbidStrength) -- Do this at the end of every turn.
  1. The Unit:GiveExperience() method is a boolean and does not allow you to state any arguments betweeen the "()".
  2. you were missing an 'end' (shown in red)
  3. make sure the file where this code is contained is set up as an InGameUIAddin in ModBuddy. See Post #3 of this tutorial: whoward69's what ModBuddy setting for what file types tutorial
 
Back
Top Bottom