Help with a command!
#1

Alright, I'm working on a small command. When I type /knock a voice appears and asks me if I want drugs or weapons. Now, what I want to implement is that either you say "drugs" or "weapons" normally in the chatbox and if you type drugs you will get a menu with drugs, etc. If you write something else than drugs or weapons the server will say "ERROR: Please type what you want; DRUGS or WEAPONS."

My code sofar:
pawn Код:
CMD:knock(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1852.2755,-1990.1522,13.5469))
    {
        SendClientMessage(playerid, COLOR_PURPLE, "* The door opens slightly.");
        SendClientMessage(playerid, -1, "Andres: Ey' holmes? You need DRUGS or WEAPONS?");
    }
    else if(IsPlayerInRangeOfPoint(playerid, 5.0, 2637.0984,-1991.6788,14.3240))
    {
        SendClientMessage(playerid, COLOR_PURPLE, "* The door opens slightly.");
        SendClientMessage(playerid, -1, "Jamal: A'yo, nigga. Chu' want DRUGS or WEAPONS?");
    } else return SendClientMessage(playerid, COLOR_RED, "[Error]: You need to be at the right door to knock");
    return 1;
}
Reply
#2

use OnPlayerText, so you will be abel to enter "Drugs" or "weapons" as text and detect it that way.
you need to set a variable ofc, so that your code for when the player, for example, types "drugs" doesen't execute everytime. Just when the player typed "/knock" and then "drugs" or "weapons"

could look like:

Код:
new IsKnocking[MAX_PLAYERS];

CMD:knock(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 1852.2755,-1990.1522,13.5469))
    {
        SendClientMessage(playerid, COLOR_PURPLE, "* The door opens slightly.");
        SendClientMessage(playerid, -1, "Andres: Ey' holmes? You need DRUGS or WEAPONS?");
		IsKnocking[playerid]++;
    }
    else if(IsPlayerInRangeOfPoint(playerid, 5.0, 2637.0984,-1991.6788,14.3240))
    {
        SendClientMessage(playerid, COLOR_PURPLE, "* The door opens slightly.");
        SendClientMessage(playerid, -1, "Jamal: A'yo, nigga. Chu' want DRUGS or WEAPONS?");
        IsKnocking[playerid]++;
    } else return SendClientMessage(playerid, COLOR_RED, "[Error]: You need to be at the right door to knock");
    return 1;
}


public OnPlayerText(playerid, text[])
{
	if(IsKnocking[playerid])
	{
	    if(strcmp(text,"drugs"))
	    {
	    //........ your code........
	    }
	    else if(strcmp(text,"weapons"))
	    {
	    //........ your code........
	    }
	    IsKnocking[playerid]--;
	}
	return 1;
}
Reply
#3

I can write whatever and he'll still say "Alright, here's the drugs."

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(IsKnocking[playerid])
    {
        if(strcmp(text,"drugs"))
        {
            SCM(playerid, -1, "Alright, here's the drugs.");
            TogglePlayerControllable(playerid,1);
        }
        else if(strcmp(text,"weapons"))
        {
            SCM(playerid, -1, "Alright, here's the weapons.");
            TogglePlayerControllable(playerid,1);
        }
        IsKnocking[playerid]--;
    }
    return 1;
}
Reply
#4

Add;
pawn Код:
else
{
      SCM(playerid, -1, "You must type either '/knock drugs' or '/knock weapons'.");
}
After the "else if" statement.

Also sorry for bad indention, on mobile.
Reply
#5

It's not working. Whatever I say I still just get "Alright, here's the drugs."

pawn Код:
public OnPlayerText(playerid, text[])
{    
    if(IsKnocking[playerid])
    {
        if(strcmp(text,"drugs"))
        {
            SCM(playerid, -1, "Alright, here's the drugs.");
            TogglePlayerControllable(playerid,1);
        }
        else if(strcmp(text,"weapons"))
        {
            SCM(playerid, -1, "Alright, here's the weapons.");
            TogglePlayerControllable(playerid,1);
        }
        else
{
      SCM(playerid, -1, "You must type either '/knock drugs' or '/knock weapons'.");
}
        IsKnocking[playerid]--;
    }
    return 1;
}
Reply
#6

pawn Код:
public OnPlayerText(playerid, text[])
{    
    if(IsKnocking[playerid])
    {
        if(!strcmp(text, "drugs", true))
        {
            SCM(playerid, -1, "Alright, here's the drugs.");
            TogglePlayerControllable(playerid, 1);
        }
        else if(!strcmp(text, "weapons", true))
        {
            SCM(playerid, -1, "Alright, here's the weapons.");
            TogglePlayerControllable(playerid, 1);
        }
        else SCM(playerid, -1, "You must type either 'drugs' or 'weapons'.");
        IsKnocking[playerid]--;
    }
    return 1;
}
Reply
#7

strcmp
pawn Код:
public OnPlayerText(playerid, text[])
{    
    if(IsKnocking[playerid])
    {
        if(!strcmp(text,"drugs") && strlen(text) > 0)
        {
            SCM(playerid, -1, "Alright, here's the drugs.");
            TogglePlayerControllable(playerid,1);
            IsKnocking[playerid] = 0;
        }
        else if(!strcmp(text,"weapons") && strlen(text) > 0)
        {
            SCM(playerid, -1, "Alright, here's the weapons.");
            TogglePlayerControllable(playerid,1);
            IsKnocking[playerid] = 0;
        }
        else
{
      SCM(playerid, -1, "You must type either '/knock drugs' or '/knock weapons'.");
}
        IsKnocking[playerid] = 0;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)