Mσнαмα∂ Hєℓιѕн Posted August 15, 2018 Share Posted August 15, 2018 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
VenomOG Posted August 15, 2018 Share Posted August 15, 2018 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
Mσнαмα∂ Hєℓιѕн Posted August 15, 2018 Author Share Posted August 15, 2018 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
JeViCo Posted August 15, 2018 Share Posted August 15, 2018 (edited) 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 August 15, 2018 by JeViCo Link to comment
Mσнαмα∂ Hєℓιѕн Posted August 15, 2018 Author Share Posted August 15, 2018 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
XaskeL Posted August 15, 2018 Share Posted August 15, 2018 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
XaskeL Posted August 15, 2018 Share Posted August 15, 2018 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
Keiichi1 Posted August 15, 2018 Share Posted August 15, 2018 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
JeViCo Posted August 16, 2018 Share Posted August 16, 2018 (edited) 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 August 16, 2018 by JeViCo 1 Link to comment
Mσнαмα∂ Hєℓιѕн Posted August 16, 2018 Author Share Posted August 16, 2018 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
JeViCo Posted August 16, 2018 Share Posted August 16, 2018 5 minutes ago, Mσнαмα∂ Hєℓιѕн said: your script is working but player can't G to vehicle! i can't understand could you explain? Link to comment
Mr.Loki Posted August 16, 2018 Share Posted August 16, 2018 1 minute ago, JeViCo said: i can't understand could you explain? He means that players can't enter the passenger seat pressing the G key. Link to comment
Mσнαмα∂ Hєℓιѕн Posted August 16, 2018 Author Share Posted August 16, 2018 2 minutes ago, JeViCo said: i can't understand could you explain? do you have TeamSpeak3 ? Just now, Mr.Loki said: He means that players can't enter the passenger seat pressing the G key. you are right! Link to comment
JeViCo Posted August 16, 2018 Share Posted August 16, 2018 2 minutes ago, Mσнαмα∂ Hєℓιѕн said: do you have TeamSpeak3 ? you are right! ok, i understand now) Replace this part if seat ~=1 then with this if seat == 0 then 1 Link to comment
Mσнαмα∂ Hєℓιѕн Posted August 16, 2018 Author Share Posted August 16, 2018 2 minutes ago, JeViCo said: ok, i understand now) Replace this part if seat ~=1 then with this if seat == 0 then working thanks you bro Link to comment
JeViCo Posted August 16, 2018 Share Posted August 16, 2018 2 minutes ago, Mσнαмα∂ Hєℓιѕн said: working thanks you bro any time, mate Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now