Making a command work with a key.
#3

Now, the command performs to the closest player (No need to type the ID)
pawn Код:
CMD:infect(playerid,params[])
{
    if(gTeam[playerid] == TEAM_ZOMBIES)
    {
        new string[128];
        new targetid = GetClosestPlayer(playerid);
        new pName[MAX_PLAYER_NAME];
        new tName[MAX_PLAYER_NAME];
        if(!IsPlayerConnected(targetid)) return NOACCESS
        GetPlayerName(playerid,pName,sizeof(pName));
        GetPlayerName(targetid,tName,sizeof(tName));

        if(GetDistanceBetweenPlayers(playerid,targetid) < 4)
        {
            format(string,sizeof(string),"{FFA500}*%s has infected %s and now he's a zombie",pName,tName);
            SendClientMessageToAll(COLOR_WHITE,string);
            gTeam[targetid] = TEAM_ZOMBIES;
            SetPlayerColor(targetid,COLOR_ORANGE);
            SetPlayerPos(targetid,-273.5326,1152.8778,20.7803);
            SetPlayerHealth(targetid,100.0);
         }
    }
    else xSCM"{FFA500}*{EEEEEE}You're not a zombie!");
    return 1;
}
You need this stock to get the closest player: (Put it at the bottom of your script)
pawn Код:
stock GetClosestPlayer(playerid)
{
    new Float:cdist, targetid = -1;
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i) && GetPlayerState(i) != PLAYER_STATE_SPECTATING && playerid != i && (targetid < 0 || cdist > GetDistanceBetweenPlayers(playerid, i)))
        {
            targetid = i;
            cdist = GetDistanceBetweenPlayers(playerid, i);
        }
    }
    return targetid;
}

For the key thing, use OnPlayerKeyStateChange.
Reply


Messages In This Thread
Making a command work with a key. - by Johnson_Brooks - 16.06.2014, 22:36
Respuesta: Making a command work with a key. - by Zume - 16.06.2014, 23:38
Re: Making a command work with a key. - by iFiras - 17.06.2014, 00:07
Re: Making a command work with a key. - by Jefff - 17.06.2014, 00:22
Re: Making a command work with a key. - by Threshold - 17.06.2014, 01:34
Re: Making a command work with a key. - by Johnson_Brooks - 17.06.2014, 22:29
Re: Making a command work with a key. - by Jefff - 17.06.2014, 22:38
Re: Making a command work with a key. - by Johnson_Brooks - 17.06.2014, 22:55
Re : Making a command work with a key. - by Chipardeur - 17.06.2014, 23:00

Forum Jump:


Users browsing this thread: 1 Guest(s)