SA-MP Forums Archive
What's wrong with this line? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: What's wrong with this line? (/showthread.php?tid=192392)



What's wrong with this line? - Mystique - 22.11.2010

Well, as I'm trying to make a lock command through a function called GetClosestVehicle, this isn't working.
If I don't include that if I own it it works, then it takes the closest vehicle but when I put these owner variables into it it won't just work. Does anyone have a idea what this is about?

Код:
if(strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true))



Re: What's wrong with this line? - Flyfishes - 22.11.2010

What's the error?


Re: What's wrong with this line? - Mystique - 22.11.2010

The thing is that there is no error. That's the thing that confuses me. that strcmp thing works in the /engine command but then the GetClosestVehicle(playerid,5) is GetPlayerVehicleID(playerid). And the GetClosestVehicle thing works perfectly whe not including this strcmp but I need it to check if the player owns the car.


Re: What's wrong with this line? - Lenny the Cup - 22.11.2010

strcmp returns 0 if the strings match, but also if any of them is empty


Re: What's wrong with this line? - Scenario - 22.11.2010

pawn Код:
if(!strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true))



Re: What's wrong with this line? - Mystique - 22.11.2010

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
if(!strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true))
That made me able to lock and unlock every vehicle in the server.


Re: What's wrong with this line? - Scenario - 22.11.2010

You have an error in your code then, the line I provided is the correct one to use.


Re: What's wrong with this line? - XePloiT - 22.11.2010

RealCop228 is right but its depends on what comes after this line


Re: What's wrong with this line? - Mystique - 22.11.2010

pawn Код:
if(strcmp(cmd, "/carlock", true) ==0)
    {
     if(GetClosestVehicle(playerid, 5))
     {
      for(new p = 0; p < MAX_PLAYERS; p++)
      {
        if(!strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true))
        {
       
        if(CarLock[GetClosestVehicle(playerid,5)] == 0)
        {
        CarLock[GetClosestVehicle(playerid,5)] = 1;
        SetVehicleParamsForPlayer(GetClosestVehicle(playerid,5),p,0,1);
        new str[128];
        format(str, sizeof(str), "*%s presses a key which locks the doors of the vehicle", pName(playerid));
        ProxDetector(30.0,playerid,str,MECHAT,MECHAT,MECHAT,MECHAT,MECHAT);
        return 1;
        }
        else if(CarLock[GetClosestVehicle(playerid,5)] == 1)
        {
        CarLock[GetClosestVehicle(playerid,5)] = 0;
        SetVehicleParamsForPlayer(GetClosestVehicle(playerid,5),p,0,0);
        new str[128];
        format(str, sizeof(str), "*%s presses a key which unlocks the doors of the vehicle", pName(playerid));
        ProxDetector(30.0,playerid,str,MECHAT,MECHAT,MECHAT,MECHAT,MECHAT);
        return 1;
        }
        }

       }


     }
     return 1;
     }



Re: What's wrong with this line? - Scenario - 22.11.2010

I am editing your code now, but I see no use for these functions;

