Sign in to follow this  
wesleywillems17

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 )

 

Share this post


Link to post

When play isn't in a team getPlayerTeam returns false, so a simple if team check will solve the issue.

Share this post


Link to post
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 )

 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.