Negriukas Posted August 20, 2014 Posted August 20, 2014 Hello guys, I'm creating my own chatbubbles for my server, And i'm facing some kind of errors which i can't exactly understand, My code was working fine til i added the typing check, which it check when player is typing or if console is active then add a chatbubble showing ("Typing!"), Here is my client side code local messageToDraw = {} local chattingPlayers = {} local chatBubbleFor = {} local hideOwn local showTime local characterAddition local maxBubbles local showTheBubbles = true function income(message,messagetype) if source ~= getLocalPlayer() or not hideOwn then if messagetype == 2 then if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then addPlayerChatBubble(source,message,messagetype) end elseif messagetype == 1 then addPlayerChatBubble(source,message,messagetype) elseif messagetype == "typing" then addPlayerChatBubble(source,"Typing!","typing") else addPlayerChatBubble(source,message,messagetype) end end end function addPlayerChatBubble(source,message,messagetype) local notfirst = false for i,p in ipairs(messageToDraw) do if p[1] == source then p[4] = p[4] + 1 notfirst = true end end local infotable = {source,message,messagetype,0} table.insert(messageToDraw,infotable) setElementData(source, "chatbubblesTyping", true, false) if messagetype ~= "typing" then hidePlayerTypingBubble(source) setTimer(deletePlayerChatBubble, 10000, 1, {source,message,messagetype} ) end if not notfirst then setTimer(deletePlayerChatBubble,showTime + (#message * characterAddition),1,infotable) end end function deletePlayerChatBubble(infotable) for i,p in ipairs(messageToDraw) do if p[1] == infotable[1] and p[2] == infotable[2] then for i2,p2 in ipairs(messageToDraw) do if p2[1] == p[1] and p[4] - p2[4] == 1 then setTimer(deletePlayerChatBubble,showTime + (#p2[2] * characterAddition),1,p2) end end table.remove(messageToDraw,i) break end end end function getTextsToRemove() for i,p in ipairs(messageToDraw) do if p[1] == source then deletePlayerChatBubble(p) end end end addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) function renderTheDisplay() if showTheBubbles then for i,p in ipairs(messageToDraw) do if isElement(p[1]) then if getElementHealth(p[1]) > 0 then local camPosXl, camPosYl, camPosZl = getPedBonePosition (p[1], 6) local camPosXr, camPosYr, camPosZr = getPedBonePosition (p[1], 7) local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 local cx,cy,cz = getCameraMatrix() local px,py,pz = getElementPosition(p[1]) local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) local posx,posy = getScreenFromWorldPosition(x,y,z+0.050*distance+0.10) local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() local elementtoignore2 = getPedOccupiedVehicle(p[1]) or p[1] if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxBubbles or p[4] < maxBubbles ) then -- change this when multiple ignored elements can be specified local width = dxGetTextWidth(p[2],1,"default-bold") dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 5,19,tocolor(0,0,0,255)) dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 11,19,tocolor(0,0,0,40)) dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 15,17,tocolor(0,0,0,255)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 19,17,tocolor(0,0,0,40)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) local r,g,b = 255,255,255 if p[3] == 2 then r,g,b = 154, 254, 46 elseif p[3] == 1 then r,g,b = 254,46,154 end dxDrawText(p[2],posx - (0.5 * width),posy - (p[4] * 20),posx - (0.5 * width),posy - (p[4] * 20),tocolor(r,g,b,255),1,"default-bold","left","top",false,false,false) end end end end end end addEventHandler("onClientRender",getRootElement(),renderTheDisplay) function getServerSettings() triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) function saveSettings(settings) showTime = settings[1] characterAddition = settings[2] maxBubbles = settings[3] hideOwn = settings[4] addEvent("onChatbubblesMessageIncome",true) addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) end addEvent("onBubbleSettingsReturn",true) addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) function setPlayerTyping() if (isChatBoxInputActive() or isConsoleActive()) and not typing then triggerServerEvent("onPlayerStartTyping", localPlayer) typing = true end if not (isChatBoxInputActive() or isConsoleActive()) and typing then triggerServerEvent("onPlayerFinishTyping", localPlayer) typing = false end end setTimer(setPlayerTyping, 50, 0) function showPlayerTypingBubble() if source ~= getLocalPlayer() or not hideOwn then addPlayerChatBubble(source, "Typing!", "typing") end end addEvent("onPlayerStartTyping", true) addEventHandler("onPlayerStartTyping", root, showPlayerTypingBubble) function hidePlayerTypingBubble(me) if not source then source = me end deletePlayerChatBubble({ source = source, message = "Typing!", messagetype = "typing" }) end addEvent("onPlayerFinishTyping", true) addEvent("onClientPlayerChat", true) addEventHandler("onPlayerFinishTyping", root, hidePlayerTypingBubble) addEventHandler("onClientPlayerChat", root, hidePlayerTypingBubble) function updateList(newEntry, newStatus) chattingPlayers[newEntry] = newStatus if(not chatBubbleFor[newEntry]) then showPlayerTypingBubble(localPlayer) end hidePlayerTypingBubble(localPlayer) end addEvent("updateChatList", true) addEventHandler ( "updateChatList", getRootElement(), updateList ) ERROR: chatbubbles/client:76:attempt to compare number with boolean
Anubhav Posted August 20, 2014 Posted August 20, 2014 local messageToDraw = {} local chattingPlayers = {} local chatBubbleFor = {} local hideOwn local showTime local characterAddition local maxBubbles local showTheBubbles = true function income(message,messagetype) if source ~= getLocalPlayer() or not hideOwn then if messagetype == 2 then if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then addPlayerChatBubble(source,message,messagetype) end elseif messagetype == 1 then addPlayerChatBubble(source,message,messagetype) elseif messagetype == "typing" then addPlayerChatBubble(source,"Typing!","typing") else addPlayerChatBubble(source,message,messagetype) end end end function addPlayerChatBubble(source,message,messagetype) local notfirst = false for i,p in ipairs(messageToDraw) do if p[1] == source then p[4] = p[4] + 1 notfirst = true end end local infotable = {source,message,messagetype,0} table.insert(messageToDraw,infotable) setElementData(source, "chatbubblesTyping", true, false) if messagetype ~= "typing" then hidePlayerTypingBubble(source) setTimer(deletePlayerChatBubble, 10000, 1, {source,message,messagetype} ) end if not notfirst then setTimer(deletePlayerChatBubble,showTime + (#message * characterAddition),1,infotable) end end function deletePlayerChatBubble(infotable) for i,p in ipairs(messageToDraw) do if p[1] == infotable[1] and p[2] == infotable[2] then for i2,p2 in ipairs(messageToDraw) do if p2[1] == p[1] and p[4] - p2[4] == 1 then setTimer(deletePlayerChatBubble,showTime + (#p2[2] * characterAddition),1,p2) end end table.remove(messageToDraw,i) break end end end function getTextsToRemove() for i,p in ipairs(messageToDraw) do if p[1] == source then deletePlayerChatBubble(p) end end end addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) function renderTheDisplay() if showTheBubbles then for i,p in ipairs(messageToDraw) do if isElement(p[1]) then local camPosXl, camPosYl, camPosZl = getPedBonePosition (p[1], 6) local camPosXr, camPosYr, camPosZr = getPedBonePosition (p[1], 7) local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 local cx,cy,cz = getCameraMatrix() local px,py,pz = getElementPosition(p[1]) local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) local posx,posy = getScreenFromWorldPosition(x,y,z+0.050*distance+0.10) local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() local elementtoignore2 = getPedOccupiedVehicle(p[1]) or p[1] if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxBubbles or p[4] < maxBubbles ) then -- change this when multiple ignored elements can be specified local width = dxGetTextWidth(p[2],1,"default-bold") dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 5,19,tocolor(0,0,0,255)) dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 11,19,tocolor(0,0,0,40)) dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 15,17,tocolor(0,0,0,255)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 19,17,tocolor(0,0,0,40)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) local r,g,b = 255,255,255 if p[3] == 2 then r,g,b = 154, 254, 46 elseif p[3] == 1 then r,g,b = 254,46,154 end dxDrawText(p[2],posx - (0.5 * width),posy - (p[4] * 20),posx - (0.5 * width),posy - (p[4] * 20),tocolor(r,g,b,255),1,"default-bold","left","top",false,false,false) end end end end end addEventHandler("onClientRender",getRootElement(),renderTheDisplay) function getServerSettings() triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) function saveSettings(settings) showTime = settings[1] characterAddition = settings[2] maxBubbles = settings[3] hideOwn = settings[4] addEvent("onChatbubblesMessageIncome",true) addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) end addEvent("onBubbleSettingsReturn",true) addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) function setPlayerTyping() if (isChatBoxInputActive() or isConsoleActive()) and not typing then triggerServerEvent("onPlayerStartTyping", localPlayer) typing = true end if not (isChatBoxInputActive() or isConsoleActive()) and typing then triggerServerEvent("onPlayerFinishTyping", localPlayer) typing = false end end setTimer(setPlayerTyping, 50, 0) function showPlayerTypingBubble() if source ~= getLocalPlayer() or not hideOwn then addPlayerChatBubble(source, "Typing!", "typing") end end addEvent("onPlayerStartTyping", true) addEventHandler("onPlayerStartTyping", root, showPlayerTypingBubble) function hidePlayerTypingBubble(me) if not source then source = me end deletePlayerChatBubble({ source = source, message = "Typing!", messagetype = "typing" }) end addEvent("onPlayerFinishTyping", true) addEvent("onClientPlayerChat", true) addEventHandler("onPlayerFinishTyping", root, hidePlayerTypingBubble) addEventHandler("onClientPlayerChat", root, hidePlayerTypingBubble) function updateList(newEntry, newStatus) chattingPlayers[newEntry] = newStatus if(not chatBubbleFor[newEntry]) then showPlayerTypingBubble(localPlayer) end hidePlayerTypingBubble(localPlayer) end addEvent("updateChatList", true) addEventHandler ( "updateChatList", getRootElement(), updateList )
-.Paradox.- Posted August 20, 2014 Posted August 20, 2014 local messageToDraw = {} local chattingPlayers = {} local chatBubbleFor = {} local hideOwn local showTime local characterAddition local maxBubbles local showTheBubbles = true function income(message,messagetype) if source ~= getLocalPlayer() or not hideOwn then if messagetype == 2 then if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then addPlayerChatBubble(source,message,messagetype) end elseif messagetype == 1 then addPlayerChatBubble(source,message,messagetype) elseif messagetype == "typing" then addPlayerChatBubble(source,"Typing!","typing") else addPlayerChatBubble(source,message,messagetype) end end end function addPlayerChatBubble(source,message,messagetype) local notfirst = false for i,p in ipairs(messageToDraw) do if p[1] == source then p[4] = p[4] + 1 notfirst = true end end local infotable = {source,message,messagetype,0} table.insert(messageToDraw,infotable) setElementData(source, "chatbubblesTyping", true, false) if messagetype ~= "typing" then hidePlayerTypingBubble(source) setTimer(deletePlayerChatBubble, 10000, 1, {source,message,messagetype} ) end if not notfirst then setTimer(deletePlayerChatBubble,showTime + (#message * characterAddition),1,infotable) end end function deletePlayerChatBubble(infotable) for i,p in ipairs(messageToDraw) do if p[1] == infotable[1] and p[2] == infotable[2] then for i2,p2 in ipairs(messageToDraw) do if p2[1] == p[1] and p[4] - p2[4] == 1 then setTimer(deletePlayerChatBubble,showTime + (#p2[2] * characterAddition),1,p2) end end table.remove(messageToDraw,i) break end end end function getTextsToRemove() for i,p in ipairs(messageToDraw) do if p[1] == source then deletePlayerChatBubble(p) end end end addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) function renderTheDisplay() if showTheBubbles then for i,p in ipairs(messageToDraw) do if isElement(p[1]) then local camPosXl, camPosYl, camPosZl = getPedBonePosition (p[1], 6) local camPosXr, camPosYr, camPosZr = getPedBonePosition (p[1], 7) local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 local cx,cy,cz = getCameraMatrix() local px,py,pz = getElementPosition(p[1]) local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) local posx,posy = getScreenFromWorldPosition(x,y,z+0.050*distance+0.10) local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() local elementtoignore2 = getPedOccupiedVehicle(p[1]) or p[1] if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxBubbles or p[4] < maxBubbles ) then -- change this when multiple ignored elements can be specified local width = dxGetTextWidth(p[2],1,"default-bold") dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 5,19,tocolor(0,0,0,255)) dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 11,19,tocolor(0,0,0,40)) dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 15,17,tocolor(0,0,0,255)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 19,17,tocolor(0,0,0,40)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) local r,g,b = 255,255,255 if p[3] == 2 then r,g,b = 154, 254, 46 elseif p[3] == 1 then r,g,b = 254,46,154 end dxDrawText(p[2],posx - (0.5 * width),posy - (p[4] * 20),posx - (0.5 * width),posy - (p[4] * 20),tocolor(r,g,b,255),1,"default-bold","left","top",false,false,false) end end end end end addEventHandler("onClientRender",getRootElement(),renderTheDisplay) function getServerSettings() triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) function saveSettings(settings) showTime = settings[1] characterAddition = settings[2] maxBubbles = settings[3] hideOwn = settings[4] addEvent("onChatbubblesMessageIncome",true) addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) end addEvent("onBubbleSettingsReturn",true) addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) function setPlayerTyping() if (isChatBoxInputActive() or isConsoleActive()) and not typing then triggerServerEvent("onPlayerStartTyping", localPlayer) typing = true end if not (isChatBoxInputActive() or isConsoleActive()) and typing then triggerServerEvent("onPlayerFinishTyping", localPlayer) typing = false end end setTimer(setPlayerTyping, 50, 0) function showPlayerTypingBubble() if source ~= getLocalPlayer() or not hideOwn then addPlayerChatBubble(source, "Typing!", "typing") end end addEvent("onPlayerStartTyping", true) addEventHandler("onPlayerStartTyping", root, showPlayerTypingBubble) function hidePlayerTypingBubble(me) if not source then source = me end deletePlayerChatBubble({ source = source, message = "Typing!", messagetype = "typing" }) end addEvent("onPlayerFinishTyping", true) addEvent("onClientPlayerChat", true) addEventHandler("onPlayerFinishTyping", root, hidePlayerTypingBubble) addEventHandler("onClientPlayerChat", root, hidePlayerTypingBubble) function updateList(newEntry, newStatus) chattingPlayers[newEntry] = newStatus if(not chatBubbleFor[newEntry]) then showPlayerTypingBubble(localPlayer) end hidePlayerTypingBubble(localPlayer) end addEvent("updateChatList", true) addEventHandler ( "updateChatList", getRootElement(), updateList ) I think removing that line will attempt to perform arithmetic on a boolean value and getPedBonePosition will return false; Bad pointer..
Anubhav Posted August 20, 2014 Posted August 20, 2014 local messageToDraw = {} local chattingPlayers = {} local chatBubbleFor = {} local hideOwn local showTime local characterAddition local maxBubbles local showTheBubbles = true function income(message,messagetype) if source ~= getLocalPlayer() or not hideOwn then if messagetype == 2 then if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then addPlayerChatBubble(source,message,messagetype) end elseif messagetype == 1 then addPlayerChatBubble(source,message,messagetype) elseif messagetype == "typing" then addPlayerChatBubble(source,"Typing!","typing") else addPlayerChatBubble(source,message,messagetype) end end end function addPlayerChatBubble(source,message,messagetype) local notfirst = false for i,p in ipairs(messageToDraw) do if p[1] == source then p[4] = p[4] + 1 notfirst = true end end local infotable = {source,message,messagetype,0} table.insert(messageToDraw,infotable) setElementData(source, "chatbubblesTyping", true, false) if messagetype ~= "typing" then hidePlayerTypingBubble(source) setTimer(deletePlayerChatBubble, 10000, 1, {source,message,messagetype} ) end if not notfirst then setTimer(deletePlayerChatBubble,showTime + (#message * characterAddition),1,infotable) end end function deletePlayerChatBubble(infotable) for i,p in ipairs(messageToDraw) do if p[1] == infotable[1] and p[2] == infotable[2] then for i2,p2 in ipairs(messageToDraw) do if p2[1] == p[1] and p[4] - p2[4] == 1 then setTimer(deletePlayerChatBubble,showTime + (#p2[2] * characterAddition),1,p2) end end table.remove(messageToDraw,i) break end end end function getTextsToRemove() for i,p in ipairs(messageToDraw) do if p[1] == source then deletePlayerChatBubble(p) end end end addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) function renderTheDisplay() if showTheBubbles then for i,p in ipairs(messageToDraw) do if isElement(p[1]) then if isPedDead(p[1]) then return end local camPosXl, camPosYl, camPosZl = getPedBonePosition (p[1], 6) local camPosXr, camPosYr, camPosZr = getPedBonePosition (p[1], 7) local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 local cx,cy,cz = getCameraMatrix() local px,py,pz = getElementPosition(p[1]) local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) local posx,posy = getScreenFromWorldPosition(x,y,z+0.050*distance+0.10) local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() local elementtoignore2 = getPedOccupiedVehicle(p[1]) or p[1] if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxBubbles or p[4] < maxBubbles ) then -- change this when multiple ignored elements can be specified local width = dxGetTextWidth(p[2],1,"default-bold") dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 5,19,tocolor(0,0,0,255)) dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 11,19,tocolor(0,0,0,40)) dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 15,17,tocolor(0,0,0,255)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 19,17,tocolor(0,0,0,40)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) local r,g,b = 255,255,255 if p[3] == 2 then r,g,b = 154, 254, 46 elseif p[3] == 1 then r,g,b = 254,46,154 end dxDrawText(p[2],posx - (0.5 * width),posy - (p[4] * 20),posx - (0.5 * width),posy - (p[4] * 20),tocolor(r,g,b,255),1,"default-bold","left","top",false,false,false) end end end end end addEventHandler("onClientRender",getRootElement(),renderTheDisplay) function getServerSettings() triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) function saveSettings(settings) showTime = settings[1] characterAddition = settings[2] maxBubbles = settings[3] hideOwn = settings[4] addEvent("onChatbubblesMessageIncome",true) addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) end addEvent("onBubbleSettingsReturn",true) addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) function setPlayerTyping() if (isChatBoxInputActive() or isConsoleActive()) and not typing then triggerServerEvent("onPlayerStartTyping", localPlayer) typing = true end if not (isChatBoxInputActive() or isConsoleActive()) and typing then triggerServerEvent("onPlayerFinishTyping", localPlayer) typing = false end end setTimer(setPlayerTyping, 50, 0) function showPlayerTypingBubble() if source ~= getLocalPlayer() or not hideOwn then addPlayerChatBubble(source, "Typing!", "typing") end end addEvent("onPlayerStartTyping", true) addEventHandler("onPlayerStartTyping", root, showPlayerTypingBubble) function hidePlayerTypingBubble(me) if not source then source = me end deletePlayerChatBubble({ source = source, message = "Typing!", messagetype = "typing" }) end addEvent("onPlayerFinishTyping", true) addEvent("onClientPlayerChat", true) addEventHandler("onPlayerFinishTyping", root, hidePlayerTypingBubble) addEventHandler("onClientPlayerChat", root, hidePlayerTypingBubble) function updateList(newEntry, newStatus) chattingPlayers[newEntry] = newStatus if(not chatBubbleFor[newEntry]) then showPlayerTypingBubble(localPlayer) end hidePlayerTypingBubble(localPlayer) end addEvent("updateChatList", true) addEventHandler ( "updateChatList", getRootElement(), updateList )
Negriukas Posted August 20, 2014 Author Posted August 20, 2014 local messageToDraw = {} local chattingPlayers = {} local chatBubbleFor = {} local hideOwn local showTime local characterAddition local maxBubbles local showTheBubbles = true function income(message,messagetype) if source ~= getLocalPlayer() or not hideOwn then if messagetype == 2 then if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then addPlayerChatBubble(source,message,messagetype) end elseif messagetype == 1 then addPlayerChatBubble(source,message,messagetype) elseif messagetype == "typing" then addPlayerChatBubble(source,"Typing!","typing") else addPlayerChatBubble(source,message,messagetype) end end end function addPlayerChatBubble(source,message,messagetype) local notfirst = false for i,p in ipairs(messageToDraw) do if p[1] == source then p[4] = p[4] + 1 notfirst = true end end local infotable = {source,message,messagetype,0} table.insert(messageToDraw,infotable) setElementData(source, "chatbubblesTyping", true, false) if messagetype ~= "typing" then hidePlayerTypingBubble(source) setTimer(deletePlayerChatBubble, 10000, 1, {source,message,messagetype} ) end if not notfirst then setTimer(deletePlayerChatBubble,showTime + (#message * characterAddition),1,infotable) end end function deletePlayerChatBubble(infotable) for i,p in ipairs(messageToDraw) do if p[1] == infotable[1] and p[2] == infotable[2] then for i2,p2 in ipairs(messageToDraw) do if p2[1] == p[1] and p[4] - p2[4] == 1 then setTimer(deletePlayerChatBubble,showTime + (#p2[2] * characterAddition),1,p2) end end table.remove(messageToDraw,i) break end end end function getTextsToRemove() for i,p in ipairs(messageToDraw) do if p[1] == source then deletePlayerChatBubble(p) end end end addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) function renderTheDisplay() if showTheBubbles then for i,p in ipairs(messageToDraw) do if isElement(p[1]) then if isPedDead(p[1]) then return end local camPosXl, camPosYl, camPosZl = getPedBonePosition (p[1], 6) local camPosXr, camPosYr, camPosZr = getPedBonePosition (p[1], 7) local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 local cx,cy,cz = getCameraMatrix() local px,py,pz = getElementPosition(p[1]) local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) local posx,posy = getScreenFromWorldPosition(x,y,z+0.050*distance+0.10) local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() local elementtoignore2 = getPedOccupiedVehicle(p[1]) or p[1] if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxBubbles or p[4] < maxBubbles ) then -- change this when multiple ignored elements can be specified local width = dxGetTextWidth(p[2],1,"default-bold") dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 5,19,tocolor(0,0,0,255)) dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (p[4] * 20)),width + 11,19,tocolor(0,0,0,40)) dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 15,17,tocolor(0,0,0,255)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (p[4] * 20)),width + 19,17,tocolor(0,0,0,40)) dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (p[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) local r,g,b = 255,255,255 if p[3] == 2 then r,g,b = 154, 254, 46 elseif p[3] == 1 then r,g,b = 254,46,154 end dxDrawText(p[2],posx - (0.5 * width),posy - (p[4] * 20),posx - (0.5 * width),posy - (p[4] * 20),tocolor(r,g,b,255),1,"default-bold","left","top",false,false,false) end end end end end addEventHandler("onClientRender",getRootElement(),renderTheDisplay) function getServerSettings() triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) function saveSettings(settings) showTime = settings[1] characterAddition = settings[2] maxBubbles = settings[3] hideOwn = settings[4] addEvent("onChatbubblesMessageIncome",true) addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) end addEvent("onBubbleSettingsReturn",true) addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) function setPlayerTyping() if (isChatBoxInputActive() or isConsoleActive()) and not typing then triggerServerEvent("onPlayerStartTyping", localPlayer) typing = true end if not (isChatBoxInputActive() or isConsoleActive()) and typing then triggerServerEvent("onPlayerFinishTyping", localPlayer) typing = false end end setTimer(setPlayerTyping, 50, 0) function showPlayerTypingBubble() if source ~= getLocalPlayer() or not hideOwn then addPlayerChatBubble(source, "Typing!", "typing") end end addEvent("onPlayerStartTyping", true) addEventHandler("onPlayerStartTyping", root, showPlayerTypingBubble) function hidePlayerTypingBubble(me) if not source then source = me end deletePlayerChatBubble({ source = source, message = "Typing!", messagetype = "typing" }) end addEvent("onPlayerFinishTyping", true) addEvent("onClientPlayerChat", true) addEventHandler("onPlayerFinishTyping", root, hidePlayerTypingBubble) addEventHandler("onClientPlayerChat", root, hidePlayerTypingBubble) function updateList(newEntry, newStatus) chattingPlayers[newEntry] = newStatus if(not chatBubbleFor[newEntry]) then showPlayerTypingBubble(localPlayer) end hidePlayerTypingBubble(localPlayer) end addEvent("updateChatList", true) addEventHandler ( "updateChatList", getRootElement(), updateList ) Attempt to compare arithmet with boolean and getPedBonePosition is returning false bad pointer at 'ped'
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