Server can now use commands :)

This commit is contained in:
Cooldude2606
2017-06-01 22:13:34 +01:00
parent 41611ec9e3
commit d020667090

View File

@@ -114,7 +114,7 @@ function giveRank(player,rank,byPlayer)
player.permission_group = game.permissions.get_group(rank.name) player.permission_group = game.permissions.get_group(rank.name)
drawToolbar(player) drawToolbar(player)
drawPlayerList() drawPlayerList()
global.oldRanks[player.index]=oldRank.name if oldRank.name ~= 'Jail' then global.oldRanks[player.index]=oldRank.name end
end end
function revertRank(player,byPlayer) function revertRank(player,byPlayer)
@@ -511,75 +511,136 @@ end
function commandInit() function commandInit()
commands.add_command('server_interface','Server use only, no players',function(event) commands.add_command('server_interface','Server use only, no players',function(event)
if event.parameter then else return end if event.parameter then else return end
local byPlayer = game.players[event.player_index] if event.player_index then
if byPlayer then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') game.players[event.player_index].print('401 - Unauthorized: Access is denied due to invalid credentials') return
else else
local returned,value = pcall(loadstring(event.parameter)) local returned,value = pcall(loadstring(event.parameter))
if type(value) == 'table' then game.write_file('log.txt', '\n $£$ '..table.tostring(value), true, 0) if type(value) == 'table' then game.write_file('log.txt', '\n $£$ '..table.tostring(value), true, 0)
else game.write_file('log.txt', '\n '..tostring(value), true, 0) end end else game.write_file('log.txt', '\n '..tostring(value), true, 0) end
end
end) end)
commands.add_command('autoMessage','Sends the auto message to all players',function(event) autoMessage() end) commands.add_command('autoMessage','Sends the auto message to all players',function(event) autoMessage() end)
--base layout for all commands
commands.add_command('onlineTime','<player_name> Get a players online time',function(event) commands.add_command('onlineTime','<player_name> Get a players online time',function(event)
if event.parameter then else game.players[event.player_index].print('Invaild Input, /onlineTime <player>') return end if event.player_index then --is it a player or the server
local byPlayer = game.players[event.player_index] local byPlayer = game.players[event.player_index] -- it's a player so gets them
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end if event.parameter then else byPlayer.print('Invaild Input, /onlineTime <player>') return end -- are there any arguments
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end -- is the user have vaild rank to use command
if #args == 1 then else byPlayer.print('Invaild Input, /onlineTime <player> ') return end local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end -- gets all the arguments passed
local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', input is case senitive') return end if #args == 1 then else byPlayer.print('Invaild Input, /onlineTime <player> ') return end -- is enouth arguments passed to aloow the command to work
byPlayer.print(ticktohour(player.online_time)..'H '..(ticktominutes(player.online_time)-60*ticktohour(player.online_time))..'M') local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end -- arguments vaildtion
end) byPlayer.print(ticktohour(player.online_time)..'H '..(ticktominutes(player.online_time)-60*ticktohour(player.online_time))..'M') -- finally the command is done
commands.add_command('reviveEntitys','<range> Reives all entitys in this range. Admins can use all as range',function(event) else -- when the server runs commands no output is given to any user, also server has no rank validation
if event.parameter then else game.players[event.player_index].print('Invaild Input, /onlineTime <player>') return end return -- example as this code can't work from there server as no output
local byPlayer = game.players[event.player_index] --if event.parameter then else return end -- are there any arguments
local pos = byPlayer.position if pos then else byPlayer.print('Invaild Location, what did you do') return end --local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end -- gets all the arguments passed
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end --if #args == 1 then else return end -- is enouth arguments passed to aloow the command to work
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end --local player = game.players[args[1]] if player then else return end -- arguments vaildtion
if #args == 1 then else byPlayer.print('Invaild Input, /onlineTime <player> ') return end --byPlayer.print(ticktohour(player.online_time)..'H '..(ticktominutes(player.online_time)-60*ticktohour(player.online_time))..'M') -- finally the command is done
local range = tonumber(args[1]) if range or args[1] == 'all' then else byPlayer.print('Invaild Range, must be number below 50') return end
if args[1] == 'all' then
if getRank(byPlayer).power > 1 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() return end
elseif range < 50 and range > 0 then else byPlayer.print('Invaild Range, must be number below 50') return end
for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive()
end end
end) end)
commands.add_command('tp','<player> <to_player>, teleports one player to another',function(event) --reviveEntities
if event.parameter then else game.players[event.player_index].print('Invaild Input, /tp <player> <to_player>') return end commands.add_command('reviveEntities','<range> Reives all entitys in this range. Admins can use all as range',function(event)
local byPlayer = game.players[event.player_index] if event.player_index then
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 2 then else byPlayer.print('Invaild Input, /tp <player> <to_player>') return end
local p1 = game.players[args[1]] if p1 then else byPlayer.print('Invaild Player Name,'..args[1]..', input is case senitive') return end
local p2 = game.players[args[2]] if p2 then else byPlayer.print('Invaild Player Name,'..args[2]..', input is case senitive') return end
if p1 == p2 then byPlayer.print('Invaild Players, must be two diffrent players') end
if p1.connected and p2.connected then else byPlayer.print('Invaild Player, player is not online') return end
if getRank(byPlayer).power > getRank(p1).power then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
p1.teleport(game.surfaces[p2.surface.name].find_non_colliding_position("player", p2.position, 32, 1))
end)
commands.add_command('kill','<player>, if no player stated then you kill your self',function(event)
if event.parameter then
local byPlayer = game.players[event.player_index] local byPlayer = game.players[event.player_index]
if event.parameter then else byPlayer.print('Invaild Input, /reviveEntities <range/all>') return end
local pos = byPlayer.position
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else byPlayer.print('Invaild Input, /kill <player> ') return end if #args == 1 then else byPlayer.print('Invaild Input, /reviveEntities <range/all>') return end
local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', input is case senitive') return end local range = tonumber(args[1]) if range or args[1] == 'all' then else byPlayer.print('Invaild Range, must be number below 50') return end
if player.connected then else byPlayer.print('Invaild Player, player is not online') return end if args[1] == 'all' then
if player.character then player.character.die() else byPlayer.print('Invaild Player, their are already dead') return end if getRank(byPlayer).power > 1 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end return
elseif range < 50 and range > 0 then else byPlayer.print('Invaild Range, must be number below 50') return end
for key, entity in pairs(game.surfaces[1].find_entities_filtered({area={{pos.x-range,pos.y-range},{pos.x+range,pos.y+range}},type = "entity-ghost"})) do entity.revive()
end
else else
local byPlayer = game.players[event.player_index] for key, entity in pairs(game.surfaces[1].find_entities_filtered({type = "entity-ghost"})) do entity.revive() end return
if byPlayer.character then byPlayer.character.die() else byPlayer.print('Invaild Player, you are already dead') return end
end end
end) end)
-- tp
commands.add_command('tp','<player> <to_player>, teleports one player to another',function(event)
if event.player_index then
local byPlayer = game.players[event.player_index]
if event.parameter then else byPlayer.print('Invaild Input, /tp <player> <to_player>') return end
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 2 then else byPlayer.print('Invaild Input, /tp <player> <to_player>') return end
local p1 = game.players[args[1]] if p1 then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end
local p2 = game.players[args[2]] if p2 then else byPlayer.print('Invaild Player Name,'..args[2]..', try using tab key to auto-coomplet the name') return end
if p1 == p2 then byPlayer.print('Invaild Players, must be two diffrent players') return end
if p1.connected and p2.connected then else byPlayer.print('Invaild Player, player is not online') return end
if getRank(byPlayer).power > getRank(p1).power then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
p1.teleport(game.surfaces[p2.surface.name].find_non_colliding_position("player", p2.position, 32, 1))
else
if event.parameter then else return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 2 then else return end
local p1 = game.players[args[1]] if p1 then else return end
local p2 = game.players[args[2]] if p2 then else return end
if p1 == p2 then return end
if p1.connected and p2.connected then else return end
p1.teleport(game.surfaces[p2.surface.name].find_non_colliding_position("player", p2.position, 32, 1))
end
end)
-- kill
commands.add_command('kill','<player>, if no player stated then you kill your self',function(event)
if event.player_index then
local byPlayer = game.players[event.player_index]
if event.parameter then
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else byPlayer.print('Invaild Input, /kill <player> ') return end
local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end
if getRank(byPlayer).power > getRank(player).power and getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
if player.connected then else byPlayer.print('Invaild Player, player is not online') return end
if player.character then player.character.die() else byPlayer.print('Invaild Player, their are already dead') return end
else
if byPlayer.character then byPlayer.character.die() else byPlayer.print('Invaild Player, you are already dead') return end
end
else
if event.parameter then else return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else return end
local player = game.players[args[1]] if player then else return end
if player.connected then else return end
if player.character then player.character.die() else return end
end
end)
-- jail/unjail
commands.add_command('jail','<player>, jail the player disallowing them to move',function(event) commands.add_command('jail','<player>, jail the player disallowing them to move',function(event)
if event.parameter then else game.players[event.player_index].print('Invaild Input, /jail <player>') return end if event.player_index then
local byPlayer = game.players[event.player_index] local byPlayer = game.players[event.player_index]
if getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end if #args == 1 then else byPlayer.print('Invaild Input, /jail <player> ') return end
if #args == 1 then else byPlayer.print('Invaild Input, /jail <player> ') return end local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end
local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', input is case senitive') return end if getRank(byPlayer).power > getRank(player).power and getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
if player.connected then else byPlayer.print('Invaild Player, player is not online') return end if player.connected then else byPlayer.print('Invaild Player, player is not online') return end
if player == byPlayer then byPlayer.print('Invaild Player, you can\' jail yourself') return end if player == byPlayer then byPlayer.print('Invaild Player, you can\'t jail yourself') return end
if player.permission_group.name ~= 'Jail' then giveRank(player,'Jail',byPlayer) else revertRank(player,byPlayer) end if player.permission_group.name ~= 'Jail' then giveRank(player,'Jail',byPlayer) end
else
if event.parameter then else return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else return end
local player = game.players[args[1]] if player then else return end
if player.permission_group.name ~= 'Jail' then giveRank(player,'Jail',byPlayer) end
end
end)
commands.add_command('unjail','<player>, jail the player disallowing them to move',function(event)
if event.player_index then
local byPlayer = game.players[event.player_index]
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else byPlayer.print('Invaild Input, /unjail <player> ') return end
local player = game.players[args[1]] if player then else byPlayer.print('Invaild Player Name,'..args[1]..', try using tab key to auto-coomplet the name') return end
if getRank(byPlayer).power > getRank(player).power and getRank(byPlayer).power > 4 then byPlayer.print('401 - Unauthorized: Access is denied due to invalid credentials') return end
if player.permission_group.name == 'Jail' then revertRank(player,byPlayer) end
else
if event.parameter then else return end
local args = {} for word in event.parameter:gmatch('%w+') do table.insert(args,word) end
if #args == 1 then else return end
local player = game.players[args[1]] if player then else end
if player.permission_group.name == 'Jail' then revertRank(player,byPlayer) end
end
end) end)
end end
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
@@ -631,7 +692,7 @@ addTab('Readme','Admins','List of all the people who can ban you :P',
for i, line in pairs(admins) do for i, line in pairs(admins) do
frame.add{name=i, type="label", caption={"", line}, single_line=false} frame.add{name=i, type="label", caption={"", line}, single_line=false}
end end
drawPlayerTable(player, frame, false,{'admin'}) drawPlayerTable(player, frame, false,{admin=true})
end) end)
addTab('Readme','Players','List of all the people who have been on the server', addTab('Readme','Players','List of all the people who have been on the server',
function(player,frame) function(player,frame)
@@ -698,7 +759,7 @@ addTab('Admin','Edit Ranks', 'Edit the ranks of players below you',
frame.rank.rank_input.selected_index = 1 frame.rank.rank_input.selected_index = 1
drawButton(frame.rank,'setRanks','Set Ranks','Sets the rank of all selected players') drawButton(frame.rank,'setRanks','Set Ranks','Sets the rank of all selected players')
drawButton(frame.rank,'clearSelection','Clear Selection','Clears all currently selected players') drawButton(frame.rank,'clearSelection','Clear Selection','Clears all currently selected players')
drawPlayerTable(player, frame, true, {'lower'}) drawPlayerTable(player, frame, true, {powerOver=true})
end) end)
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
---------------------------Admin+ Gui--------------------------------------------------- ---------------------------Admin+ Gui---------------------------------------------------