Jump to content

I am trying to create a script which blows the vehicle at 'x' object


Alex2112

Recommended Posts

Hi, as the title says I am trying to make a script that blows vehicle at 6959 object but I want the player to be warned with a text like this one 

 

 dxDrawText("Do not try to camp!", 0, 0, x, y, tocolor(255, 0, 0), 2, "pricedown", "center", "center")

but I want to add SetTimer too, because players should have time to read/ and to go back to track.

This is the script which I have tried to do.

 

addEventHandler("onClientVehicleCollision", getRootElement(), function(hitElement)
    if source ~= getPedOccupiedVehicle(localPlayer) then return end
    if getElementType(hitElement) == "object" and getElementModel(hitElement) == 6959 then
        blowVehicle(source)
    end
end)

The problem is I do not really know where to add the DrawText and SetTimer too

 

Thanks for helping me !

Link to post

To draw the text, you need to put it in an onClientRender event, because you need to draw it at every frame.
Then you need to add an "onClientRender" event handler to draw your text.
You can then use a timer to remove the event handler, so that the text disappears after the timer executes.

Example:
 

-- Create a function that draws your text.
function drawWarning()
	dxDrawText("Do not try to camp!", 0, 0, x, y, tocolor(255, 0, 0), 2, "pricedown", "center", "center")
end


addEventHandler("onClientVehicleCollision", getRootElement(), function(hitElement)
    if source ~= getPedOccupiedVehicle(localPlayer) then return end
    if getElementType(hitElement) == "object" and getElementModel(hitElement) == 6959 then
    	-- Show text (handle "onClientRender" event)
    	addEventHandler("onClientRender", root, drawWarning)
      	-- Create a timer that makes sure the "onClientRender" handler gets removed when it expires.
      	setTimer(removeEventHandler, 5000, 1, "onClientRender", root, drawWarning)
      
        blowVehicle(source)
    end
end)

 

Link to post

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