Jump to content
Sign in to follow this  
JOHN007

Random Snake Location Script

Recommended Posts

Hello.

 

The great TPW has provided a script which will dynamically spawn these bloody snakes but upon spawn they die.

 

They need a driver allocated to the snake which is Citizen1.

 

May I ask if anyone could spare some of their valuable time which I eternally appreciate. I will pay you through Patreon if needs be I don't mind. Time = money so I understand.

 

There's a small bug in the code which doesn't spawn the crew/driver. This is the reason why the snake dies upon spawn.

 

// Random snake spawner 
// TPW 20171025

hint "TPW Snakes active";
sleep 1;

// Variables
_min = 5; // minimum distance (m) from player to spawn snake
_max = 20; // maximum distance (m) from player to spawn snake - snakes will be removed if further than this from player
_time = 10; // maximum time (sec) in between each snake spawning
_maxsnakes = 10; // maximum number of snakes
_treemin = 5; // minimum number of trees within _max around player needed in order to spawn snakes
_hind1Group = creategroup east;

// Main loop
_snakearray = [];
while {true} do
    {
    // Delete distant snakes
    for "_i" from 0 to ((count _snakearray) - 1) do     
        {
        _snake = _snakearray select _i;
        if (_snake distance player > _max) then
            {
            _snakearray set [_i,-1];
            deletevehicle _snake;
            hint format ["Deleting %1",_snake];
            };
        };
    _snakearray = _snakearray - [-1];

    //Spawn new snake
        if (count _snakearray < _maxsnakes) then
        {
        // Random position around player 
        _pos = getposasl player;
        _dir = random 360;
        _dist = _min + random (_max - _min);
        _posx = (_pos select 0) + (_dist * sin _dir);
        _posy = (_pos select 1) +  (_dist * cos _dir);

        // If not in water???What??
		if !(surfaceiswater [_posx,_posy]) then
            { 
            _snake = createVehicle (["CSJ_Snake", "CSJ_Snake2", "CSJ_Snake3"] select floor random 3) [_posx,_posy];
			_driver = _hind1Group createUnit ["Citizen1", _spawn, [], 0, "NONE"];
			_driver assignAsDriver _snake;
			_driver moveindriver _snake;
			_driver hideobject true;
            //_snake = createAgent [_model,[_posx,_posy], [], 0, "FORM"];
            _snakearray = _snakearray +  [_snake];
            hint format ["Spawning %1",_snake];
            };
    };
    hint format ["%1 snakes", count _snakearray];
    sleep random _time;
    };

The actual snake isn't the problem as we have tried to spawn a bike with a driver using the same script method.

 

Thankyou for your time and hope to speak soon. SOS.

 

John.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×