Jump to content

[HELP] Vehicle Faction


Recommended Posts

Posted

hi guys i have a problem for vehicle factions!

 

local policeVehicles =
{
	{597, 1645.125, -1367.453125, 17.443872451782},
	{597, 1641.125, -1367.453125, 17.443872451782},
	{597, 1637.125, -1367.453125, 17.443872451782},
	{597, 1633.125, -1367.453125, 17.443872451782},
	{597, 1629.125, -1367.453125, 17.443872451782},
	{597, 1625.125, -1367.453125, 17.443872451782},
	{447, 1680.181640625, -1418.8740234375, 85.044067382813},
	{447, 1680.181640625, -1400.8740234375, 85.044067382813},
	{447, 1680.181640625, -1382.8740234375, 85.044067382813},
}
local police = "Police"

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 == 0 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 ( "#ffff00Shoma Dar Faction F.B.I Nistid!", player,240,155,15,true)
			end
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh )

what is this problem ?

all players can enter Police Vehicle :/

@JeViCo

Posted

fixed i guess

local policeVehicles =
{
	{597, 1645.125, -1367.453125, 17.443872451782},
	{597, 1641.125, -1367.453125, 17.443872451782},
	{597, 1637.125, -1367.453125, 17.443872451782},
	{597, 1633.125, -1367.453125, 17.443872451782},
	{597, 1629.125, -1367.453125, 17.443872451782},
	{597, 1625.125, -1367.453125, 17.443872451782},
	{447, 1680.181640625, -1418.8740234375, 85.044067382813},
	{447, 1680.181640625, -1400.8740234375, 85.044067382813},
	{447, 1680.181640625, -1382.8740234375, 85.044067382813},
}
local police = "Police"

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

function vh ( player, seat )
	if seat == 0 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 ( "#ffff00Shoma Dar Faction F.B.I Nistid!", player,240,155,15,true)
			end
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh )

 

Posted
9 minutes ago, JeViCo said:

fixed i guess


local policeVehicles =
{
	{597, 1645.125, -1367.453125, 17.443872451782},
	{597, 1641.125, -1367.453125, 17.443872451782},
	{597, 1637.125, -1367.453125, 17.443872451782},
	{597, 1633.125, -1367.453125, 17.443872451782},
	{597, 1629.125, -1367.453125, 17.443872451782},
	{597, 1625.125, -1367.453125, 17.443872451782},
	{447, 1680.181640625, -1418.8740234375, 85.044067382813},
	{447, 1680.181640625, -1400.8740234375, 85.044067382813},
	{447, 1680.181640625, -1382.8740234375, 85.044067382813},
}
local police = "Police"

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

function vh ( player, seat )
	if seat == 0 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 ( "#ffff00Shoma Dar Faction F.B.I Nistid!", player,240,155,15,true)
			end
		end
	end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), vh )

 

faction member Police can't enter vehicle :|

 

Posted
2 minutes ago, Mσнαмα∂ Hєℓιѕн said:

faction member Police can't enter vehicle :|

 

Do you set the element data of the member of the police faction? I mean I'm quite sure that element data is not the only thing determining whether someone is police or not. 

Posted (edited)
9 minutes ago, WorthlessCynomys said:

Do you set the element data of the member of the police faction? I mean I'm quite sure that element data is not the only thing determining whether someone is police or not. 


I want to make only members of the police cops be able to board the policeVehicles!
Edited by Mσнαмα∂ Hєℓιѕн
Posted
5 minutes ago, Mσнαмα∂ Hєℓιѕн said:


I want to make only members of the police cops be able to board the policeVehicles!

And that is decided by element data.

Do you use debugscript? Have any errors?

Who can enter the vehicle now? Police can't and everyone else can? 

Posted

i checked and everying working. Something wrong with your faction name (replace "with F.B.I or rewrite script a little bit if you want to give access for several factions")

OR

You have a teams instead of elementData

 

  • Thanks 1

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