Backsage Posted August 11, 2015 Share Posted August 11, 2015 Hi, today I ran into a problem with dxDrawText again. It shows the text to me, but it's not showing the text to other players! It's doing it again! Client side: function createRound() if (source == SetRoundButton) then if (guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[3]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[4])) then NoTimeLimitNeedsKPToWinNoRespawnLimit = true outputChatBox("You've selected a round with No Time Limit, Needs KP to Win, and no Respawn Limit") -- works elseif (guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and guiCheckBoxGetSelected(GUIEditor.checkbox[4]) and guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[3])) then NoTimeLimitNeedsDPToWinNoRespawnLimit = true outputChatBox("You've selected a round with No Time Limit, Needs DP to Win, and no Respawn Limit") -- works elseif (guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[3]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[4])) then TimeLimitWhoeverGetsTheMostKPWinsNoRespawnLimit = true outputChatBox("You've selected a round with a Time Limit, whoever gets the most KP wins, and no Respawn Limit") -- works elseif (guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and guiCheckBoxGetSelected(GUIEditor.checkbox[3]) and guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[4])) then TimeLimitWhoeverGetsTheMostDPWinsNoRespawnLimit = true outputChatBox("You've selected a round with a Time Limit, whoever gets the most DP wins, and no Respawn Limit") -- works elseif (guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[3]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[4])) then TimeLimitPersonWithTheMostRepawnsLoses = true outputChatBox("You've selected a round with a Time Limit and the person with the most respawns loses") -- works elseif (guiCheckBoxGetSelected(GUIEditor.checkbox[7]) and guiCheckBoxGetSelected(GUIEditor.checkbox[5]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[8]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[6]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[2]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[1]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[3]) and not guiCheckBoxGetSelected(GUIEditor.checkbox[4])) then NoTimeLimitPersonWhoReachesSpecifiedRespawnsLoses = true outputChatBox("You've selected a round with No Time Limit and the person who reaches specified respawns loses") -- works end RoundTimeLimit = tonumber(guiGetText(GUIEditor.edit[1])) RoundRespawnLimit = tonumber(guiGetText(GUIEditor.edit[3])) PaymentsPerKill = tonumber(guiGetText(GUIEditor.edit[4])) NeedsKPToWin = tonumber(guiGetText(GUIEditor.edit[6])) NeedsDPToWin = tonumber(guiGetText(GUIEditor.edit[5])) PlayerTeam1CurrentKP = 0 PlayerTeam2CurrentKP = 0 PlayerTeam1CurrentDP = 0 PlayerTeam2CurrentDP = 0 PlayerTeam1CurrentRespawns = 0 PlayerTeam2CurrentRespawns = 0 end end function round5(attacker) for k, v in ipairs(colshape) do if (isElementWithinColShape(attacker, v) and isElementWithinColShape(source, v)) then playerInCol = true if (TimeLimitPersonWithTheMostRepawnsLoses == true) then if (getElementHealth(source) == 0 and source == player2) then PlayerTeam2CurrentRespawns = PlayerTeam2CurrentRespawns + 1 triggerServerEvent("onRound5Player2Killed", getLocalPlayer(), source, cor) elseif (getElementHealth(source) == 0 and source == player) then PlayerTeam1CurrentRespawns = PlayerTeam1CurrentRespawns + 1 triggerServerEvent("onRound5Player1Killed", getLocalPlayer(), source, cor) end end end end end addEventHandler("onClientPlayerWasted", root, round5) function round5teams(attacker) for k, v in ipairs(colshape) do if (isElementWithinColShape(attacker, v) and isElementWithinColShape(source, v)) then playerInCol = true if (TimeLimitPersonWithTheMostRepawnsLoses == true) then if (getElementHealth(source) == 0 and getPlayerTeam(source) == team) then PlayerTeam2CurrentRespawns = PlayerTeam2CurrentRespawns + 1 triggerServerEvent("onRound5Team2Killed", getLocalPlayer(), source, cor) elseif (getElementHealth(source) == 0 and getPlayerTeam(source) == team2) then PlayerTeam1CurrentRespawns = PlayerTeam1CurrentRespawns + 1 triggerServerEvent("onRound5Team1Killed", getLocalPlayer(), source, cor) end end end end end addEventHandler("onClientPlayerWasted", root, round5teams) function round5alltext() local dim = getElementDimension(localPlayer) for i, v in ipairs (getElementsByType("player")) do if (dim == 1) then dxDrawText("P1 RP: " .. PlayerTeam1CurrentRespawns, 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("P2 RP: " .. PlayerTeam2CurrentRespawns, 767, 358, 940, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) end end end function thisistest(score) addEventHandler("onClientRender", root, round5alltext) end addEvent("round5addtext", true) addEventHandler("round5addtext", root, thisistest) function thisistest2() removeEventHandler("onClientRender", root, round5alltext) end addEvent("round5removetext", true) addEventHandler("round5removetext", root, thisistest2) addCommandHandler("showdx", function() local dim = getElementDimension(localPlayer) for i, v in ipairs (getElementsByType("player")) do if (dim == 1) then triggerServerEvent("onRound5ShowText", getLocalPlayer(), PlayerTeam1CurrentRespawns, PlayerTeam2CurrentRespawns) end end end ) addCommandHandler("removedx", function () local dim = getElementDimension(localPlayer) for i, v in ipairs (getElementsByType("player")) do if (dim == 1) then triggerServerEvent("onRound5RemoveText", getLocalPlayer()) end end end ) Server side: function round5AddText(score1, score2) local dim1players = getElementsInDimension("player", 1) for k, v in ipairs (dim1players) do local text1 = "P1 RP: " local text2 = "P2 RP: " triggerClientEvent(v, "round5addtext", v, text1, text2) end end addEvent("onRound5ShowText", true) addEventHandler("onRound5ShowText", root, round5AddText) function round5RemoveText() local dim1players = getElementsInDimension("player", 1) for k, v in ipairs (dim1players) do triggerClientEvent(v, "round5removetext", v) end end addEvent("onRound5RemoveText", true) addEventHandler("onRound5RemoveText", root, round5RemoveText) function getElementsInDimension(theType,dimension) local elementsInDimension = { } for key, value in ipairs(getElementsByType(theType)) do if getElementDimension(value)==dimension then table.insert(elementsInDimension,value) end end return elementsInDimension end function round5spawnplayer(player, cor) local plrSkin = getElementModel(player) local rndTeleport = math.random(1, #cor) local x, y, z = cor[rndTeleport][1], cor[rndTeleport][2], cor[rndTeleport][3] if player then setTimer( spawnPlayer, 2000, 1, player, x, y, z, 0, plrSkin, 0, 1) end end addEvent("onRound5Player2Killed", true) addEventHandler("onRound5Player2Killed", root, round5spawnplayer) function round5spawnplayer2(player, cor) local plrSkin = getElementModel(player) local rndTeleport = math.random(1, #cor) local x, y, z = cor[rndTeleport][1], cor[rndTeleport][2], cor[rndTeleport][3] if player then setTimer( spawnPlayer, 2000, 1, player, x, y, z, 0, plrSkin, 0, 1) end end addEvent("onRound5Player1Killed", true) addEventHandler("onRound5Player1Killed", root, round5spawnplayer2) function round5spawnplayer3(player, cor) local plrSkin = getElementModel(player) local rndTeleport = math.random(1, #cor) local x, y, z = cor[rndTeleport][1], cor[rndTeleport][2], cor[rndTeleport][3] if player then setTimer( spawnPlayer, 2000, 1, player, x, y, z, 0, plrSkin, 0, 1) end end addEvent("onRound5Team2Killed", true) addEventHandler("onRound5Team2Killed", root, round5spawnplayer3) function round5spawnplayer4(player, cor) local plrSkin = getElementModel(player) local rndTeleport = math.random(1, #cor) local x, y, z = cor[rndTeleport][1], cor[rndTeleport][2], cor[rndTeleport][3] if player then setTimer( spawnPlayer, 2000, 1, player, x, y, z, 0, plrSkin2, 0, 1) end end addEvent("onRound5Team1Killed", true) addEventHandler("onRound5Team1Killed", root, round5spawnplayer4) Link to comment
Backsage Posted August 11, 2015 Author Share Posted August 11, 2015 Yes, they are. It's just, I don't know. It was working a couple days ago. Link to comment
GTX Posted August 11, 2015 Share Posted August 11, 2015 If it was working then I've no idea. Try debugging your code like: for k, v in ipairs(dim1players) do local text1 = "P1 RP: " local text2 = "P2 RP: " outputDebugString("Sent to "..getPlayerName(v)) triggerClientEvent(v, "round5addtext", v, text1, text2) end Link to comment
Etha Posted August 12, 2015 Share Posted August 12, 2015 function round5AddText(score1, score2) local dim1players = getElementsInDimension("player", 1) for k, v in ipairs (dim1players) do local text1 = "P1 RP: " local text2 = "P2 RP: " triggerClientEvent(v, "round5addtext", getRootElement(), text1, text2) end end addEvent("onRound5ShowText", true) addEventHandler("onRound5ShowText", root, round5AddText) function round5RemoveText() local dim1players = getElementsInDimension("player", 1) for k, v in ipairs (dim1players) do triggerClientEvent(v, "round5removetext", getRootElement()) end end addEvent("onRound5RemoveText", true) addEventHandler("onRound5RemoveText", root, round5RemoveText) Link to comment
Backsage Posted August 12, 2015 Author Share Posted August 12, 2015 When a client sets the players and then sets/creates the round and then does /round5showdx, it gives me (the admin) an error in the debugscript: ERROR: tdm-panel/gui30.lua:1712: attempt to concatenate global 'PlayerTeam1CurrentRespawns' (a nil value). And it just spams the debugscript. If that other client was an admin and did /debugscript 3 and me (the admin) did/round5showdx, it would show up in the debugscript. And it doesn't even matter what kind of round the other client side. If someone set a round first, then the text for that round will show up on the other client's screen, even if the other's client's round is different.So it's not showing up because the other client didn't set the round yet. How do I fix this? And Etha, your code didn't work Link to comment
Etha Posted August 12, 2015 Share Posted August 12, 2015 it spams because u wrote here onClientRender function thisistest(score) addEventHandler("onClientRender", root, round5alltext) end addEvent("round5addtext", true) addEventHandler("round5addtext", root, thisistest) here u have very strange check (dim == 1) why ?: function round5alltext() local dim = getElementDimension(localPlayer) for i, v in ipairs (getElementsByType("player")) do if (dim == 1) then dxDrawText("P1 RP: " .. PlayerTeam1CurrentRespawns, 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("P2 RP: " .. PlayerTeam2CurrentRespawns, 767, 358, 940, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) end end end and about error in debugger: what is this PlayerTeam1CurrentRespawns & PlayerTeam2CurrentRespawns in function round5alltext()? u trying concatenate nil value cuz they r undefined solution: add after function createRound()..end this string addEventHandler( "onClientResourceStart", resourceRoot,createRound) after all, u can't concatenate integer values..wrap them via tostring() like as: dxDrawText("P1 RP: " .. tostring(PlayerTeam1CurrentRespawns), 118, 358, 291, 380, tocolor(255, 174, 0, 255), 1.30, "default-bold", "left", "top", false, false, false, false, false) Link to comment
Backsage Posted August 12, 2015 Author Share Posted August 12, 2015 Almost works, except that it shows P1 RP: nil and P2 RP: nil to the other client's screen. Need it to be 0. And the dim == 1 check is to make sure that the text only shows up in that dimension. Edit: I think what I need to do is use onPlayerSpawn server side which will trigger a special event client side that'll add scores and trigger the render. Nvm, I've fixed the bug. 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