(s)ection Posted February 28, 2014 Share Posted February 28, 2014 ha, i have a problem when the player exit of the vehicle the marker and the blip don't destroy help please function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",player,255,255,0 ) local am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) local ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) function OnExit ( am ,ab ,thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then destroyElement( source ) outputChatBox ( "You quitted your job.",player,255,0,0 ) destroyElement ( ab ) destroyElement ( am ) end end addEventHandler ( "onVehicleExit", getRootElement(), OnExit ) Link to comment
WhoAmI Posted February 28, 2014 Share Posted February 28, 2014 function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",player,255,255,0 ) am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) Try this. Link to comment
AboShanab Posted February 28, 2014 Share Posted February 28, 2014 function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",thePlayer,255,255,0 ) am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) function OnExit ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then destroyElement( source ) outputChatBox ( "You quitted your job.",thePlayer,255,0,0 ) destroyElement ( ab ) destroyElement ( am ) end end addEventHandler ( "onVehicleExit", getRootElement(), OnExit ) Link to comment
(s)ection Posted February 28, 2014 Author Share Posted February 28, 2014 Thanks iAbo and WhoAmI the script of iAbo works Link to comment
(s)ection Posted February 28, 2014 Author Share Posted February 28, 2014 But now I don't have money when I hit the marker : function MarkerHit4 ( player ) outputChatBox ( "[You win 1034$ !",player,255,255,0 ) givePlayerMoney ( player, 1034 ) end addEventHandler( "onMarkerHit", am, MarkerHit4 ) Link to comment
WhoAmI Posted February 28, 2014 Share Posted February 28, 2014 function MarkerHit4 ( element ) if (getElementType(element) == "player") then outputChatBox ( "[You win 1034$ !", element, 255, 255, 0 ) givePlayerMoney ( element, 1034 ) elseif (getElementType(element) == "vehicle") then local player = getVehicleOccupant(element) if (player) then outputChatBox ( "[You win 1034$ !", player, 255, 255, 0 ) givePlayerMoney ( player, 1034 ) end end end addEventHandler( "onMarkerHit", am, MarkerHit4 ) Link to comment
(s)ection Posted February 28, 2014 Author Share Posted February 28, 2014 function MarkerHit4 ( element ) if (getElementType(element) == "player") then outputChatBox ( "[You win 1034$ !", element, 255, 255, 0 ) givePlayerMoney ( element, 1034 ) elseif (getElementType(element) == "vehicle") then local player = getVehicleOccupant(element) if (player) then outputChatBox ( "[You win 1034$ !", player, 255, 255, 0 ) givePlayerMoney ( player, 1034 ) end end end addEventHandler( "onMarkerHit", am, MarkerHit4 ) Sorry but it's don't work Link to comment
(s)ection Posted February 28, 2014 Author Share Posted February 28, 2014 Huh, You mean it ? [13:49:09] WARNING: editor_test\server.lua:52: Bad argument @ 'getElementModel' [Expected element at argument 1, got number '448'] [13:49:09] WARNING: editor_test\server.lua:96: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil] [13:49:10] WARNING: editor_test\server.lua:32: Bad argument @ 'getElementType' [Expected element at argument 1, got boolean] Link to comment
Moderators Citizen Posted February 28, 2014 Moderators Share Posted February 28, 2014 Wow Wow guys slow down a bit and just let's get back into the first problem: The code WhoAmI and iAbo told you are just bad ! They will work for at most 1 player at a time ! If a second player start the job, then ab and am that were holding the blip and the marker of the first player will now contain the blip and the marker of the second. So when the first player will exit the vehicle, his blip and marker will still be visible for him because the code destroyed the blip and the marker of the second player. Is it still what you wanted ? I don't think so. This code will work on client side (you just need to replace the 2 server events by the clients ones). Or do it nicely doing like this: function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",thePlayer,255,255,0 ) local am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) local ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) --Link the blip to the marker this way, if you destroy the marker, it will destroy the blip too setElementParent(ab, am) -- saving the marker on the player element setElementData(source, "jobDestination", am) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) function OnExit ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then -- getting the marker stored on the player element local am = getElementData(thePlayer, "jobDestination") if am then --if we got the marker destroyElement( source ) outputChatBox ( "You quitted your job.",thePlayer, 255, 0, 0 ) -- destroy the marker and it's children (blip is a child of marker) destroyElement ( am ) setElementData(thePlayer, "jobDestination", false) end end end addEventHandler ( "onVehicleExit", getRootElement(), OnExit ) Link to comment
(s)ection Posted February 28, 2014 Author Share Posted February 28, 2014 Thanks a lot Citizen Link to comment
Moderators Citizen Posted February 28, 2014 Moderators Share Posted February 28, 2014 function MarkerHit4 ( element ) if (getElementType(element) == "player") then outputChatBox ( "[You win 1034$ !", element, 255, 255, 0 ) givePlayerMoney ( element, 1034 ) elseif (getElementType(element) == "vehicle") then local player = getVehicleOccupant(element) if (player) then outputChatBox ( "[You win 1034$ !", player, 255, 255, 0 ) givePlayerMoney ( player, 1034 ) end end end addEventHandler( "onMarkerHit", am, MarkerHit4 ) This addEventHandler is executed at load time (when the server starts) but of course, am is equal to nil because no one can start the job before the server has been started. And WTF ! Your code would give the player 1034$ twice ! Because the event will be triggered for the vehicle AND the player. By the way, we can't do it like that with the code I posted above. We have to add the event handler when the marker is created (and optionally use an anonymous function). Here is the new OnEnter function (it's a good practice to start the function names with a lowercase letter => onEnter): function OnEnter ( thePlayer, seat, jacked ) if ( getElementModel ( source ) == 448 ) then outputChatBox ( "Job started !",thePlayer,255,255,0 ) local am = createMarker(-2075.11133,900.70227,64.13281 - 1, "cylinder", 3, 0, 102, 51, 153) local ab = createBlip (-2075.11133,900.70227,64.13281, 0, 3, 102,51,153 ) --Link the blip to the marker this way, if you destroy the marker, it will destroy the blip too setElementParent(ab, am) -- saving the marker on the player element setElementData(source, "jobDestination", am) --Adding the event handler: addEventHandler( "onMarkerHit", am, function ( elem ) if not getElementType(elem) ~= "player" then return end --abort if not a player --abort if the player who entered in it wasn't HIS marker if getElementData(elem, "jobDestination") ~= source then return end local money = 1034 givePlayerMoney(elem, money) --give him his cash outputChatBox("[You won "..money.."$ !", elem, 255, 255, 0 ) end) -- You probably want to do that too (I didn't think about it in my previous post) -- hide the marker for everyone setElementVisibleTo(marker, root, false) --show it back for the player setElementVisibleTo(marker, thePlayer, true) end end addEventHandler ( "onVehicleEnter", getRootElement(), OnEnter ) As you can see, I also added this: -- You probably want to do that too (I didn't think about it in my previous post) -- hide the marker for everyone setElementVisibleTo(marker, root, false) --show it back for the player setElementVisibleTo(marker, thePlayer, true) Link to comment
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