Jump to content

addEvent("s_finish",true) addEvent("s_vote",true) addEvent("s_startEngine",true)


Recommended Posts

من فضلكم شباب عندي مود سباق اريد التعديل عليه . المود هو سباق سيارات لكن المشكلة لما تدخل السباق لا تقدر تلغي والسيارة لا تتحطم ولا تموت 

اريد التعديل عليه حيث يصير سباق سيارة واحدة بوقت زمني محدد اذا تعديت المدة تخسر السباق وايضا اريد لما تصطدم بالسيارة تتحطم ويمكنك الغاء السباق بالخروج من السيارة ومباشرة تذهب الى احداثيات بداية السباق لتبدا من جديد وشكرا

 

 client :

addEvent("c_raceStart",true)
l_markerposX={2366, 2343, 2244, 2219, 2215, 2269, 2688, 2715, 2542, 2528, 2494, 2487}
l_markerposY={-1658, -1706, -1732, -1870, -1951, -2065, -2049, -1952, -1932, -1756, -1732, -1670}
l_Z=13.2
l_Z2=13.5
l_marker={}
l_blip={}
l_target=0
l_count=nil
l_racecar=nil
l_player=nil

function f_race(who,is)
    if(l_target>0)and(l_racecar~=nil)and(l_marker[l_target]==source)and(getPedOccupiedVehicle(who)==l_racecar)then
        triggerServerEvent("s_checkpos",who,l_target)
        outputChatBox("Checkpoint "..l_target.." Reached!")
        playSoundFrontEnd(43)
        destroyElement(source)
        destroyElement(l_blip[l_target])
        if(l_target<11)then
            l_blip[l_target+1]=createBlipAttachedTo(l_marker[l_target+1],19)
            l_marker[l_target+2]=createMarker(l_markerposX[l_target+2],l_markerposY[l_target+2],l_Z,"checkpoint",4,255,0,0,255)
            addEventHandler("onClientMarkerHit",l_marker[l_target+2],f_race)
            setMarkerTarget(l_marker[l_target+1],l_markerposX[l_target+2],l_markerposY[l_target+2],l_Z2)
            l_target=l_target+1
        elseif(l_target==11)then
            l_blip[l_target+1]=createBlipAttachedTo(l_marker[l_target+1],53)
            l_target=l_target+1
        elseif(l_target==12)then
            l_target=l_target+1
            playSound("sound/mission_accomplished.mp3")
            triggerServerEvent("s_finish",who,who,1)
        end
        triggerEvent("g_raceStart",localPlayer,l_target-1)
    end
end

function f_raceStart(num)
    l_player=num
    guiSetVisible(g_winlog,false)
    showCursor(false,false)
    l_racecar=getPedOccupiedVehicle(localPlayer)
    l_target=1
    l_count=4
    setTimer ( function()
        l_count=l_count-1
        if(l_count==3)then
            g_cntdwn=guiCreateLabel(0.5,0.4375,0.125,0.125,"3",true)
            guiSetFont(g_cntdwn,"sa-gothic")
            playSoundFrontEnd(44)
        elseif(l_count>0)then
            guiSetText(g_cntdwn,tostring(l_count))
            playSoundFrontEnd(44)
        elseif(l_count==0)then
            guiSetPosition(g_cntdwn,0.46875,0.4375,true)
            guiSetText(g_cntdwn,"GO")        
            playSoundFrontEnd(45)
        end
--        outputChatBox(tostring(l_count))
    end, 1000, 4 )
    setTimer(function()
        triggerServerEvent("s_startEngine",localPlayer)
    end,4000,1)
    setTimer(function()
        destroyElement(g_cntdwn)
    end,5000,1)
    outputChatBox("Vehicle: "..getVehicleName(l_racecar))
    outputChatBox("Driver: "..getPlayerName(localPlayer))
    triggerEvent("g_raceStart",localPlayer,l_target-1)
    for i=1,2,1 do
        l_marker=createMarker(l_markerposX,l_markerposY,l_Z,"checkpoint",4,255,0,0,255)
        addEventHandler("onClientMarkerHit",l_marker,f_race)
        if(i<2)then
            l_blip=createBlipAttachedTo(l_marker,19)
            setMarkerTarget(l_marker,l_markerposX[i+1],l_markerposY[i+1],l_Z2)
        end
    end
end
addEventHandler("c_raceStart",getRootElement(),f_raceStart)

 

gui:

 

