[LUA] Sending information in multiplayer

Lort Krassbeter

Chieftain
Joined
Mar 8, 2015
Messages
17
Location
Beyond Earth
Hi, I am wondering how to send information to another/all other players in a network multiplayer game.
1. I saw another mod use Plot.GetScriptData()/SetScriptData() to set and get data from a specific plot on the map, however this didn't work for me. Is there any method that needs to be invoked for map data to be synchronized?
2. Another method would be to use any object that is synchronized by the game automatically, e.g. adopting policies. The question there would be: How to add a policy that can not be adopted by the player manually and is invisible in the policy tree but can be adopted programatically?

Thanks in advance :)
 
I actually discovered this trick relatively recently, though whether or not it actually works in MP needs testing.

First, make a dummy building with no gold cost, and make sure it's present in all Cities. Then, make a function and hook it to GameEvents.CitySoldBuilding, and have it check for the dummy building's ID. Finally, use Network.SendSellBuilding to force the building to be "sold." What will happen is: Network.SendSellBuilding will fire and will cause GameEvents.CitySoldBuilding to be called, but the building will not actually be sold (since it doesn't have a gold cost).

There's an implementation of it in my most recent mod on the workshop if you want to take a look at its Lua.
 
I actually discovered this trick relatively recently, though whether or not it actually works in MP needs testing.

First, make a dummy building with no gold cost, and make sure it's present in all Cities. Then, make a function and hook it to GameEvents.CitySoldBuilding, and have it check for the dummy building's ID. Finally, use Network.SendSellBuilding to force the building to be "sold." What will happen is: Network.SendSellBuilding will fire and will cause GameEvents.CitySoldBuilding to be called, but the building will not actually be sold (since it doesn't have a gold cost).

There's an implementation of it in my most recent mod on the workshop if you want to take a look at its Lua.

This sounds promising! I implemented the dummy building and set everything up to test it, have to wait for a friend to join me in the next days. I'll report back when I got some testing done, thanks!
 
Hi again,
the test went very well, the mechanic worked exactly as you described. This way I am able to broadcast information to all players from a specific player and with a specific dummy building that are passed as argument in the CitySoldBuilding event.
Thank you very much!
One more question though: the CitySoldBuilding event is not listed on the wiki page http://modiki.civfanatics.com/index.php/GameEvents_(Civ5_Type). Where do I find those unlisted events? I am searching for a "CityPurchased" event or similar.
 
BTW CityPurchased is CityConstructed with the 4th parameter (bGold) true
 
Hi again,
the test went very well, the mechanic worked exactly as you described. This way I am able to broadcast information to all players from a specific player and with a specific dummy building that are passed as argument in the CitySoldBuilding event.
Thank you very much!

This is very good news!

This opens up a lot of possibilities of what can be done in multiplayer without a replacement DLL. Will probably need to go back and add this in to several of my mods.
 
Sorry for the double post, but it's been a little bit and I feel this deserves a bump due to a new discovery.

When you use Network.SendSellBuilding, the building ID you send doesn't even have to exist in the Buildings table. This means that you can use any arbitrary number up to 2,147,483,647! Didn't really test this much, but I'm assuming that negative numbers down to -2,147,483,648 will work as well.

This certainly opens up a huge realm of possibilities. For example, you could now define a range of 64 numbers to use for your function, and use the 64 different values to determine which PlayerID the function will refer to. For example, if you had a Civilization whose UA allowed them to "curse" another player, you could actually accept the input of which Player ID the user wants to curse and write the function appropriately.
 
Sorry for the double post, but it's been a little bit and I feel this deserves a bump due to a new discovery.

When you use Network.SendSellBuilding, the building ID you send doesn't even have to exist in the Buildings table. This means that you can use any arbitrary number up to 2,147,483,647! Didn't really test this much, but I'm assuming that negative numbers down to -2,147,483,648 will work as well.

This certainly opens up a huge realm of possibilities. For example, you could now define a range of 64 numbers to use for your function, and use the 64 different values to determine which PlayerID the function will refer to. For example, if you had a Civilization whose UA allowed them to "curse" another player, you could actually accept the input of which Player ID the user wants to curse and write the function appropriately.
Nice, observation! I tested it in MP and it works just fine. That's really awesome, however if there will be a number of mods working with this method we should setup a list of ID's that are being used by those, so they don't interfere. For now: I am using -111, -112 and -113 :D
 
Back
Top Bottom