DB Vehicle Hitpoint Fix For Pwnoz0r Server Package

Stapo

Modding Veteran
As you may not know, but pwnoz0rs current build has got a small problem.
that problem is that when you run the server and it runs the vehicle spawn script, it gives vehicles the wrong hitpoints as in a UH1H-DZ would be given the hitpoints of a ATV. but the reason its doing that is because something is not right in Pspawn... BUT my co-mod developer Alby figured it out and fixed it and im releasing the fix to everyone and also to be a smartass to pwnoz0r..

So what you have to do is load up navicat (server must be running) and go to functions, you should then see a function called Pspawn. right click on it and go to 'Design Function', once in the designer delete all the code in Pspawn and replace it with this:

Code:
BEGIN
    DECLARE bSpawned        TINYINT(1) DEFAULT 0;
    DECLARE iLID                INT DEFAULT 0;
 
    WHILE (bSpawned = 0) DO
       
        SET iLID = LAST_INSERT_ID();
       
        INSERT INTO object_data (ObjectUID, Instance, Classname, Damage, CharacterID, Worldspace, Inventory, Hitpoints, Fuel, Datestamp)
        SELECT ot.ObjectUID, '1', ot.Classname, ot.Damage, '0', ot.Worldspace, '[]', ot.Hitpoints, '0.01', SYSDATE()
            FROM (SELECT oc.Classname, oc.Chance, oc.MaxNum, oc.Damage, oc.Hitpoints, os.ObjectUID, os.Worldspace
                FROM object_classes AS oc
                INNER JOIN object_spawns AS os
                ON oc.Classname = os.Classname
                ORDER BY RAND()) AS ot
            WHERE NOT EXISTS (SELECT od.ObjectUID
                            FROM object_data AS od
                            WHERE ot.ObjectUID = od.ObjectUID)
            AND fGetClassCount(ot.Classname) < ot.MaxNum
            AND fGetSpawnFromChance(ot.Chance) = 1
            LIMIT 1;
           
            IF (LAST_INSERT_ID() <> iLID) THEN
                SET bSpawned = 1;
            END IF;
           
    END WHILE;
END
then save it, clear your 'object_data' table and restart the server and check the 'object_data' and you should see all the vehicles with their correct hitpoints.

NOTE TO PWNOZOR: Include this in your next Github commit
 

Pwn

Administrator
Staff member
I just fixed this my own way. Tested both mine was like a 50/50 shot at using the right HP. Just going to use yours thanks much.
 

Stapo

Modding Veteran
Code:
BEGIN
 
    DECLARE intOffset        INT DEFAULT 0;
  DECLARE bDoSpawn        TINYINT(1) DEFAULT 0;
    DECLARE bSpawned        TINYINT(1) DEFAULT 0;
    DECLARE iLID                INT DEFAULT 0;
 
 
    WHILE (bDoSpawn = 0) DO
 
        SELECT FLOOR(RAND() * COUNT(*))
            INTO intOffset
            FROM object_classes;
 
        SELECT Classname, Chance, MaxNum, Damage, Hitpoints
            INTO @rsClassname, @rsChance, @rsMaxNum, @rsDamage, @rsHitpoints
            FROM object_classes
            LIMIT intOffset, 1;
 
        IF (fGetClassCount(@rsClassname) < @rsMaxNum) THEN
            IF (fGetSpawnFromChance(@rschance) = 1) THEN
                SET bDoSpawn = 1;
            END IF;
        END IF;
 
    END WHILE;
 
 
