Jump to content

[HELP] onPlayerJoin


Dope88

Recommended Posts

Hello, I want to remodel my vehicles when the Players join on my server. Code works with the command but the game crashes with the onPlayerJoin Event. Thanks for Help

server.lua:

--[[resourceRoot = getResourceRootElement(getThisResource())

function fahrzeugErstellen(id)
	local fahrzeug = createVehicle(544, -1993.19, 209.32, 27.39  )
	setElementModel(fahrzeug, id)
	--triggerClientEvent(resourceRoot, "fahrzeugAnfrage", resourceRoot, fahrzeug)
end
addEvent('fahrzeugErstellen', true)
addEventHandler('fahrzeugErstellen', resourceRoot, fahrzeugErstellen)


--fahrzeugErstellen()]]

resourceRoot = getResourceRootElement(getThisResource())

fahrzeug = createVehicle(544, -1993.19, 209.32, 27.39)

function fahrzeugErstellen(playerSource)
	triggerClientEvent('fahrzeugModellieren', resourceRoot, fahrzeug)
end
addCommandHandler('fahrzeugErstellen', fahrzeugErstellen)

function onPlayerJoin(playerSource, commandName)
	setTimer ( function()
		executeCommandHandler ( "fahrzeugErstellen", playerSource )
	end, 60000, 1 )
end
addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoin)

client.lua:

resourceRoot = getResourceRootElement(getThisResource())

function fahrzeugModellieren(fahrzeug)
  --if ( fileExists ( "pdBus.txd" ) then
    --if ( fileExists ( "pdBus.dff" ) then
      local txd = engineLoadTXD('pdBus.txd')
      local dff = engineLoadDFF('pdBus.dff')
      local id = engineRequestModel('vehicle', 544)

      engineImportTXD(txd, id)
      engineReplaceModel(dff, id)

      setElementModel(fahrzeug, id)
    --end
  --end
end
addEvent('fahrzeugModellieren', true)
addEventHandler('fahrzeugModellieren', resourceRoot, fahrzeugModellieren)

 

Link to comment

Firstly, I noticed that you have commented out the fahrzeugErstellen() function in your server.lua file, which creates the vehicle with the specified model ID. Therefore, when the fahrzeugErstellen(playerSource) function is called, it is not creating a new vehicle. You can uncomment the function to fix this issue.

Secondly, I can see that in your client.lua file, you have commented out the conditionals for checking whether the texture and model files exist. This may lead to errors if the files do not exist. 

Additionally, in the fahrzeugModellieren() function, you are requesting the model ID using engineRequestModel('vehicle', 544), but you should use engineLoadDFF('pdBus.dff') instead. You can then use the returned model ID to import the texture and replace the model.

Lastly, in your onPlayerJoin function, you are passing commandName as a parameter, but you are not using it. You can remove it to prevent any potential issues.

 

  • Like 1
Link to comment

when you use the onPlayerJoin event you are trying to create a vehicle too quickly its not guaranteed that the player will have finished loading in before the event is called If you try to create a vehicle before the player has finished loading in the game will probably crash

onClientResourceStart
--//--
executeCommandHandler("fahrzeugErstellen")

  Those will Check if the resources has been loaded it will use the command

  • Like 1
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...