Page 1 of 2

Extra commands(alpha 0.1)

PostPosted: Wed Mar 07, 2012 23:47
by jordan4ibanez
Here's spawn & /afk command:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
spawn = {x = 47, y = 7.5, z = -40.5}

minetest.register_on_chat_message(function(name, message, playername, player)
    local cmd = "/spawn"
    if message:sub(0, #cmd) == cmd then
        if message == '/spawn' then
        local player = minetest.env:get_player_by_name(name)
        minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
        player:setpos(spawn)
        return true --deds to sfan5
        end
    end

    local cmd ="/afk"
    if message:sub(0, #cmd) == cmd then
            if message == '/afk' then
            local player = minetest.env:get_player_by_name(name)
            minetest.chat_send_all(name.." is AFK! ")
            return true --deds to sfan5
        end
    end
end)

--Deds to Kahrl
minetest.register_on_newplayer(function(player)
    player:setpos(spawn)
    return true
end)

--Deds to Kahrl
minetest.register_on_respawnplayer(function(player, pos)
    player:setpos(spawn)
    return true
end)


Replace x=0 y=0 z=0 with your spawn quards

Features:
-/spawn command (returns you to spawn)
-puts new players in the spawn
-puts players into spawn on death
-/afk command (prints playername is AFK!)

To do:
-Merge Randomproof's awesome code
-Make Admins ..that can set spawn(randomproof)
-Make /afk print "PLAYER is no longer AFK!" if player moves or if /afk is sent again
-Add a death notice using (minetest.register_on_dieplayer) ..so use (player, "has died!")
-When death notice is made then have the possibility of death information..if a player is in lava ..then print (player, "burned to death") or (player, "hit the ground too hard!")
-/jail command
-/setjail command
-/unjail command
Jail command would work better than in minecraft's bukkit server..basically /setjail would work like /setspawn would
/jail "player" would send a person into an unbreakable (hopefully) area which if they move ..they are sent back to the exact place where /setjail was sent this would also remove all their items ..and /unjail "player" would release the player back into the spawn

PostPosted: Wed Mar 07, 2012 23:51
by Death Dealer
Nice

PostPosted: Wed Mar 07, 2012 23:55
by jordan4ibanez
Death Dealer wrote:Nice

thank you!

PostPosted: Thu Mar 08, 2012 05:30
by Gatharoth
Okay, so I remember you said something that even kahrl couldn't even force the respawn.

Now what if you used

minetest.register_on_dieplayer(func(ObjectRef))

or this

minetest.register_on_respawnplayer(func(ObjectRef))?

I can think of a work-around for the respawn with the register_on_respawnplayer. When the player respawns, you can check if the player has a set spawn, if he/she does, then you teleport the player to that spawn point.

I don't know if you can force a player respawn via lua or not. So I am not sure about the register_on_dieplayer.

PostPosted: Thu Mar 08, 2012 06:31
by sfan5
Nice Mod!

PostPosted: Thu Mar 08, 2012 12:23
by jordan4ibanez
Gatharoth wrote:Okay, so I remember you said something that even kahrl couldn't even force the respawn.

Now what if you used

minetest.register_on_dieplayer(func(ObjectRef))

or this

minetest.register_on_respawnplayer(func(ObjectRef))?

I can think of a work-around for the respawn with the register_on_respawnplayer. When the player respawns, you can check if the player has a set spawn, if he/she does, then you teleport the player to that spawn point.

I don't know if you can force a player respawn via lua or not. So I am not sure about the register_on_dieplayer.

oh i figured out what was wrong :P

sfan5 wrote:Nice mod!

thank you! hopefully i get more and more commands into it :D

PostPosted: Thu Mar 08, 2012 15:49
by Utilisatrice
Hi,

How to use this ?

PostPosted: Thu Mar 08, 2012 16:00
by sfan5
Look in the first Post!

PostPosted: Thu Mar 08, 2012 16:09
by Utilisatrice
Hi sfan5,

No, I know how to use in game but where I must place this file, I need to recompile the source ? Or I myself was in the mod folder?

PostPosted: Thu Mar 08, 2012 16:11
by Jordach
Nope. Copy and paste that into a file called init.lua

Now, move that into /minetest/data/mods/command/init.lua

Then the commands can be used.

PostPosted: Thu Mar 08, 2012 16:38
by randomproof
Here, I wrote a version that will save the players position to a file. I also fixed the chat commands a bit. To save a spawn point just got where you ant it and type "/setspawn" that is it. Right now a mod can not set what direction you are looking so you will be looking in whatever direction you were look in in when you died. Also you should set the variable 'default_spawn' to a good value.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- needed by 'table_save' and 'table_load'
local function exportstring( s )
  s = string.format( "%q",s )
  -- to replace
  s = string.gsub( s,"\\\n","\\n" )
  s = string.gsub( s,"\r","\\r" )
  s = string.gsub( s,string.char(26),""..string.char(26).."" )
  return s
end
--// The Save Function
local function table_save(  tbl,filename )
   local charS,charE = "   ","\n"
   local file,err
   -- create a pseudo file that writes to a string and return the string
   if not filename then
      file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
      charS,charE = "",""
   -- write table to tmpfile
   elseif filename == true or filename == 1 then
      charS,charE,file = "","",io.tmpfile()
   -- write table to file
   -- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error
   else
      file,err = io.open( filename, "w" )
      if err then return _,err end
   end
   -- initiate variables for save procedure
   local tables,lookup = { tbl },{ [tbl] = 1 }
   file:write( "return {"..charE )
   for idx,t in ipairs( tables ) do
      if filename and filename ~= true and filename ~= 1 then
         file:write( "-- Table: {"..idx.."}"..charE )
      end
      file:write( "{"..charE )
      local thandled = {}
      for i,v in ipairs( t ) do
         thandled[i] = true
         -- escape functions and userdata
         if type( v ) ~= "userdata" then
            -- only handle value
            if type( v ) == "table" then
               if not lookup[v] then
                  table.insert( tables, v )
                  lookup[v] = #tables
               end
               file:write( charS.."{"..lookup[v].."},"..charE )
            elseif type( v ) == "function" then
               file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
            else
               local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
               file:write(  charS..value..","..charE )
            end
         end
      end
      for i,v in pairs( t ) do
         -- escape functions and userdata
         if (not thandled[i]) and type( v ) ~= "userdata" then
            -- handle index
            if type( i ) == "table" then
               if not lookup[i] then
                  table.insert( tables,i )
                  lookup[i] = #tables
               end
               file:write( charS.."[{"..lookup[i].."}]=" )
            else
               local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
               file:write( charS..index.."=" )
            end
            -- handle value
            if type( v ) == "table" then
               if not lookup[v] then
                  table.insert( tables,v )
                  lookup[v] = #tables
               end
               file:write( "{"..lookup[v].."},"..charE )
            elseif type( v ) == "function" then
               file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
            else
               local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
               file:write( value..","..charE )
            end
         end
      end
      file:write( "},"..charE )
   end
   file:write( "}" )
   -- Return Values
   -- return stringtable from string
   if not filename then
      -- set marker for stringtable
      return file.str.."--|"
   -- return stringttable from file
   elseif filename == true or filename == 1 then
      file:seek ( "set" )
      -- no need to close file, it gets closed and removed automatically
      -- set marker for stringtable
      return file:read( "*a" ).."--|"
   -- close file and return 1
   else
      file:close()
      return 1
   end
end

--// The Load Function
local function table_load( sfile )
   -- catch marker for stringtable
   if string.sub( sfile,-3,-1 ) == "--|" then
      tables,err = loadstring( sfile )
   else
      tables,err = loadfile( sfile )
   end
   if err then return _,err
   end
   tables = tables()
   for idx = 1,#tables do
      local tolinkv,tolinki = {},{}
      for i,v in pairs( tables[idx] ) do
         if type( v ) == "table" and tables[v[1]] then
            table.insert( tolinkv,{ i,tables[v[1]] } )
         end
         if type( i ) == "table" and tables[i[1]] then
            table.insert( tolinki,{ i,tables[i[1]] } )
         end
      end
      -- link values, first due to possible changes of indices
      for _,v in ipairs( tolinkv ) do
         tables[idx][v[1]] = v[2]
      end
      -- link indices
      for _,v in ipairs( tolinki ) do
         tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
      end
   end
   return tables[1]
end

local spawn_locations_db_filename = minetest.get_worldpath() .. "/spawn_locations.tbl"

spawn_locations = table_load(spawn_locations_db_filename)

if type(spawn_locations) ~= "table" then
    spawn_locations = {}
end

default_spawn = {x = 0, y = 0, z = 0}

minetest.register_on_chat_message(function(name, message)
    cmd = "/setspawn"
    if message:sub(0, #cmd) == cmd then
        player = minetest.env:get_player_by_name(name)
        spawn_locations[name] = player:getpos()

        table_save( spawn_locations, spawn_locations_db_filename )
        return true
    end
    cmd = "/afk"
    if message:sub(0, #cmd) == cmd then
        minetest.chat_send_all(name, " is AFK!")
        return true
    end
    cmd = "/not_afk"
    if message:sub(0, #cmd) == cmd then
        minetest.chat_send_all(name, " is back from AFK!")
        return true
    end
end)

--Deds to Kahrl
minetest.register_on_newplayer(function(player)
    player:setpos(default_spawn)
    return true
end)

--Deds to Kahrl
minetest.register_on_respawnplayer(function(player, pos)
    name = player:get_player_name()
    if spawn_locations[name] ~= nil then
        player:setpos(spawn_locations[name])
    else
        player:setpos(default_spawn)
    end
    return true
end)

PostPosted: Thu Mar 08, 2012 16:38
by Utilisatrice
Hi,

Yes, it works there had a ")" in too, so the command /spawn works but the command /afk doesn't work :

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
17:37:53: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: ...t\minetest\bin\Release\..\data\mods\command\init.lua:19: bad argument #1 to 'chat_send_all' (string expected, got userdata)
17:37:53: ERROR[ServerThread]: stack traceback:

In thread 5080:
C:\Users\****\Desktop\Minetest\minetest\src\server.cpp:113: ServerThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 5080:
#0  ServerThread::Thread
(Leftover data: #1  Server::Receive)
(Leftover data: #2  Server::ProcessData)
(Leftover data: #3  Server::getClient)
(Leftover data: #4  BlockEmergeQueue::addBlock)
DEBUG STACK FOR THREAD 51dc:
#0  main
(Leftover data: #1  ClientMap::renderMap)
(Leftover data: #2  ClientEnvironment::step)
(Leftover data: #3  Client::Receive)
(Leftover data: #4  Client::ProcessData)
(Leftover data: #5  MeshUpdateQueue::addBlock)
DEBUG STACK FOR THREAD 572c:
#0  MeshUpdateThread::Thread

PostPosted: Thu Mar 08, 2012 17:27
by jordan4ibanez
Utilisatrice wrote:Hi,

Yes, it works there had a ")" in too, so the command /spawn works but the command /afk doesn't work :

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
17:37:53: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: ...t\minetest\bin\Release\..\data\mods\command\init.lua:19: bad argument #1 to 'chat_send_all' (string expected, got userdata)
17:37:53: ERROR[ServerThread]: stack traceback:

In thread 5080:
C:\Users\****\Desktop\Minetest\minetest\src\server.cpp:113: ServerThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 5080:
#0  ServerThread::Thread
(Leftover data: #1  Server::Receive)
(Leftover data: #2  Server::ProcessData)
(Leftover data: #3  Server::getClient)
(Leftover data: #4  BlockEmergeQueue::addBlock)
DEBUG STACK FOR THREAD 51dc:
#0  main
(Leftover data: #1  ClientMap::renderMap)
(Leftover data: #2  ClientEnvironment::step)
(Leftover data: #3  Client::Receive)
(Leftover data: #4  Client::ProcessData)
(Leftover data: #5  MeshUpdateQueue::addBlock)
DEBUG STACK FOR THREAD 572c:
#0  MeshUpdateThread::Thread

fixed

FIXED:
-Made /spawn and /afk real commands
-Made /afk function correctly!

PostPosted: Thu Mar 08, 2012 17:30
by jordan4ibanez
randomproof wrote:Here, I wrote a version that will save the players position to a file. I also fixed the chat commands a bit. To save a spawn point just got where you ant it and type "/setspawn" that is it. Right now a mod can not set what direction you are looking so you will be looking in whatever direction you were look in in when you died. Also you should set the variable 'default_spawn' to a good value.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- needed by 'table_save' and 'table_load'
local function exportstring( s )
  s = string.format( "%q",s )
  -- to replace
  s = string.gsub( s,"\\\n","\\n" )
  s = string.gsub( s,"\r","\\r" )
  s = string.gsub( s,string.char(26),""..string.char(26).."" )
  return s
end
--// The Save Function
local function table_save(  tbl,filename )
   local charS,charE = "   ","\n"
   local file,err
   -- create a pseudo file that writes to a string and return the string
   if not filename then
      file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
      charS,charE = "",""
   -- write table to tmpfile
   elseif filename == true or filename == 1 then
      charS,charE,file = "","",io.tmpfile()
   -- write table to file
   -- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error
   else
      file,err = io.open( filename, "w" )
      if err then return _,err end
   end
   -- initiate variables for save procedure
   local tables,lookup = { tbl },{ [tbl] = 1 }
   file:write( "return {"..charE )
   for idx,t in ipairs( tables ) do
      if filename and filename ~= true and filename ~= 1 then
         file:write( "-- Table: {"..idx.."}"..charE )
      end
      file:write( "{"..charE )
      local thandled = {}
      for i,v in ipairs( t ) do
         thandled[i] = true
         -- escape functions and userdata
         if type( v ) ~= "userdata" then
            -- only handle value
            if type( v ) == "table" then
               if not lookup[v] then
                  table.insert( tables, v )
                  lookup[v] = #tables
               end
               file:write( charS.."{"..lookup[v].."},"..charE )
            elseif type( v ) == "function" then
               file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
            else
               local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
               file:write(  charS..value..","..charE )
            end
         end
      end
      for i,v in pairs( t ) do
         -- escape functions and userdata
         if (not thandled[i]) and type( v ) ~= "userdata" then
            -- handle index
            if type( i ) == "table" then
               if not lookup[i] then
                  table.insert( tables,i )
                  lookup[i] = #tables
               end
               file:write( charS.."[{"..lookup[i].."}]=" )
            else
               local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
               file:write( charS..index.."=" )
            end
            -- handle value
            if type( v ) == "table" then
               if not lookup[v] then
                  table.insert( tables,v )
                  lookup[v] = #tables
               end
               file:write( "{"..lookup[v].."},"..charE )
            elseif type( v ) == "function" then
               file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
            else
               local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
               file:write( value..","..charE )
            end
         end
      end
      file:write( "},"..charE )
   end
   file:write( "}" )
   -- Return Values
   -- return stringtable from string
   if not filename then
      -- set marker for stringtable
      return file.str.."--|"
   -- return stringttable from file
   elseif filename == true or filename == 1 then
      file:seek ( "set" )
      -- no need to close file, it gets closed and removed automatically
      -- set marker for stringtable
      return file:read( "*a" ).."--|"
   -- close file and return 1
   else
      file:close()
      return 1
   end
end

--// The Load Function
local function table_load( sfile )
   -- catch marker for stringtable
   if string.sub( sfile,-3,-1 ) == "--|" then
      tables,err = loadstring( sfile )
   else
      tables,err = loadfile( sfile )
   end
   if err then return _,err
   end
   tables = tables()
   for idx = 1,#tables do
      local tolinkv,tolinki = {},{}
      for i,v in pairs( tables[idx] ) do
         if type( v ) == "table" and tables[v[1]] then
            table.insert( tolinkv,{ i,tables[v[1]] } )
         end
         if type( i ) == "table" and tables[i[1]] then
            table.insert( tolinki,{ i,tables[i[1]] } )
         end
      end
      -- link values, first due to possible changes of indices
      for _,v in ipairs( tolinkv ) do
         tables[idx][v[1]] = v[2]
      end
      -- link indices
      for _,v in ipairs( tolinki ) do
         tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
      end
   end
   return tables[1]
end

local spawn_locations_db_filename = minetest.get_worldpath() .. "/spawn_locations.tbl"

spawn_locations = table_load(spawn_locations_db_filename)

if type(spawn_locations) ~= "table" then
    spawn_locations = {}
end

default_spawn = {x = 0, y = 0, z = 0}

minetest.register_on_chat_message(function(name, message)
    cmd = "/setspawn"
    if message:sub(0, #cmd) == cmd then
        player = minetest.env:get_player_by_name(name)
        spawn_locations[name] = player:getpos()

        table_save( spawn_locations, spawn_locations_db_filename )
        return true
    end
    cmd = "/afk"
    if message:sub(0, #cmd) == cmd then
        minetest.chat_send_all(name, " is AFK!")
        return true
    end
    cmd = "/not_afk"
    if message:sub(0, #cmd) == cmd then
        minetest.chat_send_all(name, " is back from AFK!")
        return true
    end
end)

--Deds to Kahrl
minetest.register_on_newplayer(function(player)
    player:setpos(default_spawn)
    return true
end)

--Deds to Kahrl
minetest.register_on_respawnplayer(function(player, pos)
    name = player:get_player_name()
    if spawn_locations[name] ~= nil then
        player:setpos(spawn_locations[name])
    else
        player:setpos(default_spawn)
    end
    return true
end)

alright thank you very much..will put this in :)

PostPosted: Thu Mar 08, 2012 18:29
by Utilisatrice
Script work 100%.

But maybe you should do a command indicating that the player no longer have afk.

Exemple :

/afk => Utilisatrice is now afk.

When i type /afk again => Utilisatrice do not have afk.

PostPosted: Thu Mar 08, 2012 18:32
by sfan5
Utilisatrice wrote:Script work 100%.

But maybe you should do a command indicating that the player no longer have afk.

Exemple :

/afk => Utilisatrice is now afk.

When i type /afk again => Utilisatrice do not have afk.

Good Idea

PostPosted: Thu Mar 08, 2012 20:02
by jordan4ibanez
Utilisatrice wrote:Script work 100%.

But maybe you should do a command indicating that the player no longer have afk.

Exemple :

/afk => Utilisatrice is now afk.

When i type /afk again => Utilisatrice do not have afk.

great idea!

PostPosted: Thu Mar 08, 2012 20:13
by jordan4ibanez
Utilisatrice wrote:Script work 100%.

But maybe you should do a command indicating that the player no longer have afk.

Exemple :

/afk => Utilisatrice is now afk.

When i type /afk again => Utilisatrice do not have afk.

great idea!
&
if you move..it says Utilisatrice is no longer afk

PostPosted: Thu Mar 08, 2012 20:47
by Death Dealer
jordan4ibanez wrote:Here's spawn & /afk command:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
spawn = {x = 47, y = 7.5, z = -40.5}

minetest.register_on_chat_message(function(name, message, playername, player)
    local cmd = "/spawn"
    if message:sub(0, #cmd) == cmd then
        if message == '/spawn' then
        local player = minetest.env:get_player_by_name(name)
        minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
        player:setpos(spawn)
        return true --deds to sfan5
        end
    end

    local cmd ="/afk"
    if message:sub(0, #cmd) == cmd then
            if message == '/afk' then
            local player = minetest.env:get_player_by_name(name)
            minetest.chat_send_all(name.." is AFK! ")
            return true --deds to sfan5
        end
    end
end)

--Deds to Kahrl
minetest.register_on_newplayer(function(player)
    player:setpos(spawn)
    return true
end)

--Deds to Kahrl
minetest.register_on_respawnplayer(function(player, pos)
    player:setpos(spawn)
    return true
end)


Replace x=0 y=0 z=0 with your spawn quards

Features:
-/spawn command (returns you to spawn)
-puts new players in the spawn
-puts players into spawn on death
-/afk command (prints playername is AFK!)

To do:
-Make /spawn a real command (with privs) DONE!
-Make Admins ..that can set spawn
-Make /afk a real commandDONE!
-Make /afk print the players name( so your name is celeron55 /afk = "celeron55 is AFK!")DONE!
-Add a death notice using (minetest.register_on_dieplayer) ..so use (player, "has died!")
-When death notice is made then have the possibility of death information..if a player is in lava ..then print (player, "burned to death") or (player, "hit the ground too hard!")

i really like the descriptions of death, very cool. good job.

PostPosted: Thu Mar 08, 2012 21:45
by jordan4ibanez
thank you DD!

I am greatly requesting someone to make a /teleport playername playername command!

PostPosted: Thu Mar 08, 2012 21:51
by kahrl
Idea: Maybe /afk should delay the message until somebody tries to chat with the afk person?
That would reduce afk message spam.

Example:

Alice: /afk
Server (to Alice): You are now AFK
...
Bob: what's up Alice
Server (to all): Alice is AFK!
Bob: dang it
Chris: Alice... I guess she's got her reasons, but I just don't want to know
...
Alice: /afk
Server (to Alice): You are no longer AFK
-- perhaps if somebody mentioned Alice while she was AFK, like Bob and Chris above, the server should now send
Server (to all): Alice is no longer AFK
Bob: greetings

PostPosted: Thu Mar 08, 2012 22:53
by jordan4ibanez
kahrl wrote:Idea: Maybe /afk should delay the message until somebody tries to chat with the afk person?
That would reduce afk message spam.

Example:

Alice: /afk
Server (to Alice): You are now AFK
...
Bob: what's up Alice
Server (to all): Alice is AFK!
Bob: dang it
Chris: Alice... I guess she's got her reasons, but I just don't want to know
...
Alice: /afk
Server (to Alice): You are no longer AFK
-- perhaps if somebody mentioned Alice while she was AFK, like Bob and Chris above, the server should now send
Server (to all): Alice is no longer AFK
Bob: greetings

That is a bit over dramatic lmfao xD
BUT it is a good idea!

PostPosted: Wed Mar 14, 2012 23:12
by bgsmithjr
Error about trying to register 'local player' which is nil, crashes my game. But, the /spawn command works. afk works. but doesnt return from afk, /setspawn works. new player spawn works, but on death respawn crashes.

PostPosted: Thu Mar 15, 2012 22:47
by TubbzChain
where do i place the command thing at so it works?

PostPosted: Sun Mar 18, 2012 20:06
by bgsmithjr
I am sorry, when running a server from a windows pc, and connecting with a linux client. The player respawn on death crashes the server. And the modified script crashes the server on startup from windows.

PostPosted: Sun Mar 18, 2012 20:12
by bgsmithjr
TubbzChain wrote:where do i place the command thing at so it works?

create a folder minetest/data/mods/, named 'commands'. In that folder create a file named init.lua, in that file paste the code from the forum. Next to that file create a file named depends.txt, which contains the word default.

PostPosted: Wed Mar 21, 2012 11:45
by TubbzChain
bgsmithjr wrote:
TubbzChain wrote:where do i place the command thing at so it works?

create a folder minetest/data/mods/, named 'commands'. In that folder create a file named init.lua, in that file paste the code from the forum. Next to that file create a file named depends.txt, which contains the word default.

ty XD ive been trying to figure it out for a while and i just was able to check the fourm again to see if anyone answered my question, thanks though :D

PostPosted: Sat Apr 07, 2012 22:11
by jordan4ibanez
bgsmithjr wrote:I am sorry, when running a server from a windows pc, and connecting with a linux client. The player respawn on death crashes the server. And the modified script crashes the server on startup from windows.

this is for latest github && this still works great btw

PostPosted: Sat Apr 07, 2012 22:20
by bgsmithjr
Yeah, it was my fault, I got it working.

PostPosted: Tue Oct 22, 2013 20:36
by Element
where do i put this code
jordan4ibanez wrote:Here's spawn & /afk command:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
spawn = {x = 47, y = 7.5, z = -40.5}

minetest.register_on_chat_message(function(name, message, playername, player)
    local cmd = "/spawn"
    if message:sub(0, #cmd) == cmd then
        if message == '/spawn' then
        local player = minetest.env:get_player_by_name(name)
        minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
        player:setpos(spawn)
        return true --deds to sfan5
        end
    end

    local cmd ="/afk"
    if message:sub(0, #cmd) == cmd then
            if message == '/afk' then
            local player = minetest.env:get_player_by_name(name)
            minetest.chat_send_all(name.." is AFK! ")
            return true --deds to sfan5
        end
    end
end)

--Deds to Kahrl
minetest.register_on_newplayer(function(player)
    player:setpos(spawn)
    return true
end)

--Deds to Kahrl
minetest.register_on_respawnplayer(function(player, pos)
    player:setpos(spawn)
    return true
end)


Replace x=0 y=0 z=0 with your spawn quards

Features:
-/spawn command (returns you to spawn)
-puts new players in the spawn
-puts players into spawn on death
-/afk command (prints playername is AFK!)

To do:
-Merge Randomproof's awesome code
-Make Admins ..that can set spawn(randomproof)
-Make /afk print "PLAYER is no longer AFK!" if player moves or if /afk is sent again
-Add a death notice using (minetest.register_on_dieplayer) ..so use (player, "has died!")
-When death notice is made then have the possibility of death information..if a player is in lava ..then print (player, "burned to death") or (player, "hit the ground too hard!")
-/jail command
-/setjail command
-/unjail command
Jail command would work better than in minecraft's bukkit server..basically /setjail would work like /setspawn would
/jail "player" would send a person into an unbreakable (hopefully) area which if they move ..they are sent back to the exact place where /setjail was sent this would also remove all their items ..and /unjail "player" would release the player back into the spawn