Jump to content

Trigger & Table problem


MAB

Recommended Posts

I am triggering an client event to add some strings to a table.. not working.. or let me by more clear..

ty is not found always...

Always says "Name Joined the game." but never "Name left the game."

that is because ty is not found so what to do?

NOTICE: tested by increasing the time of the timer

client:

  
local sx,sy = guiGetScreenSize() 
local joins = {} 
  
function delete2(n,t) 
    for i=1,#joins do 
        if joins[i].name == n and joins[i].ty == t then 
           table.remove(joins,i) 
        end 
    end 
end 
  
function addOnQuit(n,t) 
table.insert(joins,{name = n, ty = t}) 
setTimer(delete2,3000,1,n,t) 
end 
addEvent("addone2",true) 
addEventHandler("addone2",root,addOnQuit) 
  
function draw() 
    for i=1,#joins do 
        if joins[i].ty then 
           local ty = joins[i].ty 
           dxDrawImage(10,(sy/2)+(i*10),16,16,"images/quit.png") 
           dxDrawText(joins[i].n.." left the game. ["..ty.."]",30,(sy/2)+(i*10)+3,nil,nil,tocolor(255,255,255,255),1,"default-bold") 
        else 
           local name = joins[i].name 
           dxDrawImage(10,(sy/2)+(i*10),16,16,"images/join.png") 
           dxDrawText(name.." joined the game.",30,(sy/2)+(i*10)+3,nil,nil,tocolor(255,255,255,255),1,"default-bold") 
        end 
    end 
end 
addEventHandler("onClientRender",root,draw) 

server:

function trigger2(t) 
local name = getPlayerName(source) 
triggerClientEvent("addone2",root,name,t) 
end 
addEventHandler("onPlayerQuit",root,trigger2) 

Link to comment
  • Moderators

Where are your debug lines? ..............................................................................................................................................................

Not even one?

youre-fired.jpg

source: http://focusedshooter.com/2015/05/25/ge ... -so-wrong/

function trigger2(t) 
    local name = getPlayerName(source) 
    outputDebugString("serverside name: " .. name .. ", t: " .. t) -- debug 
    triggerClientEvent("addone2",resourceRoot,name,t) 
end 
addEventHandler("onPlayerQuit",root,trigger2) 

function addOnQuit(n,t) 
    outputDebugString("clientside n: " .. n .. ", t: " .. t) -- debug 
    table.insert(joins,{name = n, ty = t}) 
    setTimer(delete2,3000,1,n,t) 
end 
addEvent("addone2",true) 
addEventHandler("addone2",root,addOnQuit) 

function draw() 
    -- 
    local joinersCount = 0 -- debug 
    local quitersCount = 0 -- debug 
    -- 
    for i=1,#joins do 
        if joins[i].ty then 
            local ty = joins[i].ty 
            dxDrawImage(10,(sy/2)+(i*10),16,16,"images/quit.png") 
            dxDrawText(joins[i].n.." left the game. ["..ty.."]",30,(sy/2)+(i*10)+3,nil,nil,tocolor(255,255,255,255),1,"default-bold") 
            -- 
            quitersCount = quitersCount+1 -- debug 
            -- 
        else 
            local name = joins[i].name 
            dxDrawImage(10,(sy/2)+(i*10),16,16,"images/join.png") 
            dxDrawText(name.." joined the game.",30,(sy/2)+(i*10)+3,nil,nil,tocolor(255,255,255,255),1,"default-bold") 
            -- 
            joinersCount = joinersCount+1 -- debug 
            -- 
        end 
    end 
    -- 
    dxDrawText("joinersCount: " .. joinersCount .. ", quitersCount: " .. quitersCount, 300, 300) -- debug 
    -- 
end 
addEventHandler("onClientRender",root,draw) 

function delete2(n,t) 
    for i=1,#joins do 
        if joins[i].name == n and joins[i].ty == t then 
            outputDebugString("item found and will be removed from table, n: " .. n .. ", t: " .. t) -- debug 
            table.remove(joins,i) 
            break -- BREAK IT!!!! OMG!!!!!!!!!!!!!!!!!!!!!!!!!! 
        end 
    end 
end 

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