Jump to content

[HELP] DESTROY WANTEDLEVEL


#RooTs

Recommended Posts

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

function nostar() 
setTimer(function() 
star = createPickup (653.35773, -1769.18567, 13.57368, 3, 1247, 60000 ) 
addEventHandler("onPickupHit",star, 
function(player) 
setPlayerWantedLevel(player,getPlayerWantedLevel(player)-1) 
destroyElement(star) 
end) 
end,60000,0) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Tested this and this works

Link to comment
function nostar() 
setTimer(function() 
star = createPickup (653.35773, -1769.18567, 13.57368, 3, 1247, 60000 ) 
addEventHandler("onPickupHit",star, 
function(player) 
if not getPlayerWantedLevel(player) == 0 then 
setPlayerWantedLevel(player,getPlayerWantedLevel(player)-1) 
destroyElement(star) 
end 
end) 
end,60000,0) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Edit:// Use this code below to clear up the debug errors

function nostar() 
setTimer(function() 
star = createPickup (653.35773, -1769.18567, 13.57368, 3, 1247, 60000 ) 
addEventHandler("onPickupHit",star, 
function(player) 
if isElement( star ) and getElementType(star) == "pickup" and getElementModel(star) == 1247 then 
if not getPlayerWantedLevel(player) == 0 then 
setPlayerWantedLevel(player,getPlayerWantedLevel(player)-1) 
destroyElement(star) 
end 
end 
end) 
end,60000,0) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Link to comment

All the given examples works but not if they are used wrongly, see the wiki documentation for the event, onPickupHit:

This event is triggered when a player hits a pickup.

It will work for players but not if you're inside a vehicle. I would suggest creating this as an object and add a colshape around it, colshapes trigger on any type of element. The handling with respawns and stuff like that needs to be done manually but that won't be any problem, I've already seen a few samples in here which applies this kind of handling on the pickup which is just waste of server performance.

Link to comment

Sure, it's easy. This solution is based on the sample by Twerky with a few modifications. It's not tested thought but it should work. Good luck.

local star = nil 
local area = nil 
function nostar() 
    setTimer(function() 
        if isElement(star) then 
            destroyElement(star) 
        end 
        if isElement(area) then 
            destroyElement(area) 
        end 
        star = createObject (1247, 653.35773, -1769.18567, 13.57368 ) 
        area = createColRectangle ( 648.35773, -1774.18567, 10, 10 ) 
        addEventHandler ( "onColShapeHit", area,  
        function( hitElement, matchingDimension ) 
            if getElementType ( hitElement ) == "player" then 
                if getPlayerWantedLevel(hitElement) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(hitElement)-1) 
                    destroyElement(star) 
                end 
            elseif getElementType ( hitElement ) == "vehicle" then 
                local player = getVehicleOccupant(hitElement) 
                if player and getPlayerWantedLevel(player) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(player)-1) 
                    destroyElement(star) 
                end 
            end 
        end 
    end,60000,0) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Link to comment
local star = nil 
local area = nil 
function nostar() 
    setTimer(function() 
        if isElement(star) then 
            destroyElement(star) 
        end 
        if isElement(area) then 
            destroyElement(area) 
        end 
        star = createObject (1247, 653.35773, -1769.18567, 13.57368 ) 
        area = createColRectangle ( 648.35773, -1774.18567, 10, 10 ) 
        addEventHandler ( "onColShapeHit", area, 
        function( hitElement, matchingDimension ) 
            if getElementType ( hitElement ) == "player" then 
                if getPlayerWantedLevel(hitElement) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(hitElement)-1) 
                    destroyElement(star) 
                end 
            elseif getElementType ( hitElement ) == "vehicle" then 
                local player = getVehicleOccupant(hitElement) 
                if player and getPlayerWantedLevel(player) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(player)-1) 
                    destroyElement(star) 
                end 
            end 
        end,60000,0) 
    end) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Link to comment

Yeah I missed that ')' om line 27 I see. Those errors can't be taken literally obviously.

local star = nil 
local area = nil 
function nostar() 
    setTimer(function() 
        if isElement(star) then 
            destroyElement(star) 
        end 
        if isElement(area) then 
            destroyElement(area) 
        end 
        star = createObject (1247, 653.35773, -1769.18567, 13.57368 ) 
        area = createColRectangle ( 648.35773, -1774.18567, 10, 10 ) 
        addEventHandler ( "onColShapeHit", area,  
        function( hitElement, matchingDimension ) 
            if getElementType ( hitElement ) == "player" then 
                if getPlayerWantedLevel(hitElement) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(hitElement)-1) 
                    destroyElement(star) 
                end 
            elseif getElementType ( hitElement ) == "vehicle" then 
                local player = getVehicleOccupant(hitElement) 
                if player and getPlayerWantedLevel(player) > 0 then 
                    setPlayerWantedLevel(hitElement,getPlayerWantedLevel(player)-1) 
                    destroyElement(star) 
                end 
            end 
        end) 
    end,60000,0) 
end 
addEventHandler("onResourceStart",resourceRoot,nostar) 

Link to comment
star = createObject (1247, 653.35773, -1769.18567, 13.57368 ) 
 area = createColRectangle ( 648.35773, -1774.18567, 10, 10 ) 

2 errors

imagem.PNG

can not be the object has to be PICKUP ( OBJECT ) FAIL

createPickup (1548, -1681, 13, 3, 1239, 60000 ) 

Link to comment

Maybe, were currently moving all AC servers to new hardware but I might be able to test it in a few hours. Still don't think it's possible for pick ups to trigger when they getting hit by a vehicle. It doesn't work in single players and will probably not work in MTA either.

Link to comment
Maybe, were currently moving all AC servers to new hardware but I might be able to test it in a few hours. Still don't think it's possible for pick ups to trigger when they getting hit by a vehicle. It doesn't work in single players and will probably not work in MTA either.

It is possible, create a colshape around the pickup, make it trigger whenever an elements hits it and get the vehiclecontroller to remove the wanted level from.

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