MYSQL Vehicle system bug
#1

Before you say anything I'm learning MYSQL and am having trouble with script i want to use as its not creating the table or loading the vehicles as their saved.

pawn Код:
/*------------------------------------------
This is a simple dynamic vehicle loading and saving system.
This system allows the server owner to load and save vehicles to/from
a MySQL database. When you load the filterscript, the vehicles that
are saved to the database, will be loaded automatically.

This system also saves and loads vehicle license plates too, which are set
when you use the command to save them. There is only one command for this
filterscript and it is "/savecar".

Commands:
/savecar - This will save the vehicle to the database, it has 3 extra parameters, which are: Colour 1, Colour 2 and Vehicle Plate.

Extra Credits:
ZeeX for ZCMD.
****** for sscanf2.
SA-MP team for the ability to script for SA-MP and for the a_samp include.
iGetty for creating this filterscript.

Please don't remove any credits for this script as it was created for the SA-MP
community out of good will and I would appreciate it if you could at least be
respectful enough to keep them there.

Thank you for using the script.

iGetty.
------------------------------------------*/


#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <zcmd>

#define MYSQL_HOST  "" //Your host
#define MYSQL_USER  ""      //Your username
#define MYSQL_PASS  ""          //Your password
#define MYSQL_DATA  ""  //Your database

new DynamicCarID[MAX_VEHICLES], DynamicCar[MAX_VEHICLES], DynamicCarCol[MAX_VEHICLES][3];

new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "LSPD Cruiser",
    "SFPD Cruiser", "LVPD Cruiser", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};

public OnFilterScriptInit()
{
    mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATA, MYSQL_PASS);
    print("\n--------------------------------------");
    print(" Dynamic Vehicles by iGetty loaded");
    print("--------------------------------------\n");
   
    LoadDynamicVehicles();
    return 1;
}

public OnFilterScriptExit()
{
    print("\n--------------------------------------");
    print(" Dynamic Vehicles by iGetty unloaded");
    print("--------------------------------------\n");
    return 1;
}

command(savecar, playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new Float:x, Float:y, Float:z, Float:a, mod = GetVehicleModel(GetPlayerVehicleID(playerid)), col1, col2, pl[9], vehicleid = GetPlayerVehicleID(playerid), string[128];
            if(sscanf(params, "iis[8]", col1, col2, pl))return SendClientMessage(playerid, -1, "Usage: /savecar [colour 1] [colour 2] [plate]");
            {
                if(strlen(pl) > 8)return SendClientMessage(playerid, -1, "The vehicles plate must be less than 8 characters long.");
                GetVehiclePos(vehicleid, x, y, z);
                GetVehicleZAngle(vehicleid, a);
                SaveDynamicVehicle(x, y, z, a, mod, col1, col2, pl);
                SetVehicleNumberPlate(vehicleid, pl);
                SetVehicleToRespawn(vehicleid);
                SetVehiclePos(vehicleid, x, y, z);
                SetVehicleZAngle(vehicleid, a);
                ChangeVehicleColor(vehicleid, col1, col2);
                format(string, sizeof(string), "You have saved this %s to the database. Colours: %s and %s, license plate: %s.", GetVehicleName(vehicleid), GetVehicleColorName(col1), GetVehicleColorName(col2), pl);
                SendClientMessage(playerid, -1, string);
            }
        }
        else return SendClientMessage(playerid, -1, "You must be the driver of this vehicle to save it to the database.");
    }
    else return SendClientMessage(playerid, -1, "You must be inside of a vehicle to save it to the database.");
    return 1;
}

stock SaveDynamicVehicle(Float:x, Float:y, Float:z, Float:a, mod, c1, c2, plate[])
{
    new
        Query[512];

    format(Query, sizeof(Query), "INSERT INTO `dynamicvehicles` (model, x, y, z, a, c1, c2, plate) VALUES(%d, %f, %f, %f, %f, %i, %i, '%s')",
    mod, x, y, z, a, c1, c2, plate);

    mysql_query(Query);
    mysql_free_result();
    return 1;
}

