Jump to content

Help with Veh Spawner


xXMADEXx

Recommended Posts

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) 

Link to comment
  ----------- 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 by Guest
Link to comment

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 

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