scaryface87 Posted May 16, 2015 Posted May 16, 2015 (edited) Hello , I would like to know if its possible to get for example 25% chances that it gonna say You won Also is it possible to get Math.random with words? like it need to random chose a word in a table for example like Lover Badass ? function lotto() outputChatBox("You won!") -- u got 25% chance to get this else you get "you lose" end Edited May 17, 2015 by Guest
Walid Posted May 16, 2015 Posted May 16, 2015 Yes you can use Math.random with words. Example local Table = { -- Words here } word = Table[math.random(#Table)]
scaryface87 Posted May 16, 2015 Author Posted May 16, 2015 Hi im getting an error bad argument #1 to random(interval is empty) local Table = { word1, word2 } function randomizer() word = Table[math.random(#Table)] outputChatBox("Random word "..word.."") end
Walid Posted May 16, 2015 Posted May 16, 2015 simply because (word1 ; word2) a nil value try this local Table = { "Walid", "scaryface87", }
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 Is it posssible to add an commandhandler to edit the tables? for example if i do /addword word3 it will add word 3 and if i do /removeword word3 it will remove it? local Table = { "word1", "word2" } function randomizer() word = Table[math.random(#Table)] outputChatBox("Random word "..word.."") end
WhoAmI Posted May 17, 2015 Posted May 17, 2015 addCommandHandler ( "addword", function ( player, cmd, word ) if word then table.insert ( Table, tostring ( word ) ) end end ) addCommandHandler ( "removeword", function ( player, cmd, word ) if word then for k, v in pairs ( Table ) do if v == word then table.remove ( Table, k ) break end end end end )
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 Is it possible to get all words in the table shown in a gui? (gridlist) i tried the following already but it didnt work : window1 = guiCreateWindow(471, 219, 200, 210, "Words in randomizer", false) guiWindowSetSizable(window1, false) gridlist1 = guiCreateGridList(16, 50, 167, 146, false, window1) local row1 = guiGridListAddRow(gridlist1) local collumn1 = guiGridListAddColumn(gridlist1, "Words", 0.9) guiGridListSetItemText ( gridlist1, row1, collumn1, i dont know wht to put here) -- not ssure if this gonna work , idont know how to call the table in
Walid Posted May 17, 2015 Posted May 17, 2015 you need to use something like that for i, v in pairs (Table) do -- you code here end
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 Hm i dont get what to put after collumn1 then after combining it like this ; for i, v in pairs (Table) do window1 = guiCreateWindow(471, 219, 200, 210, "Words in randomizer", false) guiWindowSetSizable(window1, false) gridlist1 = guiCreateGridList(16, 50, 167, 146, false, window1) local row1 = guiGridListAddRow(gridlist1) local collumn1 = guiGridListAddColumn(gridlist1, "Words", 0.9) guiGridListSetItemText ( gridlist1, row1, collumn1, ) -- not ssure if this gonna work , idont know how to call the table in end
Walid Posted May 17, 2015 Posted May 17, 2015 Example addEventHandler("onClientResourceStart",resourceRoot, function() window1 = guiCreateWindow(471, 219, 200, 210, "Words in randomizer", false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) gridlist1 = guiCreateGridList(16, 50, 167, 146, false, window1) collumn1 = guiGridListAddColumn(gridlist1, "Words", 0.9) end ) function addWordToGridList() for i, v in pairs (Table) do local row = guiGridListAddRow(gridlist1) guiGridListSetItemText (gridlist1, row, collumn1,tostring(v[1]),false, false) end end
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 Hi It didnt work i think i messed someting with splitting it up from client and server Server : local Table = { "word1", "word2" } function randomizer() word = Table[math.random(#Table)] outputChatBox("Random word "..word.."") end addCommandHandler("words",randomizer) function showits() triggerClientEvent(sourcePlayer,"showit",sourcePlayer) end addCommandHandler("showit",showits) function addWordToGridList() for i, v in pairs (Table) do local row = guiGridListAddRow(gridlist1) guiGridListSetItemText (gridlist1, row, collumn1,tostring(v[1]),false, false) end end addCommandHandler ( "addword", function ( player, cmd, word ) if word then table.insert ( Table, tostring ( word ) ) end end ) addCommandHandler ( "removeword", function ( player, cmd, word ) if word then for k, v in pairs ( Table ) do if v == word then table.remove ( Table, k ) break end end end end ) Client : addEventHandler("onClientResourceStart",resourceRoot, function() window1 = guiCreateWindow(471, 219, 200, 210, "Words in randomizer", false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) gridlist1 = guiCreateGridList(16, 50, 167, 146, false, window1) collumn1 = guiGridListAddColumn(gridlist1, "Words", 0.9) end ) function show() guiSetVisible(window1,true) end addEvent("showit",true) addEventHandler("showit",getRootElement(),show)
Walid Posted May 17, 2015 Posted May 17, 2015 (edited) lol are you serious you want to use "guiGridListSetItemText" server side your code is wrong. Edited May 17, 2015 by Guest
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 (edited) Oh i didnt see , i tought it was the commandhandler of /addword , my excuses , trying ur code atm Edited May 17, 2015 by Guest
Walid Posted May 17, 2015 Posted May 17, 2015 Oh i didnt see , i tought it was the commandhandler of /addword , my excuses but its still not working after moving that this how you can fix it -- Server side local Table = { "word1", "word2" } function showits(player) if isElement(player) then triggerClientEvent(player,"showit",player,getWordsTable()) end end addCommandHandler("showit",showits) addCommandHandler ( "addword", function ( player, cmd, word ) if word then table.insert ( Table, tostring ( word ) ) end end ) function randomizer() word = Table[math.random(#Table)] outputChatBox("Random word "..word.."") end addCommandHandler("words",randomizer) addCommandHandler ( "removeword", function ( player, cmd, word ) if word then for k, v in pairs ( Table ) do if v == word then table.remove ( Table, k ) break end end end end ) function getWordsTable() return Table end -- Client side addEventHandler("onClientResourceStart",resourceRoot, function() window1 = guiCreateWindow(471, 219, 200, 210, "Words in randomizer", false) guiWindowSetSizable(window1, false) guiSetVisible(window1,false) gridlist1 = guiCreateGridList(16, 50, 167, 146, false, window1) collumn1 = guiGridListAddColumn(gridlist1, "Words", 0.9) end ) function addWordToGridList(Table) guiSetVisible(window1,true) for i, v in pairs (Table) do local row = guiGridListAddRow(gridlist1) guiGridListSetItemText (gridlist1, row, collumn1,tostring(v[1]),false, false) end end addEvent("showit",true) addEventHandler("showit",root,addWordToGridList)
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 (edited) The gui isnt showing up Edited May 17, 2015 by Guest
Walid Posted May 17, 2015 Posted May 17, 2015 The gui isnt showing up -- Check your resolution or put the window "center" function addWordToGridList(Table) guiSetVisible(window1,true) showCursor(true) for i, v in pairs (Table) do local row = guiGridListAddRow(gridlist1) guiGridListSetItemText (gridlist1, row, collumn1,tostring(v[1]),false, false) end end addEvent("showit",true) addEventHandler("showit",root,addWordToGridList)
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 Ok that worked ouut , now it says nil nil in the gridlist
Walid Posted May 17, 2015 Posted May 17, 2015 Ok that worked ouut , now it says nil nil in the gridlist post debugscript here
Walid Posted May 17, 2015 Posted May 17, 2015 Nothing is in the debugscript Try this without using getWordsTable function function showits(player) Words = {} if isElement(player) then for i , v in pairs (Table) local word = tostring(v[1]) table.insert(Words,{word}) end triggerClientEvent(player,"showit",player,Words) end addCommandHandler("showit",showits)
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 server lua 10: do exepted near local lua 10 (line 10) is local word = tostring(v[1])
Walid Posted May 17, 2015 Posted May 17, 2015 (edited) server lua 10: do exepted near locallua 10 (line 10) is local word = tostring(v[1]) function showits(player) Words = {} for i , v in pairs (Table) do local word = tostring(v) table.insert(Words,{word}) end triggerClientEvent(player,"showit",player,Words) end addCommandHandler("showit",showits) Edit Edited May 17, 2015 by Guest
scaryface87 Posted May 17, 2015 Author Posted May 17, 2015 still showing nill in the gridlist , no debugerrors
Walid Posted May 17, 2015 Posted May 17, 2015 (edited) still showing nill in the gridlist , no debugerrors Copy and past my code . i edit it it's working fine Edited May 17, 2015 by Guest
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