WHILE (bSpawned = 0) DO
 
        SELECT FLOOR(RAND() * COUNT(*))
            INTO intOffset
            FROM object_spawns
            WHERE Classname = @rsClassname;
 
        SET iLID = LAST_INSERT_ID();
 
        INSERT INTO object_data (ObjectUID, Instance, Classname, Damage, CharacterID, Worldspace, Inventory, Hitpoints, Fuel, Datestamp)
            SELECT ObjectUID, '1', Classname, @rsDamage, '0', Worldspace, '[]', @rsHitpoints, '0.01', SYSDATE()
                FROM object_spawns
                WHERE NOT ObjectUID IN (SELECT DISTINCT ObjectUID FROM object_data)
                LIMIT intOffset, 1;
 
        IF (LAST_INSERT_ID() <> iLID) THEN
            SET bSpawned = 1;
        END IF;
 
    END WHILE;
 
END
 

f0rt

Moderator
Staff member
:) i use this, long time ago:
Code:
BEGIN
    DECLARE intOffset    INT DEFAULT 0;
    DECLARE bDoSpawn    INT DEFAULT 0;
    DECLARE intCounter    INT DEFAULT 0;
 
    SELECT COUNT(*)
        INTO intOffset
        FROM object_classes;
 
    WHILE (bDoSpawn  < intOffset) DO
        SELECT Classname, Chance, MaxNum, Damage, Hitpoints
            INTO @rsClassname, @rsChance, @rsMaxNum, @rsDamage, @rsHitpoints
            FROM object_classes
            LIMIT bDoSpawn, 1;
        SET intCounter = fGetClassCount(@rsClassname);
 
          WHILE (  intCounter<@rsMaxNum ) DO
          IF (fGetSpawnFromChance(@rschance) = 1) THEN
            INSERT INTO object_data (ObjectUID, Instance, Classname, Damage, CharacterID, Worldspace, Inventory, Hitpoints, Fuel, Datestamp)
                SELECT ObjectUID, '222',object_spawns.Classname,@rsDamage,'0',object_spawns.Worldspace,'[]', @rsHitpoints, '0.05', SYSDATE()
                    FROM object_spawns
                    LEFT JOIN object_data using(ObjectUID) where ObjectID is NULL AND object_spawns.Classname LIKE @rsClassname
                    LIMIT 0, 1;
        END IF;
        SET intCounter=intCounter+1;
        END WHILE;
    SET bDoSpawn = bDoSpawn + 1;
    END WHILE;
END
 

MaRs

Well-Known Member
:) i use this, long time ago:
Code:
BEGIN
    DECLARE intOffset    INT DEFAULT 0;
    DECLARE bDoSpawn    INT DEFAULT 0;
    DECLARE intCounter    INT DEFAULT 0;
 
    SELECT COUNT(*)
        INTO intOffset
        FROM object_classes;
 
    WHILE (bDoSpawn  < intOffset) DO
        SELECT Classname, Chance, MaxNum, Damage, Hitpoints
            INTO @rsClassname, @rsChance, @rsMaxNum, @rsDamage, @rsHitpoints
            FROM object_classes
            LIMIT bDoSpawn, 1;
        SET intCounter = fGetClassCount(@rsClassname);
 
          WHILE (  intCounter<@rsMaxNum ) DO
          IF (fGetSpawnFromChance(@rschance) = 1) THEN
            INSERT INTO object_data (ObjectUID, Instance, Classname, Damage, CharacterID, Worldspace, Inventory, Hitpoints, Fuel, Datestamp)
                SELECT ObjectUID, '222',object_spawns.Classname,@rsDamage,'0',object_spawns.Worldspace,'[]', @rsHitpoints, '0.05', SYSDATE()
                    FROM object_spawns
                    LEFT JOIN object_data using(ObjectUID) where ObjectID is NULL AND object_spawns.Classname LIKE @rsClassname
                    LIMIT 0, 1;
        END IF;
        SET intCounter=intCounter+1;
        END WHILE;
    SET bDoSpawn = bDoSpawn + 1;
    END WHILE;
END
And why didnt you post the fix for us !!!!! :p
 

f0rt

Moderator
Staff member
when i made it, i post on tunngle forum.
seems we need to make common DB schema. for post-antirocket project.
 
Top