SinisterCarnage

One Vehicle to randomly spawn in the server

16 posts in this topic

Hello, 

i am currently hosting a server and wish to add one vehicle that randomly spawns thoughout the map. Such as a C130 or VTOL that would sell for allot of poptabs and would be worth hunting down. I only want one of them to spawn every server restart and I want it to be random where it spawns every time. Any help would be appreciated. 

Share this post


Link to post
Share on other sites
Advertisement

create a new folder inside your mission root folder, name it scripts (if one dose not already exist)

paste the following into notepad++ and save as randVehicleSpawn.sqf

Spoiler

private ["_specVehicleMarker","_specVehicle","_flatPos","_accepted","_position","_objPos","_vehicle","_marker"];

//-------------------- Config part
_specVehicleMarker = 1;    // Show vehicle on the map 1=show, 0=no show
_specVehicle = "B_T_VTOL_01_infantry_F"; //sets vehicle type

//-------------------- find a random, relatively flat, empty spot for the vehicle
    _flatPos = [0,0,0];
    _accepted = false;
    while {!_accepted} do {
        _position = [] call BIS_fnc_randomPos;
        _flatPos = _position isFlatEmpty [5,0,0.2,sizeOf "Land_TentHangar_V1_F",0,false];

        while {(count _flatPos) < 2} do {
            _position = [] call BIS_fnc_randomPos;
            _flatPos = _position isFlatEmpty [5,0,0.2,sizeOf "Land_TentHangar_V1_F",0,false];
        };
            _accepted = true;
    };
    _objPos = [_flatPos, 25, 35, 10, 0, 0.5, 0] call BIS_fnc_findSafePos;
    
//-------------------- crate the vehicle and set direction
    _vehicle = _specVehicle createVehicle _flatPos;
    _vehicle allowdamage false;
    waitUntil {!isNull _vehicle};
    _vehicle setDir (random 360);
    _vehicle setVectorUp surfaceNormal position _vehicle;
    _vehicle allowdamage true;
    
//-------------------- show a debug marker for the vehicle if _specVehicleMarker = 1
    if (_specVehicleMarker == 1) then
    {
    _marker = createmarker ["Vehicle Position",_flatPos];
    _marker setMarkerColor "ColorOrange";
    _marker setMarkerType "hd_destroy";
    _marker setMarkerText " Special Vehicle Position";
    };

place randVehicleSpawn.sqf inside the scripts folder

at the top of initServer.sqf  (underneath /**
 * Created with Exile Mod 3DEN Plugin
 * exile.majormittens.co.uk
 */)

paste the following

[] execVM "scripts\randVehicleSpawn.sqf";

repbo and enjoy

this is not original code, just a quick copy/paste together of existing code, but it works 

  • Like 5
  • Thanks 1

Share this post


Link to post
Share on other sites
9 hours ago, dekela said:

create a new folder inside your mission root folder, name it scripts (if one dose not already exist)

paste the following into notepad++ and save as randVehicleSpawn.sqf

  Reveal hidden contents

private ["_specVehicleMarker","_specVehicle","_flatPos","_accepted","_position","_objPos","_vehicle","_marker"];

//-------------------- Config part
_specVehicleMarker = 1;    // Show vehicle on the map 1=show, 0=no show
_specVehicle = "B_T_VTOL_01_infantry_F"; //sets vehicle type

//-------------------- find a random, relatively flat, empty spot for the vehicle
    _flatPos = [0,0,0];
    _accepted = false;
    while {!_accepted} do {
        _position = [] call BIS_fnc_randomPos;
        _flatPos = _position isFlatEmpty [5,0,0.2,sizeOf "Land_TentHangar_V1_F",0,false];

        while {(count _flatPos) < 2} do {
            _position = [] call BIS_fnc_randomPos;
            _flatPos = _position isFlatEmpty [5,0,0.2,sizeOf "Land_TentHangar_V1_F",0,false];
        };
            _accepted = true;
    };
    _objPos = [_flatPos, 25, 35, 10, 0, 0.5, 0] call BIS_fnc_findSafePos;
    
//-------------------- crate the vehicle and set direction
    _vehicle = _specVehicle createVehicle _flatPos;
    _vehicle allowdamage false;
    waitUntil {!isNull _vehicle};
    _vehicle setDir (random 360);
    _vehicle setVectorUp surfaceNormal position _vehicle;
    _vehicle allowdamage true;
    
//-------------------- show a debug marker for the vehicle if _specVehicleMarker = 1
    if (_specVehicleMarker == 1) then
    {
    _marker = createmarker ["Vehicle Position",_flatPos];
    _marker setMarkerColor "ColorOrange";
    _marker setMarkerType "hd_destroy";
    _marker setMarkerText " Special Vehicle Position";
    };

place randVehicleSpawn.sqf inside the scripts folder

at the top of initServer.sqf  (underneath /**
 * Created with Exile Mod 3DEN Plugin
 * exile.majormittens.co.uk
 */)

paste the following


[] execVM "scripts\randVehicleSpawn.sqf";

repbo and enjoy

this is not original code, just a quick copy/paste together of existing code, but it works 

oh my .... thats perfect Thanks! just talked with my bud about something like this a few hours ago heh but... could you maybe make a version wich takes 1 Vehicle from a list of possible vehicles ? duno if thats possible tho >.>

Share this post


Link to post
Share on other sites
Quote

but... could you maybe make a version wich takes 1 Vehicle from a list of possible vehicles ? duno if thats possible tho >.>

Yes it's possible.  What list of vehicles would you like to chose from? 

Share this post


Link to post
Share on other sites
46 minutes ago, dekela said:

Yes it's possible.  What list of vehicles would you like to chose from? 

one of each VTOL's so once Blackfish and the other one Y-32 Xi'an

Share this post


Link to post
Share on other sites
12 hours ago, Joshi120 said:

one of each VTOL's so once Blackfish and the other one Y-32 Xi'an

as quasi normal posted, 

_specVehicle = selectRandom ["O_T_VTOL_02_infantry_F","B_T_VTOL_01_infantry_F"]; //sets vehicle type

 

  • Like 3

Share this post


Link to post
Share on other sites
4 hours ago, dekela said:

as quasi normal posted, 


_specVehicle = selectRandom ["O_T_VTOL_02_infantry_F","B_T_VTOL_01_infantry_F"]; //sets vehicle type

 

Awesome! Thanks a lot :3

Share this post


Link to post
Share on other sites
Advertisement

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.