CMD problem
#7

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; // To send a client message for him to tell that the player accepted his invite
new gotinvited; // The name is pretty obvious
// 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
            finvited[targetid] = 1;
            fnumber[targetid] = 1;
            finviter = playerid;
            gotinvited = targetid;
        }
        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] = 1;
            fnumber[targetid] = 2;
            finviter = playerid;
            gotinvited = targetid;
        }
        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] = 1;
            fnumber[targetid] = 3;
            finviter = playerid;
            gotinvited = targetid;
        }
        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] = 1;
            fnumber[targetid] = 4;
            finviter = playerid;
            gotinvited = targetid;
        }
     }
    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(finvited[playerid] == 1) // Got a better idea
    {
        GetPlayerName(finviter, name, sizeof(name));
        GetPlayerName(gotinvited, name1, sizeof(name1));
        PlayerInfo[playerid][Faction] = fnumber;
        format(string, sizeof(string), "You have accepted %s invitation to join faction number %d.", name, fnumber);
        SendClientMessage(playerid, -1, string);
        format(string, sizeof(string), "%s has accepted your invitation to join your faction.", name2);
        SendClientMessage(finviter, -1, string);
        finvited[playerid] = 0;
    }
    return 1;
}
Re-wrote some stuff... Hope no other bugs happen.
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: 1 Guest(s)