Jump to content

Script Warning


Benevolence

Recommended Posts

This is the script.

local chatting = 0 
local chatters = { } 
  
function checkForChat() 
    local recon = getElementData(getLocalPlayer(), "reconx") 
     
    if not (reconx) then 
        if (isChatBoxInputActive() and chatting==0) then 
            chatting = 1 
            triggerServerEvent("chat1", getLocalPlayer()) 
        elseif (not isChatBoxInputActive() and chatting==1) then 
            chatting = 0 
            triggerServerEvent("chat0", getLocalPlayer()) 
        end 
    end 
end 
setTimer(checkForChat, 100, 0) 
  
  
  
function addChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            return 
        end 
    end 
    table.insert(chatters, source) 
end 
addEvent("addChatter", true) 
addEventHandler("addChatter", getRootElement(), addChatter) 
  
function delChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            table.remove(chatters, key) 
        end 
    end 
end 
addEvent("delChatter", true) 
addEventHandler("delChatter", getRootElement(), delChatter) 
addEventHandler("onClientPlayerQuit", getRootElement(), delChatter) 
  
function render() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local reconx = getElementData(getLocalPlayer(), "reconx") 
    for key, value in ipairs(chatters) do 
        if (isElement(value)) then 
            if getElementType(value) == "player" then 
                local px, py, pz = getPedBonePosition(value, 6) 
                 
                local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) 
                if isElementOnScreen(value) and not getElementData(value, "reconx") and not getElementData(value, "freecam:state") then 
                    if (dist>25) then 
                        chatters[value] = nil 
                        return 
                    end 
                 
                    local lx, ly, lz = getCameraMatrix() 
                    local vehicle = getPedOccupiedVehicle(value) 
                    local collision, cx, cy, cz, element = processLineOfSight(lx, ly, lz, rx, ry, rz+1, true, true, true, true, false, false, true, false, vehicle or value) 
                    if not (collision) or (reconx) then 
                        local screenX, screenY = getScreenFromWorldPosition(px, py, pz+0.5) 
                        if (screenX and screenY) then 
                            dist = dist / 5 
                                 
                            if (dist<1) then dist = 1 end 
                            if (dist>4 and reconx) then dist = 4 end 
                             
                             
                            local offset = 70 / dist 
                             
                            local draw = dxDrawImage(screenX, screenY, 60 / dist, 60 / dist, "chat.png") 
                        end 
                    end 
                end 
            else 
                chatters[key] = nil 
            end 
        else 
            chatters[key] = nil 
        end 
    end 
end 
addEventHandler("onClientRender", getRootElement(), render) 
  
chaticon = true 
function toggleChatIcon() 
    if (chaticon) then 
        triggerServerEvent("chaticon0", getLocalPlayer()) 
        outputChatBox("Chat icons are now disabled.", 255, 0, 0) 
        chaticon = false 
        removeEventHandler("onClientRender", getRootElement(), render) 
    else 
        triggerServerEvent("chaticon1", getLocalPlayer()) 
        outputChatBox("Chat icons are now enabled.", 0, 255, 0) 
        chaticon = true 
        addEventHandler("onClientRender", getRootElement(), render) 
    end 
end 
addCommandHandler("togglechaticons", toggleChatIcon, false) 
addCommandHandler("togchaticons", toggleChatIcon, false) 

I get an error on debugscript "attempt to perform arithmetic on global 'rz' (a nil value)" on the line:

local collision, cx, cy, cz, element = processLineOfSight(lx, ly, lz, rx, ry, rz+1, true, true, true, true, false, false, true, false, vehicle or value) 

Which is line 60 in the lua script above.

Link to comment

You haven't got these variables at all, that's why the error.

I guess rx, ry, rz is the element rotation.

local chatting = 0 
local chatters = { } 
  
function checkForChat() 
    local recon = getElementData(getLocalPlayer(), "reconx") 
    
    if not (reconx) then 
        if (isChatBoxInputActive() and chatting==0) then 
            chatting = 1 
            triggerServerEvent("chat1", getLocalPlayer()) 
        elseif (not isChatBoxInputActive() and chatting==1) then 
            chatting = 0 
            triggerServerEvent("chat0", getLocalPlayer()) 
        end 
    end 
