Jump to content

commandhandler to add/remove words?


Recommended Posts

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 by Guest
Link to comment

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 
  

Link to comment
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 
) 

Link to comment

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  
  

Link to comment

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 
  
  

Link to comment

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  

Link to comment

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) 
  
  

Link to comment
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) 

Link to comment
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) 

Link to comment
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) 

Link to comment
server lua 10: do exepted near local

lua 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 by Guest
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...