CMD problem
#3

pawn Код:
new finvited[MAX_PLAYERS]; // To store the player's ID
new fnumber[MAX_PLAYERS]; // For storing the faction number that he was invited to join
new finviter[MAX_PLAYERS]; // To send a client message for him to tell that the player accepted his invite
// All of the lines above can be placed ontop of the script - not the very top like after the enums.
CMD:finvite(playerid,params[])
{
    new factionid,targetid, targetname[24], playername[24], string[128]; // Why not creating all of the "new"s here? :D
    switch(PlayerInfo[playerid][Faction])
    {
        case 1: // Switch is faster than "if"
        {
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
            if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
            GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
            GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
            format(string, sizeof(string), "You have been invited to %s squad! Use /acceptfaction", targetname);//Formats the message that will be sent to you (the player)
            SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
//              pInfo[targetid][Faction] = 1; Instead of those two lines we will get store some variables for use in other commands
//          pInfo[targetid][Rank] = 1; (I explain better with commands)
            finvited[targetid] = targetid;
            fnumber[targetid] = 1;
        }
        case 2:
        {
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
            if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
            GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
            GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
            format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
            SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
            finvited[targetid] = targetid;
            fnumber[targetid] = 2;
        }
        case 3:
        {
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
            if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
            GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
            GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
            format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
            SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
            finvited[targetid] = targetid;
            fnumber[targetid] = 3;
        }
        case 4:
        {
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
            if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
            if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
            GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
            GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
            format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
            SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
            finvited[targetid] = targetid;
            fnumber[targetid] = 4;
        }
     }
    return 1; //Returns a value
}

CMD:acceptfaction(playerid, params[])
{
    new string[100], name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME]; // you can use this to make sure it's all working well
    if(finvite[playerid] > -1) // Normally in any kind of server the player ids start from 0 - 1 - 2 - 3 -4 so on
    {
        GetPlayerName(finviter, name, sizeof(name));
        GetPlayerName(finvited, name1, sizeof(name1));
        PlayerInfo[playerid][Faction] = fnumber;
        format(string, sizeof(string), "You have accepted %s request to join faction number %d",name, fnumber);
        SendClientMessage(playerid, -1, string);
        format(string, sizeof(string), "%s has accepted your invite to join your faction!", name1);
        SendClientMessage(finviter, -1, string);
    }
    return 1;
}

CMD:fkick(playerid, params[]) //Format to create a command
{ //Open bracket
    new id, string[128];
    if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"Usage: /fkick [playerid]");
    // I moved the sscanf line to above the inner code to be able to compare the targetid's faction and the playerid's faction
    // They are equal, the player gets kicked
    if(pInfo[playerid][Faction] == PlayerInfo[id][Faction] && pInfo[playerid][Rank] == 6)
    {

       SendClientMessage(id,COLOR_RED,"You have been kicked from RAF squad!");
       format(string,sizeof(string),"You have kicked %s(%d) from the squad",GetName(id),id);
       SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
       pInfo[id][Faction] = 0;
       pInfo[id][Rank] = 0;
    }
    else
    {
       SendClientMessage(playerid, -1, "Player is not in you faction!");
       return 1;
    }      
    return 1;
} //Closed
You can try this hope it works out well for you as I did it in a hurry, if you find any bugs just notify me I will gladly fix/edit it.

EDIT: I have placed for you all commands /fkick /finvite /acceptfaction and some explaination inside the code and changed the 'if' statements as 'switch' is faster.
Reply


Messages In This Thread
CMD problem - by DarkLored - 19.02.2014, 20:53
Re: CMD problem - by Golimad - 19.02.2014, 21:39
Re: CMD problem - by MattTucker - 19.02.2014, 21:55
Re: CMD problem - by DarkLored - 19.02.2014, 22:10
Re: CMD problem - by MattTucker - 19.02.2014, 22:16
Re: CMD problem - by DarkLored - 19.02.2014, 22:33
Re: CMD problem - by MattTucker - 19.02.2014, 22:57
Re: CMD problem - by DarkLored - 19.02.2014, 23:13
Re: CMD problem - by MattTucker - 19.02.2014, 23:19
Re: CMD problem - by DarkLored - 19.02.2014, 23:24

Forum Jump:


Users browsing this thread: 2 Guest(s)