<< Back to Programming Forum   Search

Posts 1 - 21 of 21   
New to modding war zone! Help needed!: 2/3/2020 22:39:39

Angel 
Level 10
Report
Hello, everyone. I recently found out you can create your own mods for warzone. I have an idea for a mod where the neutral territories advance every turn. I figured out how I can edit the number of armies on a neutral square using the Wastelands mod code and configuring it. Here is what I came out with:

function RandomizeWastelands(game, standing)
for _, territory in pairs(standing.Territories) do
local numArmies = territory.NumArmies.NumArmies;
if (territory.OwnerPlayerID == WL.PlayerID.Neutral) then
local newArmies = math.random(2, 4);
if (newArmies < 0) then newArmies = 0 end;
if (newArmies > 100000) then newArmies = 100000 end;
territory.NumArmies = WL.Armies.Create(newArmies);
end
end
end

I use this in the RandomizeWastelands.lua however, I now want to make it so every go, one army is added onto all neutral squares. I tried using Server_AdvanceTurn.lua and making it like this:


function Server_AdvanceTurn_Order(game, order, result, skipThisOrder, addNewOrder)
--I think this needs to go here?
end


function Server_AdvanceTurn_End(game, standing)
for _, territory in pairs(standing.Territories) do
local numArmies = territory.NumArmies.NumArmies;
if (territory.OwnerPlayerID == WL.PlayerID.Neutral) then
local newArmies = math.random(0, 2);
if (newArmies < 0) then newArmies = 0 end;
if (newArmies > 100000) then newArmies = 100000 end;
territory.NumArmies = WL.Armies.Create(newArmies);
end
end

end

However, the mod crashes when I use this code. I get the following error from the mod console in Warzone when trying to advance a move:

250: ERROR: Server_AdvanceTurn.lua:(2,1-51): attempt to index a function value

GameID=123
Hook=Server_AdvanceTurn_End

I cannot figure out how to fix it. As I said, I want to add a number of armies to every neutral territory every go.

I hope someone can help me!

Many Thanks,
Angel
New to modding war zone! Help needed!: 2/3/2020 22:57:04


DanWL 
Level 62
Report
For hooks you don't need, you don't have to include them.

My guess is that you've misread Server_AdvanceTurn_End documentation. The hook is passed Game and addNewOrder.
Game: Provides read-only information about the game.
addNewOrder: A function that you can call to add a GameOrder to the end of the turn. Pass a single GameOrder as the only argument to this function. You may call this function multiple times if you wish.

I'll add a fix soon

Edited 2/3/2020 23:09:18
New to modding war zone! Help needed!: 2/3/2020 23:03:07

Angel 
Level 10
Report
Hi. Thanks for responding but that doesn't seem to be working. I now get this error:

250: ERROR: Server_AdvanceTurn.lua:(5,4-54): attempt to index a function value

GameID=123
Hook=Server_AdvanceTurn_End


Hopefully, we can resolve this together.

Many Thanks,
Angel
New to modding war zone! Help needed!: 2/3/2020 23:09:49


DanWL 
Level 62
Report
See above, done some editing, will post a fix shortly
New to modding war zone! Help needed!: 2/3/2020 23:12:15


DanWL 
Level 62
Report
function Server_AdvanceTurn_End(game)
	local standing = game.ServerGame.LatestTurnStanding;
	local minArmies = 0;
	local maxArmies = 100000;

	for _, territory in pairs(standing.Territories) do
		if (territory.OwnerPlayerID == WL.PlayerID.Neutral) then
			local newNumArmies = math.random(0, 2);

			if (newNumArmies < minArmies) then newNumArmies = minArmies end;
			if (newNumArmies > maxArmies) then newNumArmies = maxArmies end;

			territory.NumArmies = WL.Armies.Create(newNumArmies);
		end
	end
end


Edited 2/3/2020 23:23:34
New to modding war zone! Help needed!: 2/3/2020 23:19:26


DanWL 
Level 62
Report
For future reference in the error message "250: ERROR: Server_AdvanceTurn.lua:(2,1-51): attempt to index a function value":

