-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameStateHook.lua
60 lines (56 loc) · 2.46 KB
/
GameStateHook.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Game hook mod injector
function arrayToString(arrayOfStrings)
res = ""
for i = 1, table.maxn(arrayOfStrings) do
res = res .. '"' .. arrayOfStrings[i] .. '",'
end
return '[' .. res:sub(1, -2) .. ']'
end
function listener()
local playerTurns = ""
for i,a in pairs(Players) do
if a:IsEverAlive() and (not a:IsMinorCiv()) then
local allies = {}
local enemies = {}
for j,b in pairs(Players) do
if (a:IsAllies(b)) then
table.insert(allies, b:GetNickName())
end
if (Teams[a:GetTeam()]:IsAtWar(b:GetTeam())) then
table.insert(enemies, tostring(b:GetID()))
end
end
playerTurns = playerTurns .. "{" ..
'"id" : ' .. tostring(a:GetID()) .. "," ..
'"nickName" : ' .. '"' .. a:GetNickName() .. '"' .. "," ..
'"isHuman" : ' .. tostring(a:IsHuman()) .. "," ..
'"civilization" : ' .. '"' .. a:GetCivilizationShortDescription() .. '"' .. "," ..
'"isTurnComplete" : ' .. tostring(a:HasReceivedNetTurnComplete()) .. "," ..
'"isTurnActive" : ' .. tostring(a:IsTurnActive()) .. "," ..
'"isOnline" : ' .. tostring(Network.IsPlayerConnected(a:GetID())) .. "," ..
'"isAlive" : ' .. tostring(a:IsAlive()) .. "," ..
'"currentEra" : ' .. a:GetCurrentEra() .. "," ..
'"numWonders" : ' .. a:GetNumWorldWonders() .. "," ..
'"enemies" : ' .. arrayToString(enemies) .. "," ..
'"allies" : ' .. arrayToString(allies) ..
"},"
end
end
local gameState = ""
gameState = gameState .. "{" .. '"isUnitedNationActive" : ' .. tostring(Game.IsUnitedNationsActive()) .. "," ..
'"winner" : ' .. tostring(Game.GetWinner()) .. "," ..
'"victoryType" : ' .. tostring(Game.GetVictory()) ..
"}"
print("----JSON----{" .. '"gameTurn" : ' .. tostring(Game.GetGameTurn()) .."," .. '"players" : [' .. playerTurns:sub(1, -2) .. "]," .. '"game": ' .. gameState .. "}----JSON----")
end
print("----GameHook: GameHook listener initialized.")
Events.RemotePlayerTurnEnd.Add(listener)
Events.RemotePlayerTurnStart.Add(listener)
Events.ActivePlayerTurnStart.Add(listener)
Events.ActivePlayerTurnEnd.Add(listener)
Events.MultiplayerGamePlayerDisconnected.Add(listener)
Events.MultiplayerGamePlayerUpdated.Add(listener)
Events.MultiplayerHotJoinCompleted.Add(listener)
Events.WarStateChanged.Add(listener);
Events.SerialEventEraChanged.Add(listener);
Events.WonderStateChanged.Add(listener);