Jump to content

[HELP] With mission


Recommended Posts

I tried to create a little 'mission' where a vehicle is spawned and if the player enters the vehicle, a marker appears and this works. If the player hits the marker, a text message should appear, but it doesn't.

I get the following error:

WARNING: mission\script.lua:15: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Here's my code:

local veh1 = createVehicle (478, 2474, -1690.4, 13.6, 0, 0, 0) 
  
function showMarker (vehicle) 
    if getElementType (vehicle) == "vehicle" and getElementModel (vehicle) == 478 then 
        theMarker = createMarker (2515.6001, -1671.9, 11.8, "cylinder", 5.0, 100, 200, 100, 200) 
    end 
end 
addEventHandler("onPlayerVehicleEnter", getRootElement(), showMarker) 
  
function showText () 
    if theMarker == true then  
        outputChatBox("It worked!") 
    end 
end 
addEventHandler("onMarkerHit", theMarker, showText) 

Thanks for helping me :)

Link to comment
local veh1 = createVehicle(478, 2474, -1690.4, 13.6, 0, 0, 0) 
  
function showMarker(vehicle) 
    if vehicle == veh1 and getElementModel(vehicle) == 478 and not theMarker then 
        theMarker = createMarker (2515.6001, -1671.9, 11.8, "cylinder", 5.0, 100, 200, 100, 200) 
    end 
end 
addEventHandler("onPlayerVehicleEnter", root, showMarker) 
  
function showText () 
    if source == theMarker then 
        outputChatBox("It worked!") 
    end 
end 
addEventHandler("onMarkerHit", root, showText) 

Link to comment
local veh1 = createVehicle(478, 2474, -1690.4, 13.6, 0, 0, 0) 
  
function showMarker(vehicle) 
    if vehicle == veh1 and getElementModel(vehicle) == 478 and not theMarker then 
        theMarker = createMarker (2515.6001, -1671.9, 11.8, "cylinder", 5.0, 100, 200, 100, 200) 
    end 
end 
addEventHandler("onPlayerVehicleEnter", root, showMarker) 
  
function showText () 
    if source == theMarker then 
        outputChatBox("It worked!") 
    end 
end 
addEventHandler("onMarkerHit", root, showText) 

Worked! Thanks!

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