Server_AdvanceTurn.lua means file name where error is
2 is line number of where the error is
1-51 means error is somewhere between characters 1 and 51
attempt to index a function value is the error - trying to access an item of the functions return value that doesn't exist.
New to modding war zone! Help needed!: 2/3/2020 23:28:35

Angel 
Level 10
Report
Hey, DanWD. Thanks for all your help so far but the updated code still isn't working. I copied it in and this is the error I am getting now:


Warzone Server returned ModFailed x=Sorry, the mod "Angel's Test Modification" has failed. Error:
Server_AdvanceTurn.lua:(13,12-64): TerritoryStanding is not writable (attempted to write to NumArmies)

GameID=123
Hook=Server_AdvanceTurn_End


Let's get this fixed together so I can learn how to make good mods for all Warzone users.

Many Thanks,
Angel

P.S Aren't you the owner or something?
New to modding war zone! Help needed!: 2/3/2020 23:43:15


DanWL 
Level 62
Report
I'm not the owner, but I do have experience with writing mods. Not done standing/territory modifications before.

Well the standing isn't writeable, so you'd have to use WL.TerritoryModification. See https://github.com/dabo123148/WarlightMod/blob/master/NukeCard/Server_AdvanceTurn.lua for an example. That mod reduces number of armies on territories. Getting late where I am and need to wake up early.
New to modding war zone! Help needed!: 2/3/2020 23:55:46

Angel 
Level 10
Report
Late here too. I don't really understand that, as I say I am new to this sort of thing and need guidance. When we find an answer that works I need someone to explain it. Purley so I don't have to come here and ask again and so I can help others if they need me. When you get a chance tomorrow, I plead you to come and take another look. I believe this will be a very fun mod to play for everyone and I want to make this happen and I want to learn.

Many Thanks,
Angel Oliver
New to modding war zone! Help needed!: 2/3/2020 23:58:07


TBest 
Level 60
Report
	for _,territory in pairs(standing.Territories)do
		terrMod = WL.TerritoryModification.Create(territory.ID);
		terrMod.SetOwnerOpt=winner;
		winnerCapturesAll[CurrentIndex]=terrMod;
		CurrentIndex=CurrentIndex+1;
	end


A snippet of code that sets the owner of all territories to be one player (winner). I think this will help you out how you can make your mod as setting the armies is very similar.

Hint : https://www.warzone.com/wiki/Mod_API_Reference:TerritoryModification

{For reference this is part of my mod 'LottoMod' and the full code can be found on github}
https://github.com/TBestLittleHelper/WarLightMods/tree/master/TBest_Mods

Edited 2/3/2020 23:58:44
New to modding war zone! Help needed!: 2/4/2020 17:10:19

Angel 
Level 10
Report
Hey. Just seen your reply. I'm going to start tweaking it now, for help: what does CurrentIndex mean? Thanks.

EDIT:
Tried it and game gives me an error for the line that does:
for _,territory in pairs(standing.Territories)do

I am beggining to wonder if the game does not let you change the or access stuff from game.standing when a move advances. Anyone else got any ideas or should I try emailing the creator?

Edited 2/4/2020 17:20:15
New to modding war zone! Help needed!: 2/4/2020 17:34:20

Angel 
Level 10
Report
I've had a look on the Wiki and it says the AdvanceTurn_End function can only read data from 'game' meaning it cannot edit anything there (for example 'game.standing'). Is there any other way I could do the mod?

Many Thanks,
Angel.
New to modding war zone! Help needed!: 2/4/2020 20:32:42


TBest 
Level 60
Report
Here is the code you are looking for :

function Server_AdvanceTurn_End (game,addNewOrder)
	standing = game.ServerGame.LatestTurnStanding;
	CurrentIndex=1;
	storeChanges={};

	for _,territory in pairs(standing.Territories)do
		if territory.IsNeutral then
			armies = territory.NumArmies.NumArmies;
			terrMod = WL.TerritoryModification.Create(territory.ID);
			terrMod.SetArmiesTo=armies+1;
			storeChanges[CurrentIndex]=terrMod;
			CurrentIndex=CurrentIndex+1;
		end
	end
	addNewOrder(WL.GameOrderEvent.Create(WL.PlayerID.Neutral,'ModTest',nil,storeChanges));

