Jump to content

random location!


Stevenn

Recommended Posts

Posted (edited)

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

Posted (edited)
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

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

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) 

?

Posted

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]

Posted
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

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted (edited)
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
Posted

First, why you need "theVehicle" parameter in 'onClickCreateMarker' event? Also, what is "lp".

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
First, why you need "theVehicle" parameter in 'onClickCreateMarker' event? Also, what is "lp".

because i was trying something but i remove it, and lp = getLocalPlayer()

Posted

Use:

addEventHandler ( 'onClientMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == cMarker ) then 
            triggerServerEvent ( 'truckStop', uPlayer ); 
        end 
    end 
) 

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

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

?

Posted

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.

?

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