Statistics: Posted by Franck — 05 Jan 2016, 14:40
self.Sync.mytestvar = 1
Statistics: Posted by Domino — 04 Jan 2016, 10:09
Statistics: Posted by nine2 — 02 Jan 2016, 14:07
local oldResetSyncTable = ResetSyncTable
ResetSyncTable = function()
oldResetSyncTable()
Sync.FixedEcoData = {}
end
function GetEconDataRecord(id)
local row = Sync.FixedEcoData[id]
if row == nil then
row = { massConsumed=0, energyConsumed=0 }
Sync.FixedEcoData[id] = row
end
return row
end
local oldUnit = Unit
Unit = Class(oldUnit) {
SetConsumptionPerSecondMass = function(self, n)
oldUnit.SetConsumptionPerSecondMass(self, n)
local econData = GetEconDataRecord(self:GetEntityId())
econData.massConsumed = n
end,
SetConsumptionPerSecondEnergy = function(self, n)
oldUnit.SetConsumptionPerSecondEnergy(self, n)
local econData = GetEconDataRecord(self:GetEntityId())
econData.energyConsumed = n
end,
}
local oldOnSync = OnSync
FixedEcoData = {}
function OnSync()
if not table.empty(Sync.FixedEcoData) then
FixedEcoData = table.merged(FixedEcoData,Sync.FixedEcoData)
end
for id,v in Sync.ReleaseIds do
FixedEcoData[id] = nil
end
oldOnSync()
end
local data = FixedEcoData[unit:GetEntityId()]
LOG(data.massConsumed)
LOG(data.energyConsumed)
Statistics: Posted by nine2 — 02 Jan 2016, 14:05
Statistics: Posted by Franck — 01 Jan 2016, 17:45
Statistics: Posted by Franck — 31 Dec 2015, 11:33
ui_only = false
Statistics: Posted by Franck — 31 Dec 2015, 11:28
DoTakeDamage = function(self, instigator, amount, vector, damageType)
---
LOG('took damage')
Sync.mytestvar = 100
---
local preAdjHealth = self:GetHealth()
self:AdjustHealth(instigator, -amount)
local health = self:GetHealth()
if( health <= 0 ) then
local oldOnSync = OnSync
function OnSync()
oldOnSync()
LOG('on sync')
---
if Sync.mytestvar then
LOG('My test var spotted in on sync func')
end
---
end
Statistics: Posted by Myxir — 31 Dec 2015, 11:08
DoTakeDamage = function(self, instigator, amount, vector, damageType)
---
Sync.mytestvar = 100
---
local preAdjHealth = self:GetHealth()
self:AdjustHealth(instigator, -amount)
local health = self:GetHealth()
if( health <= 0 ) then
local oldOnSync = OnSync
function OnSync()
oldOnSync()
---
if Sync.mytestvar then
LOG('My test var spotted in on sync func')
end
---
end
Statistics: Posted by Franck — 31 Dec 2015, 10:50
Statistics: Posted by Franck — 28 Dec 2015, 21:50
Sync.damagehits = 1
hitsTaken = {
[unitId_1] = hitsTaken_1,
[unitId_2] = hitsTaken_2,
}
-- saving reference to the old class
local oldUnit = Unit
-- replacing the old class with our modified one, so we can make changes work
Unit = Class(oldUnit) {
-- saving your value, each instance of the class (unit) has its own hitsTaken counter
hitsTaken = 0,
-- store the reference to the old Unit.lua OnDamage function
local oldOnDamage = self.OnDamage
OnDamage = function(self, instigator, amount, vector, damageType)
-- calling the old OnDamage function, otherwise it would not receive any damage anymore
oldOnDamage(self, instigator, amount, vector, damageType)
self.hitsTaken = self.hitsTaken + 1
-- make sure the table exists, otherwise we run into an error
if not Sync.hitsTaken then
Sync.hitsTaken = {}
end
-- save the var in the sync table as in the above mentioned format
Sync.hitsTaken[self:GetUnitId()] = self.hitsTaken
end
end
-- use your mod file in your mod folder: /mods/<modname>/modules/<modfile>.lua
local myModFile = import('/mods/myMod/modules/myFile.lua')
local oldOnSync = OnSync
function OnSync()
oldOnSync()
if Sync.hitsTaken then
myModFile.onHitsTaken(Sync.hitsTaken)
end
end
local storedValues = {}
-- storing them as simple as it can get
function onHitsTaken(hitsTakenTable)
for id, value in hitsTakenTable do
storedValues[id] = value
end
end
-- and providing a way to get them later
function getHitsTakenByUnit(id)
-- will return a value if we have one, 0 otherwise
return storedValues[id] or 0
end
Statistics: Posted by Myxir — 27 Dec 2015, 22:44
Statistics: Posted by Franck — 27 Dec 2015, 21:06
Sync.myModData = 5
local oldOnSync = OnSync
function OnSync()
oldOnSync()
if Sync.myModData then
-- do your stuff here
end
end
Statistics: Posted by Sheeo — 27 Dec 2015, 01:12
Statistics: Posted by Sheeo — 27 Dec 2015, 01:11
Sync.myModData = 5
local oldOnSync = OnSync
function OnSync()
oldOnSync()
if Sync.myModData then
-- do your stuff here
end
end
Statistics: Posted by Myxir — 27 Dec 2015, 01:07