strcmp name, if false, how to return?
#1

hello all!

Today, I was trying to make a command that opens a gate.
I got the gate working perfectly, But i am also trying to make that gate opening ONLY for a specific name. I used strcmp to check the name, and still it opens for others.


I mean, if the player isn't named driftking, how can I return: sorry, you are not allowed to open this gate?

because now it opens the gate for everyone.

Thanks a lot, and I am not good explaining, sorry.

pawn Код:
if(strcmp(cmd, "/open", true) == 0) {
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if (strcmp(name, "[Mw]drifking", false))
{
    if(IsPlayerInRangeOfPoint(playerid, 11.0, 1497.19000000,-710.91000000,97.61000000))
            {
            MoveObject(gate, 1497.19000000,-714.91000000,101.61000000,2);//This will move the gate
            SendClientMessage(playerid,COLOR_BLUE,"GATE OPENING! (ALERT; ALERT)");//This will send an message announcing the gate Stats!
            SetTimer("GateClose", 8000, 0);//This will start the counting till the gate will be closed
            }
   if(!IsPlayerInRangeOfPoint(playerid, 11.0, 1497.19000000,-710.91000000,97.61000000))
            {
            SendClientMessage(playerid, COLOR_YELLOW, "You are not close enough to the gate!");
            }
}
if (!strcmp(name, "[Mw]drifking", false)){SendClientMessage(playerid,COLOR_BLUE,"You are not allowed to open this gate, sorry!");}


            return 1;
 }
Thats my try. xD
Reply
#2

pawn Код:
if(strcmp(cmd, "/open", true) == 0)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if( !strcmp( name, "[Mw]drifking" ) )
    {
        if(IsPlayerInRangeOfPoint(playerid, 11.0, 1497.19000000,-710.91000000,97.61000000))
        {
            MoveObject(gate, 1497.19000000,-714.91000000,101.61000000,2);//This will move the gate
            SendClientMessage(playerid,COLOR_BLUE,"GATE OPENING! (ALERT; ALERT)");//This will send an message announcing the gate Stats!
            SetTimer("GateClose", 8000, 0);//This will start the counting till the gate will be closed
        }
        else
        {
            SendClientMessage(playerid, COLOR_YELLOW, "You are not close enough to the gate!");
        }
    }
    else
    {
        SendClientMessage(playerid,COLOR_BLUE,"You are not allowed to open this gate, sorry!");
    }
    return 1;
}
Reply
#3

Aha, Thanks a lot Falcon + rep on you


But the code you provided, it makes noone able to open the gate

EDIT: Discovered the error, the name should be [Mw]driftking, not [Mw]drifking xD
Reply
#4

Sorry about my double-post, but i found out that i wanted to use multiple, specific names to be able to open that gate.

If i want Spunky, Airplanesimen and FunKy to be able to open it too, what is needed?
Reply
#5

Quote:
Originally Posted by airplanesimen
Посмотреть сообщение
Sorry about my double-post, but i found out that i wanted to use multiple, specific names to be able to open that gate.

If i want Spunky, Airplanesimen and FunKy to be able to open it too, what is needed?
Just change the line to

pawn Код:
if( !strcmp( name, "[Mw]drifking" ) ||  !strcmp( name, "Other_Name" ) ||  !strcmp( name, "Other_name" ) )
Reply
#6

Perfect again

Thanks for showin' me this, i really appreciate it alot!

Have a nice day!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)