<< Back to Programming Forum   Search

Posts 1 - 30 of 35   1  2  Next >>   
Change result of attack/transfer: 8/30/2020 08:02:15


krinid 
Level 59
Report
How can I change the result of an attack/transfer?

In my case, I'm looking to make result.IsSuccessful change from false to true to permit multi-transfer through one's own territories, but the built in code automatically sets it so once you transfer back to territory you already own, all further movement ends up with result.IsSuccessful==false, and my code receives this order as a failed order (result.IsSuccessful==false).

In particular, for when the 1st movement after transferring to one's own territory happens, the following state applies:
    *game.ServerGame.LatestTurnStanding.Territories[order.From].NumArmies.NumArmies==# armies present on source territory
    *game.ServerGame.LatestTurnStanding.Territories[order.To].NumArmies.NumArmies==# armies present on target territory (owned by same player as source territory)
    *order.NumArmies.NumArmies==# of armies the player actually selected to move from source territory to the target territory
    *result.ActualArmies.NumArmies==0 --> this is a problem, b/c it's decided that despite the user trying to move units, it's reduced the # that actually move to 0
    *result.IsSuccessful==false --> also a problem, and likely the reason why the ActualArmies is set to 0


I've tried skipping this order and adding another order with the figures I need to occur, but the same rules apply and the same result happens again.

IsSuccessful seems to a read only variable, so I can't just change it and force the movement to be allowed.

The problem is that by the time the Order comes to my code, it's already assigned result.IsSuccessful==false and result.ActualArmies.NumArmies==0 and I can't seem to change the result to allow the move to happen.

My code is in:
function Server_AdvanceTurn_Order(game, order, result, skipThisOrder, addNewOrder)

Is this the right spot for it?
Change result of attack/transfer: 8/30/2020 09:42:26


TBest 
Level 60
Report
‘ false to true to permit multi-transfer through one's own territories‘

Are you able to override orders that are not multi-transfers? If so this might be a restriction in warzone that mods can’t bypass.

I haven’t taken a closer look yet, but this is my first hunch and I think this could be it

Edited 8/30/2020 09:43:37
Change result of attack/transfer: 8/30/2020 10:07:45


JK_3 
Level 60
Report
@krinid I think the moving of 0 armies causes the attack to fail, instead of the fail causing the 0 armies
Change result of attack/transfer: 8/30/2020 14:16:13


HangFire 
Level 10
Report
Is your inquiry related to this post?

https://www.warzone.com/Forum/443512-link-up-move-one

If so, make sure 'total' armies is there before you 'move' them. They have to register as a total # of armies first. Then they should be able to move as a whole group to the next territory.

Also, look at the code for the move armies window. (the little box with the slider bar) That also has to be changed to reflect the move order. If it doesn't "see" them, it can't move them.

Of course, I could be totally off my rocker, in which case, ignore ^ me.

Edited 8/30/2020 14:17:13
Change result of attack/transfer: 8/30/2020 15:34:04


krinid 
Level 59
Report
@HangFire, Yep, precisely related to that thread & the mod edit I'm working on. It does show total armies, just the code overrides the move to reject it and auto-skip it. See next response to JK_3 as well.

@JK_3, Possibly, but either way I can't seem to change it. By the time my code gets the moves, the # of ActualArmies is set to 0 despite it clearly showing that the # of armies the player selected is >0 and that there are actually >0 on the source territory. There's no reason the move can't occur other than that the code has presumably identified it as a post transfer move through one's own territory and thus overrides the move to disallow it.

@TBest, No, both result.ActualArmies.NumArmies & result.IsSuccessful seem to be read only properties, so all I can do is Skip this current order and add another new order of my choosing -- but my choosing ends up being the same parameters the player originally sent, and it sends this new order through the same core code and gets rejected in the same manner. I need to be able to modify the code or at least override the code that rejects this order. Surely this is possible? Does any other mod we know change the success/failure criteria of an attack? Not just Skip and recreate a different one, but actually flip the Allow/Reject status one way or the other?

