Factions
#1

Right, so it would be maybe like this;
Код:
#define RANK_PRIVATE 0
#define RANK_PrivateFirstClass 1
#define RANK_Specialist 2
#define RANK_Corporal 3
#define RANK_Sergeant 4
#define RANK_StaffSergeant 5
#define RANK_SergeantFirstClass 6
#define RANK_MasterSergeant 7
#define RANK_FirstSergeant 8
#define RANK_SergeantMajor 9
#define RANK_CommandSergeant 10
#define RANK_SecondLieutenant 11
#define RANK_FirstLieutenant 12
#define RANK_Captain 13
#define RANK_Major 14
#define RANK_LieutenantColonel 15
#define RANK_Colonel 16
#define RANK_BrigadierGeneral 17
#define RANK_MajorGeneral 18
#define RANK_LieutenantGeneral 19
#define RANK_General 20
#define RANK_Commander 21
how do I make so with the command I can set ranks to people and only SWAT commander can do it;
For example:
Private rank gets:
swat skin(285 ID)
mp5(29)
and a deagle(24)
Reply
#2

Hi,

You need A LOT more coding than just defines as you can't just define something and expect it to do what you want you must have the commands, the enums, the stocks and callbacks, not just the defines. To help you we need more code.
Reply
#3

Quote:
Originally Posted by Aleksabre
Посмотреть сообщение
Right, so it would be maybe like this;
Код:
#define RANK_PRIVATE 0
#define RANK_PrivateFirstClass 1
#define RANK_Specialist 2
#define RANK_Corporal 3
#define RANK_Sergeant 4
#define RANK_StaffSergeant 5
#define RANK_SergeantFirstClass 6
#define RANK_MasterSergeant 7
#define RANK_FirstSergeant 8
#define RANK_SergeantMajor 9
#define RANK_CommandSergeant 10
#define RANK_SecondLieutenant 11
#define RANK_FirstLieutenant 12
#define RANK_Captain 13
#define RANK_Major 14
#define RANK_LieutenantColonel 15
#define RANK_Colonel 16
#define RANK_BrigadierGeneral 17
#define RANK_MajorGeneral 18
#define RANK_LieutenantGeneral 19
#define RANK_General 20
#define RANK_Commander 21
how do I make so with the command I can set ranks to people and only SWAT commander can do it;
For example:
Private rank gets:
swat skin(285 ID)
mp5(29)
and a deagle(24)
Hello there.

Well, writing such command is quite easy. But let's start from Adam and Eve, because your question is kinda complex. Anyway.

Step 1

First at all, You'll have to make an variable which will determine each player's rank. For example:
pawn Код:
new playerRank[ MAX_PLAYERS ];
.. or, if You have an enumerator, to make Your common variables more organised just go with this one:
pawn Код:
// this is just example of how it could look like
enum PlayerInfo {
// .. some code here..
Rank
// .. some more code here..
} new Player[ MAX_PLAYERS ][ PlayerInfo ]
Now, as You could guess, You've access to manipulate rank of certain player, by using either playerRank[] or Player[][Rank] (depends on how You'd like to store this information, in enum or simple variable).

I believe that You'll somehow store player's rank, and it will be assigned to player after login or something like that. It is a good habit to have all your variables initialized to avoid some funny things.. ^^

Therefore, before we'll go any further, let's assign player rank to 0 (no rank?)

pawn Код:
public OnPlayerConnect(playerid) {
    Player[ playerid ][ Rank ] = 0;
    // or
    playerRank[ playerid ] = 0;
}
Still with me? Okay.

Step 2
Now let's focus on this command. Well, it's pretty easy, thus this step will be short.
We've defined already variable which holds player's rank. Manipulating it with command is actually pretty simple.
Let's have command named setrank with two parameters: PlayerId and RankNumber. I assume that You know zcmd and sscanf, because we'll use it right here.
pawn Код:
COMMAND:setrank(playerid, params[]) {
    new PlayerId, RankNumber;
    if( sscanf( params, "ud", PlayerId, RankNumber ) ) {
        SendClientMessage(playerid, -1, "Usage: /setrank [PlayerId/PartOfName] [Rank]");
    }
    Player[ PlayerId ][ Rank ] = RankNumber;
    // or
    playerRank[ PlayerId ] = RankNumber;
   
    return true;
}
Pretty simple, huh?

Now, You wanted only SWAT commander to be able to issue this command. How? Like in step 1, define some variable which will determine whether certain player is SWAT commander or not.
Now Your command could look something like this:
pawn Код:
COMMAND:setrank(playerid, params[]) {
    if( !Player[ playerid ][ isSwatCommander ] ) {
        SendClientMessage( playerid, -1, "Only SWAT commander can issue this command, sorry.");
        return true;
    }
    new PlayerId, RankNumber;
    if( sscanf( params, "ud", PlayerId, RankNumber ) ) {
        SendClientMessage( playerid, -1, "Usage: /setrank [PlayerId/PartOfName] [Rank]" );
    }
    Player[ PlayerId ][ Rank ] = RankNumber;
    // or
    playerRank[ PlayerId ] = RankNumber;
   
    return true;
}
You can also make this function more dumb-safe, to determine whether:
  1. PlayerId is integer, is unsigned (>=0), is less than MAX_PLAYERS
  2. PlayerId is connected to the server
  3. RankNumber is among ranks bounds (so if highest rank is 50 You cannot go over it)
  4. and whatever can You imagine
That should be it. Now, the last thing in question.

Step 3
Quote:

Private rank gets:
swat skin(285 ID)
mp5(29)
and a deagle(24)

Well, it's simple mechanism, so let's go straight with code.
pawn Код:
public OnPlayerSpawn( playerid ) {
    switch( Player[ playerid ][ Rank ] ) {
        case RANK_PRIVATE : {
            SetPlayerSkin(...)
            GivePlayerWeapon(...)
            WhateverYouDesire(...)
        }
        case RANK_PrivateFirstClass : {
            Like above..
        }
       
        ...
       
        default :
        {
            No case did not fulfill
        }
    }
}
That's pretty much everything You need to know. As always: I can help You with Your code, but I won't write it from scratch. If you have any more questions - feel free to ask.

Happy coding c:

Greetings,
LetsOWN
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)