Mefisto_PL Posted December 5, 2012 Share Posted December 5, 2012 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
Castillo Posted December 5, 2012 Share Posted December 5, 2012 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
Mefisto_PL Posted December 5, 2012 Author Share Posted December 5, 2012 bad argument #1 to find string expected got nil Link to comment
Castillo Posted December 5, 2012 Share Posted December 5, 2012 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
Mefisto_PL Posted December 5, 2012 Author Share Posted December 5, 2012 respawn_s :6 attempt to concatenate local 'mapinfo' (a table value) Link to comment
Castillo Posted December 5, 2012 Share Posted December 5, 2012 Remove this line: outputChatBox ( "Map info: ".. mapInfo ) And see what the other one returns. Link to comment
Mefisto_PL Posted December 6, 2012 Author Share Posted December 6, 2012 6:attempt to concatenate field 'name' ( a nil value) Error.. Link to comment
TwiX! Posted December 6, 2012 Share Posted December 6, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now