Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local versionNumber = "v0.1"
- function widget:GetInfo()
- return {
- name = "Excess Fail Save".. versionNumber,
- desc = "Distribute unused metal to the next best player",
- author = "author: MoriturusMortus",
- date = "Aug 04, 2013",
- license = "GNU GPL, v2 or later",
- layer = 0,
- enabled = false -- loaded by default?
- }
- end
- --------------------------------------------------------------------------------
- --Constant:
- local uPDATE = 0.8 --determine coophelper's temporal spacing (original=0.2 sec)
- local EchoLimit = 8 --limits echo outpput
- --------------------------------------------------------------------------------
- --Variable:
- local timeCounter = 0
- local myTeamID = -1
- local myAllyTeamID = -1
- local PlayerList = {}
- local allyList = {}
- local start = true
- local GCount = 0
- --------------------------------------------------------------------------------
- --Functions:
- local GetTeamResources = Spring.GetTeamResources
- local GetMyTeamID = Spring.GetMyTeamID
- local GetMyAllyTeamID = Spring.GetMyAllyTeamID
- local GetPlayerList = Spring.GetPlayerList
- local GetPlayerInfo = Spring.GetPlayerInfo
- local GetGameSeconds = Spring.GetGameSeconds
- local Echo = Spring.Echo
- --------------------------------------------------------------------------------
- --Methods:
- function widget:Initialize()
- local _, _, spec = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
- if spec then widgetHandler:RemoveWidget() return false end
- myTeamID = GetMyTeamID()
- myAllyTeamID = GetMyAllyTeamID()
- PlayerList = GetPlayerList()
- end
- function widget:Update(deltaTime)
- if (timeCounter < uPDATE) then
- timeCounter = timeCounter + deltaTime
- return
- end
- if start and GetGameSeconds() >= 1 then
- local count = 1
- local allyListElo = {}
- for i = 1, #PlayerList do
- local PlayerID=PlayerList[i]
- local Name,Active,Spectator,TeamID,AllyTeamID,_,_,_,_,CustomKeys = GetPlayerInfo(PlayerID)
- if CustomKeys and Active and not Spectator and TeamID ~= myTeamID and AllyTeamID == myAllyTeamID then
- allyList[count] = {
- ID = PlayerID,
- ELO = CustomKeys.elo,
- }
- Echo (count)
- count = count + 1
- Echo ("Player"..Name.." added!")
- end
- end
- table.sort(allyList, function(a,b)
- return a.ELO > b.ELO
- end
- )
- for i = 1, #allyList do
- local Name,Active,_,allyID,_,_,_,_,_,_ = GetPlayerInfo(allyList[i].ID)
- Echo ("Player"..Name.." "..i)
- end
- start = false
- end
- local mCur,mMax,_,mIncome,mExpense,_,_,_ = GetTeamResources(myTeamID, "metal")
- local mPlus=mIncome-mExpense
- local mSeer=mMax-mPlus
- if mCur >= mSeer then
- for i = 1, #allyList do
- local Name,Active,_,allyID,_,_,_,_,_,_ = GetPlayerInfo(allyList[i].ID)
- local mAllyCur,mAllyMax,_,mAllyIncome,mAllyExpense,_,_,_ = GetTeamResources(allyID, "metal")
- local mAllyPlus = mAllyIncome - mAllyExpense
- local mAllySeer = mAllyMax - (mAllyPlus + mIncome)
- if Active and mAllyCur<100 then
- Spring.ShareResources(allyID, "metal", mIncome)
- if (GCount >= EchoLimit) then
- GCount = GCount + 1
- else
- Echo ("Insufficient usage of your resources, your overhead will be distributed to:"..Name)
- GCount = 0
- end
- break
- end
- end
- end
- timeCounter = 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement