Define and CMD
#1

How can I make for example a little #define that will be based on player name

for example:

#define DrugLeader UnknownName

and cmd

/buydrugs

cmd would be only able to use from a guy that is defined there - his name only?
Reply
#2

I think that is possible with strcmp.
https://sampwiki.blast.hk/wiki/Strcmp


I'm not sure but I think that you will have to add "".
"UnknownName".
Reply
#3

pawn Код:
new pName[MAX_PLAYER_NAME];
new str[32];
GetPlayerName(playerid, pName, sizeof(pName));
if(format(str, sizeof(str), "%s", pName) == DrugLeader)
{
 // function
}
I think this might work, use just use some variable ..
Reply
#4

pawn Код:
#define DD Name
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/abc", cmdtext, true, 10) == 0)
    {
        new pName[MAX_PLAYER_NAME];
        new str[32];
        GetPlayerName(playerid, pName, sizeof(pName));
        if(format(str, sizeof(str), "%s", pName) == DD) // Error line
        {
            // function
            return 1;
        }
        else
        {
            //
            return 1;
        }
        return 1;
    }
    return 0;
}
pawn Код:
error 017: undefined symbol "Name"
Reply
#5

If what your asking is how to make a command that only a drug dealer in your server can use, yes that is possible. You can do it by doing this:

At the top of your script you should see a:
Код:
#endif
Under that text type:
Код:
new gTeam[MAX_PLAYERS];

#define GANG_DRUGDEALER 1 //This is where you define the drug dealer
If its not under the #endif, you will get an error code later on. I don't know why but you just do.

Next you need to make the command:

Код:
if (strcmp("/drugdealer", cmdtext, true, 10) == 0)
	{
	if(gTeam[playerid] == GANG_DRUGDEALER) { // Using this command will check if the player is a drug dealer.
	SendClientMessage(playerid, 0, "You are a drug dealer."); //Type whatever you want to say here.
         //Type your command here for what you want it to do, like giving the player drugs, or whatever.
	return 1; } //Closing the if drug dealer command.
        }
How to set a player as a drugdealer:

//You are going to need something like zcmd to do this, but for the purpose of showing you how to do it, im just going to be showing me doing it to myself using strcmp.

Код:
if (strcmp("/setdrugdealer", cmdtext, true, 10) == 0)
        {
        gTeam[playerid] = GANG_DRUGDEALER; //This sets the players team to drug dealer.
	SendClientMessage(playerid, 0, "You are now a drug dealer."); //Tells the player he is a drug dealer.
	}
If you get any errors, just ask.
Reply
#6

What exactly I want to do is, I want to define player's name for example Player1 and on CMD if name doesn't match with name that was defined on top of script it will send a msg "you are not drug dealer"
Reply
#7

You could use teams or a global variable... Define is really a bad way to do this.
Reply
#8

Here, read this, at the bottom it will show you how to give an error message if they are not a drug dealer.

Link.
Reply
#9

Well thanks for help
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)