[Help] Demolition-Derby job script


#1

So… I’m developing this client script that should trigger a job.
To trigger it:

  • Player is on a vehicle
  • Player is near the location
  • Player is near another player too

I’m trying to keep the script as simple as I can, but this doesn’t seem to work… What am I doing wrong? (thank you, this is one of my first scripts, I’m still learning)
client.lua

onJob = 0

function ToggleJob(jobid)
	if jobid = 1 then -- START JOB
		showLoadingPromt("Loading work: Demolition Derby", 5000, 3)
		Wait(5000)
		DrawMissionText('Drive around and crash in other players', 10000)
		onJob = jobid
	elseif jobid = 0
		onJob = jobid
	end
end

function DrawMissionText(m_text, showtime)
    ClearPrints()
	SetTextEntry_2("STRING")
	AddTextComponentString(m_text)
	DrawSubtitleTimed(showtime, 1)
end

AddEventHandler(function()
	if onJob = 0 then
		if IsPedSittingInAnyVehicle(GetPlayerPed(-1)) then
			if GetDistanceBetweenCoords(1618, 2158, 77, GetEntityCoords(GetPlayerPed(-1)),  true) < 10.0001 then
				if GetDistanceBetweenCoords(GetEntityCoords(GetNearestPlayerToEntity(GetPlayerPed(-1))), GetEntityCoords(GetPlayerPed(-1)), false) < 10.0001 then
					ToggleJob(1)
					Wait (5000)
					DrawMissionText('Drive around and crash in other players', 10000)
				else
				DrawMissionText('You need more players to start a Demo-Derby', 5000)
				end
			end
		end
	elseif onJob = 1 then
		if not IsPedSittingInAnyVehicle(GetPlayerPed(-1)) then
			ToggleJob(0)
		elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), 1618, 2158, 77, true) > 10.0001 then
			DrawMissionText('... Leaving the Demo-Derby ...', 5000)
			ToggleJob(0)
		end
	end
end)


#2

AddEventHandler() should be CreateThread() and a constant loop should be added to make:

CreateThread(function()
   while true do
...
   end
end)

#3

It gives me the following error at line 4:

‘then’ expected near ‘=’

It should be right

if jobid = 1 then

#4

it’s == not =…


#5

also… you’re missing a then and an equal sign


#9

I’m adding a new requirement to start the demo derby: one player has to be near me
This doesn’t seem to work:

if GetDistanceBetweenCoords(GetEntityCoords(GetNearestPlayerToEntity(GetPlayerPed(-1))), GetEntityCoords(GetPlayerPed(-1)), true) <= 320 then

neither with Vdist or Vdist2