[1.8.6.1] - How to spawn more vehicles?

Discussion in 'Scripting Discussions' started by KrisiS, Feb 13, 2016.

  1. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    I have an issue where only a handful of vehicles are spawning on a fresh database install.
    How can I up the amount of vehicles spawning?

    Also, how can I add custom vehicle spawn points?

    The database is different than I remember it being on 1.8.6.1
    [​IMG]

    Thanks for any help :)
     
  2. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    oh yeah ,.. i tried all day to setup a 1861 dayz testing server before i realized it woudnt interface with my old database schema.

    will have to lookwhen i get home, but it looks like the old database where we have spawn points and they are selected randomly .. i would say step one is to open the editor and place vehicles where you want them to spawn, save the mission ( you will need a center,group,unit to save) and then i have a php script and vps where we can automatically insert them into your database ... assuming you have a hundred or more ...
     
  3. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    I didnt look closely at the spawn function, just guessing from the tables and what they contain. I would say to add spawns you create a "location" in vehicle_locations that contains the "id" of the vehicle_spawns classname and information.
    So this is a spawn location which will spawn a vehicle of ID 12
    [​IMG]
    And from vehicle_spawns table here is ID #12
    [​IMG]

    So if we want MORE of that type of vehicle, increase MaxNum which will spawn as long as total is less than MaxVehicles defined. One issue is there is only 144 locations so until those vehicles are moved by players, no more than 144 will spawn. So go into the editor, make a couple hundred locations and we can insert them into the database using php script.


    Here is the spawn vehicles function for analysis.
    Check Declare MaxVehicles for increasing spawned amount.
    Code:
    CREATE DEFINER=`dayz`@`localhost` PROCEDURE `pSpawnVehicles`(IN `i` int)
    BEGIN
        #---------------------------------------------------------------
        #Change this to affect the maximum number of vehicles on the server.
        DECLARE MaxVehicles INT DEFAULT 80;
      
        #Change this to affect the radius that is checked for existing vehicles when spawning.
        #If set to 0 or negative vehicles will always spawn despite blocking vehicles.
        DECLARE SearchRadius DOUBLE DEFAULT 10;
        #---------------------------------------------------------------
      
        DECLARE ServerInstance INT DEFAULT i;
        DECLARE MaxNumSpawn INT DEFAULT MaxVehicles - countVehicles(ServerInstance);
      
        DROP TEMPORARY TABLE IF EXISTS temp_objects;
        CREATE TEMPORARY TABLE temp_objects AS
        (
            SELECT    CONVERT(SUBSTRING(SUBSTRING_INDEX(@ws, ",", 2), LENGTH(SUBSTRING_INDEX(@ws, ",", 1)) + 2), DECIMAL(10, 5)) AS X,
                    CONVERT(SUBSTRING(SUBSTRING_INDEX(@ws, ",", 3), LENGTH(SUBSTRING_INDEX(@ws, ",", 2)) + 2), DECIMAL(10, 5)) AS Y
            FROM object_data
            WHERE CharacterID = 0
                AND Instance = ServerInstance
                AND (@ws := Worldspace) IS NOT NULL
                AND (@ws := REPLACE(@ws, "[", "")) IS NOT NULL
                AND (@ws := REPLACE(@ws, "]", "")) IS NOT NULL
        );
      
        DROP TEMPORARY TABLE IF EXISTS temp_locations;
        CREATE TEMPORARY TABLE temp_locations AS
        (
            SELECT vehicle_locations.ID, temp2.Worldspace
            FROM
            (
                SELECT Worldspace
                FROM
                (
                    SELECT    Worldspace,
                            CONVERT(SUBSTRING(SUBSTRING_INDEX(@ws, ",", 2), LENGTH(SUBSTRING_INDEX(@ws, ",", 1)) + 2), DECIMAL(10, 5)) AS X,
                            CONVERT(SUBSTRING(SUBSTRING_INDEX(@ws, ",", 3), LENGTH(SUBSTRING_INDEX(@ws, ",", 2)) + 2), DECIMAL(10, 5)) AS Y
                    FROM (SELECT Worldspace FROM vehicle_locations GROUP BY Worldspace) AS temp
                    WHERE (@ws := Worldspace) IS NOT NULL
                        AND (@ws := REPLACE(@ws, "[", "")) IS NOT NULL
                        AND (@ws := REPLACE(@ws, "]", "")) IS NOT NULL
                ) AS temp1
                WHERE
                (
                    @distance :=
                    (
                        SELECT MIN(SQRT((temp_objects.X - temp1.X) * (temp_objects.X - temp1.X) + (temp_objects.Y - temp1.Y) * (temp_objects.Y - temp1.Y)))
                        FROM temp_objects
                    )
                ) IS NULL OR @distance > SearchRadius
            ) AS temp2
            JOIN vehicle_locations
                ON vehicle_locations.Worldspace = temp2.Worldspace
        );
      
        DROP TEMPORARY TABLE IF EXISTS temp_spawns;
        CREATE TEMPORARY TABLE temp_spawns AS
        (
            SELECT temp.ID, Classname, Worldspace, Chance, MinFuel, MaxFuel, MinDamage, MaxDamage
            FROM
            (
                SELECT *
                FROM vehicle_spawns
                WHERE (@numSpawnable := getNumSpawnable(ServerInstance, ID)) IS NOT NULL
                    AND @numSpawnable > 0
                ORDER BY RAND()
            ) AS temp
            JOIN temp_locations
                ON temp_locations.ID = temp.Location
            ORDER BY RAND()
        );
      
        SET @numSpawned = 0;
        WHILE (@numSpawned < MaxNumSpawn AND (SELECT COUNT(*) FROM temp_spawns) > 0) DO
            SET @spawnid = (SELECT ID FROM temp_spawns LIMIT 1);
            SET @chance = (SELECT Chance FROM temp_spawns LIMIT 1);
            SET @numSpawnable = getNumSpawnable(ServerInstance, @spawnid);
            IF (@numSpawnable > 0 AND RAND() < @chance) THEN
                SET @worldspace = (SELECT Worldspace FROM temp_spawns LIMIT 1);
                INSERT INTO object_data (ObjectUID, Classname, Instance, CharacterID, Worldspace, Inventory, Hitpoints, Fuel, Damage, Datestamp)
                SELECT generateUID(ServerInstance), Classname, ServerInstance, 0, Worldspace,
                    randomizeVehicleInventory(Classname),
                    randomizeVehicleHitpoints(Classname),
                    MinFuel + RAND() * (MaxFuel - MinFuel),
                    MinDamage + RAND() * (MaxDamage - MinDamage),
                    SYSDATE()
                FROM temp_spawns
                LIMIT 1;
              
                DELETE FROM temp_spawns WHERE Worldspace = @worldspace;
              
                SET @numSpawned = @numSpawned + 1;
            END IF;
          
            SET @numSpawnable = @numSpawnable - 1;
          
            IF (@numSpawnable < 1) THEN
                DELETE FROM temp_spawns WHERE ID = @spawnid;
            END IF;
        END WHILE;
      
        SELECT CONCAT(@numSpawned, " vehicles spawned.");
    END
    
    
     
  4. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    I much prefer this method of spawning vehicles. I detest the Epoch random vehicles (Delpi added DB spawns to his epoch I think).
    So these Procedures could be inserted into an epoch db, copy the vehicle tables and have actual spawned vehicles where they are supposed to be .. military vehicles near military, bicycles and motorcycles in yards, planes on the runways ...
    Both Dayz 1.8.6.1 and Epoch store vehicles in the object_data tables which are identical so .. Yeah, I am going to put this into my Overpoch server.
     
  5. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Nice one man, I won't get a chance to try this until tomorrow!
    Thank you so much for sharing mate, you're a STAR !!! :)
     
  6. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    I probably should have emphasized that the vehicle spawn function I pasted above. Has how many vehcles to spawn in total .. increase that .. its 80 right now.
     
  7. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    I will actually get a chance to test this later :)

    Where can I change the maxvehicles ?
     
    Last edited: Feb 14, 2016
  8. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    In my previous post.

    [​IMG]

    In your previous post, you posted this image.

    [​IMG]

    So now a short video ...



    Its valentines day .. all text in pink.
     
  9. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Hehe, thanks for the video :)

    My pSpawnVehicles doesn't have anything like that in it.. and it's file size is nothing
    Any ideas about that one ? xD
     
  10. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    okay, i am going to create a blank database and add in the files as they should have been added. .. I wish I had a microphone sometimes so I could annotate these quick videos.
    Anyways these are the steps I demonstrate in this video. You have to adapt the steps to whatever crappy mysql client you are using instead of mysqlworkbench. I mean, we all use MYSQL, why not use the client that Oracle created to work explicitly with a mysql server?
    I create a new database.
    I download the SQL files from the 1.8.6 repository from se1.dayz.nu
    I create a blank database.
    I open and execute the query to create a new table (just to show something that you know .. for reference)
    I open and execute the procedure query to create that in the database.

    Using mysqlworkbench



    And here is using phpmyadmin
     
  11. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Thank you man, that is really helpful.

    I get an Access Denied error because I don't have enough privileges when trying to do the same.
    I'll have to leave it for now as rl is calling :)

    PS: I use mysqlworkbench ;)
     
  12. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    Last edited: Feb 14, 2016
  13. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Unfortunately this server is hosted and rented as a single server. I can't give myself the permissions.
    I took the first screen with heidisql, I have that too :)
     
  14. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    well ... your user should have full permissions on that datsbase, if not then thats hosed up.
    i hand out free servers ... do you want a mysql server?
     
  15. KrisiS

    KrisiS Member

    Joined:
    Aug 17, 2013
    Messages:
    89
    Likes Received:
    1
    Actually, you know what... I have mySQL servers with my website host....
    I didn't think of using that to create one :/

    I'd prefer to keep it all with the same provider :)

    I think the permissions are there, I'm just not well up on SQL to work it out.
     
  16. clifdayz

    clifdayz Well-Known Member

    Joined:
    Jul 28, 2015
    Messages:
    119
    Likes Received:
    8
    There are a couple of things that affect MAX VEHICLES. The first is the setting in the pSpawnVehicles. The others are MaxNum in the vehicle_groups table and MaxNum in vehicle_spawns. The final is the sheet number of spawn locations in vehicle_locations (because the spawn code looks for vehicles already there).

    I can't remember how the vehicle groups are implemented - again I think its based on locations (instead of a simple foreign key relationship).
     
  17. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    We got this all fixed up via email. During that time, I got the dayz 1.8.6.1 vehicle spawn system integrated with my Overcrap server so I can have vehicles spawn where I place them. I will post the howto this weekend.
     
    ElDubya likes this.
  18. delpi

    delpi Well-Known Member

    Joined:
    Feb 4, 2014
    Messages:
    336
    Likes Received:
    15
    I got mentioned above. I didn't add database spawning of vehicles for Epoch, i wrote a script that spawned them from location settings in a config file for the script. It worked very well. Only downside was having to load a new file if i wanted to change anything on the spawn setup, but if your into modding that really isn't much of a downside.
     

Share This Page