Page 1 of 2
[Mod] Xray [xray] - need some help

Posted:
Wed Sep 26, 2012 01:08
by InfinityProject
Hey guys I have developed a mod that works a lot like the famous Minecraft mod. On activation all stone will become invisible, making it easy to see the important stuff like mese and iron.
V0.3 adds a xray priv to be able to use the commands.
/off is currently not working so the only way to change back to normal stone is to edit the abm. Only use on test worlds until noted.
Note: The transformation may take a while. This is a beta version and will be sped up hopefully without lag in the future.
Screenshot:
[img=xray]https://dl.dropbox.com/u/82668184/screenshot_788007.png[/img]
How to use:
/xray on
Turns stone invisible.
/xray off
Turns stone back to normal.
Depends: default
Download latest:
https://dl.dropbox.com/u/82668184/xray%200.3.zipDownload V0.1:
https://dl.dropbox.com/u/82668184/xray%200.1.zipDownload V0.2:
https://dl.dropbox.com/u/82668184/xray%200.2.zipDownload V0.3:
https://dl.dropbox.com/u/82668184/xray%200.3.zipLicense: Code GPLv3 Textures WTFPL

Posted:
Wed Sep 26, 2012 01:24
by cornernote
nice idea what if a player is standing nearby without x-ray? will they still see the invisible nodes?

Posted:
Wed Sep 26, 2012 02:07
by InfinityProject
The way this works is the server replaces all stone nodes with my invisible stone through an abm. So yes, on a server anyone can see through stone when activated. Right now the priv needed is 'shout' but I may change it to 'server; so that server admins can use it on servers.

Posted:
Wed Sep 26, 2012 03:53
by InfinityProject
Noticed an error in code. /xray off would never work. Fixed.

Posted:
Wed Sep 26, 2012 05:38
by Calinou
Suggestions:
- require "xray" privilege
- make stone transform into a pointable, waklable node with "airlike" drawtype
- make /xray a toggle command for simplicity's sake, if possible?

Posted:
Wed Sep 26, 2012 14:24
by InfinityProject
Calinou wrote:Suggestions:
- require "xray" privilege
- make stone transform into a pointable, waklable node with "airlike" drawtype
- make /xray a toggle command for simplicity's sake, if possible?
I did 2 of the above. I'm trying to get it to work with one command.

Posted:
Wed Sep 26, 2012 18:00
by InfinityProject
The xray off command isn't working. I know the abm is working because when xray is on and you place stone, it automatically turns into xray stone. When xray is off stone placed stays normal stone. Some help?
I divided it into 2 abms to see if it would work but it still didn't. Here's 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_abm({
nodenames = {"default:stone", "xray:stone"},
interval = 0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if XRAY_MODE == 1 then
if node.name == "default:stone" then
minetest.env:add_node(pos,{name="xray:stone"})
end
end
end
end
})
minetest.register_abm({
nodenames = {"xray:stone", "default:stone"},
interval = 0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if XRAY_MODE == 2 then
if node.name == "xray:stone" then
minetest.env:add_node(pos,{name="default:stone"})
end
end
end
end
})

Posted:
Wed Sep 26, 2012 19:52
by cornernote
it works for me, i tidied the code a little, and added some output so i can see what its doing, but it worked as you pasted it (except for an extra "end" you have)
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_abm({
nodenames = {"default:stone"},
interval = 0,
chance = 1,
action = function(pos, node)
if XRAY_MODE == 1 then
if node.name == "default:stone" then
print("turning default:stone to xray:stone at "..dump(pos))
minetest.env:add_node(pos,{name="xray:stone"})
end
end
end
})
minetest.register_abm({
nodenames = {"xray:stone"},
interval = 0,
chance = 1,
action = function(pos, node)
if XRAY_MODE == 2 then
if node.name == "xray:stone" then
print("turning xray:stone to default:stone at "..dump(pos))
minetest.env:add_node(pos,{name="default:stone"})
end
end
end
})

Posted:
Wed Sep 26, 2012 20:45
by cornernote
try this, it uses register_globalstep() instead of an ABM. this means it only effects the player who has xray, and it has a range that you can configure. the nodes change back to stone on their own once the player is out of range.
seems to work really nicely, very responsive, very little lag.
edit: got sick of repasting code here, pushed to github:
https://github.com/cornernote/minetest-xray

Posted:
Wed Sep 26, 2012 23:53
by InfinityProject
I honestly don't like the idea of it changing back in forth when in and out of range. But I do love the idea of using it for a single person using xray.

Posted:
Thu Sep 27, 2012 00:21
by cornernote
no worries, take what you like from the code, look forward to seeing the end result

Posted:
Thu Sep 27, 2012 13:14
by cornernote
i edited the xray:stone to be a nodebox (still fill size), but it ment that it actually turned invisible, instead of being an invisible "portal" that can see through to the sky on the other side.
when you set the range to 5-10, its actually really responsive. (i left the auto-convert back to stone in mine)

Posted:
Fri Sep 28, 2012 00:03
by InfinityProject
Looks good. Need help. I fixed /xray off for me but now the two commands counteract each other. If both commands have been activated before the stone will flash back and forth between normal and invisible. I know I need to use nil, but I am still new to coding and don't know how to use it. Can someone help?

Posted:
Fri Sep 28, 2012 00:50
by cornernote
If both commands are activated, what would you like to happen?

Posted:
Fri Sep 28, 2012 00:51
by InfinityProject
I want only one to work at a time, like when xray(off) is activated xray(on) is deactivated.

Posted:
Fri Sep 28, 2012 01:07
by cornernote
Can you shoe me your current code? Or are you using 0.3 version?

Posted:
Fri Sep 28, 2012 01:08
by InfinityProject
The only thing I've changed is xray(1) to xray(on) and xray(2) to xray(off).

Posted:
Fri Sep 28, 2012 01:45
by cornernote
I cant see how it's running both things if you have 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_abm({
nodenames = {"default:stone", "xray:stone"},
interval = 0,
chance = 4,
action = function(pos, node, active_object_count, active_object_count_wider)
if XRAY_MODE == 1 then --<< means it should only do this...
if node.name == "default:stone" then
minetest.env:add_node(pos,{name="xray:stone"})
elseif XRAY_MODE == 2 then --<< OR this
if node.name == "xray:stone" then
minetest.env:add_node(pos,{name="xray:stone"})
end
end
end
end
})
Also, you should use minetest.register_globalstep() instead of an abm. it fixes the lag issue.
If you don't want them to change back on their own, then remove the call to xray.restore(), and use an ABM to restore the nodes when the xray is off.

Posted:
Fri Sep 28, 2012 14:42
by MasterGollum
I was developing a stone layer generator and this mod was just cool to find the layers I was creating, but it didn't work fine to me. Even if the stones are transparent, many nodes are not visible until the invisible stone is removed. When I turned the xray off the invisible stones, kept being invisibles, so I messed up a huge area of my map :) luckily it was a world I was using for test purposes ;)

Posted:
Fri Sep 28, 2012 18:46
by irksomeduck
Thankyou so much

Posted:
Sat Sep 29, 2012 00:50
by cornernote
MasterGollum wrote:I was developing a stone layer generator and this mod was just cool to find the layers I was creating, but it didn't work fine to me. Even if the stones are transparent, many nodes are not visible until the invisible stone is removed. When I turned the xray off the invisible stones, kept being invisibles, so I messed up a huge area of my map :) luckily it was a world I was using for test purposes ;)
My version fixes that:
https://github.com/cornernote/minetest-xrayTry that until InfinityProject releases his next version.

Posted:
Sat Sep 29, 2012 01:03
by MasterGollum
Wow cool, thank you so much

Posted:
Sat Sep 29, 2012 16:55
by InfinityProject
You were obviously using an older version for the not able to see through stone glitch. The /off is glitchy and I'm working on a way to fix it.

Posted:
Sat Sep 29, 2012 19:19
by irksomeduck
Doesn't work... I mean it runs and loads it, understands the commands, but just doesn't work. Nothing goes invisible.

Posted:
Sun Sep 30, 2012 14:53
by InfinityProject
irksomeduck wrote:Doesn't work... I mean it runs and loads it, understands the commands, but just doesn't work. Nothing goes invisible.
Are you using mine or cornernote's version? The only problem with mine is the /off. His doesn't work for me; it just creates lag.

Posted:
Mon Oct 01, 2012 02:42
by InfinityProject
Can someone help?
I keep getting "unexpected symbol near ==" at the xray(on) == nil
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
if
XRAY_MODE == off
then
xray(on) == nil
end
if
XRAY_MODE == on
then
xray(off) == nil
end

Posted:
Mon Oct 01, 2012 03:58
by VanessaE
Use two == signs for an if, but use only one = sign for an assignment. In otherwords, it should be:
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
if
XRAY_MODE == off
then
xray(on) = nil
(similarly for the xray(off) part as well)

Posted:
Mon Oct 01, 2012 09:37
by cornernote
InfinityProject wrote:Can someone help?
I keep getting "unexpected symbol near ==" at the xray(on) == nil
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
if
XRAY_MODE == off
then
xray(on) == nil
end
if
XRAY_MODE == on
then
xray(off) == nil
end
xray() is a function, you cant assign a variable to it

Posted:
Mon Oct 08, 2012 07:35
by Calinou
Some suggestion: hide some more common blocks: dirt, grass, leaves (but not trees), sand (and desert sand/stone) and gravel (set them to an invisible node different than invisible stone, and it should revert just fine, make the invisible gravel fall). :)
Also, why is the ABM's chance set to 4?
Disabling xray doesn't turn stone back to normal for me.

Posted:
Mon Oct 08, 2012 22:31
by InfinityProject
Calinou wrote:Some suggestion: hide some more common blocks: dirt, grass, leaves (but not trees), sand (and desert sand/stone) and gravel (set them to an invisible node different than invisible stone, and it should revert just fine, make the invisible gravel fall). :)
I actually have gravel done and yes it does fall.
As for the abm I just chose a random number.
And yes, /xray off isn't working. For some reason the 2 commands counteract each other so so stone goes back and forth from invisible to visible. I need to find a way to turn a function off when the other one is on but I don't know how to do that.
Could you help?
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 function xray(mode)
XRAY_MODE = mode
end
minetest.register_chatcommand("xray", {
params = "<mode>",
description = "Make stone invisible.",
privs = {xray=true},
func = function(name, param)
if param == 'on' then xray(on)
minetest.chat_send_player(name, "Xray turned on.")
elseif param == 'off' then xray(off)
minetest.chat_send_player(name, "Xray turned off.")
else
minetest.chat_send_player(name, "Please enter 'on' or 'off'.")
end
end,
})
minetest.register_abm({
nodenames = {"default:stone", "xray:stone", "default:gravel", "xray:gravel"},
interval = 0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if XRAY_MODE == on and XRAY_ON ~= nil then
if node.name == "default:stone" then
minetest.env:add_node(pos,{name="xray:stone"})
elseif node.name == "default:gravel" then
minetest.env:add_node(pos,{name="xray:gravel"})
elseif XRAY_MODE == off and XRAY_OFF ~= nil then
if node.name == "xray:stone" then
minetest.env:add_node(pos,{name="default:stone"})
elseif node.name == "xray:gravel" then
minetest.env:add_node(pos,{name="default:gravel"})
end
end
end
end
})