Post your modding questions here

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Wed Jan 06, 2016 07:30

Do players keep their velocity after being detached from an entity?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Wed Jan 06, 2016 19:41

Byakuren wrote:Do players keep their velocity after being detached from an entity?

If you mean the velocity of the entity they were attached to then no, they do not. They will, however, suffer the effects of gravity if detaching from a height ;-)
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Wed Jan 06, 2016 20:24

stu wrote:
Byakuren wrote:Do players keep their velocity after being detached from an entity?

If you mean the velocity of the entity they were attached to then no, they do not. They will, however, suffer the effects of gravity if detaching from a height ;-)

Alright, thank you.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Wed Jan 06, 2016 20:58

Byakuren wrote:
stu wrote:
Byakuren wrote:Do players keep their velocity after being detached from an entity?

If you mean the velocity of the entity they were attached to then no, they do not. They will, however, suffer the effects of gravity if detaching from a height ;-)

Alright, thank you.

You're welcome, what was it you were trying to achieve anyway? maybe there is another way to accomplish that.
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Wed Jan 06, 2016 22:33

Hey guys,
Is there some way to a mod cause some error like that?
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
*** Error in `minetest': double free or corruption (fasttop): 0x0000000001239c60 ***
Abortado (imagem do núcleo gravada)

Or Is just my minetest build? I just retype and then it runs but it's a strange issue
Last edited by iangp on Thu Jan 07, 2016 11:36, edited 1 time in total.
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Thu Jan 07, 2016 00:34

Does minetest.get_gametime() return the number of seconds the world has been active? As in, it doesn't count up when the world is not being played. Also, is it dependent on simulation speed, i.e. will it slow down if not enough ticks are being processed quickly enough?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: Post your modding questions here

by Nathan.S » Thu Jan 07, 2016 16:22

Question about best practices, I am changing the speed that a player gets thirsty in the thirst mod based off the month from the mymonths mod. Would it be better to make the changes in the thirst mod and have that read the month, or would it be better to do the changes in the mymonths mod and have that modify the thirst mod, or would there probably not be any difference.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Thu Jan 07, 2016 16:40

Your thirst depends on the month, not the other way around, so the best thing to do would be to translate that into code and modify thirst.

This also makes it easier in case you want to distribute the modified mod, or offer a patch for thirst.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Thu Jan 07, 2016 16:48

@Nathan - Just my opinion - I think changes should be in the thirst mod since the changes only effect the thirst mod. Either way would work but keeping the code with thirst would make it so if mymonths was forked and changed then thirst could easily be changed to work with the fork. I have no objections to adding it to mymonths if that is what you choose.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Thu Jan 07, 2016 16:49

Byakuren wrote:Does minetest.get_gametime() return the number of seconds the world has been active? As in, it doesn't count up when the world is not being played. Also, is it dependent on simulation speed, i.e. will it slow down if not enough ticks are being processed quickly enough?

It returns the time in seconds since you created the world, and is only incremented while the server is running.

It apparently discards the fractions of a second when the server shuts down, so it's not 100% precise. Depending on what you need the time for, and your precision needs, you'd be better with updating your own timer and saving/restoring from a file in the world directory.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: Post your modding questions here

by Nathan.S » Thu Jan 07, 2016 17:15

Thanks guys.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Thu Jan 07, 2016 18:05

kaeza wrote:
Byakuren wrote:Does minetest.get_gametime() return the number of seconds the world has been active? As in, it doesn't count up when the world is not being played. Also, is it dependent on simulation speed, i.e. will it slow down if not enough ticks are being processed quickly enough?

It returns the time in seconds since you created the world, and is only incremented while the server is running.

It apparently discards the fractions of a second when the server shuts down, so it's not 100% precise. Depending on what you need the time for, and your precision needs, you'd be better with updating your own timer and saving/restoring from a file in the world directory.


Also note that game time isn't reliable as env_data.txt is often corrupted (so gametime may be reset after a shutdown)
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Thu Jan 07, 2016 20:51

kaeza wrote:
Byakuren wrote:Does minetest.get_gametime() return the number of seconds the world has been active? As in, it doesn't count up when the world is not being played. Also, is it dependent on simulation speed, i.e. will it slow down if not enough ticks are being processed quickly enough?

It returns the time in seconds since you created the world, and is only incremented while the server is running.

It apparently discards the fractions of a second when the server shuts down, so it's not 100% precise. Depending on what you need the time for, and your precision needs, you'd be better with updating your own timer and saving/restoring from a file in the world directory.

rubenwardy wrote:
kaeza wrote:
Byakuren wrote:Does minetest.get_gametime() return the number of seconds the world has been active? As in, it doesn't count up when the world is not being played. Also, is it dependent on simulation speed, i.e. will it slow down if not enough ticks are being processed quickly enough?

It returns the time in seconds since you created the world, and is only incremented while the server is running.

It apparently discards the fractions of a second when the server shuts down, so it's not 100% precise. Depending on what you need the time for, and your precision needs, you'd be better with updating your own timer and saving/restoring from a file in the world directory.


Also note that game time isn't reliable as env_data.txt is often corrupted (so gametime may be reset after a shutdown)


Okay, thank you both!
Every time a mod API is left undocumented, a koala dies.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 04:37

Hello everyone. I seem to have a huge problem trying to write scripts for a mod. I did my best trying to follow what the API reference says, but I get nothing but errors. Check this code:

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
minetest.register_chatcommand("getpname",function(player)
                              local user = player:get_player_name()   
                              if user ~= nil then
                                 minetest.chat_send_player(user, tostring(user))
                                return     
                              else
                                 minetest.chat_send_player(user, "No name retrieved.")
                                return
                              end
                              end)


I'm just trying to retrieve the player name and can't even do that. MT will complain about everything, no matter of what. So, this minetest.* methods has to be used under certain scopes or what? How is it that var = minetest.get_player_name() won't leave me with a string in my var (I tried that way too)?
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Fri Jan 08, 2016 12:05

RREDesigns wrote:Hello everyone. I seem to have a huge problem trying to write scripts for a mod. I did my best trying to follow what the API reference says, but I get nothing but errors. Check this code:

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
minetest.register_chatcommand("getpname",function(player)
                              local user = player:get_player_name()   
                              if user ~= nil then
                                 minetest.chat_send_player(user, tostring(user))
                                return     
                              else
                                 minetest.chat_send_player(user, "No name retrieved.")
                                return
                              end
                              end)


I'm just trying to retrieve the player name and can't even do that. MT will complain about everything, no matter of what. So, this minetest.* methods has to be used under certain scopes or what? How is it that var = minetest.get_player_name() won't leave me with a string in my var (I tried that way too)?



What are you doing (exactly)?
minetest.register_chatcommand("cmd", {chatcommand definition})
{chatcommand definition} isn't a function, it's a table.
see:
http://dev.minetest.net/minetest.register_chatcommand

You must put this function inside the table
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
{
   params = "<name>",
   description = "Some desc",
        func = function( name , param) -- name: player name, param: name passed
                              local player = minetest.get_player_by_name(param)
                              if param ~= nil then
                                   minetest.chat_send_player(player, tostring(player))
                                   return
                              else
                                   minetest.chat_send_player(player, "No name retrieved.")
                                   return
                              end
        end)
}
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Jan 08, 2016 12:23

 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 13:26

I tried to do that about 20 times, in different ways, including a funtion defined outside the list. It just doesn't work. I think I forgot to make a list this last time, so I fixed it, but it doesn't work. Then I tried to copy the code provided by "iangp" and that doesn't work either, the error:

ServerError: Lua: Runtime error from mod 'testmod' in callback on_chat_message():***/init.lua:11: bad argument #1 to 'chat_send_player' (string expected, got nil)

I clearly said I wanted to retrieve the player's name. All I need is to store it's name in a var to use it later in other strings operations. I used the chat to print it, just to check wheter it was working or not.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 13:29

Also, I was reading the mods scripts, and noticed that in most of them they make use of undefined/undeclared vars and arguments, like in the teleport mod, where "sender" and "receiver" are used all over the file, but never initialised. What's up with that?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Jan 08, 2016 13:52

I can't find a teleport mod.

Please take the time to read that chapter. The code should be this:

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
minetest.register_chatcommand("getpname", {
       description = "Some desc",
       func = function(name , param)
                if name ~= nil then
                       return true, name
               else
                       -- this will never run, as far as I know.
                       return false, "No name retrieved."
               end
        end)
})


When player1 runs /getpname blah blah, func will be called with
name == "player1"
param == "blah blah".

The reason that a player name rather than a player object is passed is because the player might not actually be online, but may be running commands from IRC. So don't assume that minetest.get_player_by_name will work in a chat command call back.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 14:08

Ok, cool. I'm trying that now.

How is it that "name" and "param" get their values?
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 14:09

Why "playerName = minetest.get_player_name()" doesn't work alone?
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 14:13

Ok, it works now, with func(name), since all I wanted was the player name, no parameters has to be passed.

Image

Big thanks for the help.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 14:19

This is the code in init.lua for the teleport requests I was talking earlier:

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
local timeout_delay = 60

-- Set to true to register tpr_admin priv
local regnewpriv = false

local version = "1.1"

local tpr_list = {}
local tphr_list = {}

--Teleport Request System
local function tpr_send(sender, receiver)
   if receiver == "" then
      minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
      return
   end

   --If paremeter is valid, Send teleport message and set the table.
   if not minetest.get_player_by_name(receiver) then
      return
   end

   minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
   minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')

   --Write name values to list and clear old values.
   tpr_list[receiver] = sender
   --Teleport timeout delay
   minetest.after(timeout_delay, function(name)
      if tpr_list[name] then
         tpr_list[name] = nil
      end
   end, sender)
end

local function tphr_send(sender, receiver)
   if receiver == "" then
      minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
      return
   end

   --If paremeter is valid, Send teleport message and set the table.
   if not minetest.get_player_by_name(receiver) then
      return
   end

   minetest.chat_send_player(receiver, sender ..' is requesting that you teleport to them. /tpy to accept; /tpn to deny')
   minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')

   --Write name values to list and clear old values.
   tphr_list[receiver] = sender
   --Teleport timeout delay
   minetest.after(timeout_delay, function(name)
      if tphr_list[name] then
         tphr_list[name] = nil
      end
   end, sender)
end

local function tpr_deny(name)
   if tpr_list[name] then
      minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
      tpr_list[name] = nil
   end
   if tphr_list[name] then
      minetest.chat_send_player(tphr_list[name], 'Teleport request denied.')
      tphr_list[name] = nil
   end
end

-- Copied from Celeron-55's /teleport command. Thanks Celeron!
local function find_free_position_near(pos)
   local tries = {
      {x=1,y=0,z=0},
      {x=-1,y=0,z=0},
      {x=0,y=0,z=1},
      {x=0,y=0,z=-1},
   }
   for _,d in pairs(tries) do
      local p = vector.add(pos, d)
      if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
         return p, true
      end
   end
   return pos, false
end


--Teleport Accept Systems
local function tpr_accept(name, param)

   --Check to prevent constant teleporting.
   if not tpr_list[name]
   and not tphr_list[name] then
      minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players")
      return
   end

   local chatmsg, source, target, name2

   if tpr_list[name] then
      name2 = tpr_list[name]
      source = minetest.get_player_by_name(name)
      target = minetest.get_player_by_name(name2)
      chatmsg = name2 .. " is teleporting to you."
      tpr_list[name] = nil
   elseif tphr_list[name] then
      name2 = tphr_list[name]
      source = minetest.get_player_by_name(name2)
      target = minetest.get_player_by_name(name)
      chatmsg = "You are teleporting to " .. name2 .. "."
      tphr_list[name] = nil
   else
      return
   end

   -- Could happen if either player disconnects (or timeout); if so just abort
   if not source
   or not target then
      return
   end

   minetest.chat_send_player(name2, "Request Accepted!")
   minetest.chat_send_player(name, chatmsg)

   target:setpos(find_free_position_near(source:getpos()))
end

--Initalize Permissions.

if regnewpriv then
   minetest.register_privilege("tpr_admin", {
      description = "Permission to override teleport to other players. UNFINISHED",
      give_to_singleplayer = true
   })
end

--Initalize Commands.

minetest.register_chatcommand("tpr", {
   description = "Request teleport to another player",
   params = "<playername> | leave playername empty to see help message",
   privs = {interact=true},
   func = tpr_send
})

minetest.register_chatcommand("tphr", {
   description = "Request player to teleport to you",
   params = "<playername> | leave playername empty to see help message",
   privs = {interact=true},
   func = tphr_send
})

minetest.register_chatcommand("tpy", {
   description = "Accept teleport requests from another player",
   func = tpr_accept
})

minetest.register_chatcommand("tpn", {
   description = "Deny teleport requests from another player",
   func = tpr_deny
})

minetest.log("info", "[Teleport Request] Teleport Request v" .. version .. " Loaded.")
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Jan 08, 2016 14:37

Minetest does that for you.

In the following code:

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
function foo(param1, param2)

end


param1 and param2 are local variables in that function.
Think of it a little like this, although this code won'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
function foo()
    local param1
    local param2

   -- both can be accessed here
end

-- there is no param1 or param2 here.


The caller sets the value of the params like so:

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
function foo(param1, param2)

end

foo("one value", 123)


It's minetest that calls the function for you and gives it that value. So somewhere there will be code like this:

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
local cmd = somehowGetTheCommandFromItsName(cmd_name)
local ret, msg = cmd.func(callername, parampassed)
if ret then
   print("command was successful")
else
    print("command was unsuccessful")
end
print(msg)


That about code is example code, and won't work.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Fri Jan 08, 2016 14:56

iangp wrote:Hey guys,
Is there some way to a mod cause some error like that?
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
*** Error in `minetest': double free or corruption (fasttop): 0x0000000001239c60 ***
Abortado (imagem do núcleo gravada)

