[SAMMELTHREAD] Kleine Scripting Fragen

Dein Problem konnte durch einen User gelöst werden? Bedank dich bei ihm indem du seinen Beitrag als Hilfreich markierst sowie einen Daumen oben dalässt
Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Guten Tag liebe leute,
    ich habe ein kleines Problem.
    Undzwar werden keine Objekte mehr erstellt. Von den ein auf den anderen Moment.
    Hier mein OnGameModeInit:

    Spoiler anzeigen


    public OnGameModeInit()
    {
    //MYSQL CONNECTION
    Handle = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DATA,MYSQL_PASS);
    if(mysql_errno() == 0)print("MySQL: Die Verbindung wurde erfolgreich hergestellt.."),mysql_log(LOG_ALL); else print("MySQL: Die Verbindung zur Datenbank konnte nicht hergestellt werden | Der Server wird nun heruntergefahren."),SendRconCommand("exit");
    //---------------------------------------------------------------------------------
    //
    //GENERAL SETTINGS/LOADS
    SetGameModeText("Train Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    CreatePickup(1239,1,1486.8600,-1688.4371,14.0469,0);
    new str[64];
    format(str,sizeof(str),"Type {FFFF00}/rentbike{FFFFFF}\nTo rent a Bike.");
    Create3DTextLabel(str,Weiß,1486.8600,-1688.4371,14.0469,10,0,0);
    UsePlayerPedAnims();
    DisableInteriorEnterExits();
    //---------------------------------------------------------------------------------
    //
    //LOAD EVERYTHING
    LoadVehicles();
    LoadHouses();
    LockVehicles();
    //---------------------------------------------------------------------------------
    //
    //INTERIOR EDITS | INTERIOR NAME: KATIE ROOM | ID: 2
    CreateObject(1740, 271.37711, 307.37109, 998.14581, 0.00000, 0.00000, 0.00000);
    CreateObject(1720, 273.18369, 304.97870, 998.14832, 0.00000, 0.00000, 90.00000);
    CreateObject(948, 273.93655, 306.75726, 998.14777, 0.00000, 0.00000, 297.98138);
    CreateObject(1740, 268.86151, 307.37109, 998.14581, 0.00000, 0.00000, 0.00000);
    CreateObject(1516, 273.77328, 304.98889, 998.31073, 0.00000, 0.00000, 0.00000);
    CreateObject(1720, 273.80569, 305.60049, 998.14832, 0.00000, 0.00000, 0.00000);
    CreateObject(1720, 273.80569, 304.44049, 998.14832, 0.00000, 0.00000, -180.00000);
    //---------------------------------------------------------------------------------
    //
    //MAP EDITINGS
    for(new i=0;i<MAX_ATMS;i++)
    {
    CreateObject(2942,AtmInfo[i][a_x],AtmInfo[i][a_y],AtmInfo[i][a_z],AtmInfo[i][a_a1],AtmInfo[i][a_a2],AtmInfo[i][a_a3]);
    AtmLabel[i] = Create3DTextLabel("This is an ATM.\nUse {FF7800}/atm{FFFFFF} to enter the Bank Menu.",Weiß,AtmInfo[i][a_x],AtmInfo[i][a_y],AtmInfo[i][a_z],7.50,0,0);
    }
    CreateObject(1676, 1008.94470, -936.19537, 42.74210, 0.00000, 0.00000, 8.41960);
    CreateObject(1676, 1001.64630, -937.23218, 42.74214, 0.00000, 0.00000, 8.41958);
    CreateObject(1676, 1006.00983, -936.55798, 42.74214, 0.00000, 0.00000, 8.41958);
    CreateObject(1676, 998.85504, -937.66339, 42.74214, 0.00000, 0.00000, 8.41958);
    //---------------------------------------------------------------------------------

    Spoiler anzeigen
    return 1;
    }

  • Code
    [18:23:02] [debug] Run time error 4: "Array index out of bounds"
    [18:23:02] [debug]  Accessing element at index 5 past array upper bound 4
    [18:23:02] [debug] AMX backtrace:
    [18:23:02] [debug] #0 00020874 in ?? () from ForFun.amx
    [18:23:02] [debug] #1 00001ce0 in public OnGameModeInit () from ForFun.amx
  • Welche der Variablen hast du mit [5] deklariert? Erhöhe diese.


    Falls du nicht weißt welche, erstelle im /pawno/ Ordner neben der pawno.exe eine "pawn.cfg" Datei und schreibe dort "-d3" rein (ohne Anführungszeichen). Dann öffne die pawno.exe, wähle deinen Code aus und kompiliere ihn. Dann poste nochmal den Server Log, wenn du den Server startest.

  • Code
    [18:28:34] [debug] #0 00029804 in LockVehicles () at C:\Users\Patrice\Desktop\Sa-Mp\gamemodes\ForFun.pwn:2750
    [18:28:34] [debug] #1 000023ac in public OnGameModeInit () at C:\Users\Patrice\Desktop\Sa-Mp\gamemodes\ForFun.pwn:230


    LockVehicles


    stock LockVehicles()
    {
    new engine,lights,alarm,doors,bonnet,boot,objective,count;
    {
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    if(i == PrivateVehicle[i][p_vID])
    {
    count++;
    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
    SetVehicleParamsEx(i,engine,lights,alarm,1,bonnet,boot,objective);
    }
    }
    }
    printf("%i Vehicles locked",count);
    return 1;
    }

  • stock LockVehicles()
    {
    new engine,lights,alarm,doors,bonnet,boot,objective,count;
    for(new i=0;i<sizeof(PrivateVehicle);i++)
    {
    if(PrivateVehicle[i][p_vID] != 0)
    {
    count++;
    GetVehicleParamsEx(PrivateVehicle[i][p_vID],engine,lights,alarm,doors,bonnet,boot,objective);
    SetVehicleParamsEx(PrivateVehicle[i][p_vID],engine,lights,alarm,1,bonnet,boot,objective);
    }
    }
    printf("%i Vehicles locked",count);
    return 1;
    }

  • Danke vorerst, Objekte spawnen alles tiptop.
    Jetzt kommt aber wenn ich meinem Privaten Fahrzeug betrete:

    Code
    [18:34:43] [debug] Run time error 4: "Array index out of bounds"
    [18:34:43] [debug]  Accessing element at index 5 past array upper bound 4
    [18:34:43] [debug] AMX backtrace:
    [18:34:43] [debug] #0 00019c5c in public OnPlayerEnterVehicle (playerid=0, vehicleid=1,


    Und er gibt auch aus: 0 Vehicles locked.

  • LoadVehicles


    stock LoadVehicles()
    {
    mysql_pquery(Handle, "SELECT * FROM fraccars ORDER BY ID ASC","LoadFracVehicles_Data");
    mysql_pquery(Handle, "SELECT * FROM privatecars ORDER BY ID ASC","LoadPrivateVehicles_Data");
    return 1;
    }

    LoadVehicles
    public LoadPrivateVehicles_Data()
    {
    new rows;
    rows = cache_num_rows();
    for(new i=0;i<rows;i++)
    {
    PrivateVehicle[i][p_modelID] = cache_get_field_content_int(i, "Modelid");
    PrivateVehicle[i][p_x] = cache_get_field_content_float(i, "PosX");
    PrivateVehicle[i][p_y] = cache_get_field_content_float(i, "PosY");
    PrivateVehicle[i][p_z] = cache_get_field_content_float(i, "PosZ");
    PrivateVehicle[i][p_a] = cache_get_field_content_float(i, "PosA");
    PrivateVehicle[i][p_color1] = cache_get_field_content_int(i, "Color1");
    PrivateVehicle[i][p_color2] = cache_get_field_content_int(i,"Color2");
    cache_get_field_content(i,"Owner",PrivateVehicle[i][p_owner],Handle,24);
    if(PrivateVehicle[i][p_modelID] >= 400 && PrivateVehicle[i][p_modelID] <= 611)
    {
    PrivateVehicle[i][p_vID] = CreateVehicle(PrivateVehicle[i][p_modelID],PrivateVehicle[i][p_x],PrivateVehicle[i][p_y],PrivateVehicle[i][p_z],PrivateVehicle[i][p_a],PrivateVehicle[i][p_color1],PrivateVehicle[i][p_color2],-1);
    }
    else
    {
    printf("[Error] PrivateVehicle Model-ID %d doesn't exist (ID: %d).",PrivateVehicle[i][p_modelID],i);
    }
    if(GetVehicleModel(MAX_VEHICLES-1) != 0)return print("The Limit of Max Vehicles is reached.");
    if(i == MAX_PRIVATE_VEHICLES-1)return print("The Limit of Max Private Vehicles is reached.");
    }
    return 1;
    }


    OnPlayerEnterVehicle


    public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
    //new str[546];
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    if(FracVehicle[i][f_vID] == vehicleid)
    {
    if(SpielerInfo[playerid][pFrak] != FracVehicle[i][f_fracID])
    {
    TogglePlayerControllable(playerid,false);
    TogglePlayerControllable(playerid,true);
    SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not allowed to enter this Vehicle because you are not in the right Fraction.");

    OnPlayerEnterVehicle
    }
    break;
    }
    }
    return 1;
    }

  • public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
    //new str[546];
    for(new i=0;i<sizeof(FracVehicle);i++)
    {
    if(FracVehicle[i][f_vID] == vehicleid)
    {
    if(SpielerInfo[playerid][pFrak] != FracVehicle[i][f_fracID])
    {
    TogglePlayerControllable(playerid,false);
    TogglePlayerControllable(playerid,true);
    SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not allowed to enter this Vehicle because you are not in the right Fraction.");
    }
    break;
    }
    }
    return 1;
    }


    Wenn "0 Vehicles locked" kommt, dann wurden keine Privaten Fahrzeuge erstellt, wahrscheinlich steht da nichts in der Datenbank.

  • do.de - Domain-Offensive - Domains für alle und zu super Preisen
  • /lock


    ocmd:lock(playerid,params[])
    {
    if(SpielerInfo[playerid][pEingeloggt] == 0)return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not logged in.");
    for(new i=0;i<MAX_PRIVATE_VEHICLES;i++)
    {
    new Float:pos[3];
    new vID;
    vID = PrivateVehicle[i][p_vID];
    GetVehiclePos(vID,pos[0],pos[1],pos[2]);
    if(IsPlayerInRangeOfPoint(playerid,5,pos[0],pos[1],pos[2]))
    {
    if(!strlen(PrivateVehicle[i][p_owner]))continue;
    if(!strcmp(PrivateVehicle[i][p_owner], getPlayerName(playerid)))
    {
    CarLock(vID);
    return 1;
    }
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }


    stock CarLock


    stock CarLock(vehicleid)
    {
    new engine,lights,alarm,doors,bonnet,boot,objective;
    {
    GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 0)
    {
    SetVehicleParamsEx(vehicleid,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(PrivateVehicle[vehicleid][p_owner],Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    else
    {
    SendClientMessage(PrivateVehicle[vehicleid][p_owner],Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    SetVehicleParamsEx(vehicleid,engine,lights,alarm,0,bonnet,boot,objective);
    return 2;
    }
    }
    }

  • Ach, ich weiß warum. Das liegt an den MySQL Funktionen, die rufen das LoadPrivateVehicles_Data ja erst danach auf (Zeitverzögerung), daher stehen da die Daten noch nicht drin.
    Nimm das LockVehicles(); aus OnGameModeInit raus und schreibe es ganz unten bei LoadPrivateVehicles_Data hin, dann geht's.

  • Jeffry:
    Ne idee warum das Object nicht an das Fahrzeug geklebt wird ?

    SetPlayerSpecialAction(playerid,0);
    Spieler[playerid][Mulltonne] = CreateObject(1337,GetPVarFloat(playerid,"mwp1"),GetPVarFloat(playerid,"mwp2"),GetPVarFloat(playerid,"mwp3"),0.0,0.0,0.0);
    AttachObjectToVehicle(Spieler[playerid][Mulltonne],GetPVarInt(playerid,"Mullwagen"),0.000000,-4.099999,-0.699999,0.000000,0.000000,0.000000);
    Spieler[playerid][Mulllader] = true;

  • Versuchs mal so:
    SetPlayerSpecialAction(playerid,0);
    Spieler[playerid][Mulltonne] = CreateObject(1337,0.0,0.0,0.0,0.0,0.0,0.0);
    AttachObjectToVehicle(Spieler[playerid][Mulltonne],GetPVarInt(playerid,"Mullwagen"),0.000000,-4.099999,-0.699999,0.000000,0.000000,0.000000);
    Spieler[playerid][Mulllader] = true;


    -4 kann aber auch ziemlich am Rand irgendwo sein.

  • Versuchs mal so:
    SetPlayerSpecialAction(playerid,0);
    Spieler[playerid][Mulltonne] = CreateObject(1337,0.0,0.0,0.0,0.0,0.0,0.0);
    AttachObjectToVehicle(Spieler[playerid][Mulltonne],GetPVarInt(playerid,"Mullwagen"),0.000000,-4.099999,-0.699999,0.000000,0.000000,0.000000);
    Spieler[playerid][Mulllader] = true;


    -4 kann aber auch ziemlich am Rand irgendwo sein.


    Klappt leider so auch nicht. Und dir Koordinaten sind schon richtig so, hab die vorher selber getestet :)