access level server
#1
Posted 03 April 2013 - 06:39 AM
my computers have player detectors form mics peripheral. They send a message to the server
and the server is supposed to tell the computer the player's access level.
but i am having problems whit finding out the sec level of the players.
Would anyone be so kind to point me in the right direction?
#2
Posted 03 April 2013 - 07:00 AM
playerLevels = { -- Table of players with security level.
[1] = {player1 = 1},
[2] = {player2 = 2},
}
local id, message = rednet.receive()
local level = nil
for i = 1, #playerLevels do -- Loop through the table
if playerLevels[i][message] then -- Check if the player's name is valid
level = i
break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
end
end
if level then -- To check if level is nil or not
if stuff then
-- do stuff
end
end
I hope I helped
Edit: Providied some more info
Edited by Engineer, 03 April 2013 - 07:16 AM.
#3
Posted 03 April 2013 - 07:01 AM
Lasere123456, on 03 April 2013 - 06:39 AM, said:
I totally agree with you if you haven't defined it
Simply create a table like this:
local secLevel = {
Player1 = 1,
Player2 = 3,
Player3 = 2
}
print(secLevel.Player1)
--Or
print(secLevel["Player1"])
Edit: Again too late? wow, I don't have any luck today
Edit2:
local secLevel = {
Player1 = 1,
Player2 = 3,
Player3 = 2
}
while true do
local id, player = rednet.receive()
rednet.send(id, secLevel[player] or 0)
end
#4
Posted 03 April 2013 - 07:06 AM
Engineer, on 03 April 2013 - 07:00 AM, said:
playerLevels = { -- Table of players with security level.
player1 = 1,
player2 = 2,
}
-- [...]
for i = 1, #playerLevels do -- Loop through the table
if playerLevels[message] then -- Check if the player's name is valid
level = i
break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
end
end
--[...]
I don't think that'll work.
If you set a string as an index for a table you can't adress it with a number
(So #tab won't work)
#5
Posted 03 April 2013 - 07:12 AM
#6
Posted 03 April 2013 - 07:16 AM
JokerRH, on 03 April 2013 - 07:06 AM, said:
Engineer, on 03 April 2013 - 07:00 AM, said:
playerLevels = { -- Table of players with security level.
player1 = 1,
player2 = 2,
}
-- [...]
for i = 1, #playerLevels do -- Loop through the table
if playerLevels[message] then -- Check if the player's name is valid
level = i
break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
end
end
--[...]
I don't think that'll work.
If you set a string as an index for a table you can't adress it with a number
(So #tab won't work)
#7
Posted 03 April 2013 - 08:11 AM
http://pastebin.com/eutyzbdf
then i sendt it this message ("rednet.send(117, "_TheSettler_", true )
but it only returns the sender id and message not the accsess level...
#8
Posted 03 April 2013 - 08:17 AM
And where is true part for in your rednet.send(--blabla)?
Or are you using channels?
Edit: Oops.. Try this one: http://pastebin.com/1bJCSNQC
Edited by Engineer, 03 April 2013 - 08:20 AM.
#9
Posted 03 April 2013 - 08:29 AM
(added the missing s in access, still don't work)
#11
Posted 03 April 2013 - 08:40 AM
#12
Posted 03 April 2013 - 09:25 AM
server
rednet.open("back")
local secLevel = {
Player1 = 1,
Player2 = 3,
Player3 = 2
}
while true do
local id, player = rednet.receive()
rednet.send(id, secLevel[player] or 0)
end
client:
local id, player = ...
id = tonumber(id)
rednet.open("right")
rednet.send(id, player)
local _, lvl = rednet.receive()
print(lvl)
Save both to a file on your computer (for example the serverprogramm to server and the clientprogram to client)
then type
server
to run the server and
client <id> <player>
(id is the id of your server computer)
to run the client
#13
Posted 03 April 2013 - 09:32 AM
Edit: Sorry for the program previously not to work. I was like: Herp-a-Derp!
#14
Posted 03 April 2013 - 09:45 AM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