addEvent("c_raceStart",true)
l_markerposX={2366, 2343, 2244, 2219, 2215, 2269, 2688, 2715, 2542, 2528, 2494, 2487}
l_markerposY={-1658, -1706, -1732, -1870, -1951, -2065, -2049, -1952, -1932, -1756, -1732, -1670}
l_Z=13.2
l_Z2=13.5
l_marker={}
l_blip={}
l_target=0
l_count=nil
l_racecar=nil
l_player=nil

function f_race(who,is)
    if(l_target>0)and(l_racecar~=nil)and(l_marker[l_target]==source)and(getPedOccupiedVehicle(who)==l_racecar)then
        triggerServerEvent("s_checkpos",who,l_target)
        outputChatBox("Checkpoint "..l_target.." Reached!")
        playSoundFrontEnd(43)
        destroyElement(source)
        destroyElement(l_blip[l_target])
        if(l_target<11)then
            l_blip[l_target+1]=createBlipAttachedTo(l_marker[l_target+1],19)
            l_marker[l_target+2]=createMarker(l_markerposX[l_target+2],l_markerposY[l_target+2],l_Z,"checkpoint",4,255,0,0,255)
            addEventHandler("onClientMarkerHit",l_marker[l_target+2],f_race)
            setMarkerTarget(l_marker[l_target+1],l_markerposX[l_target+2],l_markerposY[l_target+2],l_Z2)
            l_target=l_target+1
        elseif(l_target==11)then
            l_blip[l_target+1]=createBlipAttachedTo(l_marker[l_target+1],53)
            l_target=l_target+1
        elseif(l_target==12)then
            l_target=l_target+1
            playSound("sound/mission_accomplished.mp3")
            triggerServerEvent("s_finish",who,who,1)
        end
        triggerEvent("g_raceStart",localPlayer,l_target-1)
    end
end

function f_raceStart(num)
    l_player=num
    guiSetVisible(g_winlog,false)
    showCursor(false,false)
    l_racecar=getPedOccupiedVehicle(localPlayer)
    l_target=1
    l_count=4
    setTimer ( function()
        l_count=l_count-1
        if(l_count==3)then
            g_cntdwn=guiCreateLabel(0.5,0.4375,0.125,0.125,"3",true)
            guiSetFont(g_cntdwn,"sa-gothic")
            playSoundFrontEnd(44)
        elseif(l_count>0)then
            guiSetText(g_cntdwn,tostring(l_count))
            playSoundFrontEnd(44)
        elseif(l_count==0)then
            guiSetPosition(g_cntdwn,0.46875,0.4375,true)
            guiSetText(g_cntdwn,"GO")        
            playSoundFrontEnd(45)
        end
--        outputChatBox(tostring(l_count))
    end, 1000, 4 )
    setTimer(function()
        triggerServerEvent("s_startEngine",localPlayer)
    end,4000,1)
    setTimer(function()
        destroyElement(g_cntdwn)
    end,5000,1)
    outputChatBox("Vehicle: "..getVehicleName(l_racecar))
    outputChatBox("Driver: "..getPlayerName(localPlayer))
    triggerEvent("g_raceStart",localPlayer,l_target-1)
    for i=1,2,1 do
        l_marker=createMarker(l_markerposX,l_markerposY,l_Z,"checkpoint",4,255,0,0,255)
        addEventHandler("onClientMarkerHit",l_marker,f_race)
        if(i<2)then
            l_blip=createBlipAttachedTo(l_marker,19)
            setMarkerTarget(l_marker,l_markerposX[i+1],l_markerposY[i+1],l_Z2)
        end
    end
end
addEventHandler("c_raceStart",getRootElement(),f_raceStart)

 

server:

 

addEvent("s_finish",true)
addEvent("s_vote",true)
addEvent("s_startEngine",true)
addEvent("s_checkpos",true)
r_markerposX=2463
r_markerposY=-1658
r_markerposZ=14
r_pos={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0}
r_join={}
r_join2={}
r_player=0
r_finished=0
r_vehplate="RACE CAR"
r_startM=createMarker(r_markerposX,r_markerposY,r_markerposZ,"checkpoint",4,0,255,0,255,getRootElement())
r_startB=createBlipAttachedTo(r_startM,12, 0.5, 0 ,0, 0, 0, 0, 400)
r_voted=0
r_vote={}
r_started=0
r_play=0

