SA-MP Forums Archive
What's wrong? - 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)
+--- Thread: What's wrong? (/showthread.php?tid=604663)



What's wrong? - justjamie - 08.04.2016

hi,
what's wrong in this code?
pawn Код:
(strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false))



Respuesta: What's wrong? - Thewin - 08.04.2016

PlayerInfo[playerid][playerteam] & Vehicles[vehicleid][carteam] are string or integrer?


Re: Respuesta: What's wrong? - justjamie - 08.04.2016

Quote:
Originally Posted by Thewin
Посмотреть сообщение
PlayerInfo[playerid][playerteam] & Vehicles[vehicleid][carteam] are string or integrer?
string

EDIT = Integrer


Respuesta: What's wrong? - Thewin - 08.04.2016

so post more code and errors


Re: Respuesta: What's wrong? - justjamie - 08.04.2016

Quote:
Originally Posted by Thewin
Посмотреть сообщение
so post more code and errors
okay,
look.

I'm making a /engine command, but i want only people that are in a specified playerteam, can engine the vehicle with the same carteam.
So police = id 7, i put the car on 7 & every player id 7.
I want them to use /engine and if they arn't in that playerteam, they have to get the error ""You do not own this vehicle and you don't have the dupe keys!" .

This is my whole code for /engine

pawn Код:
COMMAND:engine(playerid, params[])
{
    new xr = GetPlayerVehicleID(playerid);
    new engine,lights,alarm,doors,bonnet,boot,objective;
    new sender[MAX_STRING];
    new vehicleid = GetPlayerNearestVehicle(playerid);
    if(PlayerTemp[playerid][hname]==1) myStrcpy(sender,"Stranger");
    else myStrcpy(sender,NameEx(playerid));
    if(IsPlayerInAnyVehicle(playerid) && Vehicles[xr][carmodel] == 481 && Vehicles[xr][carmodel] == 509) return SendClientError(playerid, "You are not in any vehicle, or there is no engine implented.");
    {
        if(Vehicles[vehicleid][cartype]==3) return SendClientError(playerid, "Please use /rengine!");
        new State;
        State = GetPlayerState(playerid);
        if(State!=PLAYER_STATE_DRIVER)  return SendClientMessage(playerid,COLOR_GREY,"You are not the driver!");
        new vid = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
        if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && (strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false)) && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
        {
            return SendClientError(playerid, "You do not own this vehicle and you don't have the dupe keys!");
        }
        //if(VehicleInfo[vid][iBroken]==1) return SendClientError(playerid,"Engine can not be started, Engine is broken");
        if(engine == 0)
        {
            SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
            format(iStr, sizeof(iStr), "turns on the engine of the %s.", GetVehicleName(vehicleid));
            Action(playerid, iStr);
            TogglePlayerControllable(playerid, true);
        }
        else
        {
            SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
            format(iStr, sizeof(iStr), "turns off the engine of the %s.", GetVehicleName(vehicleid));
            Action(playerid, iStr);
            TogglePlayerControllable(playerid, true);
        }
    }
    return 1;
}

this is the code i want to fix:

pawn Код:
new vid = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
        if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && (strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false)) && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
        {
            return SendClientError(playerid, "You do not own this vehicle and you don't have the dupe keys!");
        }

i putted this in it:
pawn Код:
(strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false))
But still everyone with every playerteam can toggle the engine


Respuesta: What's wrong? - Thewin - 08.04.2016

Код:
 (strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false))
change to

Код:
strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false)
the line would be

Код:
if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false) && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
and only returns the message when all the conditions are met because ure using "&& (AND)"


Respuesta: What's wrong? - Thewin - 08.04.2016

Uh, if they are integrer u cant use strcmp, strcmp only compare two strings, u need compare the vars directly like:

Код:
PlayerInfo[playerid][playerteam] != Vehicles[vehicleid][carteam]
the line would be like

Код:
if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && PlayerInfo[playerid][playerteam] != Vehicles[vehicleid][carteam] && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))



Re: Respuesta: What's wrong? - justjamie - 08.04.2016

Quote:
Originally Posted by Thewin
Посмотреть сообщение
Код:
 (strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false))
change to

Код:
strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false)
the line would be

Код:
if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false) && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
and only returns the message when all the conditions are met because ure using "&& (AND)"
People with playerteam 7 still can't toggle the engine


Respuesta: What's wrong? - Thewin - 08.04.2016

see my other comment


Respuesta: What's wrong? - Thewin - 08.04.2016

try with

Code:
if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && PlayerInfo[playerid][playerteam] != Vehicles[vehicleid][carteam] && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))



Re: Respuesta: What's wrong? - justjamie - 08.04.2016

Quote:
Originally Posted by Thewin
Посмотреть сообщение
Код:
 (strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false))
change to

Код:
strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false)
the line would be

Код:
if(strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false) && strcmp(Vehicles[vehicleid][carowner], "Unity_Station") && strcmp(Vehicles[vehicleid][carowner], "Truck_Depot") && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
and only returns the message when all the conditions are met because ure using "&& (AND)"
Works, thanks.
+rep