Jump to content

race script - hitElement?


Recommended Posts

---server---

  
  
    function start(thePlayer) 
    for i, vehicle in ipairs(getElementsByType("vehicle")) do 
        setElementFrozen(vehicle, true) 
        setElementFrozen(thePlayer,true) 
        triggerClientEvent("startcountdown",getRootElement()) 
        setTimer(setElementFrozen,10000,1,vehicle,false) 
        setTimer(setElementFrozen,10000,1,thePlayer,false) 
    end 
    end 
    addCommandHandler("countdown",start) 

---client---

root = getRootElement() 
function Countdown (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/10.png",false) 
    setTimer ( Countdown9, 1000, 1 ) 
    outputChatBox ( "countdown started", root, 255, 255, 255, true ) 
    end 
function Countdown9 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/9.png",false) 
    setTimer ( Countdown8, 1000, 1 ) 
end 
function Countdown8 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/8.png",false) 
    setTimer ( Countdown7, 1000, 1 ) 
end 
function Countdown7 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/7.png",false) 
    setTimer ( Countdown6, 1000, 1 ) 
end 
function Countdown6 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/6.png",false) 
    setTimer ( Countdown5, 1000, 1 ) 
end 
function Countdown5 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/5.png",false) 
    setTimer ( Countdown4, 1000, 1 ) 
end 
function Countdown4 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/4.png",false) 
    setTimer ( Countdown3, 1000, 1 ) 
end 
function Countdown3 (root ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/3.png",false) 
    setTimer ( Countdown2, 1000, 1 ) 
end 
function Countdown2 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/2.png",false) 
    setTimer ( Countdown1, 1000, 1 ) 
end 
function Countdown1 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/1.png",false) 
    setTimer ( Countdown0, 1000, 1 ) 
end 
function Countdown0 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,320,81,"images/go.png",false) 
    setTimer ( CountdownEnd, 3000, 1 ) 
end 
function CountdownEnd (root) 
    guiSetVisible ( imagecount, false ) 
    end 
addEvent("startcountdown",true) 
addEventHandler("startcountdown",getRootElement(), Countdown) 
  

how to freeze vehicle that only hit the marker? cause its freezing all the players in the server..

cause i want to make a race script, race participants should hit the marker to participate the race..

pls give me some tips..

Link to comment
---server---
  
  
    function start(thePlayer) 
    for i, vehicle in ipairs(getElementsByType("vehicle")) do 
        setElementFrozen(vehicle, true) 
        setElementFrozen(thePlayer,true) 
        triggerClientEvent("startcountdown",getRootElement()) 
        setTimer(setElementFrozen,10000,1,vehicle,false) 
        setTimer(setElementFrozen,10000,1,thePlayer,false) 
    end 
    end 
    addCommandHandler("countdown",start) 

In that code, you loop through all vehicles, and you freeze them all.

Post your code where you handled the event onMarkerHit.

Link to comment

racemarker = createMarker(192,182,13,"cylinder",20,0,255,0,100)

function start(hitElement)

if (source == racemarker) then

for i,vehicle in ipairs(getElementByType("vehicle")) do

setElementFrozen(vehicle,true)

triggerClientEvent("startcountdown",hitElement)

setTimer(setElementFrozen,10000,1,vehicle,false)

end

end

addEventHandler("onMarkerHit",racemarker,start)

is that right?

Link to comment
racemarker = createMarker(192,182,13,"cylinder",20,0,255,0,100) 
  
function start(hitElement) 
if not isPedInVehicle(hitElement) then return end 
local vehicle = getPedOccupiedVehicle(hitElement) 
setElementFrozen(vehicle,true) 
triggerClientEvent(hitElement,"startcountdown",hitElement) 
setTimer(setElementFrozen,10000,1,vehicle,false) 
end 
addEventHandler("onMarkerHit",racemarker,start) 

Link to comment

racemarker = createMarker(-2663.51,610,13.3,"cylinder",20,0,255,0,100)

function start(hitElement)

if not isPedInVehicle(hitElement) then return end

if (source == racemarker) then

local vehicle = getPedOccupiedVehicle(hitElement)

setElementFrozen(vehicle,true)

triggerClientEvent(hitElement,"startcountdown",hitElement)

setTimer(setElementFrozen,10000,1,vehicle,false)

end

end

addCommandHandler("cd",start)

like this? its not working.

Link to comment

Sorry, try this:

racemarker = createMarker(192,182,13,"cylinder",20,0,255,0,100) 
  
function start(hitElement,cmd) 
    if(cmd)then 
        if not isPedInVehicle(hitElement) then return end 
        local vehicle = getPedOccupiedVehicle(hitElement) 
        setElementFrozen(vehicle,true) 
        triggerClientEvent(hitElement,"startcountdown",hitElement) 
        setTimer(setElementFrozen,10000,1,vehicle,false) 
    end 
end 
addEventHandler("onMarkerHit",racemarker,start) 
addCommandHandler("cd",start) 

Link to comment

---client-----

root = getRootElement() 
function Countdown (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/10.png",false) 
    setTimer ( Countdown9, 1000, 1 ) 
    outputChatBox ( "countdown started", root, 255, 255, 255, true ) 
    end 
function Countdown9 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/9.png",false) 
    setTimer ( Countdown8, 1000, 1 ) 
end 
function Countdown8 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/8.png",false) 
    setTimer ( Countdown7, 1000, 1 ) 
end 
function Countdown7 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/7.png",false) 
    setTimer ( Countdown6, 1000, 1 ) 
end 
function Countdown6 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/6.png",false) 
    setTimer ( Countdown5, 1000, 1 ) 
end 
function Countdown5 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/5.png",false) 
    setTimer ( Countdown4, 1000, 1 ) 
end 
function Countdown4 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/4.png",false) 
    setTimer ( Countdown3, 1000, 1 ) 
end 
function Countdown3 (root ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/3.png",false) 
    setTimer ( Countdown2, 1000, 1 ) 
end 
function Countdown2 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/2.png",false) 
    setTimer ( Countdown1, 1000, 1 ) 
end 
function Countdown1 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,110,190,"images/1.png",false) 
    setTimer ( Countdown0, 1000, 1 ) 
end 
function Countdown0 (root) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage(305,119,320,81,"images/go.png",false) 
    setTimer ( CountdownEnd, 3000, 1 ) 
end 
function CountdownEnd (root) 
    guiSetVisible ( imagecount, false ) 
    end 
addEvent("startcountdown",true) 
addEventHandler("startcountdown",getRootElement(), Countdown) 
  

----server----

racemarker = createMarker(-2663.51,610,13.3,"cylinder",20,0,255,0,100) 
  
function start(hitElement) 
if not isPedInVehicle(hitElement) then return end 
if (source == racemarker) then 
local vehicle = getPedOccupiedVehicle(hitElement) 
setElementFrozen(vehicle,true) 
triggerClientEvent(hitElement,"startcountdown",hitElement) 
setTimer(setElementFrozen,10000,1,vehicle,false) 
end 
end 
addCommandHandler("cd",start) 

i want to freeze all in the marker when timer starts or do a command :D

Link to comment

try this:

Server:

  
local racemarker = createMarker(-2663.51,610,13.3,"cylinder",20,0,255,0,100) 
local playersReady = 0 
local allPlayes = 0 
function start(hitElement) 
    for i,v in ipairs(getElementsByType("player"))do 
        allPlayes = allPlayes + 1 
    end 
    playersReady = playersReady + 1 
    if(playersReady == allPlayers)then 
        triggerClientEvent("startcountdown",root) 
    end 
    if not isPedInVehicle(hitElement) then return end 
    local vehicle = getPedOccupiedVehicle(hitElement) 
    setElementFrozen(vehicle,true) 
    setTimer(setElementFrozen,10000,1,vehicle,false) 
end 
addEventHandler("onMarkerHit",racemarker,start) 

Link to comment

oh, you want to start a race when the countdown is finish,

if you want to use the race gamemode then try this,

Server:

local racemarker = createMarker(-2663.51,610,13.3,"cylinder",20,0,255,0,100) 
local playersReady = 0 
local allPlayes = 0 
function start(hitElement) 
    for i,v in ipairs(getElementsByType("player"))do 
        allPlayes = allPlayes + 1 
    end 
    playersReady = playersReady + 1 
    if(playersReady == allPlayers)then 
        triggerClientEvent("startcountdown",root) 
        startResource(getResourceFromName("race")) 
    end 
    if not isPedInVehicle(hitElement) then return end 
    local vehicle = getPedOccupiedVehicle(hitElement) 
    setElementFrozen(vehicle,true) 
    setTimer(setElementFrozen,10000,1,vehicle,false) 
end 
addEventHandler("onMarkerHit",racemarker,start) 

Link to comment

lol, well, you could put everyone in a table (scripting side) then do your countdown, after that, you could start a map for those players and set the markers visible to the players in the table, and after the players reach the last marker, you could make an event called onRaceFinish...

it'll take a long time to finish but it's possible

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