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 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.
 

Hybrid Dog
Member
 
Posts: 2460
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
screenshot_20160210_223810.png (48.47 KiB) Viewed 1661 times
 

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

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: 67
Joined: Thu Jun 28, 2012 13:48

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?
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
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
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: 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: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

what this error means?

by BrunoMine » Fri Feb 12, 2016 12:42

My 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
status_tp = {}
...
status_tp[name] = false

Debug
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
attempt to index upvalue 'status_tp' (a boolean value)
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
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
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
status_tp = {}
...
status_tp[name] = false

Debug
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
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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: what this error means?

by BrunoMine » Fri Feb 12, 2016 15:36

kaeza wrote:More context needed.

My 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
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
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 » 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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
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.
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
status_tp[name] = nil

apparently it works
 

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 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: 902
Joined: Thu Apr 25, 2013 17:29
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?
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 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
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 » 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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
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
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 » 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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
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.

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
--
-- 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
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
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
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 » Sat Feb 13, 2016 14:51

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

That could have helped a lot.

Line 166:
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
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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
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: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

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: 902
Joined: Thu Apr 25, 2013 17:29
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?
 

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

Re: Post your modding questions here

by Hybrid Dog » Sat Feb 13, 2016 18:32

amadin, try the snow mod
BrunoMine, try minetest.emerge_area https://github.com/minetest/minetest/bl ... .txt#L2055
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 18:55

Hybrid Dog wrote:amadin, try the snow mod
BrunoMine, try minetest.emerge_area https://github.com/minetest/minetest/bl ... .txt#L2055


Then
minetest.emerge_area(pos, pos)
generates 'pos' ?

This does not cause distortions on the map?
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 20:23

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 get_a_node(pos)
   local node = minetest.get_node(pos)
   if node.name == "ignore" then
      minetest.emerge_area(pos, pos)
      node = minetest.get_node(pos)
   end
   return node
end

This is not working.
The node is still not 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 » Sat Feb 13, 2016 22:05

Emerge area is asynchronous - it may take a while to actually load (maybe a second or so)
Use minetest.after
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sat Feb 13, 2016 23:43

rubenwardy wrote:Emerge area is asynchronous - it may take a while to actually load (maybe a second or so)
Use minetest.after

This does not occur (even in 10 seconds).
Test.
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 emerge_a_node = function(pos)
   minetest.emerge_area(pos, pos)
   minetest.chat_send_all("emerging")
end

local get_a_node = function(pos)
   local node = minetest.get_node(pos)
   if node.name == "ignore" then
      minetest.get_voxel_manip():read_from_map(pos, pos)
      node = minetest.get_node(pos)
   end
   minetest.chat_send_all("result "..node.name)
end

local random_pos = {x=math.random(-5000, 5000), y=50, z=math.random(-5000, 5000)}
minetest.after(10, emerge_a_node, random_pos)
minetest.after(20, get_a_node, random_pos)
 

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 » Sun Feb 14, 2016 02:27

I'm sure I'm just missing the obvious but is it possible to only allow people with a privilege to place certain blocks. I'm trying to modify the MyArcade mod so only people with a priv can place the blocks, but anybody can still play the game, I want to stop griefers.

The trouble is that the games all place as a schematic, which is also placed when starting the game to give a fresh playing field. I figured out how to require a priv to place and play, but I would like anybody to be able to refresh the game and only people with the priv to place I've tried this code for placing, but it 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
   on_place = function(pos, node, placer, itemstack, pointed_thing)
      local player = minetest.get_player_by_name(placer)
      if minetest.check_player_privs(player, {myarcade = true}) then
      if can_access ~= true then
         return true
      end

I keep getting an error about get_player_name and things like that.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sun Feb 14, 2016 02:44

Nathan.S wrote:I'm sure I'm just missing the obvious but is it possible to only allow people with a privilege to place certain blocks. I'm trying to modify the MyArcade mod so only people with a priv can place the blocks, but anybody can still play the game, I want to stop griefers.

The trouble is that the games all place as a schematic, which is also placed when starting the game to give a fresh playing field. I figured out how to require a priv to place and play, but I would like anybody to be able to refresh the game and only people with the priv to place I've tried this code for placing, but it 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
   on_place = function(pos, node, placer, itemstack, pointed_thing)
      local player = minetest.get_player_by_name(placer)
      if minetest.check_player_privs(player, {myarcade = true}) then
      if can_access ~= true then
         return true
      end

I keep getting an error about get_player_name and things like that.

Did you mean
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
on_place = function(pos, node, placer, itemstack, pointed_thing)
   if minetest.check_player_privs(placer, {myarcade = true}) then
      itemstack:take_item()
   end
   return itemstack
end,
 

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 » Sun Feb 14, 2016 03:07

placer is already a player object, not a name. check_player_privs takes a name, not a player object.

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
on_place = function(pos, node, placer, itemstack, pointed_thing)
       if placer and minetest.check_player_privs(placer:get_player_name(), {myarcade = true}) then
              if can_access ~= true then
                     return true
              end
       end
end
Last edited by rubenwardy on Sun Feb 14, 2016 03:08, edited 1 time in total.
 

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 » Sun Feb 14, 2016 03:08

Just tried that, it gives this error.
attempt to call method 'get_player_name' (a nil value)
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 » Sun Feb 14, 2016 03:11

Your parameters are wrong, it should be one of:

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
on_place = func(itemstack, placer, pointed_thing)
after_place_node = func(pos, placer, itemstack, pointed_thing)


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
 on_place = function(itemstack, placer, pointed_thing)
           if placer and minetest.check_player_privs(placer:get_player_name(), {myarcade = true}) then
                  if can_access ~= true then
                         return true
                  end
           end
end


and what is can_access?
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 46 guests

cron