Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function spawnVehicle(model, options) {
- // optional argument `options` defaults to `{}`
- options = (options != null ? options : {});
- // if passed a model name instead of a hash, convert it
- if (_.isString(model))
- model = joaat(model);
- // use our ped for location to spawn, unless we specify another
- var pedid = options.pedid || window.pedid();
- var coords = getCoords(pedid);
- var heading = options.heading || ENTITY.GET_ENTITY_HEADING(pedid);
- // place vehicle 5 units ahead, unless we've specified a manual x,y,z
- var forward = options.x ? 0 : 5.0;
- var xVect = forward * Math.sin(toRadians(heading)) * -1;
- var yVect = forward * Math.cos(toRadians(heading));
- if (STREAMING.IS_MODEL_IN_CDIMAGE(model) && STREAMING.IS_MODEL_A_VEHICLE(model)) {
- // we might do something special for flying stuff
- var isAircraft = VEHICLE.IS_THIS_MODEL_A_HELI(model) || VEHICLE.IS_THIS_MODEL_A_PLANE(model);
- // make initial model request
- STREAMING.REQUEST_MODEL(model);
- // we'll make 10 attempts to see if it's loaded
- var attempts = 10;
- // callback function (runs on a timer)
- var requestFn = function() {
- var request = STREAMING.HAS_MODEL_LOADED(model);
- if (!request) {
- console.log("Model " + model.toString(16) + " hasn't loaded yet " + attempts + "");
- // try again in 100ms
- if (--attempts)
- setTimeout(requestFn, 100);
- // or give up
- else
- console.log("Failed to get model for " + model);
- return;
- }
- // Complete vehicle spawning process
- // move x,y,z properties that may have been passed in options, into
- // the coords to spawn.
- _.extend(coords, options);
- // debug the final location
- var vehicle, x, y, z, h;
- // thing to warp into a air thing in mid-air
- if (isAircraft && options.vehicleSpawnWarpInto) {
- vehicle = VEHICLE.CREATE_VEHICLE(model, coords.x + xVect, coords.y + yVect, coords.z + 1000, heading, true, true);
- VEHICLE.SET_VEHICLE_FORWARD_SPEED(vehicle, 500.0);
- VEHICLE.SET_HELI_BLADES_FULL_SPEED(vehicle);
- } else {
- // create model, don't forget the heading
- vehicle = VEHICLE.CREATE_VEHICLE(model,
- x = coords.x + xVect,
- y = coords.y + yVect,
- z = coords.z + ((options.z || options.vehicleSpawnWarpInto) ? 0 : 1),
- h = options.heading,
- true, true // what's this for again?
- );
- // prefer to drop vehicles from a height for effect
- // VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(vehicle);
- // prefer to actually get into a car the old fashioned way
- // PED.SET_PED_INTO_VEHICLE(PLAYER.GET_PLAYER_PED(), vehicle, -1);
- }
- // This is meant to make shit work good in MP
- DECORATOR.DECOR_SET_INT(vehicle, "MPBitset", 0);
- // log the pos the car should be at
- console.info("Laz-e-log: x, y, z, h", x, y, z, h);
- console.log("Spawned " + vehicle);
- // not sure why we do this, i guess it saves memory
- STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(model);
- };
- // start off timed function
- requestFn();
- }
- else {
- console.log("Stupid user that doesn't exist");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement