Jump to content

Spawning cars...


hihohihohiho

Recommended Posts

On my server i have a job for someone to spawn 10 cars into 1 spot at the airport, and type /done and get money, then the person who does it blows of the cars the the cars repsawn to where they spawned it (/v to spawn) and the it blows up from the fire that was left over... so i'm asking for a script that can do /v and it spawns it, then after it blows up then it wont go back to that same spot it was /v at.... if u dont understand, just ask me.

Link to comment

i have the same problem :(

u might want to try this

function vehicleDelete ()

local attachedElements = getAttachedElements ( source )

if ( attachedElements ) then

for ElementKey, ElementValue in ipairs ( attachedElements ) do

if ( getElementType ( ElementValue ) == "object" ) then

destroyElement ( ElementValue ) --destroy any items attached to the car

end

end

end

destroyElement ( source )

end

addEventHandler ( "onVehicleExplode", getRootElement(), vehicleDelete ) --on vehicle explode send vehicle

i found this in the forums but i havent had a chance to test yet

i think it will do what u want 8)

EDIT : just gave it a quick test and so long as vehicle explodes doesnt respawn

( spawned a sanchez then blew it up with minigun and it didnt reappear ) :shock:

Link to comment

The example above handles attached objects - if you not using attached object this will suffice :

  
addEventHandler("onVehicleExplode",getRootElement(), 
    function() 
        destroyElement(source) 
    end 
) 
  

Have you also set the vehicle respawn info when you make the vehicle ? Look at toggleVehicleRespawn().

Link to comment

hello TMA id like to know where toggle vehicle respawn is defined

ive been through the script but i cant seem to find it and id like to see how it works

i assume its possible to write an extra createvehicle function without respawn so when u spawn a car from the .map file it will continue to respawn but when you use it as a console command it wont

Thanx for L :roll: kin

EDIT : sorry just realized how dumb that question is ( just look at MTA classes on the wiki ? :oops:

Link to comment

i would suggest using the one from TMA as i have chatted to him on the forums before and he really seems to know what hes doin

as he said the script i posted is more complicated because on my server i have a number of attach element commands goin on

so all u need to get rid of cars is TMAs script :D

also oneproblem with my script is that when a car blows it doesnt respawn even if its set to spawn by the map file

EG: i use broph/fr and there are a number of vehicle round the spawn point when u start but if u destroy them they dont come back . i am currently trying to fix this problem but it may be awhile before i figure it out . i hope i will be able to get elements attached to player and just destroy those but we will see :wink:

Link to comment

as isaid mine works fine but any cars spawned by the map will not respawn after they are destroyed

not to big a problem if everyone knows how to create vehicles

oh yeah just remebered the code tab here is the function again ( should be easier to understand )

function vehicleDelete () 
     local attachedElements = getAttachedElements ( source ) 
   if ( attachedElements ) then 
      for ElementKey, ElementValue in ipairs ( attachedElements ) do 
         if ( getElementType ( ElementValue ) == "object" ) then 
            destroyElement ( ElementValue ) --destroy any items attached to the car 
         end 
      end 
   end   
   destroyElement ( source )    
end 
addEventHandler ( "onVehicleExplode", getRootElement(), vehicleDelete ) --on vehicle explode send vehicle  

u might want to look at this as another way round it

function consoleChangeVehicle (player, command, id ) 
        if ( id ) then 
          local newcar = tonumber ( id ) 
          local oldcar = getPlayerOccupiedVehicle ( player ) 
          setVehicleModel ( oldcar, newcar ) 
          else 
          outpuChatBox ( "no car id", player ) 
        end 
end 

only works with id numbers at the moment but when in a car just type command and id number and car model changes

no need to spawn more cars just stay in the 1 u got

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