/carlock Befehl nur für Besitzer

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
  • Hallo liebe Community,


    ich wolte den Command so machen das er abfragt ob der Spieler der Besitzer des Vehicles ist und es dann öffnet, aber es funktioniert nicht.



    Mein Code:
    if(strcmp(cmd, "/carlock", true) == 0)
    {
    new vehicleid;
    new engine, lights, alarm, doors, bonnet, boot, objective;
    if(IsPlayerInAnyVehicle(playerid))// Falls der Spieler in einem Fahrzeug sitzt
    {
    vehicleid = GetPlayerVehicleID(playerid);
    }
    else if(GetClosestVehicleToPlayer(playerid) != 0)// Falls ein Fahrzeug in der Nähe des Spielers ist
    {
    vehicleid = GetClosestVehicleToPlayer(playerid);
    }
    else return 1; // Ansonsten soll nichts passieren
    for(new i; i < MAX_VEHICLES; i++)
    {
    if(cInfo[vehicleid][besitzer]==sInfo[playerid][pid])
    {
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective); // Hier wird der Status der jeweiligen "Fahrzeug-Einstellungen" ausgelesen (Bsp: Ist das Fahrzeug offen oder zu?)
    if(cInfo[vehicleid][lock] == 1) // Falls die Türen zu sind...
    {
    SetVehicleParamsEx(vehicleid, engine, lights, alarm, VEHICLE_PARAMS_OFF, bonnet, boot, objective); // ... werden sie geöffnet (Der Parameter 'doors' wird auf 1 gesetzt
    GameTextForPlayer(playerid, "~w~Fahrzeug ~g~offen", 2000, 3);// Eine Meldung wird eingeblendet
    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
    cInfo[vehicleid][lock] = 0;
    }
    else if(cInfo[vehicleid][lock] == 0) // Falls die Türen offen sind...
    {
    SetVehicleParamsEx(vehicleid, engine, lights, alarm, VEHICLE_PARAMS_ON, bonnet, boot, objective);// ... werden sie geschlossen
    GameTextForPlayer(playerid, "~w~Fahrzeug ~r~verschlossen", 2000, 3);// Eine Meldung wird eingeblendet
    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
    cInfo[vehicleid][lock] = 1;
    }
    return 1;
    }
    else
    {
    SendClientMessage(playerid,Rot,"Dir gehört dieses Fahrzeug nicht!");
    }
    return 1;
    }
    return 1;
    }


    Im Script richtig eingerückt




    Mit freundlichen Grüßen,
    DexterA1

  • pierre65:
    Ja in der Datenbank


    for(new i=0; i<sizeof(cInfo); i++)
    {
    if(cInfo[i][id_x]==0)continue;
    if(cInfo[i][besitzer]!=sInfo[playerid][pid])continue;
    GetVehiclePos(cInfo[i][id_x],cInfo[i][c_x],cInfo[i][c_y],cInfo[i][c_z]);
    GetVehicleZAngle(cInfo[i][id_x],cInfo[i][c_r]);
    GetVehicleColor(cInfo[i][id_x], cInfo[i][vcolor1], cInfo[i][vcolor2]);
    cInfo[i][tuning1]=GetVehicleComponentInSlot(cInfo[i][id_x], 0);
    cInfo[i][tuning2]=GetVehicleComponentInSlot(cInfo[i][id_x], 1);
    cInfo[i][tuning3]=GetVehicleComponentInSlot(cInfo[i][id_x], 2);
    cInfo[i][tuning4]=GetVehicleComponentInSlot(cInfo[i][id_x], 3);
    cInfo[i][tuning5]=GetVehicleComponentInSlot(cInfo[i][id_x], 4);
    cInfo[i][tuning6]=GetVehicleComponentInSlot(cInfo[i][id_x], 5);
    cInfo[i][tuning7]=GetVehicleComponentInSlot(cInfo[i][id_x], 6);
    cInfo[i][tuning8]=GetVehicleComponentInSlot(cInfo[i][id_x], 7);
    cInfo[i][tuning9]=GetVehicleComponentInSlot(cInfo[i][id_x], 8);
    cInfo[i][tuning10]=GetVehicleComponentInSlot(cInfo[i][id_x], 9);
    cInfo[i][tuning11]=GetVehicleComponentInSlot(cInfo[i][id_x], 10);
    cInfo[i][tuning12]=GetVehicleComponentInSlot(cInfo[i][id_x], 11);
    cInfo[i][tuning13]=GetVehicleComponentInSlot(cInfo[i][id_x], 12);
    cInfo[i][tuning14]=GetVehicleComponentInSlot(cInfo[i][id_x], 13);
    new query[256];
    format(query,sizeof(query),"UPDATE autos SET x='%f',y='%f',z='%f',r='%f',color1='%i',color2='%i',lock='%i' WHERE id='%i'",cInfo[i][c_x],cInfo[i][c_y],cInfo[i][c_z],cInfo[i][c_r],cInfo[i][vcolor1],cInfo[i][vcolor2],cInfo[i][lock],cInfo[i][db_id]);
    mysql_function_query(dbhandle,query,false,"","");
    format(query,sizeof(query),"UPDATE autos SET tuning1='%i',tuning2='%i',tuning3='%i',tuning4='%i',tuning5='%i',tuning6='%i',tuning7='%i' WHERE id='%i'",cInfo[i][tuning1],cInfo[i][tuning2],cInfo[i][tuning3],cInfo[i][tuning4],cInfo[i][tuning5],cInfo[i][tuning6],cInfo[i][tuning7],cInfo[i][db_id]);
    mysql_function_query(dbhandle,query,false,"","");
    format(query,sizeof(query),"UPDATE autos SET tuning8='%i',tuning9='%i',tuning10='%i',tuning11='%i',tuning12='%i',tuning13='%i',tuning14='%i' WHERE id='%i'",cInfo[i][tuning8],cInfo[i][tuning9],cInfo[i][tuning10],cInfo[i][tuning11],cInfo[i][tuning12],cInfo[i][tuning13],cInfo[i][tuning14],cInfo[i][db_id]);
    mysql_function_query(dbhandle,query,false,"","");
    DestroyVehicle(cInfo[i][id_x]);
    cInfo[i][id_x]=0;
    }



    _Advanced_:
    Danke für deine Hilfe. (ironisch gemeint)

  • Naja zurück zum Thema...:


    Ich hab dass so gemacht das die PlayerID vom User beim laden in eine Variable gespeichert wird (pInfo[playerid][pUserID]), dass ist dann die ID in der Datenbank die ja nur einmalig vergeben wird.
    Außerdem sind ja bei den Autos auch die Owner gespeichert (z.b. ownerID), wenn du die ID auch in die Autovariable speicherst kannst du die beiden Abfragen, wenn die gleich sind gehört ihm wohl das Auto.^^
    Um es mal zu demonstrieren:

    pInfo[playerid][pUserID] = 5;
    vInfo[vehicleid][pOwnerID] = 3;
    if ( vInfo[vehicleid][pOwnerID] == pInfo[playerid][pUserID] ) { /* sein auto */ }
    else { /* nicht sein auto */ }

  • Ich hab ja


    if(cInfo[vehicleid][besitzer]==sInfo[playerid][pid])


    reingepackt. Besitzer = die ID des Players in der Datenbank vom Besitzer und pid ist die id vom player in der Datenbank. Aber dann kommt immer das es mir nicht gehören würde. Aber es gehört mir.



    Also er müsste praktisch wenn ich die id 9 hätte und in der datenbank bei besitzer die id 9 steht es mir erlauben macht er aber nicht.




    Sorry, doof formuliert.

  • do.de - Domain-Offensive - Domains für alle und zu super Preisen
  • Seltsam ich habe es mal printen lassen in diesem Command:


    if(strcmp(cmd, "/ltest", true) == 0)
    {
    new vehicleid;
    if(IsPlayerInAnyVehicle(playerid))// Falls der Spieler in einem Fahrzeug sitzt
    {
    vehicleid = GetPlayerVehicleID(playerid);
    }
    if(cInfo[vehicleid][besitzer]==sInfo[playerid][pid])
    {
    print("sein Auto");
    }
    else
    {
    print("nicht sein Auto");
    }
    return 1;
    }



    und es kam "nicht sein Auto" raus. Obwohl alles stimmt! Hilfe bitte!


    Ich brauche immernoch Hilfe!

    Einmal editiert, zuletzt von DexterA1 ()



  • Hab ich gemacht da kam "[15:51:04] 0 = 9?" raus. Aber er müsste die besitzerid ordnungsgemäß laden!



    Hier der Code wo er die Besitzerid lädt:
    public OnPlayerCarsLoad(playerid)
    {
    new num_fields,num_rows;
    cache_get_data(num_rows,num_fields,dbhandle);
    if(!num_rows)return 1;
    for(new i=0; i<num_rows; i++)
    {
    new id=getFreeCarID();
    cInfo[id][model]=cache_get_field_content_int(i,"model",dbhandle);
    cInfo[id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
    cInfo[id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
    cInfo[id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
    cInfo[id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
    cInfo[id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
    cInfo[id][vcolor1]=cache_get_field_content_int(i,"color1",dbhandle);
    cInfo[id][vcolor2]=cache_get_field_content_int(i,"color2",dbhandle);
    cInfo[id][tuning1]=cache_get_field_content_int(i,"tuning1",dbhandle);
    cInfo[id][tuning2]=cache_get_field_content_int(i,"tuning2",dbhandle);
    cInfo[id][tuning3]=cache_get_field_content_int(i,"tuning3",dbhandle);
    cInfo[id][tuning4]=cache_get_field_content_int(i,"tuning4",dbhandle);
    cInfo[id][tuning5]=cache_get_field_content_int(i,"tuning5",dbhandle);
    cInfo[id][tuning6]=cache_get_field_content_int(i,"tuning6",dbhandle);
    cInfo[id][tuning7]=cache_get_field_content_int(i,"tuning7",dbhandle);
    cInfo[id][tuning8]=cache_get_field_content_int(i,"tuning8",dbhandle);
    cInfo[id][tuning9]=cache_get_field_content_int(i,"tuning9",dbhandle);
    cInfo[id][tuning10]=cache_get_field_content_int(i,"tuning10",dbhandle);
    cInfo[id][tuning11]=cache_get_field_content_int(i,"tuning11",dbhandle);
    cInfo[id][tuning12]=cache_get_field_content_int(i,"tuning12",dbhandle);
    cInfo[id][tuning13]=cache_get_field_content_int(i,"tuning13",dbhandle);
    cInfo[id][tuning14]=cache_get_field_content_int(i,"tuning14",dbhandle);
    cInfo[id][lock]=cache_get_field_content_int(i,"lock",dbhandle);
    cInfo[id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
    cInfo[id][id_x]=CreateVehicle(cInfo[id][model],cInfo[id][c_x],cInfo[id][c_y],cInfo[id][c_z],cInfo[id][c_r],cInfo[id][vcolor1],cInfo[id][vcolor2],-1);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning1]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning2]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning3]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning4]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning5]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning6]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning7]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning8]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning9]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning10]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning11]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning12]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning13]);
    AddVehicleComponent(cInfo[id][id_x], cInfo[id][tuning14]);
    if(cInfo[id][lock]==1)
    {
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(cInfo[id][id_x], engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(cInfo[id][id_x], engine, lights, alarm, VEHICLE_PARAMS_ON, bonnet, boot, objective);
    //for(new x=0;x<GetMaxPlayers();x++)
    //{
    //SetVehicleParamsForPlayer(id,x,0,1);
    //}
    }
    }
    return 1;
    }


    loadPlayerCars(playerid)
    {
    new query[128];
    format(query,sizeof(query),"SELECT * FROM autos WHERE besitzer='%i'",sInfo[playerid][pid]);
    mysql_function_query(dbhandle,query,true,"OnPlayerCarsLoad","i",playerid);
    return 1;
    }





    Mit freundlichen Grüßen,
    DexterA1

    Einmal editiert, zuletzt von DexterA1 ()