ZCMD Help
#1

Hey,

So Im trying to make a command that gets a players name and if its correct opens the gate, If not it dosent and sends a message.

pawn Код:
COMMAND:open(playerid,params)
{
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
if(strfind(playername, "<Name>", true) != return SendClientMessage(playerid,COLOR_YELLOW,"[INFO]: UnAuthorised Access Attempt! The Admins Have been alerted!");
{
MoveDynamicObject(BradGate,1007.96484375,2425.19531250,12.37271976,5);
}
return 1;
}
1 Error:

pawn Код:
D:\Users\Bradley_MS1\Desktop\**** ***\gamemodes\****.pwn(2137) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Reply
#2

pawn Код:
COMMAND:open(playerid,params)
{
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    if(strfind(playername, "<Name>", true) == -1 ) return SendClientMessage(playerid,COLOR_YELLOW,"[INFO]: UnAuthorised Access Attempt! The Admins Have been alerted!");
    {
        MoveDynamicObject(BradGate,1007.96484375,2425.19531250,12.37271976,5);
    }
    return 1;
}
Reply
#3

pawn Код:
COMMAND:open(playerid,params)
{
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    if(!strcmp(playername, "<Name>", true))return SendClientMessage(playerid,COLOR_YELLOW,"[INFO]: UnAuthorised Access Attempt! The Admins Have been alerted!");
    {
        MoveDynamicObject(BradGate,1007.96484375,2425.19531250,12.37271976,5);
    }
    return 1;
}
!= was in the wrong place and you should be using strcmp for names.
Reply
#4

Quote:
Originally Posted by iggy1
Посмотреть сообщение
pawn Код:
COMMAND:open(playerid,params)
{
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    if(!strcmp(playername, "<Name>", true))return SendClientMessage(playerid,COLOR_YELLOW,"[INFO]: UnAuthorised Access Attempt! The Admins Have been alerted!");
    {
        MoveDynamicObject(BradGate,1007.96484375,2425.19531250,12.37271976,5);
    }
    return 1;
}
!= was in the wrong place and you should be using strcmp for names.
True, unless you want like.. everyone with a clan tag in their name to be able to open it or something.
Reply
#5

Quote:
Originally Posted by iggy1
Посмотреть сообщение
pawn Код:
COMMAND:open(playerid,params)
{
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    if(!strcmp(playername, "<Name>", true))return SendClientMessage(playerid,COLOR_YELLOW,"[INFO]: UnAuthorised Access Attempt! The Admins Have been alerted!");
    {
        MoveDynamicObject(BradGate,1007.96484375,2425.19531250,12.37271976,5);
    }
    return 1;
}
!= was in the wrong place and you should be using strcmp for names.
Seems to be one small Issue, That name isnt allowed to open the Gate, But everyother name is. Its ment to be so only that name can open the gate.
Reply
#6

I suggest you use strcmp, over strfind.

It's quite easier.
pawn Код:
new pName[24];
GetPlayerName(playerid, pName, 24);
if(!strcmp(pName, "<Name>", true)) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You are not authorized to do this command!");
{
     //This means their name is correct and matching the specified name.
}
return 1;
Edit:

If you look at iggy's code it has the full command.
Reply
#7

Quote:
Originally Posted by The Toni
Посмотреть сообщение
I suggest you use strcmp, over strfind.

It's quite easier.
pawn Код:
new pName[24];
GetPlayerName(playerid, pName, 24);
if(!strcmp(pName, "<Name>", true)) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You are not authorized to do this command!");
{
     //This means their name is correct and matching the specified name.
}
return 1;
Edit:

If you look at iggy's code it has the full command.
I have, But if Im Named "Billy_Macan" and I do /open I get the not authorised message. If I'm "Bilyl_Macan3" It opens the Gate.
Reply
#8

well strcmp compares strings, if it can't compare them then it's a match and if it can then there's a difference between them so this code is checking if the name equals <name>
pawn Код:
if(!strcmp(playername, "<Name>", true))
Reply
#9

Quote:
Originally Posted by cessil
Посмотреть сообщение
well strcmp compares strings, if it can't compare them then it's a match and if it can then there's a difference between them so this code is checking if the name equals <name>
pawn Код:
if(!strcmp(playername, "<Name>", true))
Which it does but is still not letting me open the Gate as Billy_Macan, Yet it allows Tom or Fred or Billy_Macan3 to
Reply
#10

replace the "!strcmp" with "0 != strcmp"
Reply
#11

I'm guessing you changed <name> to Billy_Macan, and like I said it's checking if they are a match, if you want the opposite use
pawn Код:
if(strcmp(playername, "<Name>", true))
Reply
#12

This is why I hate strcmp, but it's useful at times.

strcmp returns a false value if it's matching I think, I can't remember exactly if it's this way or the other way.

If you do what cessil said, it should work.
Reply
#13

Quote:
Originally Posted by The Toni
Посмотреть сообщение
This is why I hate strcmp, but it's useful at times.

strcmp returns a false value if it's matching I think, I can't remember exactly if it's this way or the other way.

If you do what cessil said, it should work.
Returns
-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).

Quote:
Originally Posted by cessil
Посмотреть сообщение
I'm guessing you changed <name> to Billy_Macan, and like I said it's checking if they are a match, if you want the opposite use
pawn Код:
if(strcmp(playername, "<Name>", true))
That's why I recommended 0 != strcmp, instead of just removing the !
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)