end 
setTimer(checkForChat, 100, 0) 
  
  
  
function addChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            return 
        end 
    end 
    table.insert(chatters, source) 
end 
addEvent("addChatter", true) 
addEventHandler("addChatter", getRootElement(), addChatter) 
  
function delChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            table.remove(chatters, key) 
        end 
    end 
end 
addEvent("delChatter", true) 
addEventHandler("delChatter", getRootElement(), delChatter) 
addEventHandler("onClientPlayerQuit", getRootElement(), delChatter) 
  
function render() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local reconx = getElementData(getLocalPlayer(), "reconx") 
    for key, value in ipairs(chatters) do 
        if (isElement(value)) then 
            if getElementType(value) == "player" then 
                local px, py, pz = getPedBonePosition(value, 6) 
                
                local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) 
                if isElementOnScreen(value) and not getElementData(value, "reconx") and not getElementData(value, "freecam:state") then 
                    if (dist>25) then 
                        chatters[value] = nil 
                        return 
                    end 
                
                    local lx, ly, lz = getCameraMatrix() 
                    local vehicle = getPedOccupiedVehicle(value) 
                    local rx, ry, rz = getElementRotation(value) 
                    local collision, cx, cy, cz, element = processLineOfSight(lx, ly, lz, rx, ry, rz+1, true, true, true, true, false, false, true, false, vehicle or value) 
                    if not (collision) or (reconx) then 
                        local screenX, screenY = getScreenFromWorldPosition(px, py, pz+0.5) 
                        if (screenX and screenY) then 
                            dist = dist / 5 
                                
                            if (dist<1) then dist = 1 end 
                            if (dist>4 and reconx) then dist = 4 end 
                            
                            
                            local offset = 70 / dist 
                            
                            local draw = dxDrawImage(screenX, screenY, 60 / dist, 60 / dist, "chat.png") 
                        end 
                    end 
                end 
            else 
                chatters[key] = nil 
            end 
        else 
            chatters[key] = nil 
        end 
    end 
end 
addEventHandler("onClientRender", getRootElement(), render) 
  
chaticon = true 
function toggleChatIcon() 
    if (chaticon) then 
        triggerServerEvent("chaticon0", getLocalPlayer()) 
        outputChatBox("Chat icons are now disabled.", 255, 0, 0) 
        chaticon = false 
        removeEventHandler("onClientRender", getRootElement(), render) 
    else 
        triggerServerEvent("chaticon1", getLocalPlayer()) 
        outputChatBox("Chat icons are now enabled.", 0, 255, 0) 
        chaticon = true 
        addEventHandler("onClientRender", getRootElement(), render) 
    end 
end 
addCommandHandler("togglechaticons", toggleChatIcon, false) 
addCommandHandler("togchaticons", toggleChatIcon, false) 

Link to comment
You haven't got these variables at all, that's why the error.

I guess rx, ry, rz is the element rotation.

local chatting = 0 
local chatters = { } 
  
function checkForChat() 
    local recon = getElementData(getLocalPlayer(), "reconx") 
    
    if not (reconx) then 
        if (isChatBoxInputActive() and chatting==0) then 
            chatting = 1 
            triggerServerEvent("chat1", getLocalPlayer()) 
        elseif (not isChatBoxInputActive() and chatting==1) then 
            chatting = 0 
            triggerServerEvent("chat0", getLocalPlayer()) 
        end 
    end 
end 
setTimer(checkForChat, 100, 0) 
  
  
  
function addChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            return 
        end 
    end 
    table.insert(chatters, source) 
end 
addEvent("addChatter", true) 
addEventHandler("addChatter", getRootElement(), addChatter) 
  
function delChatter() 
    for key, value in ipairs(chatters) do 
        if ( value == source ) then 
            table.remove(chatters, key) 
        end 
    end 
end 
addEvent("delChatter", true) 
addEventHandler("delChatter", getRootElement(), delChatter) 
addEventHandler("onClientPlayerQuit", getRootElement(), delChatter) 
  
function render() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local reconx = getElementData(getLocalPlayer(), "reconx") 
    for key, value in ipairs(chatters) do 
        if (isElement(value)) then 
            if getElementType(value) == "player" then 
                local px, py, pz = getPedBonePosition(value, 6) 
                
                local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz) 
                if isElementOnScreen(value) and not getElementData(value, "reconx") and not getElementData(value, "freecam:state") then 
                    if (dist>25) then 
                        chatters[value] = nil 
                        return 
                    end 
                
                    local lx, ly, lz = getCameraMatrix() 
                    local vehicle = getPedOccupiedVehicle(value) 
                    local rx, ry, rz = getElementRotation(value) 
                    local collision, cx, cy, cz, element = processLineOfSight(lx, ly, lz, rx, ry, rz+1, true, true, true, true, false, false, true, false, vehicle or value) 
                    if not (collision) or (reconx) then 
                        local screenX, screenY = getScreenFromWorldPosition(px, py, pz+0.5) 
                        if (screenX and screenY) then 
                            dist = dist / 5 
                                
                            if (dist<1) then dist = 1 end 
                            if (dist>4 and reconx) then dist = 4 end 
                            
                            
                            local offset = 70 / dist 
                            
                            local draw = dxDrawImage(screenX, screenY, 60 / dist, 60 / dist, "chat.png") 
                        end 
                    end 
                end 
            else 
                chatters[key] = nil 
            end 
        else 
            chatters[key] = nil 
        end 
    end 
end 
addEventHandler("onClientRender", getRootElement(), render) 
  
chaticon = true 
function toggleChatIcon() 
    if (chaticon) then 
        triggerServerEvent("chaticon0", getLocalPlayer()) 
        outputChatBox("Chat icons are now disabled.", 255, 0, 0) 
        chaticon = false 
        removeEventHandler("onClientRender", getRootElement(), render) 
    else 
        triggerServerEvent("chaticon1", getLocalPlayer()) 
        outputChatBox("Chat icons are now enabled.", 0, 255, 0) 
        chaticon = true 
        addEventHandler("onClientRender", getRootElement(), render) 
    end 
end 
addCommandHandler("togglechaticons", toggleChatIcon, false) 
addCommandHandler("togchaticons", toggleChatIcon, false) 

Haven't tested, but what did you do?

Link to comment

Alright, haven't been able to test that properly Solidsnake14 but it might've fixed.

I have new Warnings.

gInteriorName, gOwnerName, gBuyMessage = nil 
 
timer = nil
 
