Erneut Problem mit /lock Befehl

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 Abend liebe Leute,
    ich habe gerade erst bemerkt dass ich noch einen kleinen Fehler bei meinem /lock Befehl habe. Der Befehl ans sich selber funktioniert 1A nur 1 Problem ist da, beim Auslesen vom Owner des Fahrzeuges wird dieser leer ausgegeben. Als ich beim Laden der Fahrzeuge dies debuggte gab er mir den Owner zu dem jeweiligen Fahrzeug an.
    Obwohl p_owner leer ist sagt er es übereinstimmt trotzdem mit getPlayerName.


    Schonmal danke im vorraus.


    ocmd:lock(playerid,params[])
    {
    for(new i=0;i<MAX_PRIVATE_VEHICLES;i++)
    {
    new Float:pos[3];
    GetVehiclePos(i,pos[0],pos[1],pos[2]);
    if(IsPlayerInRangeOfPoint(playerid,5,pos[0],pos[1],pos[2]))
    {
    if(!strcmp(PrivateVehicle[i][p_owner], getPlayerName(playerid)))
    {
    printf("Owner = %s",PrivateVehicle[i][p_owner]);
    printf("Player = %s",getPlayerName(playerid));
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 1)
    {
    SetVehicleParamsEx(i,engine,lights,alarm,0,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    return 1;
    }
    else
    {
    SetVehicleParamsEx(i,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }

  • Link zur Wiki-Seite

    Zitat

    This function also returns 0 if either string is empty.


    Es gibt 0 zurück, wenn die Strings exakt gleich sind oder einer leer ist.
    Lösung:

    Code
    if(!strcmp(PrivateVehicle[i][p_owner], getPlayerName(playerid)) && strlen(PrivateVehicle[i][p_owner]) >= 1)
  • Ja habe, beim Laden aller Fahrzeuge wird ma p_owner auch richtig beim DEBUG ausgegben.


    Es ist an dein jTUT tutorial gehalten.

    forward LoadPrivateVehicles_Data();
    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)
    {
    printf("Owner: %s (ID: %i)",PrivateVehicle[i][p_owner],i);
    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;
    }

  • ocmd:lock(playerid,params[])
    {
    for(new i=0;i<MAX_PRIVATE_VEHICLES;i++)
    {
    new Float:pos[3];
    GetVehiclePos(i,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)))
    {
    printf("Owner = %s",PrivateVehicle[i][p_owner]);
    printf("Player = %s",getPlayerName(playerid));
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 1)
    {
    SetVehicleParamsEx(i,engine,lights,alarm,0,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    return 1;
    }
    else
    {
    SetVehicleParamsEx(i,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    Was ist jetzt? Bekommst du nun keine Nachricht mehr?
    Beziehungsweise, was bekommst du denn bei den beiden Debuggs raus?

  • Es funktioniert jetzt, aber auch nicht immer.
    Ich habe mir 2x ein Fahrzeug gespawned welches mir gehört und MAX_PRIVATE_VEHICLES zu MAX_VEHICLES abgeändert.
    Nun bekomme ich aber nur bei 1nem erstellen Fahrzeug die Lock Nachrichten.


    //EDIT:
    ocmd:lock(playerid,params[])
    {
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    new Float:pos[3];
    GetVehiclePos(i,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)))
    {
    printf("Owner = %s",PrivateVehicle[i][p_owner]);
    printf("Player = %s",getPlayerName(playerid));
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 1)
    {
    SetVehicleParamsEx(i,engine,lights,alarm,0,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    return 1;
    }
    else
    {
    SetVehicleParamsEx(i,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }

  • Ja, weil er bis zum 1. Fahrzeug von dir geht, und da aufhört.
    Speicherst du nicht auch irgendwie die Fahrzeug-ID ab? Damit können wir das ein wenig umbauen.

  • Wenn ich mich nicht komplett irre ja,

    Und beim Createn des Fahrzeuges
    Sieht es so aus:
    ocmd:pcreate(playerid,params[])
    {
    if(!IsPlayerAnAdmin(playerid))return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not allowed to use this Command.");
    if(!IsPlayerAdminRank(playerid,4))return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not allowed to use this Command.");
    new model,owner[24],c1,c2;
    if(GetVehicleModel(MAX_VEHICLES-1))return SendClientMessage(playerid,Rot,"Error: {FFFFFF}The Limit of MAX_VEHICLES is reached.");
    if(sscanf(params,"siii",owner,model,c1,c2))return SendClientMessage(playerid,Rot,"Error: {FFFFFF}Use /pcreate [Owner] [Model ID] [Color 1] [Color 2]");
    if(model < 400 || model > 611)return SendClientMessage(playerid,Rot,"Error: {FFFFFF}The VehicleID can't be smaller then 400 or higher then 600.");
    if(c1 < 1 || c1 > 255)return SendClientMessage(playerid,Rot,"Error: {FFFFFF}In the Color ID 1 is an error. It can't be smaller then 1 and can't be higher then 255.");
    if(c2 < 1 || c2 > 255)return SendClientMessage(playerid,Rot,"Error: {FFFFFF}In the Color ID 2 is an error. It can't be smaller then 1 and can't be higher then 255.");
    for(new i=0;i<MAX_PRIVATE_VEHICLES;i++)
    {
    if(PrivateVehicle[i][p_vID] == 0)
    {
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    PrivateVehicle[i][p_modelID] = model;
    PrivateVehicle[i][p_x] = x;
    PrivateVehicle[i][p_y] = y;
    PrivateVehicle[i][p_z] = z;
    PrivateVehicle[i][p_a] = a;
    PrivateVehicle[i][p_color1] = c1;
    PrivateVehicle[i][p_color2] = c2;
    format(PrivateVehicle[i][p_owner],24,"%s",owner);
    new query[342];
    mysql_format(Handle,query,sizeof(query),"INSERT INTO privatecars (id, Modelid, PosX, PosY, PosZ, PosA, Color1, Color2, Owner) VALUES ('%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d', '%s')",
    i,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],PrivateVehicle[i][p_owner]);
    mysql_pquery(Handle,query);
    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);
    PutPlayerInVehicle(playerid,PrivateVehicle[i][p_vID],0);
    return SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}The Private Vehicle was created and saved.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}The Limit of MAX_PRIVATE_VEHICLES is reached.");
    }

  • Ok. Dann schreib das mal so:
    ocmd:lock(playerid,params[])
    {
    for(new i=0;i<MAX_VEHICLES;i++)
    {
    new Float:pos[3];
    GetVehiclePos(i,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)) && i == PrivateVehicle[i][p_vID])
    {
    printf("Owner = %s",PrivateVehicle[i][p_owner]);
    printf("Player = %s",getPlayerName(playerid));
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 1)
    {
    SetVehicleParamsEx(i,engine,lights,alarm,0,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    return 1;
    }
    else
    {
    SetVehicleParamsEx(i,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }

  • ocmd:lock(playerid,params[])
    {
    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)))
    {
    printf("Owner = %s",PrivateVehicle[i][p_owner]);
    printf("Player = %s",getPlayerName(playerid));
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(vID,engine,lights,alarm,doors,bonnet,boot,objective);
    if(doors == 1)
    {
    SetVehicleParamsEx(vID,engine,lights,alarm,0,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have unlocked your Vehicle.");
    return 1;
    }
    else
    {
    SetVehicleParamsEx(vID,engine,lights,alarm,1,bonnet,boot,objective);
    SendClientMessage(playerid,Gelb,"[SInfo] {FFFFFF}You have locked your Vehicle.");
    return 1;
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }
    }
    return SendClientMessage(playerid,Rot,"Error: {FFFFFF}You are not near by your Vehicle.");
    }




    EDIT: (Post unten)
    CaZe: Da dein Problem behoben ist, wäre es super, wenn du den Thread als erledigt markierst. Danke! :)

    3HZXdYd.png

    Einmal editiert, zuletzt von Jeffry ()