Jump to content

random location!


Stevenn

Recommended Posts

i dont know what i am doing wrong

bad argument @ 'createMarker'

local locationTable = 
    { 
        { -2128, -80, 36 }, 
    } 
    
function getRandomLocation ( ) 
    return unpack ( locations [ math.random ( #locationTable ) ] ) 
end 
  
  
function buttonClick(button) 
    if (button) ~= "left" then return end 
    if (source == acceptJob) then 
    triggerEvent ( "markerLocation3",lp ) 
        end 
end 
addEventHandler("onClientGUIClick", resourceRoot, buttonClick, true) 
     
addEvent ( "markerLocation3", true) 
function markerLocation () 
        markerLocation2 = createMarker ( x, y, z, "cylinder",250,250,250 )  
        blip = createBlipAttachtedTo ( markerLocation2, 53 ) 
        end 
addEventHandler("markerLocation3",root,markerLocation) 
         
acceptJob = guiCreateButton(37,58,94,49,"Accept",false,truckWindow) 

viewtopic.php?f=91&t=42187#p426764

Edited by Guest
Link to comment
i dont know what i am doing wrong
local locationTable = 
    { 
        { -2128, -80, 36 }, 
    } 
    
function getRandomLocation ( ) 
    return unpack ( locations [ math.random ( #locationTable ) ] ) 
end 
  
  
function buttonClick(button) 
    if (button) ~= "left" then return end 
    if (source == acceptJob) then 
    triggerEvent ( "markerLocation3",lp ) 
        end 
end 
addEventHandler("onClientGUIClick", resourceRoot, buttonClick, true) 
     
addEvent ( "markerLocation3", true) 
function markerLocation () 
        markerLocation2 = createMarker ( x, y, z, "cylinder",250,250,250 )  
        blip = createBlipAttachtedTo ( markerLocation2, 53 ) 
        end 
addEventHandler("markerLocation3",root,markerLocation) 
         
acceptJob = guiCreateButton(37,58,94,49,"Accept",false,truckWindow) 

viewtopic.php?f=91&t=42187#p426764

Try changing:

  
function getRandomLocation ( ) 
    -- Here you try to unpack from table 'locations' ( That doesnt exist ) 
    return unpack ( locations [ math.random ( #locationTable ) ] ) 
end 
  

to:

  
function getRandomLocation ( ) 
    -- Instead unpack from 'locationTable' 
    return unpack ( locationTable [ math.random ( #locationTable ) ] ) 
end 
  

Link to comment
local tLocations = 
{ 
    { -2128, -80, 36 }; 
} 
  
addEvent ( 'onClickCreateMarker', true ); 
  
acceptJob = guiCreateButton ( 37, 58, 94, 49, 'Accept', false, truckWindow ); 
  
function getRandomLocation ( ) 
    return unpack ( tLocations [ math.random ( #tLocations ) ] ); 
end 
  
addEventHandler ( 'onClientGUIClick', root, 
    function ( uType ) 
        if ( uType ~= 'left' ) then 
            return; 
        end 
         
        if ( source == acceptJob ) then 
            triggerEvent ( 'onClickCreateMarker', localPlayer ); 
        end 
    end 
) 
  
addEventHandler ( 'onClickCreateMarker', root, 
    function ( ) 
        local nX, nY, nZ     = getRandomLocation ( ); 
        local cMarker        = createMarker ( nX, nY, nZ, 'cylinder', 250, 250, 250 ); 
        local blip           = createBlipAttachedTo ( cMarker, 53 ); 
    end 
) 

Edited by Guest
Link to comment

you never get any values for x,y,z:

local locationTable = { 
    { -2128, -80, 36 }, 
} 
    
function getRandomLocation ( ) 
    return unpack ( locationTable [ math.random ( #locationTable ) ] ) 
end 
  
function buttonClick(button) 
    if (source == acceptJob) and (button == "left") then 
        triggerEvent ( "markerLocation3",lp ) 
    end 
end 
addEventHandler("onClientGUIClick", resourceRoot, buttonClick, true) 
    
addEvent ( "markerLocation3", true) 
function markerLocation () 
    local x,y,z = getRandomLocation() 
    markerLocation2 = createMarker ( x, y, z, "cylinder",250,250,250 ) 
    blip = createBlipAttachtedTo ( markerLocation2, 53 ) 
end 
addEventHandler("markerLocation3",root,markerLocation) 
        
acceptJob = guiCreateButton(37,58,94,49,"Accept",false,truckWindow) 

Link to comment

ty it works draken, but how can I do this ?

addEventHandler ( "onClientMarkerHit", cMarker , 
    function  ( ) 
        if getElementModel(getPedOccupiedVehicle(lp)) == 437 then 
            triggerServerEvent ( "busStop", lp ) 
        end 
    end 
) 

bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Link to comment
ty it works draken, but how can I do this ?
addEventHandler ( "onClientMarkerHit", cMarker , 
    function  ( ) 
        if getElementModel(getPedOccupiedVehicle(lp)) == 437 then 
            triggerServerEvent ( "busStop", lp ) 
        end 
    end 
) 

bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

cMarker is not global. You must remove "local" before cMarker in the code to use it in other functions.

See: http://en.wikipedia.org/wiki/Global_variable

Link to comment
ty it works draken, but how can I do this ?
addEventHandler ( "onClientMarkerHit", cMarker , 
    function  ( ) 
        if getElementModel(getPedOccupiedVehicle(lp)) == 437 then 
            triggerServerEvent ( "busStop", lp ) 
        end 
    end 
) 

bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

cMarker is not global. You must remove "local" before cMarker in the code to use it in other functions.

See: http://en.wikipedia.org/wiki/Global_variable

addEventHandler ( 'onClickCreateMarker', root, 
    function ( ) 
        local nX, nY, nZ     = getRandomLocation ( ); 
        cMarker        = createMarker ( nX, nY, nZ, "cylinder",4,250,250,255 ); 
        local blip           = createBlipAttachedTo ( cMarker, 53 ); 
    end 
) 
addEventHandler ( "onClientMarkerHit", cMarker, 
    function  ( ) 
            triggerServerEvent ( "truckStop", localPlayer ) 
        end 
) 

doesn't work...

Edited by Guest
Link to comment
Use:
addEventHandler ( 'onClientMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == cMarker ) then 
            triggerServerEvent ( 'truckStop', uPlayer ); 
        end 
    end 
) 

this is a single client code without any checks for element that hit the marker.

so when 1 player hits the marker, the same event will be sent by multiple clients.

it should only trigger if hitElement == localPlayer.

Link to comment

hit element here is uPlayer.

tbh i dont get why, fine with confusing prefixes like "uSomething" and unconventional semicolons.

but hit element not necessarily is a player. so that name is misleading.

and you should learn about variables and how do they work. this is programming basics.

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