Post your modding questions here

amadin
Member
 
Posts: 548
Joined: Tue Jun 16, 2015 16:23

Attach to an object with using set_attach function

by amadin » Tue Feb 09, 2016 10:43

In multiplayer, if the player is attached to an object (for example a horse) with using set_attach function, and the object is out of sight of another player (as well as the second player logged later than the first was attached), then the second player lost the first player model. It's look like a horse without player but player is on the horse.
How to fix this?
 

Byakuren
Member
 
Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Wed Feb 10, 2016 00:07

Is the position for players always the bottom of the collisionbox, or is it just hardcoded 1 below the collisionbox origin?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Hybrid Dog
Member
 
Posts: 2734
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Wed Feb 10, 2016 15:53

The eye position ()mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm,,,,,m ,mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm (ignoring bobbing) is 1.625 m higher than the position got with player:getpos(), so l assume if pos is player:getpos() then the collision box is {pos.x-0.5, pos.y, pos.z-0.5, pos.x+0.5, pos.y+2, pos.z+0.5}. Sorry for the ms, something issmm,m, sorry, was, on my keyboard.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 

drkwv
Member
 
Posts: 87
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

Re: Post your modding questions here

by drkwv » Wed Feb 10, 2016 16:21

How to know if ALT is pressed by the player?
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Wed Feb 10, 2016 16:34

drkwv wrote:How to know if ALT is pressed by the player?

You can't detect hardware keys, but you can detect game keys by using get_player_control.
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
 

Byakuren
Member
 
Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Wed Feb 10, 2016 18:10

Hybrid Dog wrote:The eye position ()mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm,,,,,m ,mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm (ignoring bobbing) is 1.625 m higher than the position got with player:getpos(), so l assume if pos is player:getpos() then the collision box is {pos.x-0.5, pos.y, pos.z-0.5, pos.x+0.5, pos.y+2, pos.z+0.5}. Sorry for the ms, something issmm,m, sorry, was, on my keyboard.


The player collisionbox is {-0.3, -1, -0.3, 0.3, 1, 0.3} (so would map to {pos.x-0.3, pos.y, pos.z-0.3, pos.x + 0.3, pos.y + 2, pos.z + 0.3}) by default, but that was not my question.

My question is whether the player position offset from the collisionbox origin is hardcoded at -1, or if it adapts to match the current collisionbox. Under a normal collisionbox, the player collisionbox's bottom is at the position returned by getpos, which happens to be 1 below the origin of the collisionbox as specified in a player's object properties. If for example I changed the collision box to {-0.3, -2, -0.3, 0.3, 50, 0.3}, would that place the player position 2 below the collisionbox origin, or at 1 below the collisionbox origin again?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Hybrid Dog
Member
 
Posts: 2734
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Wed Feb 10, 2016 21:46

l tested it, the collisionbox isn't automatically heightened to make the player's feet touch its bottom:
Image
btw: The player position doesn't change, player collision is coded for the client, so the collisionbox doesn't have an effect on the movement, which can also be seen on the screenshot.
Attachments
screenshot_20160210_223810.png
(48.47 KiB) Not downloaded yet

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 

Byakuren
Member
 
Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Thu Feb 11, 2016 00:07

Hybrid Dog wrote:l tested it, the collisionbox isn't automatically heightened to make the player's feet touch its bottom:
Image
btw: The player position doesn't change, player collision is coded for the client, so the collisionbox doesn't have an effect on the movement, which can also be seen on the screenshot.


Thank you Hybrid Dog. My purpose was just calculating the center of the player's collisionbox, so I don't need to worry about whether it affects player collision or not.
Every time a mod API is left undocumented, a koala dies.
 

drkwv
Member
 
Posts: 87
Joined: Thu Jun 28, 2012 13:48
GitHub: aa6

Re: Post your modding questions here

by drkwv » Thu Feb 11, 2016 07:31

Is an endless loop checking every player's player:get_player_control() is the only way to implement sprinting in game? Doesn't it affects performance in a bad way because of excessive checks every tick? Is there another way to implement it more efficient? Like putting an event emitter on a client (that would check keypresses every tick on a client but let it burn) and putting an event handler on a server?
Code: Select all
for playerName,playerInfo in pairs(players) do
  local player = minetest.get_player_by_name(playerName)
  if player:get_player_control()["aux1"] and player:get_player_control()["up"] then
    players[playerName]["shouldSprint"] = true
    ...

https://github.com/GunshipPenguin/sprin ... sprint.lua
 

User avatar
paramat
Developer
 
Posts: 3580
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

Re: Post your modding questions here

by paramat » Fri Feb 12, 2016 02:19

Perhaps use a sprint-toggling item with an 'on use' function. Make sure to enable sprinting by editing per-player physics.
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

what this error means?

by BrunoMine » Fri Feb 12, 2016 12:42

My code
Code: Select all
status_tp = {}
...
status_tp[name] = false

Debug
Code: Select all
attempt to index upvalue 'status_tp' (a boolean value)
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: what this error means?

by kaeza » Fri Feb 12, 2016 15:12

BrunoMine wrote:My code
Code: Select all
status_tp = {}
...
status_tp[name] = false

Debug
Code: Select all
attempt to index upvalue 'status_tp' (a boolean value)

More context needed.
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
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: what this error means?

by BrunoMine » Fri Feb 12, 2016 15:36

kaeza wrote:More context needed.

My Code
Code: Select all
local status_tp = {}

func_status_tp = function(name)
   if name then
      status_tp[name] = false
   end
end

minetest.register_on_joinplayer(function(player)
   local name = player:get_player_name()
   status_tp[name] = true
   minetest.after(3, func_status_tp, name)
end)
Last edited by BrunoMine on Fri Feb 12, 2016 15:49, edited 1 time in total.
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Fri Feb 12, 2016 15:44

Try putting `local` before `status_tp = {}`. If it works, you may have another mod somewhere setting the global `status_tp` to other value.

EDIT: You should always use locals unless really needed (e.g. exported API), and then only use a single global named the same as your mod. The console/log should print a warning about unintended globals if you set the log level high enough.
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
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Fri Feb 12, 2016 15:48

kaeza wrote:Try putting `local` before `status_tp = {}`. If it works, you may have another mod somewhere setting the global `status_tp` to other value.

In fact I put it (but save this information).
I tried to use nil and not false.
Code: Select all
status_tp[name] = nil

apparently it works
 

User avatar
rubenwardy
Moderator
 
Posts: 6013
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Fri Feb 12, 2016 15:50

That is not a solution. You should still be able to set = false.

You must still make things local. The only global variable you make should be a table with the same name as your mod.
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Fri Feb 12, 2016 16:06

rubenwardy wrote:That is not a solution. You should still be able to set = false.

You must still make things local. The only global variable you make should be a table with the same name as your mod.


Okay. This is my code. It is correct?
Code: Select all
local status_tp = {}

local func_status_tp = function(name)
   if name then
      status_tp[name] = false
   end
end

minetest.register_on_joinplayer(function(player)
   local name = player:get_player_name()
   status_tp[name] = true
   minetest.after(3, func_status_tp, name)
end)
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Fri Feb 12, 2016 16:10

Does it cause errors now?
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
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 02:36

kaeza wrote:Does it cause errors now?

Continued to occur the error.
HELP!
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Sat Feb 13, 2016 03:18

It works for me. Only other thing I can think of is that the error is not in that file. Make sure you're editing the correct file and not a duplicate somewhere.
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
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 13:58

kaeza wrote:It works for me. Only other thing I can think of is that the error is not in that file. Make sure you're editing the correct file and not a duplicate somewhere.


Apparently I have to show the whole script.

Code: Select all
--
-- Mod Ant-Cracker
--
-- Ant-Fast
--

local diretrizes = anti_cracker.diretrizes.anti_fast

-- calculating variables
local dist_max_andando = (diretrizes.tempo_att*diretrizes.velocidade_max)
local dist_max_andando_suspeito = (diretrizes.tempo_att_suspeitos*diretrizes.velocidade_max)
local dist_verif_emissor = diretrizes.dist_verif + dist_max_andando + 1
local dist_verif_receptor = diretrizes.dist_verif
local spawn = minetest.setting_get_pos("static_spawnpoint") or {x=0,y=0,z=0}
local blocos_receptor = diretrizes.blocos_tp_livre
local blocos_emissor = diretrizes.blocos_tp_emissor
for i, bloco in ipairs(diretrizes.blocos_tp_livre) do
   table.insert(blocos_emissor, bloco)
end

local ultima_pos = {}
local status_tp = {}
local acumulador = {}
local suspeitos = {}

local cancelar_suspeito = function(name)
   if name then
      local Nsuspeitos = {}
      for pname, n in pairs(suspeitos) do
         if name ~= pname then
            Nsuspeitos[pname] = suspeitos[pname]
         end
      end
      suspeitos = Nsuspeitos
   end
end

-- Updates the position of the player
local timer = 0
minetest.register_globalstep(function(dtime)
   timer = timer + dtime
   if timer >= diretrizes.tempo_att then
      timer = 0
      for name, n in pairs(ultima_pos) do
         local player = minetest.get_player_by_name(name)
         if player and not suspeitos[name] then
            ultima_pos[name] = player:getpos()
         end
      end
   end
end)

-- Updates the position of the player suspects
local timer2 = 0
minetest.register_globalstep(function(dtime)
   timer2 = timer2 + dtime
   if timer2 >= diretrizes.tempo_att_suspeitos then
      timer2 = 0
      for name, n in pairs(suspeitos) do
         local player = minetest.get_player_by_name(name)
         if player and ultima_pos[name] then
            ultima_pos[name] = player:getpos()
         end
      end
   end
end)

local zerar_status_tp = function(name)
   if name then
      status_tp[name] = false
   end
end

local zerar_acumulador = function(name)
   if name then
      acumulador[name] = false
   end
end

minetest.register_on_cheat(function(player, cheat)
   if cheat.type == "moved_too_fast" then
      if player then
         local name = player:get_player_name()
         if acumulador[name] == false and status_tp[name] == false then
            acumulador[name] = true
            minetest.after(2, zerar_acumulador, name)
            if minetest.check_player_privs(name, {teleport=true}) then
               return
            end
            -- Checks if the player is too far from your last recorded position
            local pos = player:getpos()
            local dist = dist_max_andando
            if suspeitos[name] then
               dist = dist_max_andando_suspeito
            end
            if ultima_pos[name].x+dist < pos.x
               or ultima_pos[name].x-dist > pos.x
               or ultima_pos[name].z+dist < pos.z
               or ultima_pos[name].z-dist > pos.z
               or ultima_pos[name].y+dist < pos.y
            then
               -- Verifica se tem blocos de legitimem a distancia tao longa como um tp
               if not minetest.find_node_near(ultima_pos[name], dist_verif_emissor, blocos_emissor)
                  or not minetest.find_node_near(player:getpos(), dist_verif_receptor, blocos_receptor)
               then
                  -- O teleport nao foi legitimo (ou o movimento pareceu muito rapido)
                  local msg = "Aparentemente "..name.." moveu-se rapido demais."
                  minetest.chat_send_player(name, "[Ant-Cracker] Medida 2 | Aparentemente correste rapido demais.")
                  tomar_medida(name, 2, msg)
                  player:setpos(ultima_pos[name])
               else
                  -- O teleport foi legitimo
                  status_tp = true
                  minetest.after(2, zerar_status_tp, name)
                  ultima_pos[name] = player:getpos()
               end
            else
               -- O movimento pareceu rapido
               if not suspeitos[name] then
                  suspeitos[name] = true
                  minetest.after(20, cancelar_suspeito, name)
               end
            end
         end
      end
   end
end)

-- Inserts record players entering the server
minetest.register_on_joinplayer(function(player)
   if player then
      local name = player:get_player_name()
      ultima_pos[name] = (player:getpos())
      status_tp[name] = false
      acumulador[name] = false
   end
end)

-- Clear the variables when the player leaves the server
minetest.register_on_leaveplayer(function(player)
   if player then
      local name = player:get_player_name()
      local Nultima_pos = {}
      local Nstatus_tp = {}
      local Nacumulador = {}
      for pname, n in pairs(status_tp) do
         if name ~= pname then
            Nultima_pos[pname] = ultima_pos[pname]
            Nstatus_tp[pname] = status_tp[pname]
            Nacumulador[pname] = acumulador[pname]
         end
      end
      acumulador = Nacumulador
      ultima_pos = Nultima_pos
      status_tp = Nstatus_tp
   end
end)

-- Keeps the player instead of the spawn
minetest.register_on_respawnplayer(function(player)
   if player then
      local pos = player:getpos()
      local name = player:get_player_name()
      if minetest.find_node_near(pos, dist_verif_receptor, blocos_respawn) then
         ultima_pos[name] = pos
         status_tp = true   
         minetest.after(2, zerar_status_tp, name)
      else
         ultima_pos[name] = spawn
      end
   end
end)

-- As vezes o jogador nao vai para o spawn
minetest.register_on_dieplayer(function(player)
   if player then
      local name = player:get_player_name()
      ultima_pos[name] = spawn
      suspeitos[name] = true
      minetest.after(diretrizes.tempo_att, cancelar_suspeito, name)
   end
end)


Debug
Code: Select all
00:44:20: WARNING: Undeclared global variable "blocos_respawn" accessed at ...root/minetest/bin/../mods/anti_cracker/anti_fast.lua:164
2016-02-13 00:54:48: ACTION[Server]: Player TheMiner moved too fast; resetting position
2016-02-13 00:54:50: ERROR[Main]: UNRECOVERABLE error occurred. Stopping server. Please fix the following error:
2016-02-13 00:54:50: ERROR[Main]: Runtime error from mod '' in callback environment_Step(): ...root/minetest/bin/../mods/anti_cracker/anti_fast.lua:69: attempt to index upvalue 'status_tp' (a boolean value)
2016-02-13 00:54:50: ERROR[Main]: stack traceback:
2016-02-13 00:54:50: ERROR[Main]:    ...root/minetest/bin/../mods/anti_cracker/anti_fast.lua:69: in function 'func'
2016-02-13 00:54:50: ERROR[Main]:    /root/minetest/bin/../builtin/game/misc.lua:18: in function 'update_timers'
2016-02-13 00:54:50: ERROR[Main]:    /root/minetest/bin/../builtin/game/misc.lua:50: in function '?'
2016-02-13 00:54:50: ERROR[Main]:    /root/minetest/bin/../builtin/game/register.lua:355: in function </root/minetest/bin/../builtin/game/register.lua:335>

In thread 7fc0c76be7c0:
/root/minetest/src/server.cpp:505: void Server::step(float): A fatal error occurred: Runtime error from mod '' in callback environment_Step(): ...root/minetest/bin/../mods/anti_cracker/anti_fast.lua:69: attempt to index upvalue 'status_tp' (a boolean value)
stack traceback:
   ...root/minetest/bin/../mods/anti_cracker/anti_fast.lua:69: in function 'func'
   /root/minetest/bin/../builtin/game/misc.lua:18: in function 'update_timers'
   /root/minetest/bin/../builtin/game/misc.lua:50: in function '?'
   /root/minetest/bin/../builtin/game/register.lua:355: in function </root/minetest/bin/../builtin/game/register.lua:335>
Debug stacks:
DEBUG STACK FOR THREAD 7fc0b6bfd700:
#0  virtual void* EmergeThread::run()
(Leftover data: #1  MapBlock* ServerMap::loadBlock(v3s16))
(Leftover data: #2  void ServerMap::loadBlock(std::string*, v3s16, MapSector*, bool))
(Leftover data: #3  void ItemStack::deSerialize(std::istream&, IItemDefManager*))
DEBUG STACK FOR THREAD 7fc0b75fe700:
#0  virtual void* CurlFetchThread::run()
DEBUG STACK FOR THREAD 7fc0b7fff700:
#0  virtual void* ServerThread::run()
#1  void Server::Receive()
(Leftover data: #2  void Server::SendBlocks(float))
(Leftover data: #3  void RemoteClient::GetNextBlocks(ServerEnvironment*, EmergeManager*, float, std::vector<PrioritySortedBlockTransfer>&))
(Leftover data: #4  void ItemStack::serialize(std::ostream&) const)
(Leftover data: #5  bool getCraftingResult(Inventory*, ItemStack&, std::vector<ItemStack>&, bool, IGameDef*))
(Leftover data: #6  bool getCraftingResult(Inventory*, ItemStack&, std::vector<ItemStack>&, bool, IGameDef*))
DEBUG STACK FOR THREAD 7fc0c76be7c0:
#0  int main(int, char**)
#1  Dedicated server branch
#2  void dedicated_server_loop(Server&, bool&)
#3  void Server::step(float)
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Post your modding questions here

by kaeza » Sat Feb 13, 2016 14:51

BrunoMine wrote:Apparently I have to show the whole script.

That could have helped a lot.

Line 166:
Code: Select all
status_tp = true   

There's your problem.

EDIT: Also on line 113.
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
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 15:27

BrunoMine wrote:Sorry again.

No problems. Glad that it's solved.
 

amadin
Member
 
Posts: 548
Joined: Tue Jun 16, 2015 16:23

Re: Post your modding questions here

by amadin » Sat Feb 13, 2016 16:02

Hi all. How add thrown snowball and other items? I mean default_snowball.png from default mod.
 

User avatar
BrunoMine
Member
 
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

How genetare map

by BrunoMine » Sat Feb 13, 2016 17:58

Is there any way to generate the map without a present player?
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest