MAB Posted February 10, 2016 Share Posted February 10, 2016 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
tosfera Posted February 10, 2016 Share Posted February 10, 2016 You're using root to trigger the function towards the client. Try to use getRandomPlayer. Root never really worked for me either.. no idea what the hell the problem is with that. Link to comment
MAB Posted February 10, 2016 Author Share Posted February 10, 2016 You're using root to trigger the function towards the client. Try to use getRandomPlayer. Root never really worked for me either.. no idea what the hell the problem is with that. nah.. by thanks for the try Lindesy Stirling Link to comment
Moderators IIYAMA Posted February 10, 2016 Moderators Share Posted February 10, 2016 Where are your debug lines? .............................................................................................................................................................. Not even one? 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
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