Or Is just my minetest build? I just retype and then it runs but it's a strange issue

l don't think a mod causes such an error message.
viewforum.php?f=6
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Fri Jan 08, 2016 16:19

RREDesigns wrote:I tried to do that about 20 times, in different ways, including a funtion defined outside the list. It just doesn't work. I think I forgot to make a list this last time, so I fixed it, but it doesn't work. Then I tried to copy the code provided by "iangp" and that doesn't work either, the error:

ServerError: Lua: Runtime error from mod 'testmod' in callback on_chat_message():***/init.lua:11: bad argument #1 to 'chat_send_player' (string expected, got nil)

I clearly said I wanted to retrieve the player's name. All I need is to store it's name in a var to use it later in other strings operations. I used the chat to print it, just to check wheter it was working or not.

try replace tostring() to dump() on my code...
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Jan 08, 2016 16:26

RREDesigns wrote:Why "playerName = minetest.get_player_name()" doesn't work alone?


Where would minetest be getting the name from? Mods are ran on the serverside, not the client side. Therefore there can be more than one player, so minetest.get_player_name() won't know which one.

If you have a player object, you can do player:get_player_name()

Also, make sure you use local:

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
local playerName = player:get_player_name()


See here for more info: http://rubenwardy.com/minetest_modding_ ... and-global

