Jump to content

[Help] Faction Vehicles


Recommended Posts

 
local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

function mashinPolice (thePlayer, seat, jacked)
	if not getElementData (thePlayer, "faction") == Police and getElementModel(source) == "policeVehicles" then
	    cancelEvent()
		outputChatBox ( "#ffff00your not in police department faction", player,255,255,255,true)
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), mashinPolice )

 

this is my faction vehicle script, not working!

what is problem ?

 

I want to make only local policeVehicles available to getElementData Police!

 

Link to comment
policeVehicles = { [598]=true, [596]=true, [597]=true, [599]=true }

function enterVehicle ( thePlayer, seat, jacked ) 
    if ( policeVehicles[getElementModel ( source )] ) and ( getElementData("fanction" == "NAME") then 
        outputChatBox ( "Welcome to the faction vehicles", thePlayer ) 
    end
end
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 

Try this

Link to comment
7 hours ago, KnucklesSAEG said:

policeVehicles = { [598]=true, [596]=true, [597]=true, [599]=true }

function enterVehicle ( thePlayer, seat, jacked ) 
    if ( policeVehicles[getElementModel ( source )] ) and ( getElementData("fanction" == "NAME") then 
        outputChatBox ( "Welcome to the faction vehicles", thePlayer ) 
    end
end
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 

Try this

:/

Link to comment

try this

local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

function vh ( player, seat )
	local model = getElementModel ( source )
	local checkmodel = function()
		for _, veh in ipairs(policeVehicles) do
			if veh[1] == model then
				break
        		return true
			end
      	end
    	return false
    end
	if checkmodel and seat == 0 then
		if getElementData(player,"fanction") ~= "Police" then
			cancelEvent()
			outputChatBox ( "#ffff00your are not in police department faction", player,240,155,15,true)
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh ) 
Edited by JeViCo
Link to comment
8 hours ago, JeViCo said:

try this


local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

function vh ( player, seat )
	local model = getElementModel ( source )
	local checkmodel = function()
		for _, veh in ipairs(policeVehicles) do
			if veh[1] == model then
				break
        		return true
			end
      	end
    	return false
    end
	if checkmodel and seat == 0 then
		if getElementData(player,"fanction") ~= "Police" then
			cancelEvent()
			outputChatBox ( "#ffff00your are not in police department faction", player,240,155,15,true)
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh ) 
the policeVehicles do not spawn

 

Hi, I did not understand you! I say what I can do to define the cars that are defined in local policeVehicles to the police faction In a way that only police faction members can get into cars Others can only sit next to the driver (G)

Link to comment
local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

function mashinPolice (thePlayer, seat, jacked)
	if not getElementData (thePlayer, "faction") == Police and getElementModel(source) == "policeVehicles" then
	    cancelEvent()
		outputChatBox ( "#ffff00your not in police department faction", player,255,255,255,true)
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), mashinPolice )

My code:

 

local policeVehicles = {
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

local isVehiclePolice = {}
for i, v in ipairs(policeVehicles) do
	isVehiclePolice[ v[1] ] = true;
end

addEventHandler('onVehicleStartEnter', root,
	function(player, seat, jacked, door)
		if seat ~= 0 then
			return false
		end
		local model = getElementModel(source) 
		if isVehiclePolice[model] and not getElementData(player, "faction") == Police then -- variable 'Police' is defined?
			outputChatBox("#ffff00your not in police department faction",player,255,255,255,true)
			cancelEvent()
		end
	end
);

 

-- or not then
if isVehiclePolice[model] and not getElementData(player, "faction") == Police then
-- faction? replace to 'fraction'
-- Police? replace to "Police"
-- EXAMPLE:
if isVehiclePolice[model] and not getElementData(player, "fraction") == "Police" then

 

Link to comment
33 minutes ago, XaskeL said:

local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

function mashinPolice (thePlayer, seat, jacked)
	if not getElementData (thePlayer, "faction") == Police and getElementModel(source) == "policeVehicles" then
	    cancelEvent()
		outputChatBox ( "#ffff00your not in police department faction", player,255,255,255,true)
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), mashinPolice )

My code:

 


local policeVehicles = {
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}

local isVehiclePolice = {}
for i, v in ipairs(policeVehicles) do
	isVehiclePolice[ v[1] ] = true;
end

addEventHandler('onVehicleStartEnter', root,
	function(player, seat, jacked, door)
		if seat ~= 0 then
			return false
		end
		local model = getElementModel(source) 
		if isVehiclePolice[model] and not getElementData(player, "faction") == Police then -- variable 'Police' is defined?
			outputChatBox("#ffff00your not in police department faction",player,255,255,255,true)
			cancelEvent()
		end
	end
);

 


-- or not then
if isVehiclePolice[model] and not getElementData(player, "faction") == Police then
-- faction? replace to 'fraction'
-- Police? replace to "Police"
-- EXAMPLE:
if isVehiclePolice[model] and not getElementData(player, "fraction") == "Police" then

 

 

Link to comment
local policeVehicles = {
    [597] = true,
}

local vehiclePositions = {
    {597, -1594.15295, 674.24622, 7.18750},
}

for _, v in pairs(vehiclePositions) do
    createVehicle(v[1], v[2], v[3], v[4])
end

addEventHandler("onVehicleStartEnter", getRootElement(), function(thePlayer)
    if getElementData(thePlayer, "faction") ~= "Police" and policeVehicles[getElementModel(source)] then
        outputChatBox("#ffff00You're not in Police Department faction.", thePlayer, 255, 255, 255, true)
        cancelEvent()
    end
end)

 

Link to comment
10 hours ago, Mσнαмα∂ Hєℓιѕн said:

what I can do to define the cars that are defined in local policeVehicles to the police faction In a way that only police faction members can get into cars Others can only sit next to the driver

oh, you can use setElementData to connect cars with faction. I also added car spawn.

local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}
local police = "Police" -- name of your faction

addEventHandler("onResourceStart",resourceRoot,function()
	for _, v in ipairs(policeVehicles) do
		local veh = createVehicle(v[1],v[2],v[3],v[4],0,0,v[5]) -- spawn a car
		setElementData(veh,"carFaction",police) -- set car's faction
	end
end)

function vh ( player, seat )
	if seat ~=1 then -- allow to sit only next to the driver
		if getElementData(source,"carFaction") == police then -- check car
			if getElementData(player,"faction") ~= police then -- check player
				cancelEvent()
				outputChatBox ( "#ffff00your are not in police department faction", player,240,155,15,true)
			end
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh ) 

 

Edited by JeViCo
  • Like 1
Link to comment
11 hours ago, JeViCo said:

oh, you can use setElementData to connect cars with faction. I also added car spawn.


local policeVehicles =
{
	{597, -1594.15295, 674.24622, 7.18750, 92.063659667969},
}
local police = "Police" -- name of your faction

addEventHandler("onResourceStart",resourceRoot,function()
	for _, v in ipairs(policeVehicles) do
		local veh = createVehicle(v[1],v[2],v[3],v[4],0,0,v[5]) -- spawn a car
		setElementData(veh,"carFaction",police) -- set car's faction
	end
end)

function vh ( player, seat )
	if seat ~=1 then -- allow to sit only next to the driver
		if getElementData(source,"carFaction") == police then -- check car
			if getElementData(player,"faction") ~= police then -- check player
				cancelEvent()
				outputChatBox ( "#ffff00your are not in police department faction", player,240,155,15,true)
			end
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh ) 

 

your script is working but player can't G to vehicle!

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