Extra commands(alpha 0.1)

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

Extra commands(alpha 0.1)

by jordan4ibanez » Wed Mar 07, 2012 23:47

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
Last edited by jordan4ibanez on Thu Mar 08, 2012 22:42, edited 1 time in total.
If you can think it, you can make it.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46

by Death Dealer » Wed Mar 07, 2012 23:51

Nice
Keep calm and code python^_^
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Wed Mar 07, 2012 23:55

Death Dealer wrote:Nice

thank you!
If you can think it, you can make it.
 

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

by Gatharoth » Thu Mar 08, 2012 05:30

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.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Thu Mar 08, 2012 06:31

Nice Mod!
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 12:23

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
If you can think it, you can make it.
 

Utilisatrice
Member
 
Posts: 103
Joined: Thu Feb 16, 2012 18:04

by Utilisatrice » Thu Mar 08, 2012 15:49

Hi,

How to use this ?
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Thu Mar 08, 2012 16:00

Look in the first Post!
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

Utilisatrice
Member
 
Posts: 103
Joined: Thu Feb 16, 2012 18:04

by Utilisatrice » Thu Mar 08, 2012 16:09

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?
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Thu Mar 08, 2012 16:11

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.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Thu Mar 08, 2012 16:38

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)
Last edited by randomproof on Thu Mar 08, 2012 16:40, edited 1 time in total.
 

Utilisatrice
Member
 
Posts: 103
Joined: Thu Feb 16, 2012 18:04

by Utilisatrice » Thu Mar 08, 2012 16:38

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
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 17:27

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!
If you can think it, you can make it.
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 17:30

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 :)
If you can think it, you can make it.
 

Utilisatrice
Member
 
Posts: 103
Joined: Thu Feb 16, 2012 18:04

by Utilisatrice » Thu Mar 08, 2012 18:29

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.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Thu Mar 08, 2012 18:32

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
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 20:02

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 can think it, you can make it.
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 20:13

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
If you can think it, you can make it.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46

by Death Dealer » Thu Mar 08, 2012 20:47

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.
Keep calm and code python^_^
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 21:45

thank you DD!

I am greatly requesting someone to make a /teleport playername playername command!
If you can think it, you can make it.
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51

by kahrl » Thu Mar 08, 2012 21:51

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
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Thu Mar 08, 2012 22:53

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!
If you can think it, you can make it.
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Wed Mar 14, 2012 23:12

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.
 

TubbzChain
 

by TubbzChain » Thu Mar 15, 2012 22:47

where do i place the command thing at so it works?
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Sun Mar 18, 2012 20:06

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.
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Sun Mar 18, 2012 20:12

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.
 

TubbzChain
 

by TubbzChain » Wed Mar 21, 2012 11:45

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
 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Sat Apr 07, 2012 22:11

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
If you can think it, you can make it.
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Sat Apr 07, 2012 22:20

Yeah, it was my fault, I got it working.
 

User avatar
Element
Member
 
Posts: 269
Joined: Tue Jun 11, 2013 00:27
IRC: Elementwing4962
In-game: Elementwing4962

by Element » Tue Oct 22, 2013 20:36

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
Join Me And My Team - thornfyregaming-mc.noip.me:25565

My Server Is 1.7.9
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 26 guests

cron