asd123 Posted June 15, 2013 Posted June 15, 2013 Hey all i am trying to make this script work for my map its meant to be cops and 1 robber (race gamemode) the problem is that the script does not want to start i have no clue why. The map should end after the robber is dead but it does not. I would really like your help here is the script: 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 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 ) addEventHandler("onPlayerWasted", root, function() if getElementModel(getPedOccupiedVehicle(source)) == 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 ) addEventHandler("onResourceStop", root, function() or 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. destroyElement(policeBlip) -- This destroys the temporary blip we made. destroyElement(robberBlip) -- This destroys the temporary blip we made. end end end end end
Castillo Posted June 15, 2013 Posted June 15, 2013 no errors Seriously? you obviously didn't check, because it has several. 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 ) addEventHandler("onPlayerWasted", root, function() if getElementModel(getPedOccupiedVehicle(source)) == 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 ) 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. destroyElement(policeBlip) -- This destroys the temporary blip we made. destroyElement(robberBlip) -- This destroys the temporary blip we made. end end end end )
asd123 Posted June 15, 2013 Author Posted June 15, 2013 no errors Seriously? you obviously didn't check, because it has several. 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 ) addEventHandler("onPlayerWasted", root, function() if getElementModel(getPedOccupiedVehicle(source)) == 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 ) 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. destroyElement(policeBlip) -- This destroys the temporary blip we made. destroyElement(robberBlip) -- This destroys the temporary blip we made. end end end end ) Sorry i am new to these kinds of things How can i fix it?
Castillo Posted June 15, 2013 Posted June 15, 2013 Fix what? I already fixed them, just copy that code.
asd123 Posted June 15, 2013 Author Posted June 15, 2013 oh thanks is there anyway i know it will work because it needs 3 or more to test and when i played it with myself there is no evidence that it has worked.
asd123 Posted June 15, 2013 Author Posted June 15, 2013 Like i said i cant my server will not allow people to join
Cruze Posted June 15, 2013 Posted June 15, 2013 Maj use Hamachi software follow every step,and then open the ports,invite some players to test it and have fun.
asd123 Posted June 15, 2013 Author Posted June 15, 2013 Solidsnake there is an error i found on the debugscript here is the picture : http://postimg.org/image/kk0xpuyx1/
Castillo Posted June 15, 2013 Posted June 15, 2013 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 ) addEventHandler("onPlayerWasted", root, function() if getElementModel(getPedOccupiedVehicle(source)) == 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 ) 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 )
asd123 Posted June 15, 2013 Author Posted June 15, 2013 Should i add other lines on the meta? or is it only one for the script to work?
asd123 Posted June 15, 2013 Author Posted June 15, 2013 I found another error while testing it on my self here is a picture: http://postimg.org/image/sk7f386iv/
Castillo Posted June 15, 2013 Posted June 15, 2013 Make sure the player is in a vehicle, that error is caused because is trying to get the element model from nothing.
asd123 Posted June 16, 2013 Author Posted June 16, 2013 The script still does not work when robber is dead the robber is in a sandking. Here is the debugscript picture: http://postimg.org/image/5xahyf9nf/
denny199 Posted June 16, 2013 Posted June 16, 2013 It's because race i think, the vehicle will be destroyed before it cheks it, use the race events "onPlayerRaceWasted" instead of "onPlayerWasted" ( --Eventname: source arguments --onPlayerRaceWasted player vehicle playersVehicle )
iPrestege Posted June 16, 2013 Posted June 16, 2013 addEventHandler("onPlayerWasted", root, function ( ) if isPedInVehicle ( source ) and getElementModel(getPedOccupiedVehicle(source)) == rmodel then for i, v in ipairs(getElementsByType("player")) do setElementHealth(v, 0) end outputChatBox("Cops win!", root, 255, 0, 0, true) end end ) Try this if there's a error post it.
asd123 Posted June 16, 2013 Author Posted June 16, 2013 The map still does not end when the robber is dead but this time there are no errors on debugscript How can i fix this?
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