I considered that since I've already recognized this as a post transfer move through one's own territory, I could just manually edit the # of armies in the FROM and TO territories ... but this is actually only feasible for Transfers where it's a simple take from FROM territory and add to TO territory, but it could well be an Attack, in which case I really need to let the core WZ engine handle it to deal with all the facets of of battle (kill rates, cards, other mods, etc). Else I'd have to radically simplify the attack which ruins the game and would ignore several facets of play and make a straight up attack differ from an attack after a transfer through own territory, which makes the mod kind of meaningless.

So in essence I believe I can handle multi-transfers, and also straight up multi-attacks, just not mixed multi-attacks after a transfer.
Change result of attack/transfer: 8/30/2020 15:44:03


JK_3 
Level 60
Report
I forgot when the server calls which function, but perhaps it would be possible to call a function that happens before the turn gets calculated by the server.

That way you could manually subtract the #armies in A and B and add them to C, then let the server take it from there.
This would prob require attack by % to work, so all the armies attack instead of just the few that were in C originally.
Change result of attack/transfer: 8/30/2020 18:20:14


HangFire 
Level 10
Report
krinid, what if you changed the value to n? Would it still default to 0 for the second transfer?

Odd that a 2nd transfer will show the total number of armies there, yet ignore the merge to move them.

Just a thought. Maybe it needs to show two results. Could be why the second transfer is ignored because it doesn't recognize it as a result. You need two results for a merge?

Edited 8/30/2020 18:22:44
Change result of attack/transfer: 8/30/2020 22:47:58


krinid 
Level 59
Report
@JK, Agree with you, but unfortunately I'm not slick enough with the API to know which function that would be, or if it even exists ... does any other mod materially change how an attack works that it would change the outcome? I know there are a number of mods that are independent attacks of their own like Nuke, Pestilence ... and those are honestly easier b/c they aren't changing existing moves, they are actually new moves of their own with manual adjustments that ignore all other attack factors or cards (eg: you can Nuke or cast Pestilence someone you can't attack b/c of a Diplo card, etc). And b/c these "attacks" are unique and materially different from regular attacks, this can be deemed acceptable, but what I'm trying to do here is in fact a regular attack, so it needs to go through the same code to be consistent.

Actually goes along with another idea I have for a mod, which is to modify kill rates based on in-game stateful criteria, so it would necessary for that as well.

@HangFire, It doesn't work that way. The # of armies shows the intended moved # of armies, but the ActualArmies shows the resultant # of armies that will actually make the attack. Adding a new order with different #'s doesn't change the fact that the game code knows that it just did a transfer ... I need to somehow trick the game into not knowing that these units transferred before this attack move.
Change result of attack/transfer: 9/1/2020 14:03:11


krinid 
Level 59
Report
I'll take a look at Stack Limit ... I think this might have clues. Not 100% sure but I think this mod prevents you from having a stack beyond a set limit of x, so if you move units to a target territory which could result in that exceeding x, it leaves the excess units behind.

Though I think this would never happen during an attack (can never increase units after an attack unless someone writes a mod to permit negative kill rates), and if it's only during transfers, it's possible that it's handled in the same mechanism I illustrated above (manually modifying the unit counts on FROM and TO territories).
Change result of attack/transfer: 9/1/2020 14:59:04


HangFire 
Level 10
Report
This mod, prevents territories from crossing a customizable amount of armies on it. If you deploy armies, make sure they don't go over the army limit, since that will delete those that go over the cap. Same goes for the game creation(so if you make e.g. custom scenario or set starting armies per territory, verify that those are not over the limit). You don't have to worry about losing armies due to transfering, the orders will be adapted so you don't lose any.
Trusted: no
Change result of attack/transfer: 9/1/2020 16:18:48


TBest 
Level 60
Report
Figured it out. Easier then I expected too :) I guess Warzone just sets ActualArmies to 0 when the armies have been 'spent'.


