Jump to content

[HELP] CreateVehicle


Recommended Posts

Posted

Hello guys, i tried all night to understand my code about CreateVehicle, i'm working with Server Script, CreateVehicle and Warp, well, i want to make the localplayer create own vehicle, now, i have a problem i create my car, but the other guy creates his car then my car destroy. please hep me! thats my code:

  
--Server Side 
marker = createMarker(.....) 
function CreateVeh(thePlayer) 
if (thePlayer) then 
        heli = createVehicle( 425, 234, 1967, 17, 0,0, 90) 
        warpPedIntoVehicle(thePlayer, heli, 0 , true) 
        end 
end 
addEventHandler("onMarkerHit" , marker, CreateVeh) 
  

PLEASE HELP ME! THANKS!

Posted

So, when the other player hits the marker , your vehicle destroys ? If yes then try defining the variable 'heli' locally and not globally.

local heli = createVehicle( 425, 234, 1967, 17, 0,0, 90) 

//EDIT: Sorry If I have misread what you were trying to say, Just don't understand your english very well

Posted

You can set a timer to destroy the vehicle when the player exits the vehicle, and when he enters again, kill the timer.

Posted

You're welcome and

If you have problems, then you can post your code. and If I'm online then maybe I can fix it for you.

Posted

lol, Problem man... :(

look this:

  
MarcadorBus1Car = createMarker(..) 
addEventHandler("onMarkerHit" , MarcadorBus1Car, 
function(thePlayer) 
    if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then 
         
                    local busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) 
                    warpPedIntoVehicle(thePlayer, busao, 0 , true) 
                     
        end  
end 
  
--///////////////////////////////////////// 
function qndSairBus1(thePlayer) 
if (thePlayer) then 
    if getElementModel(source) == 431 then 
         desBus1 = setTimer(destroiBus1, 5000, 1) 
    end 
end 
end 
addEventHandler("onVehicleExit" , rootElement, qndSairBus1) 
  
function destroiBus1() 
        if isElement(busao) then destroyElement(busao) end 
end  
  

The vehicle not destroy with local variable... helpe me please

Posted

Try this

  
MarcadorBus1Car = createMarker(..) 
addEventHandler("onMarkerHit" , MarcadorBus1Car, 
function(thePlayer) 
    if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then 
         busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) 
         warpPedIntoVehicle(thePlayer, busao, 0 , true) 
    end  
end) 
     
function qndSairBus1(vehicle,seat) 
if seat == 0 then 
    if getElementModel(source) == 431 then 
         desBus1 = setTimer(destroiBus1, 5000, 1) 
    end 
end 
end 
addEventHandler("onVehicleExit" , getRootElement(), qndSairBus1) 
  
function qndSairBus2(vehicle,seat) 
if seat == 0 or seat == 1 or seat == 2 or seat == 3 or seat == 4 then 
    if getElementModel(source) == 431 then 
    killTimer(desBus1) 
    end 
end 
end 
addEventHandler("onVehicleEnter" , getRootElement(), qndSairBus2) 
  
function destroiBus1() 
        if isElement(busao) then destroyElement(busao) end 
end  
  

Posted
Try this
  
MarcadorBus1Car = createMarker(..) 
addEventHandler("onMarkerHit" , MarcadorBus1Car, 
function(thePlayer) 
    if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then 
         busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) 
         warpPedIntoVehicle(thePlayer, busao, 0 , true) 
    end  
end) 
     
function qndSairBus1(vehicle,seat) 
if seat == 0 then 
    if getElementModel(source) == 431 then 
         desBus1 = setTimer(destroiBus1, 5000, 1) 
    end 
end 
end 
addEventHandler("onVehicleExit" , getRootElement(), qndSairBus1) 
  
function qndSairBus2(vehicle,seat) 
if seat == 0 or seat == 1 or seat == 2 or seat == 3 or seat == 4 then 
    if getElementModel(source) == 431 then 
    killTimer(desBus1) 
    end 
end 
end 
addEventHandler("onVehicleEnter" , getRootElement(), qndSairBus2) 
  
function destroiBus1() 
        if isElement(busao) then destroyElement(busao) end 
end  
  

Fix your code

MarcadorBus1Car = createMarker(x, y, z, "cylinder", 1.5, 255, 0, 0, 255) 
busao = { } 
desBus1 = { } 
  
function(thePlayer) 
    if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) and source == MarcadorBus1Car then 
        if isElement(busao[thePlayer]) then 
            destroyElement(busao[thePlayer]) 
        end 
        busao[thePlayer] = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) 
        warpPedIntoVehicle(thePlayer, busao[thePlayer], 0 ) 
    end  
end 
   
function Exit(vehicle,seat) 
    if seat == 0 then 
        if getElementModel(source) == 431 then 
            desBus1[vehicle] = setTimer(destroiBus1, 5000, 1, vehicle) 
        end 
    end 
end 
  
function Enter(vehicle) 
    if getElementModel(source) == 431 then 
        killTimer(desBus1[vehicle]) 
    end 
end 
  
function destroiBus1(plr) 
    if isElement(busao[plr]) then 
        destroyElement(busao[plr]) 
    end 
end  
  
addEventHandler("onMarkerHit", resourceRoot, Hit) 
addEventHandler("onVehicleExit", root, Exit) 
addEventHandler("onVehicleEnter", root, Enter) 

Posted

I tried this code, works perfectly, thank you!, but i have another problem with my code.

i want to make one time the event, for example the player enters into the car , do something and get the car again do other things

I have functions on "onVehicleEnter"

look my code:

  
function playerEnter(thePlayer) 
if getElementModel(source) == 431 then 
   // Do Something one time 
end 
end 
  
addEventHandler("onVehicleEnter" , getRootElement(), playerEnter) 
  
  

thnaks

Posted

ok, theplayer got a car, the handler "onVehicleEnter" do something, for example outputChatBox("Text 1" ), ok, the player out of his vehicle and enter the his vehicle again, the handler do something new for example outputChatBox("Text 2" ) ,

thanks

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