strcmp usage -
Snowman12 - 28.01.2012
Hey,
For some reason this doesn't work:
pawn Код:
CMD:drift(playerid, params[])
{
// if(sscanf(params, "d")) return SCM(playerid, -1, ""COL_RED"Usage:"COL_GREY" /drift "COL_ORANGE"[1 - 53]");
if(isnull(params)) return SCM(playerid, -1, ""COL_RED"Usage:"COL_GREY" /drift "COL_ORANGE"[1 - 5]");
if(strcmp("1", params))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid),-358.1943,1531.2909,75.1698);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 264.7289);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid,-358.1943,1531.2909,75.1698);
SetPlayerFacingAngle(playerid, 264.7289);
SetCameraBehindPlayer(playerid);
}
}
if(strcmp(params, "2"))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 2265.3010,1399.5085,42.8203);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 269.7637);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid,2265.3010,1399.5085,42.8203);
SetPlayerFacingAngle(playerid, 269.7637);
SetCameraBehindPlayer(playerid);
}
}
if(strcmp(params, "3"))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid), -2489.8352,-616.3492,132.5658);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 178.7448);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid, -2489.8352, -616.3492, 132.5659);
SetPlayerFacingAngle(playerid, 178.7448);
SetCameraBehindPlayer(playerid);
}
}
if(strcmp(params, "4"))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 2243.2185,1963.3853,31.7797);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 178.7448);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid, 2243.2185, 1963.3853, 31.7797);
SetPlayerFacingAngle(playerid, 178.7448);
SetCameraBehindPlayer(playerid);
}
}
if(strcmp(params, "5"))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 1146.2200,2178.7068,10.8203);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 178.7448);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid, 1146.2200, 2178.7068, 10.8203);
SetPlayerFacingAngle(playerid, 178.7448);
SetCameraBehindPlayer(playerid);
}
}
return 1;
}
Haven't really learned strcmp well but it TPs me to the same locations. Any idea?
Re: strcmp usage -
[ABK]Antonio - 28.01.2012
You could probably just use
pawn Код:
new Number = strval(params);
if(Number == 1)
{
//our stuff
}
Respuesta: strcmp usage -
OPremium - 28.01.2012
strcmp will return 0 if the strings are the same
Instead of this:
Just do this:
https://sampwiki.blast.hk/wiki/Strcmp
EDIT: Also have in mind what the poster above said
Re: strcmp usage -
Dokins - 28.01.2012
It's not Strcmp you should use (compares a string, and although it will work if you use
pawn Код:
if(strcmp(params, "1", true))
{
//Code here.
}
You should probably use a more efficient method by making it an integer so that way you can do it like this
if(value == 1)
{
//code
}
It's much more efficient!
Re: strcmp usage -
=WoR=Varth - 28.01.2012
https://sampwiki.blast.hk/wiki/Strcmp
See the result given.
But just do what [ABK]Antonio said.
Re: strcmp usage -
Mosslah - 28.01.2012
I think you can also use cases, but I'm not entirely sure. I think you should just follow what the posters above told you, as that would work better than strcmp.
Re: strcmp usage -
Konstantinos - 28.01.2012
First of all, sscanf doesn't work like that.
pawn Код:
new
driftid;
if( sscanf( params, "i", driftid ) ) return SendClientMessage(...);
But in your case, I suggest you to use isnull like you used, without sscanf.
Also,
pawn Код:
if( strcmp( params, "1", true ) == 0 )
{
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid),-358.1943,1531.2909,75.1698);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 264.7289);
SetCameraBehindPlayer(playerid);
}
else return SCM(playerid, -1, ""COL_RED"Error:"COL_GREY" You must be the driver of the vehicle.");
}
else
{
SetPlayerPos(playerid,-358.1943,1531.2909,75.1698);
SetPlayerFacingAngle(playerid, 264.7289);
SetCameraBehindPlayer(playerid);
}
}
// Continue..
Re: strcmp usage -
Snowman12 - 28.01.2012
Yeah isnull worked best for it thanks for the comments guys