Stevenn Posted April 15, 2012 Posted April 15, 2012 (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 April 15, 2012 by Guest
unknooooown Posted April 15, 2012 Posted April 15, 2012 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
drk Posted April 15, 2012 Posted April 15, 2012 (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 April 15, 2012 by Guest
Aibo Posted April 15, 2012 Posted April 15, 2012 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)
Stevenn Posted April 15, 2012 Author Posted April 15, 2012 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]
drk Posted April 15, 2012 Posted April 15, 2012 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
Stevenn Posted April 15, 2012 Author Posted April 15, 2012 (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 April 15, 2012 by Guest
drk Posted April 15, 2012 Posted April 15, 2012 First, why you need "theVehicle" parameter in 'onClickCreateMarker' event? Also, what is "lp".
Stevenn Posted April 15, 2012 Author Posted April 15, 2012 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()
Stevenn Posted April 15, 2012 Author Posted April 15, 2012 Well, when I hit the "cMarker" I want to trigger the server event, but like I said: Expected element at argument 2, got nil
drk Posted April 15, 2012 Posted April 15, 2012 Use: addEventHandler ( 'onClientMarkerHit', root, function ( uPlayer ) if ( source == cMarker ) then triggerServerEvent ( 'truckStop', uPlayer ); end end )
Aibo Posted April 15, 2012 Posted April 15, 2012 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.
Stevenn Posted April 15, 2012 Author Posted April 15, 2012 if ( source == cMarker and hitElement == localPlayer ) then ?
Aibo Posted April 15, 2012 Posted April 15, 2012 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.
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