stock LoadDynamicVehicles()
{
    new Str[128], VehicleID, VehicleModel, Float:VehicleX, Float:VehicleY, Float:VehicleZ, Float:VehicleA, Col1, Col2, vehPlate[10], i = 0;

    mysql_query("SELECT * FROM `dynamicvehicles`");
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>iiffffiis[10]", VehicleID, VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleA, Col1, Col2, vehPlate);

            CreateVehicle(VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleA, Col1, Col2, -1);

            SetVehicleNumberPlate(i, vehPlate);

            SetVehicleToRespawn(i);
           
            DynamicCarID[i] = VehicleID;
            DynamicCarCol[i][1] = Col1;
            DynamicCarCol[i][2] = Col2;
            DynamicCar[i] = 1;
            i++;
        }
    }
    mysql_free_result();
    printf("--- %i vehicles loaded from the MySQL Database. ---", i);
    return 1;
}

stock GetVehicleName(vehicleid)
{
    new String[28];
    format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return String;
}

stock GetVehicleColorName(color)
{
    new clr[32];
    switch(color)
    {
        case 0: clr ="Black";
        case 1: clr ="White";
        case 2: clr ="Blue";
        case 3: clr ="Red";
        case 4: clr ="Grey-Green";
        case 5: clr ="Purple";
        case 6: clr ="Yellow";
        case 7: clr ="Blue";
        case 8: clr ="Silver";
        case 9: clr ="Dark sGrey";
        case 10: clr ="Midnight Blue";
        case 11: clr ="Dark Grey";
        case 12: clr ="Teal";
        case 13: clr ="Dark Grey";
        case 14: clr ="Light Grey";
        case 15: clr ="Silver";
        case 16: clr ="Dark Green";
        case 17: clr ="Dark Red";
        case 18: clr ="Dark Red";
        case 19: clr ="Grey";
        case 20: clr ="Royal Blue";
        case 21: clr ="Rich Maroon";
        case 22: clr ="Rich Maroon";
        case 23: clr ="Grey";
        case 24: clr ="Dark Grey";
        case 25: clr ="Dark Grey";
        case 26: clr ="Light Grey";
        case 27: clr ="Grey";
        case 28: clr ="Midnight Blue";
        case 29: clr ="Light Grey";
        case 30: clr ="Dark Maroon";
        case 31: clr ="Red";
        case 32: clr ="Baby Blue";
        case 33: clr ="Grey";
        case 34: clr ="Grey";
        case 35: clr ="Dark Grey";
        case 36: clr ="Dark Grey";
        case 37: clr ="";
        case 38: clr ="Tea Green";
        case 39: clr ="Steel blue";
        case 40: clr ="Black";
        case 41: clr ="Light Brown";
        case 42: clr ="Bright Maroon";
        case 43: clr ="Maroon";
        case 44: clr ="Myrtle Green";
        case 45: clr ="Maroon";
        case 46: clr ="Olive Green";
        case 47: clr ="Olive";
        case 48: clr ="Khaki Brown";
        case 49: clr ="Light Grey";
        case 50: clr ="Silver Grey";
        case 51: clr ="Dark Green";
        case 52: clr ="Dark Teal";
        case 53: clr ="Navy Blue";
        case 54: clr ="Navy Blue";
        case 55: clr ="Brown";
        case 56: clr ="Light Grey";
        case 57: clr ="Beige";
        case 58: clr ="Maroon";
        case 59: clr ="Grey-Blue";
        case 60: clr ="Grey";
        case 61: clr ="Old Gold";
        case 62: clr ="Maroon";
        case 63: clr ="Grey";
        case 64: clr ="Grey";
        case 65: clr ="Old Gold";
        case 66: clr ="Dark Brown";
        case 67: clr ="Light Blue";
        case 68: clr ="Light Khaki";
        case 69: clr ="Light Pink";
        case 70: clr ="Bright Maroon";
        case 71: clr ="Light Blue";
        case 72: clr ="Grey";
        case 73: clr ="Tea Green";
        case 74: clr ="Dark Maroon";
        case 75: clr ="Dark Blue";
        case 76: clr ="Light Brown";
        case 77: clr ="Ecru Brown";
        case 78: clr ="Maroon";
        case 79: clr ="Royal Blue";
        case 80: clr ="Rich Maroon";
        case 81: clr ="Light Brown";
        case 82: clr ="Bright Maroon";
        case 83: clr ="Dark Teal Green";
        case 84: clr ="Brown";
        case 85: clr ="Rich Maroon";
        case 86: clr ="Green";
        case 87: clr ="Blue ";
        case 88: clr ="Maroon";
        case 89: clr ="Beige";
        case 90: clr ="Grey";
        case 91: clr ="Dark Blue";
        case 92: clr ="Grey";
        case 93: clr ="Sky Blue";
        case 94: clr ="Blue";
        case 95: clr ="Navy Blue";
        case 96: clr ="Silver";
        case 97: clr ="Light Blue";
        case 98: clr ="Grey";
        case 99: clr ="Light Brown ";
        case 100: clr ="Blue";
        case 101: clr ="Dark Blue";
        case 102: clr ="Light Brown";
        case 103: clr ="Blue";
        case 104: clr ="Brown";
        case 105: clr ="Dark Grey";
        case 106: clr ="Blue";
        case 107: clr ="Light Brown";
        case 108: clr ="Yale Blue";
        case 109: clr ="Dark Grey";
        case 110: clr ="Brown";
        case 111: clr ="Light Grey";
        case 112: clr ="Blue";
        case 113: clr ="Brown";
        case 114: clr ="Dark Grey";
        case 115: clr ="Dark Red";
        case 116: clr ="Navy Blue";
        case 117: clr ="Dark Maroon";
        case 118: clr ="Light Blue";
        case 119: clr ="Brown";
        case 120: clr ="Light Brown";
        case 121: clr ="Dark Maroon";
        case 122: clr ="Grey";
        case 123: clr ="Brown";
        case 124: clr ="Rich Maroon";
        case 125: clr ="Dark Blue";
        case 126: clr ="Pink";
    }
    return clr;
}
Reply
#2

