Jaysds1 Posted June 16, 2013 Share Posted June 16, 2013 try this: local timeleft = 60 -- Seconds till robber escapes. local rmodel = 495 -- Robber vehicle ID. local pmodel = 599 -- Police vehicle ID. addEvent ( "onMapStarting", true ) addEventHandler ( "onMapStarting", root, function ( ) -- BLIP REMOVAL LOOP for _,player in ipairs(getElementsByType("player")) do --set blip invisible for _,element in ipairs(getAttachedElements(player)) do if getElementType(element) == "blip" then setElementVisibleTo(element, root, false) -- This temporary makes the blip invisable. end end --Assigning Loop if isPedInVehicle(player) then -- If the player is in a vehicle. local theVehicle = getPedOccupiedVehicle (player) local pVehModel = getElementModel(theVehicle) if pVehModel == rmodel then -- If it's the robber vehicle. createBlipAttachedTo(theVehicle, 23) -- Creates a skull blip attached to the robber. elseif pVehModel == pmodel then -- If it's the police vehicle. createBlipAttachedTo(theVehicle, 30) -- Creates a siren blip attached to all cops. end end end setTimer( function() outputChatBox("Robber wins!", root, 255, 0, 0) for _,player in ipairs(getElementsByType("player")) do setElementHealth(player, 0) end end, timeleft*1000, 1 ) end ) addEventHandler("onPlayerWasted", root, function() if isPedInVehicle(source) and getElementModel(getPedOccupiedVehicle(source)) == rmodel then for _,player in ipairs(getElementsByType("player")) do setElementHealth(player, 0) end outputChatBox("Cops win!", root, 255, 0, 0, true) end end ) addEventHandler("onResourceStop", resourceRoot, function() if source~=resource then return end for _,player in ipairs(getElementsByType("player")) do for _,element in ipairs(getAttachedElements(player)) do if getElementType(element) == "blip" then if isElementVisibleTo(element,root) then --check if the blip is visible --if it is then it must be the blip we created earlier destroyElement(element) else --if it isn't then it must be the blip we hide earlier setElementVisibleTo(element,root,true) end end end end end ) Link to comment
asd123 Posted June 16, 2013 Author Share Posted June 16, 2013 No thats still not working Link to comment
denny199 Posted June 16, 2013 Share Posted June 16, 2013 Try to test it WITHOUT editor. And use this: addEvent ( "onPlayerRaceWasted", true ) addEventHandler("onPlayerRaceWasted", root, function (car) if getElementModel(getPedOccupiedVehicle(car)) == rmodel then for i, v in ipairs(getElementsByType("player")) do setElementHealth(v, 0) end outputChatBox("Cops win!", root, 255, 0, 0, true) end end ) Link to comment
asd123 Posted June 16, 2013 Author Share Posted June 16, 2013 Yes we did test it without the editor but still the same problem. Link to comment
Castillo Posted June 16, 2013 Share Posted June 16, 2013 That won't work, because you are trying to get the occupied vehicle of a vehicle. local timeleft = 60 -- Seconds till robber escapes. local rmodel = 495 -- Robber vehicle ID. local pmodel = 599 -- Police vehicle ID. addEvent ( "onMapStarting", true ) addEventHandler ( "onMapStarting", root, function ( ) -- BLIP REMOVAL LOOP for i,v in ipairs(getElementsByType("player")) do local elements = getAttachedElements(v) for i,v in ipairs(elements) do if (getElementType(v) == "blip") then setElementVisibleTo(v, root, false) -- This temporary makes the blip invisable. end end end -- ASSIGNATION LOOP for i,v in ipairs(getElementsByType("player")) do local theVehicle = getPedOccupiedVehicle (v) if theVehicle then -- If the player is in a vehicle. if getElementModel(theVehicle) == tonumber(rmodel) then -- If it's the robber vehicle. robberblip = createBlipAttachedTo(theVehicle, 23) -- Creates a skull blip attached to the robber. elseif getElementModel(theVehicle) == tonumber(pmodel) then -- If it's the police vehicle. policeblip = createBlipAttachedTo(theVehicle, 30) -- Creates a siren blip attached to all cops. end end end setTimer( function() outputChatBox("Robber wins!", root, 255, 0, 0, true) for i, v in ipairs(getElementsByType("player")) do setElementHealth(v, 0) end end, timeleft*1000, 1 ) end ) addEvent ( "onPlayerRaceWasted", true ) addEventHandler("onPlayerRaceWasted", root, function ( theVehicle ) if isElement ( theVehicle ) then if getElementModel ( theVehicle ) == tonumber(rmodel) then for i, v in ipairs(getElementsByType("player")) do setElementHealth(v, 0) end outputChatBox("Cops win!", root, 255, 0, 0, true) end end end ) addEventHandler("onResourceStop", root, function() for i,v in ipairs(getElementsByType("player")) do local elements = getAttachedElements(v) for i,v in ipairs(elements) do if (getElementType(v) == "blip") then setElementVisibleTo(v, root, true) -- This makes the blip visable again. if isElement ( policeBlip ) then destroyElement(policeBlip) -- This destroys the temporary blip we made. end if isElement ( robberBlip ) then destroyElement(robberBlip) -- This destroys the temporary blip we made. end end end end end ) Link to comment
denny199 Posted June 16, 2013 Share Posted June 16, 2013 Ah yeah, little mistake was needed to eat Link to comment
asd123 Posted June 17, 2013 Author Share Posted June 17, 2013 I now have another problem on this topic: viewtopic.php?f=94&t=60917 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