C++/Lua Request Thread

I've got this ready, just want to know: any Great Person expended? Or just Writers/Artists/Musicians?

Oh, I know this one! Helps that I designed the unit.
Yeah, it's for a specific unique unit (artist) as opposed to any random GP.
 
Quick question - is there any way to get when a tile is pillaged?
 
Quick question - is there any way to get when a tile is pillaged?

You could check it via Plot:IsImprovementPillaged(), but there would be no specific way of obtaining the plot without a GameEvent to function it up. Perhaps UnitSetXYZ...
 
SerialEventImprovementDestroyed

That doesn't fire on pillaging, it fires when an improvement is destroyed, by being removed entirely (e.g. to be replaced with another improvement) - and even then, only when the human player is viewing the tile (and IIRC even then only when not in strategic view).
 
Quick question - is there any way to get when a tile is pillaged?
There is a work-around method that can be deployed to determine the current condition of all improvements, and whether the condition has changed since last checked, but it is not instantaneous in real-time, will really only work for BNW1, will not be useful for affecting or detecting any unit (or player) that just conducted the pillage, and requires persistence of a data-table across game-saves2 as well as some fairly 'hefty' processing every turn3. If any of those are 'concept killers' for you, there really isn't any point to going into any further detail.





1 uses GameEvents.BuildFinished( playerID, x, y, improvementID ) which is only available in BNW.
2 the preferred method would be to use TableSaverLoader for table-data persistence.
3 which in the late-game and on slower computers might result in some significant turn-processing delay.
 
