MRXBBC Posted April 28, 2020 Share Posted April 28, 2020 (edited) function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end function test (source) Key = generateString(12) outputChatBox ( "Generated string was: " .. Key, root, 0, 255, 0 ) end addCommandHandler("test",teste ) Hello Community, I would like some help with the following code, I would like the generated string to be saved in a table, and then checked if it exists or not Edited April 28, 2020 by MRXBBC Link to comment
Moderators Patrick Posted April 28, 2020 Moderators Share Posted April 28, 2020 (edited) I don't understand exactly what you want, but: local KEYS = {} local string = generateString(12) KEYS[string] = true -- save string to table if KEYS[string] then -- check, is string in the table print("Key exists in table!") end Edited April 28, 2020 by Patrick 1 Link to comment
MRXBBC Posted April 28, 2020 Author Share Posted April 28, 2020 (edited) 33 minutes ago, Patrick said: I don't understand exactly what you want, but: local KEYS = {} local string = generateString(12) KEYS[string] = true -- save string to table if KEYS[string] then -- check, is string in the table print("Key exists in table!") end I did so, I would like the player to use the command together with the generated key function teste (source) KEYS[Key] = true Key = generateString(12) outputChatBox ( "Generated string was: " .. Key, root, 0, 255, 0 ) end addCommandHandler("teste",teste ) addCommandHandler("Gen", function(keyuser) if KEYS[Key] then outputChatBox ( "You Key: " .. Keys[Key], root, 0, 255, 0 ) else outputChatBox ( "not", root, 0, 255, 0 ) end end) Edited April 28, 2020 by MRXBBC Link to comment
-Ilker. Posted April 28, 2020 Share Posted April 28, 2020 (edited) local data = { Keys = { } , PlayerKey = { } } ; local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( player ) local Key = generateString(12) data.Keys[Key] = true; data.PlayerKey[player] = Key; outputChatBox("Your Code : "..tostring(Key),player) end ) ; addCommandHandler ( "Gen" , function ( player ) if ( data.PlayerKey[player] ) then outputChatBox("Your Key : "..tostring(data.PlayerKey[player]),player,0,255,0,true) else outputChatBox("You don't have key",player,255,0,0,true) end end ) ; Edited April 28, 2020 by -Ilker. 1 Link to comment
MRXBBC Posted April 28, 2020 Author Share Posted April 28, 2020 17 minutes ago, -Ilker. said: local data = { Keys = { } , PlayerKey = { } } ; function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( player ) local Key = generateString(12) data.Keys[Key] = true; data.PlayerKey[player] = Key; outputChatBox("Your Code : "..tostring(Key),player) end ) ; addCommandHandler ( "Gen" , function ( player ) if ( data.PlayerKey[player] ) then outputChatBox("Your Key : "..tostring(data.PlayerKey[player]),player,0,255,0,true) else outputChatBox("You don't have key",player,255,0,0,true) end end ) ; is this just for the player who generated a key? or can any other player use it? Link to comment
-Ilker. Posted April 28, 2020 Share Posted April 28, 2020 each player has a special key Link to comment
MRXBBC Posted April 28, 2020 Author Share Posted April 28, 2020 4 minutes ago, -Ilker. said: each player has a special key I only wanted one player to generate the key and pass it on to others Link to comment
-Ilker. Posted April 28, 2020 Share Posted April 28, 2020 local data = { Keys = { } } ; local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( ) local Key = generateString(12) data.Keys[Key] = true; outputChatBox(tostring(Key).." this is a new key",root) end ) ; addCommandHandler ( "Gen" , function ( ) if ( data.Keys ) then outputChatBox("You Key : "..tostring(data.Keys),root,0,255,0,true) else outputChatBox("not",root,255,0,0,true) end end ) ; 1 Link to comment
MRXBBC Posted April 28, 2020 Author Share Posted April 28, 2020 Just now, -Ilker. said: local data = { Keys = { } } ; local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( ) local Key = generateString(12) data.Keys[Key] = true; outputChatBox(tostring(Key).." this is a new key",root) end ) ; addCommandHandler ( "Gen" , function ( ) if ( data.Keys ) then outputChatBox("You Key : "..tostring(data.Keys),root,0,255,0,true) else outputChatBox("not",root,255,0,0,true) end end ) ; thanx bro Link to comment
MRXBBC Posted April 28, 2020 Author Share Posted April 28, 2020 18 minutes ago, -Ilker. said: Np . returned You Key: table: 0x55ecae718cf0 Link to comment
-Ilker. Posted April 28, 2020 Share Posted April 28, 2020 6 minutes ago, MRXBBC said: returned You Key: table: 0x55ecae718cf0 yeah i'm sorry , you can use this value = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( player ) local Key = generateString(12) value = Key outputChatBox(Key.." this is a new key",root) end ) ; addCommandHandler ( "Gen" , function ( player ) if ( value ~= nil ) then outputChatBox("You Key : "..tostring(value),root,0,255,0,true) else outputChatBox("not",player,255,0,0,true) end end ) ; 1 Link to comment
MRXBBC Posted April 30, 2020 Author Share Posted April 30, 2020 On 28/04/2020 at 16:50, -Ilker. said: yeah i'm sorry , you can use this value = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end addCommandHandler ( "teste" , function ( player ) local Key = generateString(12) value = Key outputChatBox(Key.." this is a new key",root) end ) ; addCommandHandler ( "Gen" , function ( player ) if ( value ~= nil ) then outputChatBox("You Key : "..tostring(value),root,0,255,0,true) else outputChatBox("not",player,255,0,0,true) end end ) ; Oops, brother, I implemented the code this way, but I wanted to define a validity for the keys, would you? --server-- value = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end function Teste ( ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then local Key = generateString(12) value = Key outputChatBox(Key.."New Key",root) else outputChatBox("Out",root) end end addEvent ("Gen:Set", true) addEventHandler ("Gen:Set", root, Teste) addCommandHandler ( "User" , function ( player ) if ( value ~= nil ) then outputChatBox("Your Key: "..tostring(value),source,0,255,0,true) setElementData ( player, "Vip", "Unlock" ) else outputChatBox("key does not exist",player,255,0,0,true) end end ) ; Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now