function Server_AdvanceTurn_Order(game, order, result, skipThisOrder, addNewOrder)
    if (order.proxyType == 'GameOrderAttackTransfer') then
        if (result.IsAttack == false) then
            local attackers = 100 --Maybe you have to get the proper number here from the territory. But 100 is fine for this example
            --Write to GameOrderResult	 (result)
			local NewAttackingArmiesKilled = WL.Armies.Create(attackers) 
            result.ActualArmies  = NewAttackingArmiesKilled
        end;
    end
end


Change result of attack/transfer: 9/1/2020 17:58:02


HangFire 
Level 10
Report
As long as ^ that, leads to this

> "move 10 troops from A into C, and 10 from B into C, and then from there, advance all 20 into the next territory."

A >10
........C >20 --->D20
B >10

^ That is what we want.
Change result of attack/transfer: 9/1/2020 19:04:07


TBest 
Level 60
Report
Sure does. Same principle. (I did test it to make sure too)
Change result of attack/transfer: 9/3/2020 14:14:28


HangFire 
Level 10
Report
Release date? I have a scenario ready for testing.
Change result of attack/transfer: 9/3/2020 14:16:18


krinid 
Level 59
Report
If it works as smoothly as that, should be 1-2 weeks. Just need time to finish the testing ... I seem to recall setting that value and having it ignored, but let me take another look & will report back.

And TBest said he tested it and it worked, so should be just a matter of figuring out what I did wrong the first time I tried it and adjusting to how TBest did it.

#TBest_knows_Best!

Edited 9/3/2020 14:18:12
Change result of attack/transfer: 9/3/2020 14:54:20


HangFire 
Level 10
Report
O.k., two weeks. Good enough. Thank you.
Change result of attack/transfer: 9/6/2020 04:16:01


krinid 
Level 59
Report
TBest - Can you pls send the contents of the whole LUA file you are testing with? I'm unable to replicate the results you're getting.

I can confirm that it properly updates the value for result.ActualArmies but result.IsSuccessful still ==false, and the turn never actually ends.

I have some print statements in function Server_AdvanceTurn_End to visually signal when the turn is ending, and as long as the 'result.ActualArmies = NewAttackingArmiesKilled' line is executed, this code never executes, the turn never ends and the move is never executed in the game UI. If I remove this line, the print line displays and the turn ends normally.
Change result of attack/transfer: 9/8/2020 22:46:51


HangFire 
Level 10
Report
So, howzit goin with the mod?
Change result of attack/transfer: 9/9/2020 00:13:21


krinid 
Level 59
Report
I'm stuck b/c I can't figure out any way past the problem I stated previously and can't replicate TBest's solution to it.
Change result of attack/transfer: 9/9/2020 00:53:51


HangFire 
Level 10
Report
edit. nvm.

Edited 9/9/2020 00:54:54
Change result of attack/transfer: 9/15/2020 02:14:51


HangFire 
Level 10
Report
Bump. All is well I presume? Looking forward to it.
Change result of attack/transfer: 9/15/2020 03:10:32


TBest 
Level 60
Report
I'm stuck b/c I can't figure out any way past the problem I stated previously and can't replicate TBest's solution to it.

Is your code on github? Feel free to @ me in the prog channel on discord
Change result of attack/transfer: 9/15/2020 03:13:53


krinid 
Level 59
Report
No, haven't posted it, just testing it locally still.

Can you send your entire LUA file you are testing with?

Also the criteria I'm testing it on is:

A (owned by player 1) moves to B (neutral)
B (owned by player 1) moves to C (neutral)
C (owned by player 1) moves to B (owned by player 1)
B moves to D (neutral)

And the B->D always fails.
Change result of attack/transfer: 9/15/2020 04:48:03


krinid 
Level 59
Report
Below is the code with some error checking where I'm trying to replicate what you've done.

function Server_AdvanceTurn_Order(game, order, result, skipThisOrder, addNewOrder)
	print ("0005 Turn_Order[start]")
	if(order.PlayerID==1) then
		skipThisOrder(WL.ModOrderControl.SkipAndSupressSkippedMessage)
	elseif(order.proxyType == 'GameOrderAttackTransfer') then
		if (result.IsAttack == false) then
			print ("10 [ATTACK/TRANSFER] IsAttack="..tostring(result.IsAttack).." pl="..order.PlayerID.." #attacks="..OtherAttacks[order.From].." #armies="..order.NumArmies.NumArmies .." #armiesFROM="..game.ServerGame.LatestTurnStanding.Territories[order.From].NumArmies.NumArmies.." TO="..game.ServerGame.LatestTurnStanding.Territories[order.To].NumArmies.NumArmies);
			print ("20   success=".. tostring(result.IsSuccessful).." ActualArmies="..result.ActualArmies.NumArmies);
			
			--local numAttackers = game.ServerGame.LatestTurnStanding.Territories[order.From].NumArmies.NumArmies;
			local numAttackers = order.NumArmies.NumArmies			
			--Write to GameOrderResult (result)
			--local NewAttackingArmiesKilled = WL.Armies.Create(numAttackers);
			--result.ActualArmies = NewAttackingArmiesKilled;
			if numAttackers == 40 then
				print ("30   success=".. tostring(result.IsSuccessful).." ActualArmies="..result.ActualArmies.NumArmies);
				local numAttackingArmies = WL.Armies.Create(numAttackers-5);
				--result.ActualArmies = NewAttackingArmiesKilled;
				result.ActualArmies = numAttackingArmies;
				print ("40   success=".. tostring(result.IsSuccessful).." ActualArmies="..result.ActualArmies.NumArmies);
			end
			--skipThisOrder(WL.ModOrderControl.SkipAndSupressSkippedMessage)
		end
		print ("50   success=".. tostring(result.IsSuccessful).." ActualArmies="..result.ActualArmies.NumArmies);
	end
	print ("1000 Turn_Order[fin]")
end


And here is the debug window output. You can see that while it does change the # actual armies from 0 to another #, it never changes success to True, and thus the move still gets skipped. Inputted moves were just A->B, B->C, where A & B are already owned territories, C is neutral. A->B always succeeds, B->C always fails.

274: [TURN START][start]
274: [TURN START][fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 10 [ATTACK/TRANSFER] IsAttack=false pl=1058239 #attacks=5 #armies=100 #armiesFROM=45 TO=0
274: 20   success=true ActualArmies=45
274: 50   success=true ActualArmies=45
274: 1000 Turn_Order[fin]
274: 0005 Turn_Order[start]
274: 10 [ATTACK/TRANSFER] IsAttack=false pl=1058239 #attacks=5 #armies=40 #armiesFROM=45 TO=2
274: 20   success=false ActualArmies=0
274: 30   success=false ActualArmies=0
274: 40   success=false ActualArmies=35
274: 50   success=false ActualArmies=35
274: 1000 Turn_Order[fin]
Change result of attack/transfer: 9/15/2020 14:36:57


TBest 
Level 60
Report
This works for me, and I think it accomplishes what you are trying to do with leaving 5 armies behind. Let me know if you want me to add comments. EDIT: duno why the copy-past is not formatting the code nicely.

function Server_AdvanceTurn_Order(game, order, result, skipThisOrder, addNewOrder)
	if(order.PlayerID==1) then
        skipThisOrder(WL.ModOrderControl.SkipAndSupressSkippedMessage)
        return;
    end
    if(order.proxyType == 'GameOrderAttackTransfer') then
		if (result.IsAttack == false) then
            if (result.IsNullified) then 
                local numAttackers = order.NumArmies.NumArmies
                
                if numAttackers > game.ServerGame.LatestTurnStanding.Territories[order.From].NumArmies.NumArmies then
                    numAttackers = game.ServerGame.LatestTurnStanding.Territories[order.From].NumArmies.NumArmies;
                end;
                
            numAttackers = numAttackers - 5;

            if (numAttackers < 0) then numAttackers = 0 end;
                local numAttackingArmies = WL.Armies.Create(numAttackers);
            
                result.ActualArmies = numAttackingArmies;
            end
        end
	end
end


Edited 9/15/2020 14:39:05
Change result of attack/transfer: 9/16/2020 03:23:57


krinid 
Level 59
Report
Still can't get it to work. To confirm, you're able to accomplish this?



1) Colombia moves 100% to Peru
2) Peru moves 100% to Colombia
3) Colombia moves 100% to Amazonas
4) Peru moves 100% to Amazonas