BUMP

This part isn't work the table has been created the information save but when server is loaded no cars load

pawn Код:
stock LoadDynamicVehicles()
{
    new Str[128], VehicleID, VehicleModel, Float:VehicleX, Float:VehicleY, Float:VehicleZ, Float:VehicleA, Col1, Col2, vehPlate[10], i = 0;

    mysql_query("SELECT * FROM `dynamicvehicles`");
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>iiffffiis[10]", VehicleID, VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleA, Col1, Col2, vehPlate);

            CreateVehicle(VehicleModel, VehicleX, VehicleY, VehicleZ, VehicleA, Col1, Col2, -1);

            SetVehicleNumberPlate(i, vehPlate);

            SetVehicleToRespawn(i);
           
            DynamicCarID[i] = VehicleID;
            DynamicCarCol[i][1] = Col1;
            DynamicCarCol[i][2] = Col2;
            DynamicCar[i] = 1;
            i++;
        }
    }
    mysql_free_result();
    printf("--- %i vehicles loaded from the MySQL Database. ---", i);
    return 1;
}
Reply
#3

Can I have a look how your "dynamicvehicles" table structure? I'm quite confused of how you INSERT and fetching the row. Which is not in the correct order perhaps. Atleast a screenshot of your table structure.
Reply
#4

removed
Reply
#5

yeah here it is

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS `dynamicvehicles` (`id` int(11) NOT NULL AUTO_INCREMENT,`model` int(11) NOT NULL,`x` float NOT NULL, `y` float NOT NULL, `z` float NOT NULL,`a` float NOT NULL,`c1` int(11) NOT NULL,`c2` int(11) NOT NULL,`plate` varchar(9) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;");
and here is a screenshot proving it saves
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)