[Tutorial] How create a Faction/Organization System on SA-MP !
#1

Introduction:


- Hello, I will show you today, how to make a simple Factions/Organization System on SA-MP !

- First, you need to have 2 includes, in your includes folder. That includes are:


- ZCMD ;
- SSCANF ;

- ZCMD - it's a command processor, wich we can mode commands more faster. [P.S: Thanks to Zeex for this command proccesor !]

- SSCANF - it's a command processor too, but in this tutorial we will use it to create "Correct Usage" In-Game. [P.S: Thanks to ****** for this SSCANF include and plugin !]



Let's start:



- After downloaded includes, and put them into includes folder [If you didn't have them], we can start scripting. First of all, we need to add includes. So at the top of script, we'll add them:

pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf>
- Now, we will choose our factions/organization type. I will choose SA-MP News Reporter [You can choose what faction/organization do you want]. Reporters - They make announce for all players about robs, weather. To start scripting, we need to define them, so we add enums. I will choose PlayerInfo enum.

pawn Код:
enum pInfo // This it's our enum !
{ // Open bracket !
   LeaderReporter, // This it's the leader of reporter. We'll use it when we will make command "/setleader"
   MemberReporter, // This it's Reporter Member. We'll use it when Leader will use /invite command !
   NONE // NONE = He doesn't have any faction. When he get kicked from one !
} // Closing bracket

new PlayerInfo[MAX_PLAYERS][pInfo]; // Define the PlayerInfo

- We added includes, and defines enums. Now we can start real scripting. But with what we start? Let's make first a command "/SetReporter" . What's this? This it's command wich an Administrator RCON can make a player leader to specified faction. We scroll down, down, and we'll add under last public:

pawn Код:
CMD:setreporter(playerid, params[])
{
    new Level; // This it's variable for Level. If Level = 0, then he isn't Leader, if 1 = He it's leader !
    new ID; // This it's variable for that playerid we'll invite to be Faction Leader !
    if(IsPlayerAdmin(playerid)) // We check if he it's RCON !
    { // Open bracket !
        if(sscanf(params,"ui", ID, Level)) return SendClientMessage(playerid,-1,"{FF0000}USAGE: {15FF00}/SetReporter [ID] [0-1] "); // He will saw Usage 1
        PlayerInfo[ID][LeaderReporter] = Level; // Will set Leader to that playerid
        SendClientMessage(playerid, -1, "{FFCC33}* Information: {FFFFFF}You received leader to {0066CC}Reporter's Faction !"); // He will saw this message, change it, if you don't like !
    } // Close bracket !
    else // Else, if he doesn't have RCON Admin !
    { // Open bracket !
        SendClientMessage(playerid, -1, "{15FF00}EROR: {FF0000}You aren't RCON!"); // He will saw this message !
    } // Close bracket !
    return 1; // Returns 1 to value !
} // Close bracket !
- Ok... we finished "/SetReporter" command. And now that player it's leader. What a faction need? To have players? But how... Let's make an /Invite command for Leaders, to allow them invite specified players in them faction !

pawn Код:
CMD:invite(playerid, params[])
{ // Open bracket !
    if(PlayerInfo[LeaderReporter] >= 1) // If he it's reporter !
    { // Open bracket !
        new ID; // This it's variable for ID, wich leaders invite them to them faction !
        if(sscanf(params,"i", ID)) return SendClientMessage(playerid,-1,"{FF0000}USAGE: {15FF00}/Invite [ID]"); // He will saw usage !
        PlayerInfo[ID][Reporter] = 1; // Will sets Reporter to him !
        SendClientMessage(playerid, -1, "(( {FFCC33}Inforamation: {15FF00}You added specified player in your faction ! {FFFFFF}))"); // This will saw leader !
        SendClientMessage(ID, -1, "(( {FFCC33}Information: {15FF00}You entered in Reporter's faction ! {FFFFFF))"); // This will saw the player !
    } // Close bracket !
    else // Else, if he isn't Reporters's Leader !
    { // Open bracket !
        SendClientMessage(playerid, -1, "{15FF00}ERROR: {FF0000}You aren't Reporter's Leader !"); // He will saw this message !
    } // Close Bracket !
    return 1; // Returns the value !
} // Close last bracket !
- We made and "/Invite" command for Leaders.. But if Leaders doesn't like a player. What gonna do ? Will kick it from faction? But how? So... let's make a /FactionKick command, wich allows leaders to kicks players to them factions and become NONE, or Civilians !

pawn Код:
CMD:factionkick(playerid, params[])
{ // Open Bracket !
    if(PlayerInfo[LeaderReporter] >= 1) // Check if it's Reporter's Leader !
    { // Open bracket !
        new ID; // Variable for ID, wich leaders will kick him from faction !
        if(sscanf(params,"i", ID)) return SendClientMessage(playerid,-1,"{FF0000}USAGE: {15FF00}/FactionKick [ID]"); // He will saw usage !
        PlayerInfo[ID][None] = 1; // He got NONE faction, or he become civilian !
        SendClientMessage(playerid, -1, "(( {FFCC33}Information: {15FF00}You kicked specified player from faction ! {FFFFFF}))"); // Leaders will saw this message !
        SendClientMessage(ID, -1, "(( {FFCC33}Information: {15FF00}You got kicked from Reporter's faction! {FFFFFF))"); // Player who got kicked from faction will saw this !
    } // Close bracket !
    else // Else, if he isn't Reporter Leader !
    {
        SendClientMessage(playerid, -1, "{15FF00}ERROR: {FF0000}You aren't Reporter Leader !"); // He will see this message !
    } // Close bracket !
    return 1; // Returns the value !
} // Close last bracket !
- Good, we finished this command too.. But.. what make a reporter? He makes announces.. But how..? So let's make an announce command for reporters !

pawn Код:
CMD:ann(playerid, params[])
{ // Open bracket !
    if(PlayerInfo[playerid][MemberReporter] >= 1) // If he's Reporter Member !
    { // Open bracket !
        new string[128]; // New variable for format string !
        if(isnull(params)) return SendClientMessage(playerid,-1,"{FF0000}USAGE: {15FF00}/ANN [Text]");
        new PlayerName[MAX_PLAYER_NAME+1]; // The string to store the name.
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName)); // We get the player name.
        format(string, sizeof(string), "{FF0000}Reporter: {15FF00}%s {FFFF00}: {FFCC33}%s", PlayerName, params); // And this it's the text format !
        SendClientMessageToAll(-1, string); // Will send format to all players !
    } // Close bracket !
    else // Else, if he isn't Member of Reporters !
    { // Open bracket !
        SendClientMessage(playerid, -1, "{15FF00}ERROR: {FF0000}You aren't Reporter Member"); // He will saw this message !
    } // Close bracket !
    return 1; // Returns the value !
} // Close last bracket !
- Finally, we finished our Faction, with commands... You can make too a base for that faction, with personal vehicles !

