Jump to content

Help with this simple map script


asd123

Recommended Posts

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 
  

Link to comment
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 
) 

Link to comment
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?

Link to comment
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 
) 

Link to comment

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 

)

Link to comment
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.

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