Jump to content

Check player team to spawn car


Recommended Posts

Hi,

I have a problem with my car spawn script.

Everything worked but when a player isn't in a team it says "Expected team at argument 1, got boolean".

I know that it has something to do because i'm not in a team.

What do i need to add to remove this bug/report?

local vehicleTable = {}
function SpawnRandomCopCar ()
	team = getPlayerTeam(source)
	if (getTeamName(team) == "Police officer") then
		local CopCar = vehicleTable[source]
		if CopCar then
			if isElement( CopCar ) then
				destroyElement( CopCar )
			end
			vehicleTable[source]= nil
		end
		x, y, z = SpawnCopCar ()
		local CopCar = createVehicle ( 596, x, y, z, 0, 0, 180 )
		warpPedIntoVehicle ( source, CopCar )
		vehicleTable[source]= CopCar
	else
		outputChatBox ( "You must be a police officer to get a police car!", source, 255, 0, 0, true )
	end
end
addEvent( "GiveCopCarFree", true )
addEventHandler( "GiveCopCarFree", root, SpawnRandomCopCar )

 

Link to comment
local vehicleTable = {}
function SpawnRandomCopCar ()
	local team = getPlayerTeam(source)
	if (team) then
		if (getTeamName(team) == "Police officer") then
			local CopCar = vehicleTable[source]
			if CopCar then
				if isElement( CopCar ) then
					destroyElement( CopCar )
				end
				vehicleTable[source]= nil
			end
			x, y, z = SpawnCopCar ()
			local CopCar = createVehicle ( 596, x, y, z, 0, 0, 180 )
			warpPedIntoVehicle ( source, CopCar )
			vehicleTable[source]= CopCar
		else
			outputChatBox ( "You must be a police officer to get a police car!", source, 255, 0, 0, true )
		end
	else
		outputChatBox ( "You must be a police officer to get a police car!", source, 255, 0, 0, true )
	end
end
addEvent( "GiveCopCarFree", true )
addEventHandler( "GiveCopCarFree", root, SpawnRandomCopCar )

 

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