Jump to content

Help with this simple map script


asd123

Recommended Posts

Posted

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 
  

Posted

Any error on the debugscript?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Is the script set as server side on the meta.xml?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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?

Posted

Fix what? I already fixed them, just copy that code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted

Get some more players to test?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That should work.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Make sure the player is in a vehicle, that error is caused because is trying to get the element model from nothing.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

)

Sometimes I dream about cheese

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

  

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