123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- minetest.register_chatcommand('survivors', {
- description = 'See what players are still on the level',
- func = function(name)
- local map_id = lobby.game[name]
- if map_id ~= 'lobby' then
- minetest.show_formspec(name, 'lobby:survivors', lobby.survivors_formspec(map_id))
- end
- end
- })
- minetest.register_chatcommand('spawn', {
- description = 'Teleport to spawn. (Builders only)',
- privs = {creative=true},
- func = function (name)
- local player = minetest.get_player_by_name(name)
- player:set_pos(lobby.spawn_pos)
- lobby.game[name] = 'lobby'
- end
- })
- minetest.register_chatcommand('msg', {
- description = 'prevents people from sending private messages.',
- func = function(name)
- minetest.chat_send_player(name, 'Private messages are disabled here.')
- end
- })
- minetest.register_chatcommand('placeblock', {
- description = 'Places a block where player stands.',
- privs = {creative=true},
- func = function(name)
- local user = minetest.get_player_by_name(name)
- local pos = user:get_pos()
- if minetest.is_protected(pos, name) then
- minetest.chat_send_player(name, 'Try again. You can\'t run this in a protected area.')
- else
- minetest.set_node(pos, {name='color:white'})
- minetest.chat_send_player(name, 'Placed starter block for you. Have fun building.')
- end
- end
- })
- minetest.register_chatcommand('lobby', {
- description = 'Travel back to the lobby when a ghost or playing solo.',
- func = function(name)
- local player = minetest.get_player_by_name(name)
- local player_attributes = player:get_meta()
- local mode = player_attributes:get_string('mode')
- if mode == 'ghost' or mode == 'solo' then
- player:set_nametag_attributes({
- color = {a = 255, r = 255, g = 255, b = 255}
- })
- player:set_properties({visual_size = {x = 10, y = 10}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
- player:set_pos(lobby.spawn_pos)
- lobby.game[name] = 'lobby'
- minetest.chat_send_player(name, 'Here you are.')
- -- if player is a builder, restore builder mode
- if lobby.is_builder(player) then
- lobby.player_to_builder(player)
- else
- -- restore normal player mode
- player_attributes:set_string('mode', 'solo')
- local player_inv = player:get_inventory()
- player_inv:set_list('main', {})
- end
- else
- minetest.chat_send_player(name, 'You can only run this command when you are a ghost or playing solo.')
- end
- end
- })
- minetest.register_chatcommand('kick', {
- description = 'Kick somebody, hopefully the traitor, from the level.',
- func = function(name, params)
- local map_id = lobby.game[name]
- local player = minetest.get_player_by_name(name)
- local player_attributes = player:get_meta()
- local mode = player_attributes:get_string('mode')
- if map_id ~= 'lobby' and mode == 'player' then
- if name == params then
- local traitor = lobby.traitors[map_id]
- local player = minetest.get_player_by_name(name)
- player:set_pos(lobby.spawn_pos)
- player:set_physics_override({speed=1})
- local player_inv = player:get_inventory()
- player_inv:set_list('main', {})
- lobby.game[name] = 'lobby'
- lobby.update_maps(map_id)
- if name == traitor then
- lobby.team_win(map_id)
- end
- end
- local survivors = lobby.players_on_level(map_id)
- local actual_votes = lobby.votes[map_id] or 0
- if not lobby.voted[name] then
- lobby.vote_timer[map_id] = 1800
- minetest.log('action', name..' just voted and reset the timer to 1800.')
- minetest.register_globalstep(function(dtime)
- if lobby.vote_timer[map_id] == 1 then
- lobby.message_to_level(map_id, 'Voting time is over.')
- minetest.log('action', 'Voting has ended')
- lobby.vote(map_id, true)
- elseif lobby.vote_timer[map_id] == 300 then
- lobby.message_to_level(map_id, 'Thirty seconds left to vote.')
- minetest.log('action', '30 seconds left to vote.')
- elseif lobby.vote_timer[map_id] == 600 then
- lobby.message_to_level(map_id, 'One minute left to vote.')
- minetest.log('action', '60 seconds left to vote.')
- elseif lobby.vote_timer[map_id] == 1200 then
- lobby.message_to_level(map_id, 'Two minutes left to vote')
- minetest.log('action', '120 seconds left to vote.')
- end
- if lobby.vote_timer[map_id] >= 0 then
- lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
- end
- end)
- if params ~= '' then
- if string.find(survivors, params) then --player inputs a player name
- minetest.chat_send_player(name, 'Thanks for your vote.')
- lobby.voted[name] = true
- lobby.votes[map_id] = actual_votes + 1
- lobby.suspect[params] = lobby.suspect[params] + 1
- lobby.vote(map_id)
- else --player votes for an invalid username
- minetest.chat_send_player(name, 'Check your spelling and try again.')
- end
- end
- else
- minetest.chat_send_player(name, 'You can\'t vote right now.')
- end
- end
- end
- })
- minetest.register_chatcommand('skip', {
- description = 'Skip voting in a kick vote.',
- func = function(name)
- local map_id = lobby.game[name]
- if map_id ~= 'lobby' then
- local actual_votes = lobby.votes[map_id] or 0
- if not lobby.voted[name] then
- minetest.log('action', name..' just skipped voting and reset the timer to 1800.')
- lobby.vote_timer[map_id] = 1800
- minetest.chat_send_player(name, 'You skipped voting this round.')
- lobby.voted[name] = true
- lobby.votes[map_id] = actual_votes + 1
- lobby.vote(map_id)
- else
- minetest.chat_send_player(name, 'You can\'t vote right now.')
- end
- end
- end
- })
- minetest.register_chatcommand('givexp', {--
- description = 'Gives a player XP',
- params = '[player, xp]',
- func = function(name, params)
- local recipient, xp_input = params:match('^(%S+)%s(.+)$')
- local xp = tonumber(xp_input)
- if recipient and xp then
- if minetest.player_exists(recipient) then
- local player = minetest.get_player_by_name(name)
- if minetest.check_player_privs(player, {server = true}) then
- if not minetest.get_player_by_name(recipient) then
- minetest.chat_send_player(name, recipient..' is not online right now. They will be given XP when they join next.')
- lobby.queue_xp(recipient, xp)
- else
- local player = minetest.get_player_by_name(recipient)
- lobby.give_xp(player, xp)
- minetest.chat_send_player(recipient, 'You just were awarded '..xp..' XP.')
- minetest.chat_send_player(name, 'You just sent '..recipient..' '..xp..' XP.')
- end
- else
- if lobby.take_xp(player, xp) then
- if not minetest.get_player_by_name(recipient) then
- minetest.chat_send_player(name, recipient..' is not online right now. They will be given XP when they join next.')
- lobby.queue_xp(recipient, xp)
- else
- local player = minetest.get_player_by_name(recipient)
- lobby.give_xp(player, xp)
- minetest.chat_send_player(recipient, 'You just were awarded '..xp..' XP.')
- minetest.chat_send_player(name, 'You just sent '..recipient..' '..xp..' XP.')
- end
- else
- minetest.chat_send_player(name, 'You can\'t give more XP than you have.')
- end
- end
- end
- end
- end
- })
- minetest.register_chatcommand('checkxp', {
- description = 'Check the current XP on a level.',
- func = function(name)
- local map_id = lobby.game[name]
- if map_id ~= 'lobby' then
- local xp = lobby.xp[map_id]
- local game_data = lobby.savedata.data[map_id]
- local required_xp = game_data['xp']
- if xp then
- minetest.chat_send_player(name, 'You currently have '..xp..' xp on this level. A total of '..required_xp..' is needed to defeat the traitor.')
- else
- minetest.chat_send_player(name, 'Welp, no XP here?')
- end
- else
- minetest.chat_send_player(name, 'Can\'t do that here.')
- end
- end
- })
- minetest.register_chatcommand('level_help', {
- description = 'Show level building help screen.',
- func = function(name)
- minetest.show_formspec(name, 'lobby:get_started', lobby.getting_started)
- end
- })
- minetest.override_chatcommand('fixlight', {
- privs = {creative = true}
- })
|