#1 and #2 already work fine, which is still an improvement on current LMA (#2 would fail).

But #3 and #4 both still fail. I'm printing out result.isSuccess, result.isNullified and result.ActualArmies.NumArmies and see that when orders #3 starts that it's false/true/0 and then after the modification of ActualArmies switches to false/false/57 which shows that the move is no longer nullified and that army count has been corrected, but it's still success=false and thus never gets executed.

Also 1 other oddity is that order #4 never executes. In fact, I can see that the code exits function Server_AdvanceTurn_Order after order #3 and halts, never processing order #4. It's likely the false/false/57 combination trying to get the WZ engine to exit an unsuccessful but non-nullified order causing it to crash and abort processing any further orders.
Change result of attack/transfer: 9/16/2020 03:33:39


TBest 
Level 60
Report
I just realized I have been testing in non-multiattack games. I assumed that transfer would behave the same, but this was a wrong assumption on my end. My code was written for normal games where multiattack is not enabled and there is no attack by %.

I do see what the issue is, I will see if I can make something working tomorrow.

Edited 9/16/2020 03:55:25
Change result of attack/transfer: 9/16/2020 04:00:12


HangFire 
Level 10
Report
Also try the mod, Limited Attack. Set to 3. Then try the following.

Order 1 - 5 troops from A, into C.
Order 2 - 5 troops from B, into C
They merge, for total of 10, to be moved into D
Order 3 - move 10 into D

.............Order 1---5>
(merge) Order 3---10-->10
.............Order 2---5>
Change result of attack/transfer: 9/16/2020 04:00:35


krinid 
Level 59
Report
That explains it. And you're correct, for non-MA games, moves #1 and #2 aren't an issue, but of course you'd never be able to execute moves #3 or #4.

Regular MA is also fine with #1 and #2 but neither #3 or #4. Current LMA mod breaks #2, which is frustrating b/c it's super non-intuitive for LMA to be more restrictive than regular non-MA, and also breaking something that's present in regular non-modded MA.

My current LMM (Limited Multi Move) code fixes #2 (simply by not inadvertently blocking it) but gets shut down on #3 and #4.

And looking forward, I think I'll need to worry about how to prevent infinite troop transfers by having enabled #2. eg: if using LMM with 3 move allowance and you transfer 10 from A->B which already has 15 units, B now has 10 units with 1 move already down, and 15 units with 0 moves, but the game will only see 25 units and I'll have to set it to either with 0 moves done (permits infinite transfers) or to 1 (reintroduces a toned down version of the #2 problem - not the instant All-Stop breaker that current LMA is, but if a transfer to a territory is the final move allowed for those units, it would then block #2 for the units on the target territory -- still an improvement, but not ideal). Anyhow, this is the "next problem" to solve, and I'm still stuck on the "current problem" and if I can't get past this, the next problem is moot.
Change result of attack/transfer: 9/16/2020 04:04:03


krinid 
Level 59
Report
@HangFire - Agree, that is another use case, but that's in the "next problem" category. Until I'm able to figure out what's stopping the A->B->C problem ("current problem"), I can't progress on to A->C B->C, C->D test case ... but 100% with you that that needs to be enabled by this mod to truly succeed -- while simultaneously not enabling infinite transfers (see my last post).
Posts 1 - 30 of 35   1  2  Next >>