30 posts
Posted 03 April 2013 - 07:39 AM
ok, so so i am trying to make a server for my computers to confirm players accsess level.
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?
1522 posts
Location
The Netherlands
Posted 03 April 2013 - 08:00 AM
So you send the playername to the server? If so you could do something like this:
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 on 03 April 2013 - 06:16 AM
148 posts
Posted 03 April 2013 - 08:01 AM
but i am having problems whit finding out the sec level of the players.
I totally agree with you if you haven't defined it :P/>
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 :D/>
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
148 posts
Posted 03 April 2013 - 08:06 AM
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 :P/>
(So #tab won't work)
30 posts
Posted 03 April 2013 - 08:12 AM
thanks
1522 posts
Location
The Netherlands
Posted 03 April 2013 - 08:16 AM
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 :P/>
(So #tab won't work)
Now it does!:P/>
30 posts
Posted 03 April 2013 - 09:11 AM
OK, so i used the code you gave me and made this:
http://pastebin.com/eutyzbdfthen i sendt it this message ("rednet.send(117, "_TheSettler_", true )
but it only returns the sender id and message not the accsess level…
1522 posts
Location
The Netherlands
Posted 03 April 2013 - 09:17 AM
Try this code:
http://pastebin.com/7dLwVKwsAnd 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 on 03 April 2013 - 07:20 AM
30 posts
Posted 03 April 2013 - 09:29 AM
Error on line 26
(added the missing s in access, still don't work)
1522 posts
Location
The Netherlands
Posted 03 April 2013 - 09:36 AM
Lol Im an herp-a-derp today:
http://pastebin.com/Rz1r8e36
30 posts
Posted 03 April 2013 - 09:40 AM
error on line 28…. nill value error
148 posts
Posted 03 April 2013 - 10:25 AM
Try this:
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
1522 posts
Location
The Netherlands
Posted 03 April 2013 - 10:32 AM
Damn now I feel like a nub again. Its better to use jokeRH's way. I modified it a little bit; ["name"] are neccesary because name can start with a number. This works, I have tested it.
pastebin.com/uf3gq346Edit: Sorry for the program previously not to work. I was like: Herp-a-Derp!
30 posts
Posted 03 April 2013 - 10:45 AM
Thanks to all of you.