wargus
wargus copied to clipboard
ActionVictory and ActionDefeat SinglePlayerTriggers
I was editing the scripts for the campaign the other day while testing the Victory/Defeat messagebox delay, in other words I was making sure the time it took for the "You are Victorious!" and "You have been Defeated" message boxes matched the original games time of delay - in this case 120 milliseconds.
I soon found out that I had to add this contingency to EVERY Victory/Defeat condition in EVERY campaign script file, which is arduous and stupid.
I eventually found this in 'stratagus.lua'
function SinglePlayerTriggers()
AddTrigger(
function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
function() return ActionDefeat() end)
AddTrigger(
function() return GetNumOpponents(GetThisPlayer()) == 0 end,
function() return ActionVictory() end)
end
and, based on the code from the second mission of the human campaign that I originally observed having a delay when you rescued the four archers and returned them to the circle of power, I took that code from that mission script and modified the 'stratagus.lua' file to that which is below
function SinglePlayerTriggers()
local cycle2Win = 120
AddTrigger(
function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
function()
if (cycle2Win == 120) then
end
cycle2Win = cycle2Win - 1
if (cycle2Win <= 0) then
ActionDefeat()
return false
end
return true end)
AddTrigger(
function() return GetNumOpponents(GetThisPlayer()) == 0 end,
function()
if (cycle2Win == 120) then
cycle2Win = cycle2Win - 1
end
if (cycle2Win <= 0) then
ActionVictory()
return false
end
return true end)
end
But the delay won't work. I cannot figure this out, and would like some help please.
I've seen that thing in human mission 2 as well. I dont know why it wouldn't work since you've put that in stratagus.lua. Did you try out in a campaign mission? I think it must be because the code doesn't consider the campaign missions as singleplayer, since the campaign missions has their own victory and defeat conditions. And the code you've added might only apply to the singleplayer custom games.
But if you ask me, I think it's better that you dont have to wait for the victory or defeat screen to show up. I think that's an improvement in wargus.
First, the things you modified there in stratagus.lua only applies to the victory and defeat when all units are gone... The missions have their own conditions, so it won't apply to them.
If you really want the delay, patch the ActionDefeat and ActionVictory functions directly so they handle the delay internally.
When you say patch them internally, you mean in the engine right? I am happy to try and do that but I haven't coded the engine for a long time. Will maybe try modifying the github code instead...idk.
No, you can monkeypatch the function in lua. I can post an example of what I mean tomorrow
DinkyDyeAussie [email protected] schrieb am Sa., 13. Mai 2017, 00:06:
When you say patch them internally, you mean in the engine right? I am happy to try and do that but I haven't coded the engine for a long time. Will maybe try modifying the github code instead...idk.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/Wargus/wargus/issues/238#issuecomment-301196737, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC0m_u3iILM0GROFEj0U9hLvYyHKvrCks5r5Nf-gaJpZM4NYaE1 .
No worries. Thanks in advance.
Sorry for the delay, here's what I mean you could do (I have just written this, not run it):
-- configure the total cycle count before ActionVictory here
local CYCLE2END_COUNT = 120
-- patch the ActionVictory (same for ActionDefeat)
local ImmediateActionVictory = ActionVictory
local cycle2win = 0
function ActionVictory()
if cycle2win <= 0 then
-- the counter will be shared across missions, so
-- reset the local counter when it was used up
cycle2win = CYCLE2END_COUNT
else
cycle2win = cycle2win - 1
if cycle2win == 0 then
return ImmediateActionVictory()
else
return true -- continue this trigger
end
end
end
Does that code go in stratagus.lua too Tim?
Yes.
DinkyDyeAussie [email protected] schrieb am Mo., 15. Mai 2017, 21:34:
Does that code go in stratagus.lua too Tim?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/Wargus/wargus/issues/238#issuecomment-301580313, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC0mw3yoSMeDXe2RaMA7y_KYH0Xzxf8ks5r6KjYgaJpZM4NYaE1 .
Just finished testing that code out. Changed CYCLE2END_COUNT and cycle2win values around, otherwise no condition was reached. Works now for both Victory and Defeat conditions in the Campaign 👍
-- configure the total cycle count before ActionVictory here
local CYCLE2END_COUNT = 0
-- patch the ActionVictory (same for ActionDefeat)
local ImmediateActionVictory = ActionVictory
local cycle2win = 120
function ActionVictory()
if cycle2win <= 0 then
-- the counter will be shared across missions, so
-- reset the local counter when it was used up
cycle2win = CYCLE2END_COUNT
else
cycle2win = cycle2win - 1
if cycle2win == 0 then
return ImmediateActionVictory()
else
return true -- continue this trigger
end
end
end
Just wondering, now that this variable is in 'stratagus.lua' instead of the respective mission files, if there is a rescue mission and you need to return a unit to the 'circle of power', the "rescue" sound no longer plays when the unit crosses the circle of power anymore. Can we hack that feature back in as well in lua? Or will it need to be a per misson script thing still?
Those missions (e.g. Human 2) should be simplified now, the cycle2win is no longer needed there, jus use a boolean local variable to see if the sound was already played, and call ActionVictory always (because it keeps its own counter)
Yeeeeeeah how do I do that? lol. I hace no idea how to do that or where to implant it.
Ill medel with it though.
Did you update the wargus on this? My missions wont work out of blue.
@DinkyDyeAussie if you feel up to it, try to add a configuration option and use that in a condition to decide if you should patch the ActionVictory and ActionDefeat or not. The option handling in the scripts is mostly in stratagus.lua. You can also add the option to the game options menu, if you want.