kieran Posted July 8, 2017 Share Posted July 8, 2017 (edited) Hello, I am trying to detect if an element is a vehicle for a team system I'm working on, I have little in the way of a script so far, but it is below... TestTeam = createTeam ( "Test", 20, 100, 150 ) job_mark = createMarker (7002.419921875, -4831.384765625, 9.60000038147, 'cylinder', 2.0, 20, 100, 150, 255) Test_mark = createMarker (7000.419921875, -4831.384765625, 9.7, 'cylinder', 1.0, 20, 100, 150, 255) function Take_Job(source) local theTeam = getPlayerTeam ( source ) if theTeam then setPlayerTeam ( source, nil ) end setPlayerTeam ( source, TestTeam ) end addEventHandler("onMarkerHit", job_mark, Take_Job) function TestMarker(source) if ( isElement(source) and getElementType(source) == 'player' ) then --Here is where I want to check if player is in vehicle. local theVeh = getPedOccupiedVehicle(source) if ( theVeh ) then return else local theTeam = getPlayerTeam ( source ) --The bit below works fine, just need to sort the small section above if theTeam == TestTeam then outputChatBox("it works!", source, 255, 0, 0) end end end end addEventHandler("onMarkerHit", job_mark, TestMarker) Basically if it's a vehicle, return, if it's a player, then later I am making a GUI etc, but for now keeping it simple with giving a message. Edited July 8, 2017 by kieran Link to comment
DNL291 Posted July 8, 2017 Share Posted July 8, 2017 (edited) function TestMarker( hitElement, dim ) if getElementType(hitElement) == 'player' and not (isPedInVehicle(hitElement)) then if getPlayerTeam ( hitElement ) == TestTeam then outputChatBox("it works!", hitElement, 255, 0, 0) end end end addEventHandler("onMarkerHit", job_mark, TestMarker) Try it, I haven't tested. Edited July 8, 2017 by DNL291 Link to comment
kieran Posted July 8, 2017 Author Share Posted July 8, 2017 (edited) @DNL291 No luck, says the same thing: [2017-07-08 06:41:27] WARNING: Teams\JobTest.lua:6: Bad argument @ 'getPlayerTeam' [Expected player at argument 1, got vehicle] [2017-07-08 06:41:27] WARNING: Teams\JobTest.lua:10: Bad argument @ 'setPlayerTeam' [Expected player at argument 1, got vehicle] And now it also says: [2017-07-08 06:41:34] WARNING: Teams\JobTest.lua:17: Bad argument @ 'getPlayerTeam' [Expected player at argument 1, got marker] (My bad, last error was my fault, but first two still there) Edited July 8, 2017 by kieran Link to comment
koragg Posted July 8, 2017 Share Posted July 8, 2017 Try this: TestTeam = createTeam( "Test", 20, 100, 150) job_mark = createMarker(7002.419921875, -4831.384765625, 9.60000038147, 'cylinder', 2.0, 20, 100, 150, 255) Test_mark = createMarker(7000.419921875, -4831.384765625, 9.7, 'cylinder', 1.0, 20, 100, 150, 255) function Take_Job(source) local theTeam if getElementType(source) == "player" then theTeam = getPlayerTeam(source) elseif getElementType(source) == "vehicle" then theTeam = getPlayerTeam(getVehicleOccupant(source)) end if theTeam then if getElementType(source) == "player" then setPlayerTeam(source, nil) elseif getElementType(source) == "vehicle" then setPlayerTeam(getVehicleOccupant(source), nil) end end if getElementType(source) == "player" then setPlayerTeam(source, TestTeam) elseif getElementType(source) == "vehicle" then setPlayerTeam(getVehicleOccupant(source), TestTeam) end end addEventHandler("onMarkerHit", job_mark, Take_Job) function TestMarker(source) if isElement(source) and getElementType(source) == 'player' and (not isPedInVehicle(hitElement)) then local theTeam if getElementType(source) == "player" then theTeam = getPlayerTeam(source) elseif getElementType(source) == "vehicle" then theTeam = getPlayerTeam(getVehicleOccupant(source)) end if theTeam == TestTeam then outputChatBox("it works!", source, 255, 0, 0) end end end addEventHandler("onMarkerHit", job_mark, TestMarker) Link to comment
Infinity# Posted July 8, 2017 Share Posted July 8, 2017 local jobTeam = createTeam("Test", 20, 100, 150) local jobMarker = createMarker(7002.419921875, -4831.384765625, 9.60000038147, "cylinder", 2.0, 20, 100, 150, 255) local testingMarker = createMarker(7000.419921875, -4831.384765625, 9.7, "cylinder", 1.0, 20, 100, 150, 255) function takeJob(hitElement, matchingDimension) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getTeamFromName("Test") then local team = getTeamFromName("Test") if team then setPlayerTeam(hitElement, team) end end end end addEventHandler("onMarkerHit", jobMarker, takeJob) function testMarker(hitElement, matchingDimension) if isPedInVehicle(hitElement) then return end if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getPlayerTeam(hitElement) and getTeamFromName("Test") then local playerTeam = getPlayerTeam(hitElement) local checkTeam = getTeamFromName("Test") if tostring(playerTeam) == tostring(checkTeam) then outputChatBox("It works!", hitElement, 255, 0, 0, false) end end end end addEventHandler("onMarkerHit", testingMarker, testMarker) This will definitely work. But since I have no idea what you're trying to do, I just did this to help you out with the bugs that are being output to your debugscript. This should fix it. Please post below to what you're trying to do, I read the first post but I didn't quite understand. Let me know so I can help you. 1 Link to comment
kieran Posted July 8, 2017 Author Share Posted July 8, 2017 (edited) Thanks all! Infinity was closest, I figured out by replacing if isPedInVehicle(hitElement) then return end with if isElement(hitElement) and getElementType(hitElement) == "vehicle" and matchingDimension then return end It would do a simple check to see if element is vehicle and return if it is. It may be a little weird to use that but it works! no errors hehe. Once again thanks @Infinity#, @koragg and @DNL291 EDIT ^^^Never mind, nothing works, it always triggers the event is server side (obviously) so I dunno if that is problem, anyway! Cheers chaps. Edited July 8, 2017 by kieran Link to comment
Infinity# Posted July 8, 2017 Share Posted July 8, 2017 (edited) But hey, tell me what you're trying to do. I might be able to do the whole thing for you@kieran Edited July 8, 2017 by Infinity# 2 Link to comment
kieran Posted July 8, 2017 Author Share Posted July 8, 2017 (edited) 1 hour ago, Infinity# said: But hey, tell me what you're trying to do. I might be able to do the whole thing for you@kieran For now I am trying to simply make a marker to set a team, only if the player is on foot he will be able to trigger the event to set team, I then am trying to get a second marker to (for now) output text to the player in the team... As you can see all this happens, but the problem is that the functions are triggered if player is in vehicle and if player is on foot, meaning they could abuse it later as I plan to make a simple GUI outlining the job, the job will be a drug delivery/weapons delivery, this is very easy to do, just make vehicles in table, attach a few crates or something to inside of vehicle and when the vehicle spawn it will trigger a client side event creating a marker, attaching a blip, and then when the player hits the marker created, he will get a cash reward depending on vehicle health. I know how to do the actual script... But for now I just want to take it easy and tackle the main issue, events being triggered when a player hits a marker. Is a lot to read? Make sense? Edited July 8, 2017 by kieran Link to comment
kieran Posted July 8, 2017 Author Share Posted July 8, 2017 Can't edit last post so no hating for double posting, here is the solution! I used "isPedOnGround" same function in one of the maps where you need to defend area 51 and attacking team must be on foot to trigger function. function testMarker(hitElement, matchingDimension) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getPlayerTeam(hitElement) and getTeamFromName("Test") then local playerTeam = getPlayerTeam(hitElement) local checkTeam = getTeamFromName("Test") if tostring(playerTeam) == tostring(checkTeam) then if isPedOnGround ( hitElement ) then outputChatBox("It works!", hitElement, 255, 0, 0, false) else outputChatBox("You must be on foot!", hitElement, 255, 0, 0, false) end end end end end addEventHandler("onMarkerHit", testingMarker, testMarker) Thanks all for help! 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