Help on Finding Lua

kiwusek

Chieftain
Joined
Sep 5, 2004
Messages
28
Hi, I am relatively new to of Lua but I've been teaching myself based on what I am finding in the game's and modder's lua files, but my main problem is I have no idea how to go about finding the lua functions or events that I need to use or reference in my mod. Ideally what I am looking for are the lua files associated with deciding what unit is allowed to go where (as in the file/function that is used for determining the ultrasonic fence's repel).

I also kind of have a basic idea of the sort of logic the script will need to follow based on what I've been seeing in the game files.
 
If you can't find it, it's because it's in the C++ DLL, for which they haven't released the source code (yet).

It's not perfect by any stretch, but the Civ5 Modiki Lua and UI Reference is still incredibly helpful in finding and deciphering the various Lua functions. If you could be more clear about what you're trying to do, someone can try to help you write the Lua or at least point you at specific functions.
 
Essentially what I am trying to do is take the repel aliens value/ability of the ultrasonic fence and transfer it over to unit. I've found the values in buildings.XML but I am a bit at a loss of getting the functions. I think I can use pazyryk's adding XML columns via lua tutorial but all I'm missing is getting the right functions to reference.

Alternatively I wonder if I can adjust the AI for aliens to avoid the area of effect for this new unit or if something exists in pathfinding that's user accessible ATM. Also I have a but more familiarity in C++ but I've been logically figuring stuff out based on current functions and ones I find in mods.

So if anyone could help one way or the other that'd be awesome. The idea is to tuck the ultrasonic fence away in an affinity tree + tech and give a cheap tactical orbital unit that does the same trick for x turns (I have everything done but the lua). And I'll pore through the wiki tonight when I get home to see how much is use able for my purposes :)

Thanks a lot for replying and the suggestion as I think I might find the answer or most of it there.
 
You're barking up the wrong tree by trying to apply a building effect to a unit. It's not that easy without access to the C++ code.

You'd need to write some Lua that overrides GameEvents.UnitSetXY for aliens attempting to get near your unit.
 
I was hoping to have it specifically for an orbital unit if that makes it any better?
 
I haven't tested it, but I don't think it matters that it's an orbital unit. The orbital units are still units even after they're launched, and I think the game considers them to be located "on" the same plot they're orbiting over (in which case the Lua would be the same whether they're orbital or not).
 
Okay so what I am thinking the approach that I should take would be to use the gamevents.setunitxy to define an exclusion zone for the satellite unit. So I'm thinking use gameinfotypes to check for the satellite and then use it again to check if the other unit is an alien lifeform - from XML the bool column that says <alienlifeform>. If that returns a yes then have the unit denied that movement option? (Not sure how this is handled).

Also I was looking through the lua examples and I'm not entirely sure how local badjacentchina = adjacenttochina works to adapt it for my unit...



Alternatively I'm thinking that it could be set for alien units to avoid the area of effect of the orbital unit...

Thanks so much you have given me a lot to go on already :)
 
What you're doing is hooking a new custom function to the event call, so every time a unit moves, your function is called first. The moving unit and the owning player are parameters (as well as the plot's coordinates), so you can either check the column you mention, or just check to see if it's the alien player.

If so, then you check to see if the range of effect of any of your orbital units applies to the attempted move (i.e., your alternative thought is the method to pursue).

I'm not in front of my home PC, so I don't know where you found the AdjacentToChina function, but I don't imagine it to be helpful to this situation. You'll utilize the Lua method to determine the distance between 2 plots.

I can help you with writing the Lua if you're confused.
 
Hey so I tried to give it a try first to try to learn/figure out some things, but I feel like its probably horribly mangled...

Code:
GameEvents.UnitSetXY.Add(function(iPlayer, unitTypeID, iX, iY)
	local plot = Map.GetPlot(iX, iY);
	local player = Players[iPlayer];
	local unit = player:GetUnitByID(iUnitID);
	local AlienRepel_kiwusek = unit.AlienRepel_kiwusek
		
if (AlienRepel()) then
	local range = GameInfo.OrbitalUnits[AlienRepel].EffectRange.INTEGER
	local alienRepelRange = Unit:GetArea(plot and range)
	local alien = GameInfo.Units.AlienLifeform.BOOLEAN
		if(alienRepelRange and alien) then
			bool Unit:CanMoveOrAttackInto(Plot plot, bool declareWar = false, bool destination = false)
		else
			return false;
else
	return false;

end

I would love some help in this as this is my first attempt at lua and I am not so sure I know what I am doing.
 
Back
Top Bottom