Jump to content

[HELP] Expected vector at argument error


LabiVila

Recommended Posts

addEventHandler ("onClientRender", root, 
    function () 
        px, py, pz = getElementPosition (localPlayer) 
    end 
) 
  
addEventHandler ("onClientClick", getRootElement(),  
    function (btn, state, ax, ay, wx, wy, wz) 
        if state == "up" then 
            outputChatBox ("Object's position: "..wx..", "..wy..", "..wz.."!") 
             
            outputChatBox ("Your position: "..px..", "..py..", "..pz.."!") 
        end 
    end 
) 
  
function metters () 
    local a = getDistanceBetweenPoints3D (px, py, pz, wx, wy, wz) 
    dxDrawText (a, x/3, y/3, x, y, tocolor (255, 255, 255, 155), 5) 
end 
addEventHandler ("onClientRender", root, metters) 
  

The outputChatBox tell current positions but Distance isn't working. I get these errors:

Bad argument @ 'getDistanceBetweenPoints3D' [Expected vector3 at argument 4, got nil]

attempt to perform arithmetic on global 'x' (a nil value)

Link to comment

Where is ur wx,wy,wz declared? It says that your wx is empty, prolly wy and wz aswell.

Dunno what ur scipt need to do but if this is somethig like start to show meters after button click, you cannot use onClientRender with out any trigger for it.

this wx,wy,wz

  
addEventHandler ("onClientClick", getRootElement(),  
    function (btn, state, ax, ay, wx, wy, wz) 
        if state == "up" then 
            outputChatBox ("Object's position: "..wx..", "..wy..", "..wz.."!") 
            
            outputChatBox ("Your position: "..px..", "..py..", "..pz.."!") 
        end 
    end 
) 
  
  

works only in this function -> function (btn, state, ax, ay, wx, wy, wz) <-- here --> end

If you would make something like this

addEventHandler ("onClientClick", getRootElement(),  
    function (btn, state, ax, ay, wx, wy, wz) 
        if state == "up" then 
     wx = wx 
      wy = wy 
      wz = wz 
            trigger = true 
            outputChatBox ("Object's position: "..wx..", "..wy..", "..wz.."!") 
            
            outputChatBox ("Your position: "..px..", "..py..", "..pz.."!") 
        end 
    end 
) 

and it will work. Thats mean that you declared it only in some function as local var

  
function metters () 
if(trigger)then 
    local a = getDistanceBetweenPoints3D (px, py, pz, wx, wy, wz) 
    dxDrawText (a, x/3, y/3, x, y, tocolor (255, 255, 255, 155), 5) 
end 
end 
addEventHandler ("onClientRender", root, metters) 
  

Link to comment

It must show the distance between player and selected object... as dxDrawText

EDIT: here's the script I do currently have:

addEventHandler ("onClientResourceStart", getRootElement(), 
    function () 
        showCursor (true) 
        outputChatBox ("Program successfully started.", 255, 255, 255) 
        outputDebugString ("Program successfully started.") 
    end 
) 
  
local trigger = false 
  
addEventHandler ("onClientRender", root, 
    function () 
        px, py, pz = getElementPosition (localPlayer) 
    end 
) 
  
addEventHandler ("onClientClick", getRootElement(),  
    function (btn, state, ax, ay, wx, wy, wz) 
        wx = wx 
        wy = wy 
        wz = wz 
        trigger = true 
        if state == "up" then 
            outputChatBox ("Object's position: "..wx..", "..wy..", "..wz.."!") 
             
            outputChatBox ("Your position: "..px..", "..py..", "..pz.."!") 
        end 
    end 
) 
  
function metters () 
    if (trigger) then 
        local a = getDistanceBetweenPoints3D (px, py, pz, wx, wy, wz) 
        dxDrawText (a, x/3, y/3, x, y, tocolor (255, 255, 255, 155), 5) 
    end 
end 
addEventHandler ("onClientRender", root, metters) 
  
  
  

Link to comment

This should give u an idea what I have in mind up there.

show_btn = guiCreateButton ( 0.2, 0.5, 0.1, 0.1, "Show", true) 
hide_btn = guiCreateButton ( 0.5, 0.5, 0.1, 0.1, "Hide", true) 
  
guiSetVisible(show_btn,true) 
guiSetVisible(hide_btn,true) 
  
showCursor(true,false) 
local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
function show_f(button, state) 
    if (source == show_btn) then 
    some_objectX,some_objectY,some_objectZ = 123.0, 32.000, 12  <-- you need to declared object position here, every new button = new position  
        addEventHandler ( "onClientRender", root, show_dis ) 
            guiSetVisible(show_btn,false) 
            guiSetVisible(hide_btn,true) 
    end 
end 
addEventHandler ( "onClientGUIClick",show_btn,show_f,false) 
  
function hide_f(button, state) 
    if (source == hide_btn) then 
  
            removeEventHandler( "onClientRender", root, show_dis ) 
                guiSetVisible(show_btn,true) 
                guiSetVisible(hide_btn,false) 
    end 
end 
addEventHandler ( "onClientGUIClick", hide_btn,hide_f,false) 
  
  
function show_dis () 
     
            local  x,y,z=getElementPosition(getLocalPlayer ( )) <-- local player position it's need to be here if you want to get  continuous update beetween object and player 
            dis = getDistanceBetweenPoints3D ( x, y, z, some_objectX,some_objectY,some_objectZ ) 
            dxDrawText ( math.floor(dis), 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )  
     
end 
  

Just copy and paste it

if you want it to show only for period of time use timer, delete hide_f and hide_btn and I suggest you to disable clicked button for the 5s. If you will have more than 1 object button is better to use the if(trigger) then .. end(in show_dis function), instand of remove and add eventHandler.

  
function show_f(button, state) 
    if (source == show_btn) then 
    some_objectX,some_objectY,some_objectZ = 123.0, 32.000, 12  
        addEventHandler ( "onClientRender", root, show_dis ) 
                setTimer ( function() 
                    removeEventHandler( "onClientRender", root, show_dis ) 
                end, 5000, 1 ) 
    end 
end 
addEventHandler ( "onClientGUIClick",show_btn,show_f,false) 
  

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