Jump to content

DM Respawn problem


Mefisto_PL

Recommended Posts

What's wrong? It's error in finding map name.

local running = false -- if race is running 
  
addEvent("onClientRequestRespawn", true) 
addEventHandler("onClientRequestRespawn", getRootElement(), 
function(mapInfo, mapOptions, gameOptions,vehicleData) 
    if (ismapDM(mapInfo.name) == 1) then 
    -- source is the player that requested respawn. 
    -- spawn at the position where last saved. 
    triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
    triggerEvent('onClientRequestSpectate', source, false) 
    spawnPlayer(source, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
    local vehicle = exports.race:getPlayerVehicle(source) 
    warpPedIntoVehicle(source, vehicle) 
    triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
    setElementData(source, "race.spectating", true) 
    setElementData(source, "status1", "dead") 
    setElementData(source, "status2", "") 
    --setElementData(source, "state", "training") 
    setElementData(source, "race.finished", true) 
    setCameraTarget(source, source) 
    setElementData(vehicle, "race.collideworld", 1) 
    setElementData(vehicle, "race.collideothers", 0) 
    setElementData(source, "race.alpha", 255) 
    setElementData(vehicle, "race.alpha", 255) 
    setElementHealth(vehicle, vehicleData.health) 
    setElementModel(vehicle, 481) -- fix motor sound. 
    setElementModel(vehicle, tonumber(vehicleData.model)) 
    setElementPosition(vehicle, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
    setElementRotation(vehicle, vehicleData.rotX, vehicleData.rotY, vehicleData.rotZ) 
    if(vehicleData.nitro ~= nil)then 
        addVehicleUpgrade(vehicle, tonumber(vehicleData.nitro)) 
    end 
    setElementFrozen(vehicle, true) 
    toggleAllControls(source, true) 
    setVehicleLandingGearDown(vehicle, true) 
    setTimer(delayedRespawn, 2000, 1, source, vehicle, vehicleData) 
    elseif (ismapDM(mapInfo.name) == 2) then 
    cancelEvent() 
    elseif (ismapDM(mapInfo.name) == 3) then 
    cancelEvent() 
end 
end 
) 
  
function ismapDM ( mapInfo ) 
if string.find( mapInfo.name, "[DM]", 1, true ) then 
    return 1 
elseif string.find( mapInfo.name, "[DD]", 1, true ) then 
    return 2 
elseif string.find( mapInfo.name, "[FUN]", 1, true ) then 
    return 3 
end 
end 
  
function delayedRespawn(player, vehicle, vehicleData) 
    triggerClientEvent(player, "clientUnfreezeOnReady", player, vehicle, vehicleData) 
end 
  
addEvent("onRaceStateChanging", true) 
addEventHandler("onRaceStateChanging", getRootElement(), 
function(newState, oldState) 
    triggerClientEvent("onClientRaceStateChanging", getRootElement(), newState, oldState) 
    if(newState == "Running")then 
        running = true 
    end 
    if(newState == "PostFinish" or newState == "NoMap")then 
        running = false 
        local player = getElementsByType("player") 
        for i = 1, #player do 
            local replaying = getElementData(player[i], "respawn.playing") 
            if(replaying)then 
                setElementData(source, "race.spectating", false) 
                setElementData(source, "status1", "dead") 
                setElementData(source, "status2", "") 
                setElementData(source, "race.finished", false) 
            end 
        end 
    end 
end) 
  
-- Add training mode before player has played once 
addEventHandler("onElementDataChange", getRootElement(), 
function(theName, oldValue) 
    if(getElementType(source) == "player")then 
        if(tostring(getElementData(source, "state")) == "waiting" and running)then 
            --triggerClientEvent(source, "onClientRaceStateChanging", source, "Running", "GridCountdown") 
        end 
    end 
end) 
  
-- Kill when respawned and gets hunter. 
addEvent("onPlayerPickUpRacePickup", true) 
addEventHandler("onPlayerPickUpRacePickup", getRootElement(), 
function(pickupID, pickupType, vehicleModel) 
    if(pickupType == "vehiclechange" and vehicleModel == 425)then 
        local state = getElementData(source, "state") or "dead" 
        if(state == "dead")then 
            setElementHealth(source, 0) 
        end 
    end 
end) 
  

Link to comment

Since you are passing a string and not a table to ismapDM, then you must here use the string.

function ismapDM ( mapName ) 
if string.find( mapName, "[DM]", 1, true ) then 
    return 1 
elseif string.find( mapName, "[DD]", 1, true ) then 
    return 2 
elseif string.find( mapName, "[FUN]", 1, true ) then 
    return 3 
end 
end 

Link to comment
addEvent("onClientRequestRespawn", true) 
addEventHandler("onClientRequestRespawn", getRootElement(), 
function(mapInfo, mapOptions, gameOptions,vehicleData) 
    outputChatBox ( "Map info: ".. mapInfo ) 
    outputChatBox ( "Map name: ".. mapInfo.name ) 
    if (ismapDM(mapInfo.name) == 1) then 
    -- source is the player that requested respawn. 
    -- spawn at the position where last saved. 
    triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
    triggerEvent('onClientRequestSpectate', source, false) 
    spawnPlayer(source, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
    local vehicle = exports.race:getPlayerVehicle(source) 
    warpPedIntoVehicle(source, vehicle) 
    triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
    setElementData(source, "race.spectating", true) 
    setElementData(source, "status1", "dead") 
    setElementData(source, "status2", "") 
    --setElementData(source, "state", "training") 
    setElementData(source, "race.finished", true) 
    setCameraTarget(source, source) 
    setElementData(vehicle, "race.collideworld", 1) 
    setElementData(vehicle, "race.collideothers", 0) 
    setElementData(source, "race.alpha", 255) 
    setElementData(vehicle, "race.alpha", 255) 
    setElementHealth(vehicle, vehicleData.health) 
    setElementModel(vehicle, 481) -- fix motor sound. 
    setElementModel(vehicle, tonumber(vehicleData.model)) 
    setElementPosition(vehicle, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
    setElementRotation(vehicle, vehicleData.rotX, vehicleData.rotY, vehicleData.rotZ) 
    if(vehicleData.nitro ~= nil)then 
        addVehicleUpgrade(vehicle, tonumber(vehicleData.nitro)) 
    end 
    setElementFrozen(vehicle, true) 
    toggleAllControls(source, true) 
    setVehicleLandingGearDown(vehicle, true) 
    setTimer(delayedRespawn, 2000, 1, source, vehicle, vehicleData) 
    elseif (ismapDM(mapInfo.name) == 2) then 
    cancelEvent() 
    elseif (ismapDM(mapInfo.name) == 3) then 
    cancelEvent() 
end 
end) 

See what does it output.

Link to comment
mapInfo.name 

Will work only with

onMapStarting 

or

onClientMapStarting 

Events

addEvent ( "onMapStarting" ) 
addEventHandler ( "onMapStarting", root, 
function ( mapInfo, mapOptions, gameOptions ) 
    cMap = nil 
    if ( ismapDM ( mapInfo.name ) == 1 ) then 
        cMap = 1; 
    elseif ( ismapDM ( mapInfo.name ) == 2 ) then 
        cMap = 2; 
    elseif ( ismapDM ( mapInfo.name ) == 3 ) then 
        cMap = 3; 
    end 
end 
) 
  
function ismapDM ( mapName ) 
    if string.find ( mapName, "[DM]", 1, true ) then 
        return 1 
    elseif string.find ( mapName, "[DD]", 1, true ) then 
        return 2 
    elseif string.find ( mapName, "[FUN]", 1, true ) then 
        return 3 
    end 
end 
  
addEvent("onClientRequestRespawn", true) 
addEventHandler("onClientRequestRespawn", getRootElement(), 
    function(mapInfo, mapOptions, gameOptions,vehicleData) 
        outputChatBox ( "Map info: ".. mapInfo ) 
        outputChatBox ( "Map name: ".. mapInfo.name ) 
        if ( cMap == 1 ) then 
            -- source is the player that requested respawn. 
            -- spawn at the position where last saved. 
            triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
            triggerEvent('onClientRequestSpectate', source, false) 
            spawnPlayer(source, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
            local vehicle = exports.race:getPlayerVehicle(source) 
            warpPedIntoVehicle(source, vehicle) 
            triggerClientEvent(source, 'onClientCall_race', source, "Spectate.stop", 'manual') 
            setElementData(source, "race.spectating", true) 
            setElementData(source, "status1", "dead") 
            setElementData(source, "status2", "") 
            --setElementData(source, "state", "training") 
            setElementData(source, "race.finished", true) 
            setCameraTarget(source, source) 
            setElementData(vehicle, "race.collideworld", 1) 
            setElementData(vehicle, "race.collideothers", 0) 
            setElementData(source, "race.alpha", 255) 
            setElementData(vehicle, "race.alpha", 255) 
            setElementHealth(vehicle, vehicleData.health) 
            setElementModel(vehicle, 481) -- fix motor sound. 
            setElementModel(vehicle, tonumber(vehicleData.model)) 
            setElementPosition(vehicle, vehicleData.posX, vehicleData.posY, vehicleData.posZ) 
            setElementRotation(vehicle, vehicleData.rotX, vehicleData.rotY, vehicleData.rotZ) 
            if(vehicleData.nitro ~= nil)then 
                addVehicleUpgrade(vehicle, tonumber(vehicleData.nitro)) 
            end 
            setElementFrozen(vehicle, true) 
            toggleAllControls(source, true) 
            setVehicleLandingGearDown(vehicle, true) 
            setTimer(delayedRespawn, 2000, 1, source, vehicle, vehicleData) 
        elseif ( cMap == 2 )  then 
            cancelEvent() 
        elseif ( cMap == 3 )  then 
            cancelEvent() 
        end 
    end 
) 

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