function f_checkpos(check)
    r_pos[check]=r_pos[check]+1
    triggerClientEvent(client,"g_posShow",client,r_pos[check])
end
addEventHandler("s_checkpos",getRootElement(),f_checkpos)

function f_reset()
    local join2={}
    local newplayer=0
    for key=1,r_player,1 do
        if(r_join2[key]~=nil)then
            newplayer=newplayer+1
            join2[newplayer]=r_join2[key]
        end
    end
    r_join2=nil
    r_join2=join2
    r_player=newplayer
end

function s_votestart()
    if(r_vote[client]==1)then
        r_vote[client]=0
        r_voted=r_voted+1
        if(r_voted==r_player)then
            triggerClientEvent(r_join2,"c_raceStart",r_startM,r_player)
            triggerClientEvent(r_join2,"g_reset",r_startM)
            destroyElement(r_startM)
            destroyElement(r_startB)
            r_started=1
            r_vote=nil
            r_vote={}
            r_join=nil
            r_join={}
            r_join2=nil
            r_join2={}
            r_voted=0
            r_player=0
        end
    end
end
addEventHandler("s_vote",getRootElement(),s_votestart)

function f_start(mark,dim)
    if(mark==r_startM)and(getVehicleType(getPedOccupiedVehicle(source))=="Automobile")and(r_player<5)then
        outputChatBox("Type /join to join the race",source)
    end
end
addEventHandler("onPlayerMarkerHit",getRootElement(),f_start)

function s_starter()
    setVehicleEngineState(getPedOccupiedVehicle(client),true)
end
addEventHandler("s_startEngine",getRootElement(),s_starter)

function f_finish(who,num,id)
    r_finished=r_finished-1
    if(num>0)then
        givePlayerMoney(who,5000*(r_pos[11]-r_pos[12]+1))
        outputChatBox("Congratulations!",who,0,255,0)
    elseif(num==0)then
        setVehicleEngineState(getPedOccupiedVehicle(who),true)
        r_vote[who]=nil
        r_join2[r_join[who]]=nil
        r_join[who]=nil
        setVehiclePlateText(getPedOccupiedVehicle(who),"IMALOSER")
        triggerClientEvent(getRootElement(),"g_exit",who,id)
        f_reset()
    end
    if(r_finished==0)and(r_started==1)then
        r_started=0
        r_startM=createMarker(r_markerposX,r_markerposY,r_markerposZ,"checkpoint",4,0,255,0,255,getRootElement())
        r_startB=createBlipAttachedTo(r_startM,12, 0.5, 0 ,0, 0, 0, 0, 400)
        r_pos=nil
        r_pos={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0}
    end
    toggleControl(who,"enter_exit",true)
    setVehicleDamageProof(getPedOccupiedVehicle(who),false)
--    destroyElement(r_car)
end
addEventHandler("s_finish",getRootElement(),f_finish)

function f_join(thePlayer)
    if(isElementWithinMarker(thePlayer,r_startM))then
        if(r_join[thePlayer]~=1)then
            if(isPedInVehicle(thePlayer))then
                r_veh=getPedOccupiedVehicle(thePlayer)
                if(getVehicleType(r_veh)=="Automobile")and(r_player<5)then
                    r_player=r_player+1
                    r_finished=r_player
                    r_join[thePlayer]=1
                    r_vote[thePlayer]=1
                    r_join2[r_player]=thePlayer
                    removePedFromVehicle(thePlayer)
                    setElementPosition(r_veh,r_markerposX,(r_markerposY-15)+(6*r_player),r_markerposZ)
                    setElementRotation(r_veh,0,0,90)
                    setElementVelocity(r_veh,0,0,0)
                    warpPedIntoVehicle(thePlayer,r_veh)
--                    r_car=createVehicle(r_vehtype,r_markerposX,r_markerposY,r_markerposZ,0,0,90)
                    setVehicleDamageProof(r_veh,true)
                    setVehiclePlateText(r_veh,r_vehplate)
                    setVehicleEngineState(r_veh,false)
                    toggleControl(thePlayer,"enter_exit",false)
                    triggerClientEvent(getRootElement(),"g_start",thePlayer,thePlayer)
                    triggerClientEvent(thePlayer,"g_show",thePlayer)
                end
            end
        end
    else
        outputChatBox("You must enter the race marker first!",thePlayer)
    end
end
addCommandHandler("join",f_join)

Link to comment
  • 3 months later...

Client.lua
 