pawn Код:
#include <a_samp>

new Veh; // Vehicle 1
new Veh2; // Vehicle 2
new Veh3; // Vehicle 3
new Veh4; // Vehicle 4

public OnGameModeInit() // public
{ // Open bracket
    Veh = AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2) // Vehicle 1
    Veh2 = AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2) // Vehicle 2
    Veh3 = AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2) // Vehicle 3
    Veh4 = AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2) // Vehicle 4
    return 1; // Returns value !
} // Close bracket !

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{ // Open bracket !
    if(vehicleid = Veh || Veh2 || Veh3 || Veh4) // If enters only in Veh1, Veh2, Veh3, Veh4
    {
        if(PlayerInfo[playerid][MemberReporter] >= 1) // Checks if he it's Reporter !
        { // Open bracket !
            SendClientMessage(playerid, -1, "Welcome in your faction car !"); // Sends message !
        } // Close bracket !
    } // Close brackets !
    else // If he isn't in that faction !
    { // Open bracket !
        SendClientMessage(playerid, -1, "This car it's only for factions !"); // Sends Message !
        RemovePlayerFromVehicle(playerid); // Remove it from vehicle !
    } // Close bracket !
    return 1; // Retruns the value !
} // Close last bracket !

Last Words:


- So we finished.. if you made all correctlly like me, should work. You can too check some usefull functions, but simples, and you should knew it:

OnPlayerEnterVehicle
AddStaticVehicle

- Hope you understand and I hope I explained well. [P.S: Sorry because code isn't very good optimized, I didn't have more time to write this tutorial . I hope you understand me, you know, school... ]
Reply
#2

Awesome! damn you really release too much things hahaha joking keep it up my friend.
Reply
#3

Good job, It'd be awesome to see a save system for it using MySQL.
Reply
#4

Change this
pawn Код:
if(sscanf(params,"i", ID, Level))
To this
pawn Код:
if(sscanf(params,"ui", ID, Level))
Btw use "u" in sscanf for playerids instead of "i"
Because "i" detects only playerids, but "u" detects player names and ids too
Reply
#5

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Awesome! damn you really release too much things hahaha joking keep it up my friend.
Quote:
Originally Posted by Crowler
Посмотреть сообщение
Good job, It'd be awesome to see a save system for it using MySQL.
Thanks !

Quote:
Originally Posted by DavidBilla
Посмотреть сообщение
Change this
pawn Код:
if(sscanf(params,"i", ID, Level))
To this
pawn Код:
if(sscanf(params,"ui", ID, Level))
Btw use "u" in sscanf for playerids instead of "i"
Because "i" detects only playerids, but "u" detects player names and ids too
Solved.
Reply
#6

Thx so much, this helped me
Reply
#7

Thx, helped to me too.
Reply
#8

pawn Код:
- SSCANF - it's a command processor too
stop making tutorials if you have no idea as to what you're talking about
Reply
#9

sscanf(); reads formatted input from a string.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)