-- Message on enter
function showIntName(name, ownerName, inttype, cost, fee)
    if (guiGetVisible(gInteriorName)) then
        if isTimer(timer) then
            killTimer(timer)
            timer = nil
        end
       
        destroyElement(gInteriorName)
        gInteriorName = nil
           
        destroyElement(gOwnerName)
        gOwnerName = nil
           
        if (gBuyMessage) then
            destroyElement(gBuyMessage)
            gBuyMessage = nil
        end
    end
   
    if name then
        if (inttype==3) then -- Interior name and Owner for rented
            gInteriorName = guiCreateLabel(0.0, 0.85, 1.0, 0.3, tostring(name), true)
            guiSetFont(gInteriorName, "sa-header")
            guiLabelSetHorizontalAlign(gInteriorName, "center", true)
            guiSetAlpha(gInteriorName, 0.0)
       
            gOwnerName = guiCreateLabel(0.0, 0.90, 1.0, 0.3, "Rented by: " .. tostring(ownerName), true)
            guiSetFont(gOwnerName, "default-bold-small")
            guiLabelSetHorizontalAlign(gOwnerName, "center", true)
            guiSetAlpha(gOwnerName, 0.0)
       
        else -- Interior name and Owner for the rest
            gInteriorName = guiCreateLabel(0.0, 0.85, 1.0, 0.3, tostring(name), true)
            guiSetFont(gInteriorName, "sa-header")
            guiLabelSetHorizontalAlign(gInteriorName, "center", true)
            guiSetAlpha(gInteriorName, 0.0)
           
            gOwnerName = guiCreateLabel(0.0, 0.90, 1.0, 0.3, "Owner: " .. tostring(ownerName), true)
            guiSetFont(gOwnerName, "default-bold-small")
            guiLabelSetHorizontalAlign(gOwnerName, "center", true)
            guiSetAlpha(gOwnerName, 0.0)
        end
        if (ownerName=="None") and (inttype==3) then -- Unowned type 3 (rentable)
            gBuyMessage = guiCreateLabel(0.0, 0.915, 1.0, 0.3, "Press F to rent for $" .. tostring(cost) .. ".", true)
            guiSetFont(gBuyMessage, "default-bold-small")
            guiLabelSetHorizontalAlign(gBuyMessage, "center", true)
            guiSetAlpha(gBuyMessage, 0.0)
        elseif (ownerName=="None") and (inttype<2) then -- Unowned any other type
            gBuyMessage = guiCreateLabel(0.0, 0.915, 1.0, 0.3, "Press F to buy for $" .. tostring(cost) .. ".", true)
            guiSetFont(gBuyMessage, "default-bold-small")
            guiLabelSetHorizontalAlign(gBuyMessage, "center", true)
            guiSetAlpha(gBuyMessage, 0.0)
        else
            local msg = "Press F to enter."
            if fee and fee > 0 then
                msg = "Entrance Fee: $" .. fee
               
                if exports.global:hasMoney( getLocalPlayer(), fee ) then
                    msg = msg .. "\nPress F to enter."
                end
            end
            gBuyMessage = guiCreateLabel(0.0, 0.915, 1.0, 0.3, msg, true)
            guiSetFont(gBuyMessage, "default-bold-small")
            guiLabelSetHorizontalAlign(gBuyMessage, "center", true)
            guiSetAlpha(gBuyMessage, 0.0)
        end
       
        timer = setTimer(fadeMessage, 50, 20, true)
    end
end
 
function fadeMessage(fadein)
    local alpha = guiGetAlpha(gInteriorName)
   
    if (fadein) and (alpha) then
        local newalpha = alpha + 0.05
        guiSetAlpha(gInteriorName, newalpha)
        guiSetAlpha(gOwnerName, newalpha)
       
        if (gBuyMessage) then
            guiSetAlpha(gBuyMessage, newalpha)
        end
       
        if(newalpha>=1.0) then
            timer = setTimer(hideIntName, 4000, 1)
        end
    elseif (alpha) then
        local newalpha = alpha - 0.05
        guiSetAlpha(gInteriorName, newalpha)
        guiSetAlpha(gOwnerName, newalpha)
       
        if (gBuyMessage) then
            guiSetAlpha(gBuyMessage, newalpha)
        end
       
        if(newalpha<=0.0) then
            destroyElement(gInteriorName)
            gInteriorName = nil
           
            destroyElement(gOwnerName)
            gOwnerName = nil
           
            if (gBuyMessage) then
                destroyElement(gBuyMessage)
                gBuyMessage = nil
            end
        end
    end
end
 
function hideIntName()
    setTimer(fadeMessage, 50, 20, false)
end
 
addEvent("displayInteriorName", true )
addEventHandler("displayInteriorName", getRootElement(), showIntName)
 
-- Creation of clientside blips
function createBlipsFromTable(interiors)
    -- remove existing house blips
    for key, value in ipairs(getElementsByType("blip")) do
        local blipicon = getBlipIcon(value)
       
        if (blipicon == 31 or blipicon == 32) then
            destroyElement(value)
        end
    end
 
    -- spawn the new ones.
    for key, value in ipairs(interiors) do
        createBlipAtXY(interiors[key][1], interiors[key][2], interiors[key][3])
    end
end
addEvent("createBlipsFromTable", true)
addEventHandler("createBlipsFromTable", getRootElement(), createBlipsFromTable)
 
function createBlipAtXY(inttype, x, y)
    if inttype == 3 then inttype = 0 end
    createBlip(x, y, 10, 31+inttype, 2, 255, 0, 0, 255, 0, 300)
end
addEvent("createBlipAtXY", true)
addEventHandler("createBlipAtXY", getRootElement(), createBlipAtXY)
 