Hi I would to know how to test a unit has not moved on their turn (where move = anything that spends a move, so fortify, sleep, nothing, heal, intercept, etc don't count as moves, but attack, set up, move, etc count as one), using lua

I tried to hook PlayerDoTurn, then check has moved, or getmoves, or anything with a move name, and nothing seems like it will work. PlayerDoTurn is called after the units' moves are refreshed apparently.

Do I need to create my own event and find where to trigger it so that the units are not refreshed? or is there a way without dll mods

I made my own hook just so I dont stop dead, but I would still like to know if there was a simple (as in no dll) alternative, like a hook that already exists
 
Hi I would to know how to test a unit has not moved on their turn (where move = anything that spends a move, so fortify, sleep, nothing, heal, intercept, etc don't count as moves, but attack, set up, move, etc count as one), using lua

I tried to hook PlayerDoTurn, then check has moved, or getmoves, or anything with a move name, and nothing seems like it will work. PlayerDoTurn is called after the units' moves are refreshed apparently.

Do I need to create my own event and find where to trigger it so that the units are not refreshed? or is there a way without dll mods

I made my own hook just so I dont stop dead, but I would still like to know if there was a simple (as in no dll) alternative, like a hook that already exists

Try as
Code:
function PlayerEndTurn()
	local iPlayer = Game.GetActivePlayer()
	local pPlayer = Players[iPlayer]
	--stuff
end
Events.ActivePlayerTurnEnd.Add(PlayerEndTurn)
This fires after the player has completed their turn (in the case of the human player, after pressing NEXT TURN) but before processing is made for the next player. No parameters are passed to ActivePlayerTurnEnd functions, so it is necessary to get the appropriate player data in a manner like as shown.

As you've discovered, GameEvents.PlayerDoTurn(iPlayer) only fires after all the unit movement amounts have been refreshed and before the player makes their unit moves, so is always going to tell you that all units have all their unit move-amounts remaining for that turn.
 
hmm, would that fire for every playertype instance or only me, the local client?, the name tells me only local

ie. local only, local client + ais, local client + remote client + ais, local+remote+ais+barbs+city states+whatnot
 
hmm, would that fire for every playertype instance or only me, the local client?, the name tells me only local

ie. local only, local client + ais, local client + remote client + ais, local+remote+ais+barbs+city states+whatnot
You seem to be conflating Game.GetActivePlayer() with whose computer is running the game. Game.GetActivePlayer() will give the ID# of the player currently being processed by the game, and includes all players of all types (human, AI, City-State, Barbarian).

In lua terms, "players" does not refer to humans, it refers to the civs, city-states, and barbarians that are part of a given game. Each of these is assigned a Player ID# when the game is started. Barbs are always player #63. In a single-player game, the human player is always player ID# 0. All the other major AI civilizations in a single-player game are given ID#'s between '1' and '21'. City States are each given a Player ID# between '22' and '62'. I've never done multiplayer nor tried to code specifically for it, but I believe the same system is applied, except I think the 2nd, 3rd, 4th, etc., human player is assigned Player ID#s '1', '2', '3', '4', etc.

If you are trying to build a mod for multiplayer use, than I have no idea whatsoever how well this will perform, especially if simultaneous turns is turned on. And multiplayer is notorious for getting desynchs from lua code unless the creator of the code is very careful to ensure that all human players in a multiplayer game are always getting the same data from an lua script. Using the math.random() method to get a random number is as I recall one notorious method of causing multiplayer de-synchs.
 
Thanks guys, no, I just started learning, just making a civ in general, no goal as to how it has to run, just that it has to run, and this info is a lot better than the wiki, sadly :P

Although making the civ work in multiplayer would be a good goal :P
 
The approach won't work for the AI anyway, as (except for garrisoned units) the AI always uses the full movement of units - usually just wandering about aimlessly. Watch a CS unit that's partly damaged, it will pointlessly patrol the borders and never heal.
 
can make check then so that the ai benefits if their last turn is on the improv I guess.

new question, I tried to add a new mission button, and it doesnt show at all, I copied MISSION_AIR_SWEEP basically and nothing, and later added Visible 1, gave it a hotkey, a description, created a matching interfacemode

I did a lot of code that more or less makes it work like an air sweep, just slightly different internal rules. But I cant test it because it the button doesnt show up on my air units... what gives, what do I need to do to have the button show up, does it need a unique priority? I see the mission is on the tables, I am just not sure it will show on my planes at all...

hmm ok... nvm... it added the button to goddamn caravans instead of planes, I have 5 buttons, the >> to open next page, and delete on it, my button being the first on the five. Afaik Im testing that the domain is air, so caravans shouldnt cut it..., Hopefully that makes it simple to tell me what Im screwing up...

Got the mission to show as disabled on planes (by just checkign is domain air and testvisible true and leaving early, but when testvisible false I want to actually check if the marked plot is valid (datax and y), i'm using the same code as canAirSweep but it disables the mission...

The interface button still shows up only on the caravan though, its the same cansweep as the mission check but only caravan (ts not even air)


EDIT: Alright finally made the button appear on the planes... and while I know why it works NOW, I still have no idea why the old code did not work THEN. I did several bigger modifications, but the main thing that solved it is that in CvUnits I moved my new logic check above the big switch on CanDoInterfaceMode. Which means that before that the interfacemode was being consumed before it reached its own switch case (and somehow it was being treated as a caravan's interfacemode, becaus eit was showing on caravans of all places)... makes no sense to me but I'll guess it's about the dll loading before my xml entry gets into the database? arent data xmls loaded as soon as you enable the mod? "configuring data" and dlls only after you start a game? whatever, it works like it should now...
 
can make check then so that the ai benefits if their last turn is on the improv I guess.

new question, I tried to add a new mission button, and it doesnt show at all, I copied MISSION_AIR_SWEEP basically and nothing, and later added Visible 1, gave it a hotkey, a description, created a matching interfacemode

I did a lot of code that more or less makes it work like an air sweep, just slightly different internal rules. But I cant test it because it the button doesnt show up on my air units... what gives, what do I need to do to have the button show up, does it need a unique priority? I see the mission is on the tables, I am just not sure it will show on my planes at all...

hmm ok... nvm... it added the button to goddamn caravans instead of planes, I have 5 buttons, the >> to open next page, and delete on it, my button being the first on the five. Afaik Im testing that the domain is air, so caravans shouldnt cut it..., Hopefully that makes it simple to tell me what Im screwing up...

Got the mission to show as disabled on planes (by just checkign is domain air and testvisible true and leaving early, but when testvisible false I want to actually check if the marked plot is valid (datax and y), i'm using the same code as canAirSweep but it disables the mission...

The interface button still shows up only on the caravan though, its the same cansweep as the mission check but only caravan (ts not even air)


EDIT: Alright finally made the button appear on the planes... and while I know why it works NOW, I still have no idea why the old code did not work THEN. I did several bigger modifications, but the main thing that solved it is that in CvUnits I moved my new logic check above the big switch on CanDoInterfaceMode. Which means that before that the interfacemode was being consumed before it reached its own switch case (and somehow it was being treated as a caravan's interfacemode, becaus eit was showing on caravans of all places)... makes no sense to me but I'll guess it's about the dll loading before my xml entry gets into the database? arent data xmls loaded as soon as you enable the mod? "configuring data" and dlls only after you start a game? whatever, it works like it should now...
As far as your last bit, mod "stuff" is only loaded into the game after you press the "NEXT" button in the mods menu. DLL files are added through an 'OnGetDLLPath' Action, but I am not sure when that fires as opposed to XML/SQL/LUA -- I assume it does so before XML, etc. All XML and SQL from all mods load before any LUA code executes. Mod load order can also interplay with mod failures when two or more mods are 'writing' to the same game-data in the database, or are each importing their own version of a standard game-file, such as lua UI files, or the DLL file (though technically this isn't an 'import'). XML in UI <Context> wraps acts quite a bit different than XML in Database <GameData> wraps: <GameData> gets loaded when the game loads the mod, and once in the Database is static except if changed by another mod's conflicting <GameData>; <Context> info is only for UI modding for building the UI panels and pop-ups.

For the rest, I think you are talking dll, which you might get more visibility to your issue by starting a thread of its own. Other than Gazebo and whoward69 there really aren't too many (any ?) of us who understand dll-talk.
 
Back
Top Bottom