Unit:PushMission() not working for AI

Vicevirtuoso

The Modetta Man
Joined
May 14, 2013
Messages
775
Location
The Wreckage, Brother
The civ I'm working on has some code to automatically generate a Great Work when certain conditions are met. Since there are no direct means of creating Great Works, the process involves creating a dummy unit with unique names/Great Works, which, when the aforementioned conditions are met, is generated with InitUnit() and then immediately creates its Great Work.

This is the PushMission() call I'm using:

Code:
pGWUnit:PushMission(MissionTypes.MISSION_CREATE_GREAT_WORK, -1, -1, 0, 0, 0, 0, pGWUnit:GetPlot(), pGWUnit)

This works without a hitch for the human player, but it won't seem to fire for AI players. Is there a specific value for one of those arguments in the middle I need to set?


Also, I've read that the Game.SelectionListGameNetMessage is better for this, since it will work in multiplayer once it gets successfully implemented. But I haven't had any success making that work for either human or AI players.

Code:
Game.SelectionListGameNetMessage(GameMessageTypes.GAMEMESSAGE_PUSH_MISSION, MissionTypes.MISSION_CREATE_GREAT_WORK, pGWUnit:GetPlot():GetX(), pGWUnit:GetPlot():GetY(), 0, false, false)


Any suggestions regarding what I'm doing wrong?
 
What unit AI (4th parameter) are you using when creating the unit with InitUnit()? Also, what event are you using to trigger this? I've heard that UI events only fire for human players.
 
My mod uses unit:PushMission(MissionTypes.MISSION_MOVE_TO, gotoX, gotoY, 0, 0, 1) very often for AI. Works fine. I leave out the last 3 args because the dll provides default values for these (and the defaults are probably what you want in most cases).

The reason for
Code:
Game.SelectionListGameNetMessage(GameMessageTypes.GAMEMESSAGE_PUSH_MISSION, ...
...is to send a command to other computers in a multiplayer game. Each computer is processing the game separately. On one player's computer, Game.GetActivePlayer() might return 1, and on another's it would be something else. The Lua code associated with UI is only running on the computer for the player interacting with the UI (for example, pressing a UI button). If you use unit:PushMission() in this code, it will only work on one computer and multiplayer games will get out of sync. That's what Game.SelectionListGameNetMessage() is for. If the Lua code is not UI but rather is called by PlayerDoTurn (or some other GameEvent) then it should be running the same on all player computers, and unit:PushMission() will work fine even in a multiplayer game.

I've just coded my mod entirely for single player (using PushMission even in UI). If multiplier ever seems like it will be a reasonable possibility, I'll just update PushMission to SelectionListGameNetMessage where it's needed (that will be the least of my headaches).

I don't know anything about MISSION_CREATE_GREAT_WORK specifically. The next two args are information needed for the mission (x, y in the case of MISSION_MOVE_TO), so I suspect some value is needed there.
 
I don't know anything about MISSION_CREATE_GREAT_WORK specifically. The next two args are information needed for the mission (x, y in the case of MISSION_MOVE_TO), so I suspect some value is needed there.

Not for MISSION_GREAT_WORK, all the info comes from the unit itself
 
Back
Top Bottom