RREDesigns wrote:This is the code in init.lua for the teleport requests I was talking earlier:

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
local timeout_delay = 60

-- Set to true to register tpr_admin priv
local regnewpriv = false

local version = "1.1"

local tpr_list = {}
local tphr_list = {}

--Teleport Request System
local function tpr_send(sender, receiver)
   if receiver == "" then
      minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
      return
   end

   --If paremeter is valid, Send teleport message and set the table.
   if not minetest.get_player_by_name(receiver) then
      return
   end

   minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
   minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')

   --Write name values to list and clear old values.
   tpr_list[receiver] = sender
   --Teleport timeout delay
   minetest.after(timeout_delay, function(name)
      if tpr_list[name] then
         tpr_list[name] = nil
      end
   end, sender)
end

local function tphr_send(sender, receiver)
   if receiver == "" then
      minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
      return
   end

   --If paremeter is valid, Send teleport message and set the table.
   if not minetest.get_player_by_name(receiver) then
      return
   end

   minetest.chat_send_player(receiver, sender ..' is requesting that you teleport to them. /tpy to accept; /tpn to deny')
   minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')

   --Write name values to list and clear old values.
   tphr_list[receiver] = sender
   --Teleport timeout delay
   minetest.after(timeout_delay, function(name)
      if tphr_list[name] then
         tphr_list[name] = nil
      end
   end, sender)
end

local function tpr_deny(name)
   if tpr_list[name] then
      minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
      tpr_list[name] = nil
   end
   if tphr_list[name] then
      minetest.chat_send_player(tphr_list[name], 'Teleport request denied.')
      tphr_list[name] = nil
   end
end

-- Copied from Celeron-55's /teleport command. Thanks Celeron!
local function find_free_position_near(pos)
   local tries = {
      {x=1,y=0,z=0},
      {x=-1,y=0,z=0},
      {x=0,y=0,z=1},
      {x=0,y=0,z=-1},
   }
   for _,d in pairs(tries) do
      local p = vector.add(pos, d)
      if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
         return p, true
      end
   end
   return pos, false
end


--Teleport Accept Systems
local function tpr_accept(name, param)

   --Check to prevent constant teleporting.
   if not tpr_list[name]
   and not tphr_list[name] then
      minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players")
      return
   end

   local chatmsg, source, target, name2

   if tpr_list[name] then
      name2 = tpr_list[name]
      source = minetest.get_player_by_name(name)
      target = minetest.get_player_by_name(name2)
      chatmsg = name2 .. " is teleporting to you."
      tpr_list[name] = nil
   elseif tphr_list[name] then
      name2 = tphr_list[name]
      source = minetest.get_player_by_name(name2)
      target = minetest.get_player_by_name(name)
      chatmsg = "You are teleporting to " .. name2 .. "."
      tphr_list[name] = nil
   else
      return
   end

   -- Could happen if either player disconnects (or timeout); if so just abort
   if not source
   or not target then
      return
   end

   minetest.chat_send_player(name2, "Request Accepted!")
   minetest.chat_send_player(name, chatmsg)

   target:setpos(find_free_position_near(source:getpos()))
end

--Initalize Permissions.

if regnewpriv then
   minetest.register_privilege("tpr_admin", {
      description = "Permission to override teleport to other players. UNFINISHED",
      give_to_singleplayer = true
   })
end

--Initalize Commands.

minetest.register_chatcommand("tpr", {
   description = "Request teleport to another player",
   params = "<playername> | leave playername empty to see help message",
   privs = {interact=true},
   func = tpr_send
})

minetest.register_chatcommand("tphr", {
   description = "Request player to teleport to you",
   params = "<playername> | leave playername empty to see help message",
   privs = {interact=true},
   func = tphr_send
})

minetest.register_chatcommand("tpy", {
   description = "Accept teleport requests from another player",
   func = tpr_accept
})

minetest.register_chatcommand("tpn", {
   description = "Deny teleport requests from another player",
   func = tpr_deny
})

minetest.log("info", "[Teleport Request] Teleport Request v" .. version .. " Loaded.")


Those variables are function parameters, and are defined when the function is defined, here:

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
local function tphr_send(sender, receiver)


iangp wrote:try replace tostring() to dump() on my code...


No. Your code is not the correct solution, he's trying to find out the name of the caller not the param passed.

Anyway, it would be player:get_player_name() not tostring or dump.
dump(player) will return <userdata>.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 17:06

Ok, that explains a lot. I was missing some of that.

In the code for the telport requests, sender and receiver are declared, but never defined. That's one of my biggest issues, I don't know how those vars get their value, or how the engine sorts them. Can I change those vars with, let's say paka and paka2, and get the same value assigned to those by the engine?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Jan 08, 2016 17:10

Yes. Both these will 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
function foo(one, two)
    print(one, two)
end


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
function foo(dog, cat)
    print(dog, cat)
end


What matters is the order, not the names.

Somewhere is in the code gives it their value, see above.

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
foo("something", "happened")


Runs the code in foo, starts with
one = dog = "something"
two = cat = "happened"
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Fri Jan 08, 2016 18:00

Why doesn't this work? Or, more specifically, why would this make minetest run at 100% CPU and become unresponsive?
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
minetest.register_node("kalite:plastic_grass", {
        tiles = "default_grass.png"
})

minetest.register_on_generated(function(minp, maxp, seed)
        if minp.y >= 14360 and minp.y <= 14440 then
                for x = minp.x, maxp.x do
                for z = minp.z, maxp.z do
                        minetest.set_node({x = x, y = 14400, z = z}, {name="default:cloud"})--[[
                        minetest.set_node({x = x, y = 14401, z = z}, {name="kalite:plastic_grass"})--]]
                end
                end
        end
end)


https://github.com/cornernote/minetest- ... it.lua#L25
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 55 guests

cron