addEvent("c_raceStart", true)
local l_markerposX = {2366, 2343, 2244, 2219, 2215, 2269, 2688, 2715, 2542, 2528, 2494, 2487}
local l_markerposY = {-1658, -1706, -1732, -1870, -1951, -2065, -2049, -1952, -1932, -1756, -1732, -1670}
local l_Z = 13.2
local l_Z2 = 13.5
local l_marker = {}
local l_blip = {}
local l_target = 0
local l_racecar = nil
local raceTimer = nil

function f_race(who)
    if l_target > 0 and l_racecar ~= nil and l_marker[l_target] == source and getPedOccupiedVehicle(who) == l_racecar then
        triggerServerEvent("s_checkpos", who, l_target)
        outputChatBox("Checkpoint " .. l_target .. " Reached!")
        playSoundFrontEnd(43)
        destroyElement(source)
        destroyElement(l_blip[l_target])
        if l_target < 11 then
            l_blip[l_target + 1] = createBlipAttachedTo(l_marker[l_target + 1], 19)
            l_marker[l_target + 2] = createMarker(l_markerposX[l_target + 2], l_markerposY[l_target + 2], l_Z, "checkpoint", 4, 255, 0, 0, 255)
            addEventHandler("onClientMarkerHit", l_marker[l_target + 2], f_race)
            setMarkerTarget(l_marker[l_target + 1], l_markerposX[l_target + 2], l_markerposY[l_target + 2], l_Z2)
            l_target = l_target + 1
        elseif l_target == 11 then
            l_blip[l_target + 1] = createBlipAttachedTo(l_marker[l_target + 1], 53)
            l_target = l_target + 1
        elseif l_target == 12 then
            l_target = l_target + 1
            playSound("sound/mission_accomplished.mp3")
            triggerServerEvent("s_finish", who, who, 1)
            if isTimer(raceTimer) then killTimer(raceTimer) end
        end
    end
end

function f_raceStart(num)
    l_racecar = getPedOccupiedVehicle(localPlayer)
    l_target = 1
    setTimer(function()
        playSoundFrontEnd(44)
    end, 1000, 3)
    setTimer(function()
        playSoundFrontEnd(45)
        triggerServerEvent("s_startEngine", localPlayer)
    end, 4000, 1)
    
    for i = 1, 2 do
        l_marker[i] = createMarker(l_markerposX[i], l_markerposY[i], l_Z, "checkpoint", 4, 255, 0, 0, 255)
        addEventHandler("onClientMarkerHit", l_marker[i], f_race)
        if i < 2 then
            l_blip[i] = createBlipAttachedTo(l_marker[i], 19)
            setMarkerTarget(l_marker[i], l_markerposX[i + 1], l_markerposY[i + 1], l_Z2)
        end
    end

    raceTimer = setTimer(function()
        triggerServerEvent("s_finish", localPlayer, localPlayer, 0)
    end, 60000, 1)
end
addEventHandler("c_raceStart", getRootElement(), f_raceStart)

addEventHandler("onClientVehicleExit", getRootElement(), function(vehicle)
    if vehicle == l_racecar then
        triggerServerEvent("s_finish", localPlayer, localPlayer, 0)
    end
end)



server.lua
 

addEvent("s_finish", true)
addEvent("s_startEngine", true)
local r_markerposX = 2463
local r_markerposY = -1658
local r_markerposZ = 14

function s_starter()
    setVehicleEngineState(getPedOccupiedVehicle(client), true)
    setVehicleDamageProof(getPedOccupiedVehicle(client), false) 
end
addEventHandler("s_startEngine", getRootElement(), s_starter)

function f_finish(who, num)
    if num > 0 then
        givePlayerMoney(who, 5000)
        outputChatBox("u've completed the race", who, 0, 255, 0)
    else
        outputChatBox("u failed the race or exited the vehicle.", who, 255, 0, 0)
    end

    setElementPosition(who, r_markerposX, r_markerposY, r_markerposZ)
    setElementRotation(who, 0, 0, 90)

    if isPedInVehicle(who) then
        local vehicle = getPedOccupiedVehicle(who)
        setElementPosition(vehicle, r_markerposX, r_markerposY, r_markerposZ)
        setElementRotation(vehicle, 0, 0, 90)
        setVehicleEngineState(vehicle, false)
        setVehicleDamageProof(vehicle, true)
    end
end
addEventHandler("s_finish", getRootElement(), f_finish)

 

Edited by NotAnyOne
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...