pawn Код:
if(GetClosestVehicle(playerid, 5))
    {
        for(new p = 0; p < MAX_PLAYERS; p++)
        {
EDIT: This seems to be the better option, you were allowing any player to enter the vehicle when you should of been allowing only the vehicle's owner to enter the vehicle. I removed some functions.

pawn Код:
if(strcmp(cmd, "/carlock", true) ==0)
{
    new str[128];
    new vehicleid = GetClosestVehicle(playerid, 5);
    if(!strcmp(CarSystem[vehicleid][Carowner], pName(playerid), true))
    {
        if(CarLock[vehicleid] == 0)
        {
            CarLock[vehicleid] = 1;
            SetVehicleParamsForPlayer(vehicleid, playerid, 0, 1);
            format(str, sizeof(str), "* %s presses a key which locks the doors of the vehicle", pName(playerid));
            ProxDetector(30.0, playerid, str, MECHAT, MECHAT, MECHAT, MECHAT, MECHAT);
        }
        else if(CarLock[vehicleid] == 1)
        {
            CarLock[vehicleid] = 0;
            SetVehicleParamsForPlayer(vehicleid, playerid, 0, 0);
            format(str, sizeof(str), "* %s presses a key which unlocks the doors of the vehicle", pName(playerid));
            ProxDetector(30.0, playerid, str, MECHAT, MECHAT, MECHAT, MECHAT, MECHAT);
        }
    }
    return 1;
}



Re: What's wrong with this line? - armyoftwo - 22.11.2010

i don't know if this will work, but you should try this:
Код:
if(strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true) == 0)
This line basically will return 0 if those two strings are the same
and take a look what it prints
Код:
printf(" Car owner: %s Player Name: %s", CarSystem[GetClosestVehicle(playerid,5)][Carowner],  pName(playerid));



Re: What's wrong with this line? - Mystique - 22.11.2010

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I am editing your code now, but I see no use for these functions;

pawn Код:
if(GetClosestVehicle(playerid, 5))
    {
        for(new p = 0; p < MAX_PLAYERS; p++)
        {
EDIT: This seems to be the better option, you were allowing any player to enter the vehicle when you should of been allowing only the vehicle's owner to enter the vehicle. I removed some functions.

pawn Код:
if(strcmp(cmd, "/carlock", true) ==0)
{
    new str[128];
    new vehicleid = GetClosestVehicle(playerid, 5);
    if(!strcmp(CarSystem[vehicleid][Carowner], pName(playerid), true))
    {
        if(CarLock[vehicleid] == 0)
        {
            CarLock[vehicleid] = 1;
            SetVehicleParamsForPlayer(vehicleid, playerid, 0, 1);
            format(str, sizeof(str), "* %s presses a key which locks the doors of the vehicle", pName(playerid));
            ProxDetector(30.0, playerid, str, MECHAT, MECHAT, MECHAT, MECHAT, MECHAT);
        }
        else if(CarLock[vehicleid] == 1)
        {
            CarLock[vehicleid] = 0;
            SetVehicleParamsForPlayer(vehicleid, playerid, 0, 0);
            format(str, sizeof(str), "* %s presses a key which unlocks the doors of the vehicle", pName(playerid));
            ProxDetector(30.0, playerid, str, MECHAT, MECHAT, MECHAT, MECHAT, MECHAT);
        }
    }
    return 1;
}
Uuh, still I am able to unlock and lock all vehicles I can find even if I'm not the owner.


Re: What's wrong with this line? - Scenario - 22.11.2010

Quote:
Originally Posted by Mystique
Посмотреть сообщение
Uuh, still I am able to unlock and lock all vehicles I can find even if I'm not the owner.
Okay, then remove the ! for the strcmp line. If that doesn't work, make sure you are assigning a variable to "Carowner".


Re: What's wrong with this line? - Mystique - 22.11.2010

Quote:
Originally Posted by armyoftwo
Посмотреть сообщение
i don't know if this will work, but you should try this:
Код:
if(strcmp(CarSystem[GetClosestVehicle(playerid,5)][Carowner], pName(playerid), true) == 0)
This line basically will return 0 if those two strings are the same
and take a look what it prints
Код:
printf(" Car owner: %s Player Name: %s", CarSystem[GetClosestVehicle(playerid,5)][Carowner],  pName(playerid));
I tested this and the ownername shows up only if you are inside the vehicle.
If you are close to it outside it won't say the ownername of it but if you for example wants it to say a message if your closest vehicle is in range it says it but as soon as I connect it with the carowner variable it won't work...

pawn Код:
public GetClosestVehicle(playerid, Float:radius)
{
    new Float:SpielerX, Float:SpielerY, Float:SpielerZ, Float:CarX, Float:CarZ, Float:CarY;
    GetPlayerPos(playerid, SpielerX, SpielerY, SpielerZ);
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        GetVehiclePos(i, CarX, CarY, CarZ);
        if((floatabs(SpielerX-CarX)<radius)&&(floatabs(SpielerY-CarY)<radius)&&(floatabs(SpielerZ-CarZ)<radius))
        {
            return i;
        }
    }
    return false;
}
Yes, it's in german but a guy made it for me long time ago.


Re: What's wrong with this line? - XePloiT - 22.11.2010

maybe because its getting the closet vehicles id and "CarLock[vehicleid]" equals 0 if its not defined so try numbers like -1 and 1 or something other... just no 0.
and everyone can use this because you didnt did any condition for admin...


Re: What's wrong with this line? - Mystique - 22.11.2010

Quote:
Originally Posted by XePloiT
Посмотреть сообщение
maybe because its getting the closet vehicles id and "CarLock[vehicleid]" equals 0 if its not defined so try numbers like -1 and 1 or something other... just no 0.
and everyone can use this because you didnt did any condition for admin...
It's mean't that the player who owns the vehicle can lock and unlock, no one else.