function removeBlipAtXY(inttype, x, y)
    if inttype == 3 or type(inttype) ~= 'number' then inttype = 0 end
    for key, value in ipairs(getElementsByType("blip")) do
        local bx, by, bz = getElementPosition(value)
        local icon = getBlipIcon(value)
       
        if (icon==31+inttype and bx==x and by==y) then
            destroyElement(value)
            break
        end
    end
end
addEvent("removeBlipAtXY", true)
addEventHandler("removeBlipAtXY", getRootElement(), removeBlipAtXY)
 
------
local wRightClick, ax, ay = nil
local house = nil
local houseID = nil
local sx, sy = guiGetScreenSize( )
function showHouseMenu( )
    ax = math.max( math.min( sx - 160, ax - 75 ), 10 )
    ay = math.max( math.min( sx - 210, ay - 100 ), 10 )
    wRightClick = guiCreateWindow(ax, ay, 150, 200, "House " .. tostring( houseID ), false)
 
    bLock = guiCreateButton(0.05, 0.13, 0.9, 0.1, "Lock/Unlock", true, wRightClick)
    addEventHandler("onClientGUIClick", bLock, lockUnlockHouse, false)
   
    bKnock = guiCreateButton(0.05, 0.27, 0.9, 0.1, "Knock on Door", true, wRightClick)
    addEventHandler("onClientGUIClick", bKnock, knockHouse, false)
       
    bCloseMenu = guiCreateButton(0.05, 0.41, 0.9, 0.1, "Close Menu", true, wRightClick)
    addEventHandler("onClientGUIClick", bCloseMenu, hideHouseMenu, false)
end
 
function knockHouse()
    triggerServerEvent("onKnocking", getLocalPlayer(), houseID)
    hideHouseMenu()
end
 
function lockUnlockHouse( )
    local px, py, pz = getElementPosition(getLocalPlayer())
    local x, y, z = getElementPosition(house)
    if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < 5 then
        triggerServerEvent( "lockUnlockHouseID", getLocalPlayer( ), houseID )
    end
    hideHouseMenu()
end
 
function hideHouseMenu( )
    if wRightClick then
        destroyElement( wRightClick )
        wRightClick = nil
        showCursor( false )
    end
    house = nil
    houseID = nil
end
 
local function hasKey( key )
    return exports.global:hasItem(getLocalPlayer(), 4, key) or exports.global:hasItem(getLocalPlayer(), 5,key)
end
function clickHouse(button, state, absX, absY, wx, wy, wz, e)
    if (button == "right") and (state=="down") and not e then
        if getElementData(getLocalPlayer(), "exclusiveGUI") then
            return
        end
       
        local element, id = nil, nil
        local px, py, pz = getElementPosition(getLocalPlayer())
        local x, y, z = nil
        local interiorres = getResourceRootElement(getResourceFromName("interior-system"))
        local elevatorres = getResourceRootElement(getResourceFromName("elevator-system"))
--[[        for key, value in ipairs(getElementsByType("pickup")) do
            if isElementStreamedIn(value) then
                x, y, z = getElementPosition(value)
                local minx, miny, minz, maxx, maxy, maxz
                local offset = 4
               
                minx = x - offset
                miny = y - offset
                minz = z - offset
               
                maxx = x + offset
                maxy = y + offset
                maxz = z + offset
               
                if (wx >= minx and wx <=maxx) and (wy >= miny and wy <=maxy) and (wz >= minz and wz <=maxz) then
                    local dbid = getElementData(value, "dbid")
                    if hasKey(dbid) and getElementParent( getElementParent( value ) ) == interiorres then -- house found
                        element = value
                        id = dbid
                        break
                    elseif getElementData( value, "other" ) and getElementParent( getElementParent( value ) ) == elevatorres then
                        -- it's an elevator
                        if hasKey(getElementDimension( value ) ) then
                            element = value
                            id = getElementDimension( value )
                            break
                        elseif hasKey(getElementDimension( getElementData( value, "other" ) ) ) then
                            element = value
                            id = getElementDimension( getElementData( value, "other" ) )
                            break
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...