end
New to modding war zone! Help needed!: 2/4/2020 20:39:16


TBest 
Level 60
Report
In terms of the mod itself, it feels like adding +1 every turn is a bit too much. (Or at least, be warned that the AI can get stuck even with plenty of income. As the AI's divide their income among the territories they own.) I would suggest playing around with maybe every other turn or even less and see what works best.
New to modding war zone! Help needed!: 2/4/2020 22:23:03

Angel 
Level 10
Report
Thanks. I am going to try this code. Fingers crossed. Do you think you could make another post explaining what each line does for my self-learning? Also, the one per turn was an example. I am not sure how I want that bit to work at the moment. Would it be possible to add two every 4 turns? (Add a 1/4 a turn or something?)
New to modding war zone! Help needed!: 2/5/2020 00:07:46

Angel 
Level 10
Report
The code worked. I implemented a sense of randomness by making the amount of armies it adds a random number between -6 and 3. However, if the number is zero or under then it will round it to zero. So that makes it a nice type of randomness. Some rounds, barley any squares will get anything added to them. Others, quite a few might be added. I am so glad with my system. Still waiting on the explanation, hope you can get some time to do it. I'll make sure to credit the ones that got me to a solution when I've finished the mod if you'd like.

I'm glad we got through this, as a team.

Many Thanks,
Angel Oliver.
New to modding war zone! Help needed!: 2/5/2020 00:23:36


DanWL 
Level 62
Report
For Lua language key words and syntax see, http://www.lua.org/manual/5.3/.
Relevant wiki links:
https://www.warzone.com/wiki/Mod_Hooks
https://www.warzone.com/wiki/Mod_API_Reference:GameStanding
https://www.warzone.com/wiki/Mod_API_Reference:Armies
https://www.warzone.com/wiki/Mod_API_Reference:TerritoryModification

You should be able to figure it out from there.

What I don't get is why you expect to be spoon fed answers. If you learnt the language basics first then looked at mod framework parts that you needed, you shouldn't have had a problem. I know that method works because I tried it myself.
New to modding war zone! Help needed!: 2/5/2020 06:40:43


TBest 
Level 60
Report
Do you think you could make another post explaining what each line does for my self-learning?

Why don't you try to comment the code and see what you can understand and what you can't? It's easier to answer a specific question then a general question. As Dan pointed out, the wiki documentation should be able to answer most, if not all of your questions.

You didn't say anything about your background, but for myself the biggest new thing in lua is the tables part discussed here : https://www.warzone.com/wiki/Mod_API_Reference

Edited 2/5/2020 06:42:58
New to modding war zone! Help needed!: 2/5/2020 17:23:35

Angel 
Level 10
Report
Taken a look at the wiki and it's cleared it all up. Thanks alot for helping a newbie. There seems to be a problem though. I am trying to make a multiplayer game with the mod (which is now on GitHub) and it says 'Whoops! An error occured.' and that something in Warzone 'broke'? Here is what shows up when I press 'Show Details':


https://ghostbin.co/paste/gjamr

(Too long to paste here)

Anyone know how to solve this? I'm trying to use the mod in a public game with multiple friends/family members. Here is the GitHub link:

https://github.com/saousername/WarzoneMods/tree/master/NuetralAdvancementsMod


Many Thanks,
Angel

Edited 2/5/2020 17:25:00
New to modding war zone! Help needed!: 2/5/2020 20:05:58


TBest 
Level 60
Report
Not seen that error before. To be clear, it shows up as a Warzone error popup and not a mod error?
(If it is a warzone error,you should report it. It could still be a mod error, however then it should be handled as a mod exception so it is still a bug)

I was able to create a mp game using your github repro, however I don't have two member accounts so I can't test it more than that easily. (read: start the game)

Attribute PlayersInvited not found on element Data

I have no clue how this could be the case. But it sounds like you/warzone tried to make a game where no players where invited? It might sound dumb, but my only suggestion is to make a MP game where you make sure to invite players? Try using open seats maybe?
New to modding war zone! Help needed!: 2/5/2020 20:18:22


TBest 
Level 60
Report
I have no problems : here is a test games i ran on it

https://www.warzone.com/MultiPlayer?GameID=20752044
Posts 1 - 21 of 21