xXMADEXx Posted January 16, 2013 Posted January 16, 2013 How can i make it, so that when someone spawns a car it locks it to team Military? I attempted it, but it didn't work: ----------- This Area Here. -------- function spawnVeh(id) local x, y, z = getElementPosition(source) local team = getTeamName(getPlayerTeam(source)) if isElement(vehicles[source]) then destroyElement(vehicles[source]) end vehicles[source] = createVehicle(id, x, y, z) warpPedIntoVehicle ( source, vehicles[source] ) setVehicleColor( vehicles[source], 0, 255, 0 ) addEventHandler("onVehicleStartEnter", vehicles[source], -- Im not sure if i can do this. if (team=="Military")then else triggerClientEvent(source,"message:addMessage",source,"You are not in the Military!",255, 0, 0) cancelEvent() end) end addEvent("CreVehice_group_military",true) addEventHandler("CreVehice_group_military", root, spawnVeh) The Ultimate Lua Tutorial! | MTA PHP SDK
DNL291 Posted January 16, 2013 Posted January 16, 2013 (edited) ----------- This Area Here. -------- function spawnVeh(id) local x, y, z = getElementPosition(source) if isElement(vehicles[source]) then destroyElement(vehicles[source]) end vehicles[source] = createVehicle(id, x, y, z) warpPedIntoVehicle ( source, vehicles[source] ) setVehicleColor( vehicles[source], 0, 255, 0 ) addEventHandler("onVehicleStartEnter", root, function (player) if ( source == vehicles[player] ) then if (getTeamName(getPlayerTeam(player))=="Military")then cancelEvent() else triggerClientEvent(player,"message:addMessage",player,"You are not in the Military!",255, 0, 0) end end end ) end addEvent("CreVehice_group_military",true) addEventHandler("CreVehice_group_military", root, spawnVeh) Edited January 16, 2013 by Guest Please do not PM me with scripting related question nor support, use the forums instead.
3NAD Posted January 16, 2013 Posted January 16, 2013 Try it and tell me the results. vehicles = {} function spawnVeh ( id ) if tonumber ( id ) then if isElement ( vehicles[source] ) then removeEventHandler ( "onVehicleStartEnter", vehicles[source], vehicleMilitary ) destroyElement ( vehicles[source] ) end local x, y, z = getElementPosition(source) vehicles[source] = createVehicle ( id, x, y, z ) warpPedIntoVehicle ( source, vehicles[source] ) setVehicleColor ( vehicles[source], 0, 255, 0 ) addEventHandler ( "onVehicleStartEnter", vehicles[source], vehicleMilitary ) else outputChatBox ( "* Error !!", source, 255, 0, 0, true ) end end addEvent ( "CreVehice_group_military", true ) addEventHandler ( "CreVehice_group_military", root, spawnVeh ) function vehicleMilitary ( thePlayer ) if getPlayerTeam ( thePlayer ) ~= getTeamFromName ( "Military" ) then triggerClientEvent ( thePlayer, "message:addMessage", thePlayer, "You are not in the Military!", 255, 0, 0 ) cancelEvent ( ) end end
xXMADEXx Posted January 16, 2013 Author Posted January 16, 2013 Thank you The Ultimate Lua Tutorial! | MTA PHP SDK
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