Jump to content

commandhandler to add/remove words?


Recommended Posts

Posted (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 by Guest
Posted

Yes you can use Math.random with words.

Example

local Table = { 
 -- Words here  
} 
  
word = Table[math.random(#Table)] 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 
  

Posted

simply because (word1 ; word2) a nil value

9b4faf180f.png

try this

local Table = { 
"Walid", 
"scaryface87", 
} 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 
  

Posted
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 
) 

Posted

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  
  

Posted

you need to use something like that

for i, v in pairs (Table) do  
-- you code here 
end  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 
  
  

Posted

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  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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) 
  
  

Posted (edited)

lol are you serious you want to use "guiGridListSetItemText" server side your code is wrong.

Edited by Guest

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
Ok that worked ouut ,

now it says nil nil in the gridlist

post debugscript here

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted (edited)
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

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted (edited)
still showing nill in the gridlist , no debugerrors

Copy and past my code . i edit it

it's working fine

Edited by Guest

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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...