Beiträge von d30af26d

    Bild:


    Eine Funktion, um zu überprüfen, ob Tabellen in einer Datenbank vorhanden sind.


    Voraussetzungen:
    • MySQL Plugin von G-sTyLeZzZ
    • MySQL Datenbank mit Verbindungsdaten


    Gesamte Funktion:
    (Pastebin)
    stock mysql_table_existence(amount, tables[][], connection = 1)
    {
    print("\n[MySQL] Checking if connection exists.");
    if(mysql_ping(connection) == 1)
    {
    print("[MySQL] Connection exists. Checking tables.\n");


    // Check if there are tables to check
    if(!strlen(tables[0]))
    {
    print("[MySQL] Script won't work. No tables avaible to check.");
    print("[MySQL] Table checking done. Have fun!\n");
    gDatabaseError = true;
    return 1;
    }


    // Storage, Query, MissingTables Counter, FoundTables Counter
    // [0] = Query
    // [1] = Storage
    new string[2][64],
    missingTables = 0,
    foundTables = 0;


    for(new t=0; t<amount; t++)
    {
    // Create Query
    format(string[0], 64, "SHOW TABLES LIKE '%s'", tables[t]);
    mysql_query(string[0], -1, -1, connection);
    mysql_store_result(connection);


    // Check if it exists
    while(mysql_fetch_row_format(string[1], "|", connection))
    {
    if(!strcmp(string[1], tables[t])) { gDatabaseError = false; break; }
    else gDatabaseError = true;
    }


    // Anti-Empty-Failure
    if(!string[1][0]) gDatabaseError = true;


    // Output Message
    if(gDatabaseError == true)
    printf("[MySQL] Table '%s' not found.", tables[t]);
    else
    printf("[MySQL] Table '%s' found.", tables[t]);


    // Release Memory and Reset
    mysql_free_result(connection);
    string[0][0] = '\0';
    string[1][0] = '\0';


    if(gDatabaseError == true) ++missingTables;
    else ++foundTables;
    gDatabaseError = false;
    }


    // Output Error, when a table is missed
    if(missingTables >= 1)
    {
    if(missingTables == 1) printf ("\n[MySQL] Script won't work. One table wasn't found.");
    else printf ("\n[MySQL] Script won't work. %d tables weren't found.", missingTables);
    printf("[MySQL] Table checking done. Have fun!\n");
    gDatabaseError = true;
    }
    else
    {
    if(foundTables == 1) printf("\n[MySQL] No table is missing. One table found.");
    else printf("\n[MySQL] No table is missing. %d tables found.", foundTables);
    printf("[MySQL] Table checking done. Have fun!\n");
    gDatabaseError = false;
    }


    printf("[MySQL] Copyright (c) [OSF]Atom - Table Check\n");
    return 1;
    }
    else
    {
    print("[MySQL] Connection doesn't exist. Aborting.\n");


    // No connection - no databas'es
    gDatabaseError = true;
    return 0;
    }
    }


    Verwendung:
    new table[][] = {"alpha", "beta", "charlie", "delta"};
    mysql_table_existence(4, table);


    Parameter:
    amount = Anzahl der Tabellen
    tables[][] = Der Array mit den Tabellen-Namen
    connection = Falls jemand eine spezielle Verbindung benutzt



    Sonstige Voraussetzungen:
    new bool:gDatabaseError = false;



    Hinweise:
    Wenn (gDatabaseError == true) ist, dann könnt ihr den Spieler vorm Registrieren,
    was vielleicht mehr Fehler gibt, aufhalten und rauskicken.

    Beispiel:

    public OnPlayerConnect(playerid)
    {
    // When a table or something else is broken
    if(gDatabaseError == true)
    {
    ShowPlayerDialog(playerid, 0, 0, "Database Error", "Sie wurden vom Server entfernt, da ein Problem mit der Datenbank vorliegt, um jegliche Fehler zu vermeiden.\n\nFreundliche Grüße\nDas Team", "Schließen", "");
    Kick(playerid);
    return 0;
    }
    return 1;
    }



    Freundliche Grüße
    Martez

    new Float:Position[3];
    GetVehiclePos(Auto[0], Position[0], Position[1], Position[2]);
    SetPlayerCheckpoint(playerid, Position[0], Position[1], Position[2], 5.0);


    Du hast Werte abgerufen, welche vom Typ Float sind, aber willst sie im Typ Integer unterbringen - es passt einfach nicht.


    #define STANDART_RADIUS 18.8772


    stock Float:GetVehicleDistanceFromPlayer(playerid, vehicleid)
    {
    new Float:Pos[6];
    GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
    GetPlayerPos(playerid, Pos[3], Pos[4], Pos[5]);
    new Float:Distance = ( (Pos[3] - Pos[0])*(Pos[3] - Pos[0]) + (Pos[4] - Pos[1])*(Pos[4] - Pos[1]) + (Pos[5] - Pos[2])*(Pos[5] - Pos[2]) );
    return Distance;
    }


    stock GetNearestVehicle(playerid)
    {
    new
    Float:Pos[3],
    Float:distance = STANDART_RADIUS,
    id = INVALID_VEHICLE_ID;
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    for(new i=0; i<MAX_VEHICLES; i++) if( GetVehicleModel(i) && (IsPlayerInRangeOfPoint(playerid, STANDART_RADIUS, Pos[0], Pos[1], Pos[2])) && (GetVehicleDistanceFromPlayer(playerid, i) < distance)) { distance = GetVehicleDistanceFromPlayer(playerid, i); id = i; }
    return id;
    }


    stock IsNearAmbulance(playerid)
    {
    return (GetVehicleModel(GetNearestVehicle(playerid)) == 416) ? (1) : (0);
    }

    Man könnte auf eine entfernte Datenbank zugreifen und zwischen Nachrichten wechseln.
    - Am besten wäre die Datenbank auf dem selben Server wie der Samp-Server auch ist - Wird schneller angezeigt, da der Text nicht vom Webspace heruntergeladen werden muss.