Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget:GetInfo()
- local version = "0.3 beta"
- return {
- name = "Commshare: Auto Inviter v" .. version,
- desc = "Automatically invites players to squad.",
- author = "_Shaman",
- date = "7-15-2018",
- license = "OH LET IT BURN CUZ I NEED MOAR MONEY",
- layer = -99999999,
- enabled = true,
- }
- end
- -- Config
- local friends = false -- do we invite our friends automatically?
- local clanmembers = false -- do we invite our clanmates automatically?
- local invitebyelo = false -- do we attempt to merge with strongest / weaker players? **May require redesign**
- local autoaccept = false -- do we automatically accept lower player's requests?
- local automergecfg = {ignore = {}, automerge = {}, autoaccept = {}, whitelist = {}} -- config table. Contains ignore and automerge.
- local ignoreall = false
- -- variables
- local clan, friendlist, myelo, mylevel, ignorelist -- These are used for determining merges.
- local mergelist = "" -- list of players to merge with.
- local mergecount = 0 -- count of the number of players we're merging with.
- local allylist = {} -- Processed Alliance members.
- local autoinvited = false -- have we automatically invited people?
- local enabledplayers = {} -- table of players who have this widget.
- -- Options
- options_path = 'Settings/Interface/Commshare'
- options_order = {
- 'invitefriends',
- 'inviteclanmembers',
- --'invitebyelo',
- --'autoaccept',
- 'ignoreall',
- }
- options = {
- invitefriends = {
- name = "Automatically Invite Friends",
- type = "bool",
- value = false,
- OnChange = function(self)
- friends = self.value
- end,
- noHotkey = true,
- desc = "Automatically invites your friends to a commshare merger."
- },
- inviteclanmembers = {
- name = "Automatically Invite Clan Members",
- type = "bool",
- value = false,
- OnChange = function(self)
- clanmembers = self.value
- end,
- noHotkey = true,
- desc = "Automatically invites your fellow clan members to a commshare merger."
- },
- invitebyelo = {
- name = "Invite Strongest Player",
- type = "bool",
- value = false,
- OnChange = function(self)
- invitebyelo = self.value
- end,
- noHotkey = true,
- desc = "Automatically requests a merge with the strongest player."
- },
- autoaccept = {
- name = "Autoaccept automated requests",
- type = "bool",
- value = false,
- OnChange = function(self)
- autoaccept = self.value
- end,
- noHotkey = true,
- desc = "Automatically accept automerge requests?"
- },
- ignoreall = {
- name = "Decline mode:",
- type = "radioButton",
- items = {
- {name = 'All',key='all',description="Ignore all invites."},
- {name = 'Non-clan members', key='nonclan',description="Ignore all nonclan members."},
- {name = 'Non-friend', key='nonfriend', description="Ignore all nonfriends."},
- {name = 'Non-clan/friends', key='nonfriendclan', description="Ignore everyone who isn't your friend or in your clan."},
- {name = 'None', key='none', description="Don't ignore any invites."}
- },
- value = 'none',
- OnChange = function(self)
- ignoreall = self.value
- end,
- noHotkey = true,
- desc = "Declines certain users based on this param."
- },
- }
- -- Loading tables used--
- function widget:GetConfigData()
- return automergecfg
- end
- function widget:SetConfigData(data)
- automergecfg = data
- end
- local function ProcessAllyTeam()
- local teamlist = Spring.GetTeamList(Spring.GetMyAllyTeamID())
- for i=1, #teamlist do
- local playerlist = Spring.GetPlayerList(teamlist[i])
- for j=1, #playerlist do
- local playerID, _, spec, teamID, _, _, _, _, _, playerKeys = Spring.GetPlayerInfo(playerlist[j])
- if not spec then
- allylist[playerID] = {
- team = playerlist[j],
- elo = playerKeys.elo,
- level = playerKeys.level,
- clan = playerKeys.clanfull,
- }
- end
- end
- end
- end
- local function ProccessCommand(str)
- local strtbl = {}
- for w in string.gmatch(str, "%S+") do
- if #strtbl < 5 then
- strtbl[#strtbl+1] = w
- else
- strtbl[5] = strtbl .. " " .. w
- end
- end
- return strtbl
- end
- local function GetHighestElo(tab)
- local highestteamid = -1
- local highestelo = 0
- for name,data in pairs(tab) do
- if data["elo"] > highestelo then
- highestelo = data["elo"]
- highestteamid = data["team"]
- end
- end
- return highestteamid
- end
- function widget:GamePreload()
- Spring.SendLuaUIMsg("automerger", "a")
- end
- function widget:RecvLuaMsg(msg, playerID)
- if msg == "automerger" then
- enabledplayers[select(1, Spring.GetPlayerInfo(playerID))] = playerID
- Spring.Echo("player " .. select(1, Spring.GetPlayerInfo(playerID)) .. " is using automerge!")
- end
- end
- function widget:Initialize()
- local _,_,spec,_ = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
- if spec then
- widgetHandler:RemoveWidget()
- end
- local customkeys = select(10, Spring.GetPlayerInfo(Spring.GetMyPlayerID()))
- clan = customkeys["clanfull"] -- the full name of your clan.
- friendlist = customkeys["friends"] -- your friends list.
- myelo = customkeys["elo"] -- your elo.
- ignorelist = customkeys["ignored"] -- your ignore list. We automatically ignore requests from these users.
- mylevel = customkeys["level"] -- your level.
- ProcessAllyTeam()
- Spring.Echo("Automerge: Determing merge list. Config:\nClan: " .. tostring(clanmembers) .. "\nfriends: " .. tostring(friends))
- for name, data in pairs(allylist) do
- if automergecfg.automerge[name] or (friends and friendlist[name]) or (clanmembers and data.clan == clan) then
- mergelist = mergelist .. " " .. name -- clever way of working around table creation.
- mergecount = mergecount + 1
- end
- end
- end
- function widget:TextCommand(msg)
- if msg:find("automerge") then
- local command = ProccessCommand(msg)
- if command[2] == "ignore" then
- if command[3] == "add" and command[4] and command[4] ~= "" then
- Spring.Echo("game_message: ignoring invites from " .. command[4] .. ".")
- if command[5] == nil or command[5] == "" then
- local randomnum = math.random(1,5)
- if randomnum == 1 then
- command[5] = "Reasons"
- elseif randomnum == 2 then
- command[5] = "emotions"
- elseif randomnum == 3 then
- command[5] = "Don't know"
- elseif randomnum == 4 then
- command[5] = "Wubwub"
- else
- command[5] = "Lobster"
- end
- end
- automergecfg.ignore[command[4]] = command[5]
- automergecfg.automerge[command[4]] = nil
- elseif command[3] == "remove" and command[4] and command[4] ~= "" then
- automergecfg.ignore[command[4]] = nil
- Spring.Echo("game_message: You are no longer ignoring " .. command[4] .. ".")
- elseif command[3] == "list" then
- local ignorelist = ""
- local count = 0
- for name,reason in pairs(automergecfg.ignore) do
- ignorelist = ignorelist .. name .. ": " .. reason .. "\n"
- count = count+1
- end
- if count > 1 then
- Spring.Echo("game_message: You are ignoring " .. count .. " users' requests:\n" .. ignorelist)
- elseif count == 1 then
- Spring.Echo("game_message: You are ignoring " .. count .. " user's request:\n" .. ignorelist)
- else
- Spring.Echo("game_message: You aren't ignoring any user's request.")
- end
- end
- elseif command[2] == "add" then
- if command[3] and command[3] ~= "" then
- if automergecfg.ignore[command[3]] or ignorelist:find(command[3]) then
- Spring.Echo("game_message: Remove " .. command[3] .. " from your ignore list first.")
- end
- automergecfg.automerge[command[3]] = true
- Spring.Echo("game_message:Added " .. command[3] .. " to automerge.")
- else
- Spring.Echo("game_message: Invalid param for add.")
- end
- elseif command[2] == "remove" then
- if command[3] and command[3] ~= "" then
- automergecfg.automerge[command[3]] = nil
- Spring.Echo("game_message:Removed " .. command[3] .. " from automerge.")
- else
- Spring.Echo("game_message: Invalid param for remove.")
- end
- elseif command[2] == "list" then
- local ignorelist = ""
- local count = 0
- for id,_ in pairs(automergecfg.automerge) do
- if count == 0 then
- ignorelist = ignorelist .. id
- else
- ignorelist = ignorelist .. ", "
- end
- count = count+1
- end
- if count > 1 then
- Spring.Echo("game_message: You are automerging with " .. count .. " users:\n" .. ignorelist)
- elseif count == 1 then
- Spring.Echo("game_message: You are automerging with " .. count .. " user:\n" .. ignorelist)
- else
- Spring.Echo("game_message: You aren't automerging with anyone.")
- end
- else
- Spring.Echo("game_message: Invalid automerge command.")
- end
- end
- end
- function widget:GameFrame(f)
- if autoinvited == false and f> 10 then
- autoinvited = true
- local invited = "I invited " -- list of players we've invited.
- for name,data in pairs(allylist) do
- if mergelist:find(name) then
- Spring.SendLuaRulesMsg("sharemode invite " .. data["team"])
- if enabledplayers[name] == nil then
- invited = invited .. name .. ","
- end
- end
- end
- if invited ~= "I invited " then
- invited = invited:sub(1, -2)
- Spring.SendCommands("say a:" .. invited .. " to join my squad.")
- end
- if invitebyelo then
- local highestplayer = GetHighestElo(playerlistprocessed)
- if highestplayer == Spring.GetMyTeamID() then
- for name,data in pairs(enabledplayers) do
- if automergecfg.ignore[name] == nil and not ignorelist:find(name) then
- Spring.SendLuaRulesMsg("sharemode invite " .. data["team"])
- end
- end
- end
- end
- end
- if f%15 == 0 then
- local invitecount = Spring.GetPlayerRulesParam(Spring.GetMyPlayerID(), "commshare_invitecount") or 0
- if invitecount > 0 then
- for i=1, invitecount do
- local id = Spring.GetPlayerRulesParam(Spring.GetMyPlayerID(), "commshare_invite_" .. i .. "_id")
- local name,_ = Spring.GetPlayerInfo(id)
- if enabledplayers[name] and autoaccept then
- Spring.SendLuaRulesMsg("sharemode accept " .. id)
- elseif automergecfg.ignore[name] or string.find(ignorelist,name) or ((ignoreall == "nonfriend" or ignoreall == "nonfriendclan") and not friendlist:find(name)) or ((ignoreall == "nonclan" or ignoreall == "nonfriendclan") and clan ~= allylist[name].clan) then
- Spring.SendLuaRulesMsg("sharemode decline " .. id)
- local reason = ""
- if string.find(ignorelist,name) then
- reason = "You are ignored by this user."
- end
- if reason == "" and automergecfg.ignore[name] then
- reason = automergecfg.ignore[name]
- end
- if reason == "" and ignoreall ~= "none" and ignoreall ~= "all" then
- reason = "Not interested in random invites."
- else
- reason = "Not interested in commshare."
- end
- Spring.SendCommands("w " .. name .. " is not interested in merging with you. Reason: " .. reason)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement