Get POS using LUA cmd Mod

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Get POS using LUA cmd Mod

by basil60 » Mon Dec 21, 2015 10:24

Hi

I'm trying to wrote a script that I can use within the LuaCmd mod, that allows me to place air blocks underfoot, while ever the Y co-ord is greater than 2. As a way of creating flat terrain!!!

I have this as a plan:
/lua
get current position
x1 = ? --x
y1 = ? --y
z1 = ? --z

while y1 > 2 do
minetest.set_node({x=x1, y=y1, z=z1}, {name="default:air"})
end


Should I treat the get current position as a list to get the y co-ord, or is there a better way? I'm both a LUA noob and a Minestest noob.

Basil
 

User avatar
Minetestforfun
Member
 
Posts: 936
Joined: Tue Aug 05, 2014 14:09
Location: On earth
GitHub: Darcidride
IRC: Darcidride + MinetestForFun
In-game: Darcidride + MinetestForFun
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Re: Get POS using LUA cmd Mod

by basil60 » Thu Dec 24, 2015 00:05

Had a look at that...but is there a difference between the mod, and "real code"???

For example, I tried some simple stuff (using methods from the Wiki) like:
/lua
minetest.get_gametime(); invalid command: lua
/lua
print(minetest.get_gametime()); invalid command: lua
/lua
inv = minetest.get_inventory({type="player", name="singleplayer"})
print(inv) invalid command: lua

I'd have assumed these may have worked (wrongly obviously). Can someone steer me in the correct direction please?
 

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: Get POS using LUA cmd Mod

by kaeza » Thu Dec 24, 2015 00:52

basil60 wrote:invalid command: lua

Are you sure you have LuaCmd enabled? Type `/mods` and see if it's there. From that message, it looks like it's not enabled (or maybe the command is not called `/lua`?).

As to your question, you need to get a player object (for example, with `minetest.get_player_by_name`), then call `getpos` on the returned player object.

I'll leave the coding to you as this is quite a nice and easy example to get started.
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
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Re: Get POS using LUA cmd Mod

by basil60 » Thu Dec 24, 2015 04:36

So, I ran
Code: Select all
/lua
player = minetest.get_player_by_name("singleplayer")
player:setpos({x=0, y=0, z=0})

It returned Invalid command:Lua

I also ran:
Code: Select all
/lua a = 2
print(a)

It returned "2".
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest