Posted 19 February 2014 - 08:15 AM
Hello!
I have been working on a workshop on a private server… I've been using openperipheral proximity sensors to see where players are compared to 9x9 rooms…
But…
If we say that i have like:
3 9x9 rooms and 1 computer with wireless modem on bottom, and sensor on top.
These computers sends all the data from the sensor( only distance from the offset, roomname, and playername ) to the monitor computer
The monitor computer receives everything, and calculates in which distance to which room is closest…
( so like if the player is 10 blocks away from sensor 1, and 9 blocks away from sensor 2, then the monitor
computer would say that the player is in the room defined by sensor 2's computer.)
So far i've made the sensors send all revelant data, from players within its range and got the monitor computer to listen to the messages…
But… how do i actually calculate ( from several modem- transmissions ) in which message keeps the closest approach?
my sensor codes
pastebin or:
and my current monitorcomputer code: i know this is not on a monitor.. but i can't since my friends minecraft crashes, caused by monitor.screen.drawWitdh….. (yup… videocard outdated)
pastebin or:
I've been trying to use math.min… but it doesnt support tables.. so i dont know how to do this
Thanks in advance….
I hope I'll be able to solve this
I have been working on a workshop on a private server… I've been using openperipheral proximity sensors to see where players are compared to 9x9 rooms…
But…
If we say that i have like:
3 9x9 rooms and 1 computer with wireless modem on bottom, and sensor on top.
These computers sends all the data from the sensor( only distance from the offset, roomname, and playername ) to the monitor computer
The monitor computer receives everything, and calculates in which distance to which room is closest…
( so like if the player is 10 blocks away from sensor 1, and 9 blocks away from sensor 2, then the monitor
computer would say that the player is in the room defined by sensor 2's computer.)
So far i've made the sensors send all revelant data, from players within its range and got the monitor computer to listen to the messages…
But… how do i actually calculate ( from several modem- transmissions ) in which message keeps the closest approach?
my sensor codes
pastebin or:
Spoiler
os.loadAPI("ocs/apis/sensor")
-----
local THIS={}
THIS["Room"]="WR-Room";
local offset = {
X = 0,
Y = 1,
Z = 0
}
function distance(pos)
local xd = pos.X - offset.X
local yd = pos.Y - offset.Y
local zd = pos.Z - offset.Z
return math.sqrt(
xd*xd+yd*yd+zd*zd
)
end
local modem = peripheral.wrap("bottom")
modem.open(25565)
local Current_username_=false
local playerDist={}
local proximity = sensor.wrap("top")
while true do
local signal = false
local targets = proximity.getTargets()
if targets then
for player, infotable in pairs(targets) do
if infotable.IsPlayer then
Current_username_=player
playerDist[player]={}
term.setCursorPos(1,1)term.clearLine() term.setCursorPos(1,1)print("Current User: "..player)
local targetDetail=proximity.getTargetDetails(player)
if targetDetail then
for info, data in pairs(targetDetail) do
if type(data)=='table' then
if tostring(info)=="Position" then
if not data then else
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
playerDist[Current_username_]={["room"]=THIS["Room"];["name"]=Current_username_;["distance"]=tostring(distance(data))}
print("Distance: "..playerDist[Current_username_]["distance"].." blocks")
modem.transmit(25565,25565,textutils.serialize(playerDist))
end
end
else
end
end
end
end
end
end
sleep(0)
end
and my current monitorcomputer code: i know this is not on a monitor.. but i can't since my friends minecraft crashes, caused by monitor.screen.drawWitdh….. (yup… videocard outdated)
pastebin or:
Spoiler
--- Monitor --- Showing were players are in the workshop.
modem = peripheral.wrap("left")
modem.open(25565)-- listening
local roomData={
--[[
[player_name]={
[room]=distance
}
--]]
}
local test = {
[1]={1;5;7;2;}
}
print(math.min(test[1][1],test[1][2],test[1][3]))
while true do
local event, side, senderChannel,receiverChannel,message, distance = os.pullEvent("modem_message")
if senderChannel==25565 then
local playerdat=textutils.unserialize(message)
for k,v in pairs(playerdat) do
local dist = v["distance"]
local room = v["room"]
roomData[k]={[room]=dist;};
end
end
for k,v in pairs(roomData) do
for i,j in pairs(v) do
local smallestDist=math.min(j)
print(tostring(smallestDist))
for k,v in pairs(roomData) do
end
roomData[k]["exactRoom"]=realRoom
end
end
end
I've been trying to use math.min… but it doesnt support tables.. so i dont know how to do this
Thanks in advance….
I hope I'll be able to solve this
Edited on 19 February 2014 - 09:33 AM