Byakuren wrote:Do players keep their velocity after being detached from an entity?
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 ;-)
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.
*** Error in `minetest': double free or corruption (fasttop): 0x0000000001239c60 ***
Abortado (imagem do núcleo gravada)
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?
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.
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)
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)
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)?
{
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)
}
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)
})
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.")
function foo(param1, param2)
end
function foo()
local param1
local param2
-- both can be accessed here
end
-- there is no param1 or param2 here.
function foo(param1, param2)
end
foo("one value", 123)
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)
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
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.
RREDesigns wrote:Why "playerName = minetest.get_player_name()" doesn't work alone?
local playerName = player:get_player_name()
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.")
local function tphr_send(sender, receiver)
iangp wrote:try replace tostring() to dump() on my code...
function foo(one, two)
print(one, two)
end
function foo(dog, cat)
print(dog, cat)
end
foo("something", "happened")
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)
Users browsing this forum: No registered users and 55 guests