SA-MP Forums Archive
strcmp name, if false, how to return? - 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: strcmp name, if false, how to return? (/showthread.php?tid=369466)



strcmp name, if false, how to return? - denNorske - 17.08.2012

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


Re: strcmp name, if false, how to return? - FalconX - 17.08.2012

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;
}



Re: strcmp name, if false, how to return? - denNorske - 17.08.2012

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


Re: strcmp name, if false, how to return? - denNorske - 17.08.2012

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?


Re: strcmp name, if false, how to return? - FalconX - 17.08.2012

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" ) )



Re: strcmp name, if false, how to return? - denNorske - 17.08.2012

Perfect again

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

Have a nice day!