Merge branch 'WIP' into Testing

This commit is contained in:
Cooldude2606
2017-04-07 16:15:45 +01:00
2 changed files with 154 additions and 116 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,30 @@ guis = {frames={},buttons={}}
--functions can not be included in the default list or be added by code
defaults = {
itemRotated = {},
test = 0
ranks={
{name='Owner',shortHand='Owner',tag='[Owner]',power=0,colour={r=170,g=0,b=0}},
{name='Community Manager',shortHand='CM',tag='[Com Mngr]',power=1,colour={r=150,g=68,b=161}},
{name='Developer',shortHand='Dev',tag='[Dev]',power=1,colour={r=179,g=125,b=46}},
{name='Admin',shortHand='Admin',tag='[Admin]',power=2,colour={r=170,g=41,b=170}},
{name='Mod',shortHand='Mod',tag='[Mod]',power=3,colour={r=233,g=63,b=233}},
{name='Donner',shortHand='P2W',tag='[P2W]',power=4,colour={r=233,g=63,b=233}},
{name='Member',shortHand='Mem',tag='[Member]',power=5,colour={r=24,g=172,b=188}},
{name='Regular',shortHand='Reg',tag='[Regukar]',power=5,colour={r=24,g=172,b=188}},
{name='Guest',shortHand='',tag='[Guest]',power=6,colour={r=255,g=159,b=27}},
{name='Jail',shortHand='Owner',tag='[Owner]',power=7,colour={r=170,g=0,b=0}}
},
autoRanks={
Owner={'badgamernl'},
['Community Manager']={'arty714'},
Developer={'Cooldude2606'},
Admin={'eissturm','PropangasEddy'},
Mod={'Alanore','Aquaday','cafeslacker','CrashKonijn','Drahc_pro','Flip','freek18','Hobbitkicker','hud','Matthias','MeDDish','Mindxt20','MottledPetrel','Mr_Happy_212','Phoenix27833','Sand3r205','ScarbVis','Smou','steentje77','TopHatGaming123'},
Donner={},
Member={},
Regular={},
Guest={},
Jail={}
}
}
warningAllowed = nil
@@ -13,7 +36,6 @@ timeForRegular = 180
CHUNK_SIZE = 32
function loadVar(t)
game.print('load')
if t == nil then
local g = nil
if game.players[1].gui.left.hidden then
@@ -23,16 +45,16 @@ function loadVar(t)
game.players[1].gui.left.hidden.style.visible = false
end
gTable = loadstring('return '..g)()
game.print(g)
else gTable = t end
itemRotated = gTable.itemRotated
test = gTable.test
ranks= gTable.ranks
autoRanks= gTable.autoRanks
end
function saveVar()
gTable.itemRotated = itemRotated
gTable.test = test
game.print('save '..table.tostring(gTable))
gTable.ranks = ranks
gTable.autoRanks = autoRanks
game.players[1].gui.left.hidden.caption = table.tostring(gTable)
end
----------------------------------------------------------------------------------------
@@ -57,15 +79,63 @@ local function clearDecorations()
for chunk in surface.get_chunks() do
removeDecorations(surface, chunk.x * CHUNK_SIZE, chunk.y * CHUNK_SIZE, CHUNK_SIZE - 1, CHUNK_SIZE - 1)
end
callAdmin("Decoratives have been removed")
callRank("Decoratives have been removed")
end
script.on_event(defines.events.on_chunk_generated, function(event)
removeDecorationsArea( event.surface, event.area )
end)
----------------------------------------------------------------------------------------
---------------------------Common use functions---------------------------------------
---------------------------Rank functions-----------------------------------------------
----------------------------------------------------------------------------------------
function getRank(player)
if player then
for _,rank in pairs(ranks) do
if player.tag == rank.tag then return rank end
end
return stringToRank('Guest')
end
end
function stringToRank(string)
if type(string) == 'string' then
for _,rank in pairs(ranks) do
if rank.name == string then return rank end
end
end
end
function callRank(msg, rank)
if rank == nil then rank = stringToRank('Mod') else rank = stringToRank(rank) end -- default mod or higher
for _, player in pairs(game.players) do
rankPower = getRank(player).power
if rankPower <= rank.power then player.print('['..rank.shortHand..']: '..msg) end
end
end
function autoRank(player)
local currentRank = getRank(player)
local playerAutoRank = nil
for rank,players in pairs(autoRanks) do
local Break = false
for _,p in pairs(players) do
if player.name == p then playerAutoRank = stringToRank(rank) Break = true break end
end
if Break then break end
end
if playerAutoRank then
if currentRank.power > playerAutoRank.power then
player.tag=playerAutoRank.tag
end
elseif ticktominutes(player.online_time) >= timeForRegular then
player.tag=stringToRank('Regular').tag
end
if getRank(player).power <= 3 and not player.admin then
callRank(player.name..' needs to be promoted.')
end
end
----------------------------------------------------------------------------------------
---------------------------Common use functions-----------------------------------------
----------------------------------------------------------------------------------------
function ticktohour (tick)
local hour = tostring(math.floor(tick/(216000*game.speed)))
@@ -77,7 +147,7 @@ function ticktominutes (tick)
return minutes
end
function callAdmin(msg)
function callRank(msg)
for _, player in pairs(game.connected_players) do
if player.admin then
player.print(msg)
@@ -111,7 +181,7 @@ function table.val_to_str ( v )
end
function table.key_to_str ( k )
if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
if "string" == type( k ) and string.match( k, "^[_%player][_%player%d]*$" ) then
return k
else
return "[" .. table.val_to_str( k ) .. "]"
@@ -135,9 +205,10 @@ end
----------------------------------------------------------------------------------------
---------------------------Gui Functions------------------------------------------------
----------------------------------------------------------------------------------------
function addFrame(frame)
guis.frames[frame] = {}
function addFrame(frame,rank,open,caption,tooltip)
guis.frames[frame] = {{require=rank,caption=caption,tooltip=tooltip}}
addButton('close', function(player,element) element.parent.parent.parent.destroy() end)
addButton('btn_'..frame, function(player,element) if player.gui.center[frame] then player.gui.center[frame].destroy() else drawFrame(player,frame,open) end end)
end
function addTab(frame, tabName, describtion, drawTab)
@@ -156,35 +227,39 @@ end
function openTab(player, frameName, tab, tabName)
local tabBar = player.gui.center[frameName].tabBarScroll.tabBar
for _,t in pairs(guis.frames[frameName]) do
if t[1] == tabName then
tabBar[t[1]].style.font_color = {r = 255, g = 255, b = 255, a = 255}
clearElement(tab)
t[3](player, tab)
else
tabBar[t[1]].style.font_color = {r = 100, g = 100, b = 100, a = 255}
if _ ~= 1 then
if t[1] == tabName then
tabBar[t[1]].style.font_color = {r = 255, g = 255, b = 255, player = 255}
clearElement(tab)
t[3](player, tab)
else
tabBar[t[1]].style.font_color = {r = 100, g = 100, b = 100, player = 255}
end
end
end
end
function drawFrame(player, frameName, tabName)
if player.gui.center[frameName] then player.gui.center[frameName].destroy() end
local frame = player.gui.center.add{name=frameName,type='frame',caption=frameName,direction='vertical'}
local tabBarScroll = frame.add{type = "scroll-pane", name= "tabBarScroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"}
local tabBar = tabBarScroll.add{type='flow',direction='horizontal',name='tabBar'}
local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"}
for _,t in pairs(guis.frames[frameName]) do
drawButton(tabBar, t[1], t[1], t[2])
if getRank(player).power <= guis.frames[frameName][1].require then
if player.gui.center[frameName] then player.gui.center[frameName].destroy() end
local frame = player.gui.center.add{name=frameName,type='frame',caption=frameName,direction='vertical'}
local tabBarScroll = frame.add{type = "scroll-pane", name= "tabBarScroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"}
local tabBar = tabBarScroll.add{type='flow',direction='horizontal',name='tabBar'}
local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"}
for _,t in pairs(guis.frames[frameName]) do
if _ ~= 1 then drawButton(tabBar, t[1], t[1], t[2]) end
end
openTab(player, frameName, tab, tabName)
drawButton(tabBar, 'close', 'Close', 'Close this window')
tab.style.minimal_height = 300
tab.style.maximal_height = 300
tab.style.minimal_width = 500
tab.style.maximal_width = 500
tabBarScroll.style.minimal_height = 60
tabBarScroll.style.maximal_height = 60
tabBarScroll.style.minimal_width = 500
tabBarScroll.style.maximal_width = 500
end
openTab(player, frameName, tab, tabName)
drawButton(tabBar, 'close', 'Close', 'Close this window')
tab.style.minimal_height = 300
tab.style.maximal_height = 300
tab.style.minimal_width = 500
tab.style.maximal_width = 500
tabBarScroll.style.minimal_height = 60
tabBarScroll.style.maximal_height = 60
tabBarScroll.style.minimal_width = 500
tabBarScroll.style.maximal_width = 500
end
function toggleVisable(frame)
@@ -226,10 +301,8 @@ end)
script.on_event(defines.events.on_player_joined_game, function(event)
loadVar()
test = test + 1
saveVar()
game.print(test)
local player = game.players[event.player_index]
autoRank(player)
player.print({"", "Welcome"})
if player.gui.left.PlayerList ~= nil then
player.gui.left.PlayerList.destroy()
@@ -241,7 +314,7 @@ script.on_event(defines.events.on_player_joined_game, function(event)
player.gui.top.PlayerList.destroy()
end
drawPlayerList()
drawToolbar()
drawToolbar(player)
local playerStringTable = encode(game.players, "players", {"name", "admin", "online_time", "connected", "index"})
game.write_file("players.json", playerStringTable, false, 0)
if not player.admin and ticktominutes(player.online_time) < 1 then
@@ -264,9 +337,6 @@ script.on_event(defines.events.on_gui_click, function(event)
break
end
end
test = test + 1
saveVar()
game.print(test)
end)
script.on_event(defines.events.on_gui_text_changed, function(event)
@@ -299,8 +369,8 @@ script.on_event(defines.events.on_marked_for_deconstruction, function(event)
if not eplayer.admin and ticktominutes(eplayer.online_time) < timeForRegular then
if event.entity.type ~= "tree" and event.entity.type ~= "simple-entity" then
event.entity.cancel_deconstruction("player")
eplayer.print("You are not allowed to do this yet, play for a bit longer. Try again in about: " .. math.floor((timeForRegular - ticktominutes(eplayer.online_time))) .. " minutes")
callAdmin(eplayer.name .. " tryed to deconstruced something")
eplayer.print("You are not allowed to do this yet, play for player bit longer. Try again in about: " .. math.floor((timeForRegular - ticktominutes(eplayer.online_time))) .. " minutes")
callRank(eplayer.name .. " tryed to deconstruced something")
end
elseif event.entity.type == "tree" or event.entity.type == "simple-entity" then
event.entity.destroy()
@@ -313,8 +383,8 @@ script.on_event(defines.events.on_built_entity, function(event)
if not eplayer.admin and ticktominutes(eplayer.online_time) < timeForRegular then
if event.created_entity.type == "tile-ghost" then
event.created_entity.destroy()
eplayer.print("You are not allowed to do this yet, play for a bit longer. Try: " .. math.floor((timeForRegular - ticktominutes(eplayer.online_time))) .. " minutes")
callAdmin(eplayer.name .. " tryed to place concrete/stone with robots")
eplayer.print("You are not allowed to do this yet, play for player bit longer. Try: " .. math.floor((timeForRegular - ticktominutes(eplayer.online_time))) .. " minutes")
callRank(eplayer.name .. " tryed to place concrete/stone with robots")
end
end
end)
@@ -398,83 +468,51 @@ end
----------------------------------------------------------------------------------------
addButton("btn_toolbar_playerList", function(player) toggleVisable(player.gui.left.PlayerList) end)
addButton("btn_toolbar_rocket_score",function(player) toggleVisable(player.gui.left.rocket_score) end)
addButton("btn_readme",function(player) if player.gui.center.Readme then player.gui.center.Readme.destroy() else drawFrame(player,'Readme','Rules') end end)
addButton("btn_admin",function(player) if player.gui.center.Admin then player.gui.center.Admin.destroy() else drawFrame(player,'Admin','Modifiers') end end)
function drawToolbar()
for i, a in pairs(game.connected_players) do
local frame = a.gui.top
clearElement(frame)
drawButton(frame,"btn_toolbar_playerList", "Playerlist", "Adds a player list to your game.")
drawButton(frame,"btn_toolbar_rocket_score", "Rocket score", "Show the satellite launched counter if a satellite has launched.")
drawButton(frame,"btn_readme", "Readme", "Rules, Server info, How to chat, Playerlist, Adminlist.")
if a.tag == '[Owner]' or a.tag == '[Developer]' or a.tag == '[Com Mngr]' or a.tag == '[Admin]' then
drawButton(frame,"btn_admin", "Admin", "All admin fuctions are here")
end
function drawToolbar(player)
local frame = player.gui.top
clearElement(frame)
drawButton(frame,"btn_toolbar_playerList", "Playerlist", "Adds player player list to your game.")
drawButton(frame,"btn_toolbar_rocket_score", "Rocket score", "Show the satellite launched counter if player satellite has launched.")
for _,f in pairs(guis.frames) do
if getRank(player).power <= f[1].require then drawButton(frame,"btn_".._, f[1].caption, f[1].tooltip) end
end
end
----------------------------------------------------------------------------------------
---------------------------Player List--------------------------------------------------
----------------------------------------------------------------------------------------
function drawPlayerList()
for i, a in pairs(game.connected_players) do
if a.gui.left.PlayerList == nil then
a.gui.left.add{type = "frame", name= "PlayerList", direction = "vertical"}
for i, player in pairs(game.connected_players) do
if player.gui.left.PlayerList == nil then
player.gui.left.add{type = "frame", name= "PlayerList", direction = "vertical"}
.add{type = "scroll-pane", name= "PlayerListScroll", direction = "vertical", vertical_scroll_policy="always", horizontal_scroll_policy="never"}
end
clearElement(a.gui.left.PlayerList.PlayerListScroll)
a.gui.left.PlayerList.PlayerListScroll.style.maximal_height = 200
Plist= player.gui.left.PlayerList.PlayerListScroll
clearElement(Plist)
Plist.style.maximal_height = 200
for i, player in pairs(game.connected_players) do
if player.character then
if player.tag == '[Jail]' or player.character.active == false then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - Jail"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=50,g=50,b=50}
player.character.active = false
player.tag = '[Jail]'
end
end
if player.admin == true and player.tag ~= '[Jail]' then
if player.name == "badgamernl" or player.name == "BADgamerNL" then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - OWNER"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=170,g=0,b=0}
player.tag = "[Owner]"
elseif player.name == "eissturm" or player.name == "PropangasEddy" then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - ADMIN"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=170,g=41,b=170}
player.tag = "[Admin]"
elseif player.name == "Cooldude2606" then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - DEV"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=179,g=125,b=46}
player.tag = "[Developer]"
elseif player.name == "arty714" then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - CM"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=150,g=68,b=161}
player.tag = "[Com Mngr]"
else
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , " - MOD"}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=233,g=63,b=233}
player.tag = "[Moderator]"
end
end
end
for i, player in pairs(game.connected_players) do
if player.admin == false and player.tag ~= '[Jail]' then
if ticktominutes(player.online_time) >= timeForRegular then
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=24,g=172,b=188}
player.tag = "[Regular]"
elseif player.name == "explosivegaming" then
for i=10,1,-1 do
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name .. i, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , i}}
a.gui.left.PlayerList.PlayerListScroll[player.name .. i].style.font_color = {r=24,g=172,b=188}
player.tag = "[TEST]"
end
else
a.gui.left.PlayerList.PlayerListScroll.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}}
a.gui.left.PlayerList.PlayerListScroll[player.name].style.font_color = {r=255,g=159,b=27}
player.tag = "[Guest]"
end
playerRank = getRank(player)
if playerRank.power <= 3 then
if playerRank.shortHand ~= '' then Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , ' - '..playerRank.shortHand}}
else Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}} end
Plist[player.name].style.font_color = playerRank.colour
player.tag = playerRank.tag
end
end
for i, player in pairs(game.connected_players) do
playerRank = getRank(player)
if playerRank.power > 3 then
if playerRank.shortHand ~= '' then Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name , ' - '..playerRank.shortHand}}
else Plist.add{type = "label", name=player.name, style="caption_label_style", caption={"", ticktohour(player.online_time), " H - " , player.name}} end
Plist[player.name].style.font_color = playerRank.colour
player.tag = playerRank.tag
end
end
end
end
@@ -545,9 +583,9 @@ function drawPlayerTable(player, frame, commands, filters)
if commands then
frame.playerTable.add{name=p.name, type="flow"}
drawButton(frame.playerTable[p.name],'goto','Tp','Goto to the players location')
drawButton(frame.playerTable[p.name],'bring','Br','Bring a player to your location')
drawButton(frame.playerTable[p.name],'bring','Br','Bring player player to your location')
if p.tag == '[Owner]' or p.tag == '[Developer]' or p.tag == '[Com Mngr]' then else
drawButton(frame.playerTable[p.name],'jail','Ja','Jail/Unjail a player')
drawButton(frame.playerTable[p.name],'jail','Ja','Jail/Unjail player player')
drawButton(frame.playerTable[p.name],'kill','Ki','Kill this player')
end
end
@@ -558,7 +596,7 @@ end
----------------------------------------------------------------------------------------
---------------------------Read Me Gui--------------------------------------------------
----------------------------------------------------------------------------------------
addFrame('Readme')
addFrame('Readme',6, 'Rules','Readme', 'Rules, Server info, How to chat, Playerlist, Adminlist.')
addTab('Readme','Rules','The rules of the server',
function(player,frame)
@@ -569,7 +607,7 @@ addTab('Readme','Rules','The rules of the server',
"Do not laydown concrete with bots without permission.",
"Do not use active provider chests without permission.",
"Do not remove/move major parts of the factory without permission.",
"Do not walk in a random direction for no reason(to save map size).",
"Do not walk in player random direction for no reason(to save map size).",
"Do not remove stuff just because you don't like it, tell people first.",
"Do not make train roundabouts.",
"Trains are Left Hand Drive (LHD) only.",
@@ -632,7 +670,7 @@ addTab('Readme','Players','List of all the people who have been on the server',
----------------------------------------------------------------------------------------
---------------------------Modifier Gui-------------------------------------------------
----------------------------------------------------------------------------------------
addFrame('Admin')
addFrame('Admin',2,'Modifiers','Admin',"All admin fuctions are here")
addButton('btn_toolbar_automessage',function() autoMessage() end)
addButton('revive_dead_entitys',function(player,frame) for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end end)
@@ -665,7 +703,7 @@ addButton("btn_Modifier_apply",
elseif number == player.force[modifier] then
player.print(modifier .. " Did not change")
else
player.print(modifier .. " needs to be a higher number or it contains an letter")
player.print(modifier .. " needs to be player higher number or it contains an letter")
end
end
end
@@ -676,7 +714,7 @@ addTab('Admin', 'Commands', 'Random useful commands',
drawButton(frame,'btn_toolbar_automessage','Auto Message','Send the auto message to all online players')
drawButton(frame,'add_dev_items','Get Blueprints','Get all the blueprints')
drawButton(frame,'revive_dead_entitys','Revive All Entitys','Brings all dead machines back to life')
drawButton(frame,'revive_dead_entitys_range','Revive Entitys','Brings all dead machines back to life in a range')
drawButton(frame,'revive_dead_entitys_range','Revive Entitys','Brings all dead machines back to life in player range')
frame.add{type='textfield',name='range',text='Range'}
drawButton(frame,'remove_biters','Kill Biters','Removes all biters in map')
drawButton(frame,'tp_all','TP All Here','Brings all players to you')
@@ -709,7 +747,7 @@ addTab('Admin', 'Modifiers', 'Edit in game modifiers',
end
drawButton(frame.flowNavigation,"btn_Modifier_apply","Apply","Apply the new values to the game")
end)
addTab('Admin', 'Player List', 'Send a message to all players',
addTab('Admin', 'Player List', 'Send player message to all players',
function(player, frame)
frame.add{name='filterTable',type='table',colspan=2}
frame.filterTable.add{name='name_label',type='label',caption='Name'}