[Tutorial] Making Simple Factions [No MySQL]
#1

This is my first tutorial, please leave feedback in the comments and let me know if I should do some more!

I was looking through the forums today and realized, their are no good filterscripts/tutorials out there for factions. So I thought I would share my way. It's simple and without MySQL. So lets start by defining factions itself.

Your right where I was. I knew how to do some stuff, but factions really stumped me. I wouldn't go into creating factions unless you have a general idea of how to make a roleplay server and general idea of some PAWN code. Such as adding mapping, vehicles, etc. And make sure you understand everything! If you don't, leave me a comment and I will explain it as best as I can.

You will need these two includes for the tutorial.

Code:
#include <zcmd>
Code:
#include <sscanf2>
- Making the Factions -
This is the most important code. Place it at the top of your script, but under #include <a_samp>.

Code:
new Faction[MAX_PLAYERS];
This, well is pretty self explanatory. It defines how many factions you can have. Keeping it on a high number until defining all your factions may be key to not going over the limit and being confused if you get errors from it.

Code:
#define MAX_FACTIONS            100
Now it is time to start to define the actual factions themselves. This is easy to do. Lets say your server will be based mainly in San Fierro. Lets define the SFPD (San Fierro Police Department) But first, you need to define factionless, like jobless.

Code:
#define FACTIONLESS             0
#define SFPD                    1
Wow! Now you have successfully created factions! Not as hard as it seems is it? What's that? I'm missing something? Oh yeah! An invite command.

- Making faction related commands -
Let's start to make the command in which you must be in the faction to do. It's a simple code. But first you want a command to invite someone, right? Well here goes.

Code:
#define COLOR_LIGHTBLUE    0x0BBF6AA
This just defines the colour I use for the command

Code:
CMD:invite(playerid, params[])
{
    new targetid; // Let's you invite other people or yourself, but using your/their player ID
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /invite [id]"); // Prevents you from not using and ID, and if you do it gives you the correct syntax. 
    if(Faction[playerid] != 0) return SendClientMessage(playerid, COLOR_WHITE, "They are already in a faction, tehy can't join another one!"); // Get's the player's current faction, if it doesn't equal factionless, it won't let him join.
    SendClientMessage(targetid,COLOR_LIGHTBLUE,"You joined the SFPD!"); // Sends them a message saying they joined the SFPD
    Faction[targetid] = 1; // Set's their faction to 1 (SFPD)
    return 1;
}
Now, I don't want to do everything for you, so let me just explain how to make a command that you have to be in that faction to use.

Code:
CMD:command(playerid, params[])
{
    if(Faction[playerid] != 1) // This grabs your current faction, and if it isn't 1 (SFPD) you can't complete the command
        return SendClientMessage(playerid, 0xAFAFAFAA, "You are not in the SFPD!"); // Just sends you a message if you are not able to do the command
 
    // Your code goes here
    return 1;
}
Now, lets create a command to quit and kick someone from the faction.

Code:
CMD:quitfaction(playerid, params[])
{
    Faction[playerid] = 0; // Sets your faction to zero (Factionless)
	SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have successfully left your faction!"); // Sends a message saying you left your faction.
    return 1;
}
Code:
CMD:fkick(playerid, params[])
{
    new targetid; // Making it so you must use an ID in the syntax.
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /invitesastno [id]"); // Makes sure you  use the correct syntax, and if not gives you the correct one.
    if(Faction[playerid] != 0) return SendClientMessage(playerid, COLOR_WHITE, "They are not in the faction!");
    SendClientMessage(targetid,COLOR_LIGHTBLUE,"You were kicked out of the SFPD!"); // Sends a message
    Faction[targetid] = 0; // Sets their faction to 0 (Factionless)
    return 1;
}
There you go, that should be all you need to know to get your factions system in order.

The one that everyone has trouble with is creating the faction only vehicles. It's simple, but you need to have some faction knowledge to do it.

- Making Faction only Vehicles -


Let's make some global variables for the SFPD cruisers.

Code:
new SFPDC1; // San Fierro Police Department Cruiser 1
new SFPDC2; // Cruiser 2
new SFPDC3; // Cruiser 3, you get it.
new SFPDC4;
new SFPDC5;
new SFPDC6;
new SFPDC7;
new SFPDC8;
new SFPDC9;
new SFPDC10;
Now, lets set up the AddStaticVehicles for all of them. PLEASE DO NOT JUST COPY AND PASTE THESE VEHICLES. PLEASE USE YOUR OWN.

Code:
    SFPDC1 = AddStaticVehicle(597,-1572.6292,742.7545,-5.4790,91.7643,7,1); // C1
    SFPDC2 = AddStaticVehicle(597,-1572.7528,738.7632,-5.4615,89.8709,7,1); // C2
    SFPDC3 = AddStaticVehicle(597,-1572.7487,734.5782,-5.4615,88.6800,7,1); // C3
    SFPDC4 = AddStaticVehicle(597,-1572.5511,730.5493,-5.5274,89.4020,7,1); // C4
    SFPDC5 = AddStaticVehicle(597,-1572.5724,726.5173,-5.5282,89.7500,7,1); // C5
    SFPDC6 = AddStaticVehicle(597,-1572.6974,722.2393,-5.5282,90.0970,7,1); // C6
    SFPDC7 = AddStaticVehicle(597,-1572.4772,718.1763,-5.4672,90.2899,7,1); // C7
    SFPDC8 = AddStaticVehicle(597,-1572.5442,714.1923,-5.4672,89.7497,7,1); // C8
    SFPDC9 = AddStaticVehicle(597,-1572.5334,710.1553,-5.4674,91.2917,7,1); // C9
    SFPDC10 = AddStaticVehicle(597,-1572.5072,706.0652,-5.4672,90.6109,7,1); // C10
This one needs some extra explaining. SFPDC1 = AddStaticVehicle just basically uses the definition from the above code to define the vehicles.

For the next part you COULD use the OnPlayerEnterVehicle public, but that isn't effective. Because people could use ****** (SA:MP "hacking" program) to get into your vehicles. You should use OnPlayerUpdate for this.

Code:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInVehicle(playerid, SFPDC1)) // Grabs the vehicle ID
    {
        if(Faction[playerid] != 1) // Grabs their faction
            return RemovePlayerFromVehicle(playerid); // If it isn't 1 (SFPD) it removes you from the vehicle
    }
You can write the code using if(IsPlayerInVehicle(playerid, [VehicleID]).

The End
Thank you for using my tutorial. I saw it would be the only simple one out there and went for it. If I helped you, please leave feedback by commenting below. Also, if you really appreciate it, please REP me. Other than that, I wish you the best of luck with your gamemode, and let me know if you want me to make more tutorials. Because I will!
Reply
#2

This looks nice for a first release, but I noticed that the player doesn't have to accept.. Allows for massrecruit, eh? +Repped
Reply
#3

It's nice. Good job I suppose.
Reply
#4

Is better employ PAWN code for the people understand - It's cool the topic. + REP
Reply
#5

Great work
Reply
#6

You forgot the part where you need to include

#include <zcmd> and #include <sscanf2>
Reply
#7

Quote:
Originally Posted by [MM]18240[FMB]
View Post
This looks nice for a first release, but I noticed that the player doesn't have to accept.. Allows for massrecruit, eh? +Repped
Yeah, it is just for people who are kind of stumped like I was on how to create them. But, other than that it is a great start. I will start working on that later as I am not the best scripter for the job hehe.

Quote:
Originally Posted by FaceTutorialz
View Post
You forgot the part where you need to include

#include <zcmd> and #include <sscanf2>
This isn't a filterscript, but I'll add it anyways.
Reply
#8

Quote:
Originally Posted by BornHuman
View Post
Yeah, it is just for people who are kind of stumped like I was on how to create them. But, other than that it is a great start. I will start working on that later as I am not the best scripter for the job hehe.



This isn't a filterscript, but I'll add it anyways.
But they'll still need if, filterscript or not, but not a bad start.
Reply
#9

Why SFPDC1 2 3 ...

new SFPDC[11];

SFPDC[1] = AddStaticVehicle(597,-1572.6292,742.7545,-5.4790,91.7643,7,1); // C1
PHP Code:
    SFPDC[2]= AddStaticVehicle(597,-1572.7528,738.7632,-5.4615,89.8709,7,1); // C2
    
SFPDC[3]= AddStaticVehicle(597,-1572.7487,734.5782,-5.4615,88.6800,7,1); // C3
    
SFPDC[4]= AddStaticVehicle(597,-1572.5511,730.5493,-5.5274,89.4020,7,1); // C4
    
SFPDC[5]= AddStaticVehicle(597,-1572.5724,726.5173,-5.5282,89.7500,7,1); // C5
    
SFPDC[6]= AddStaticVehicle(597,-1572.6974,722.2393,-5.5282,90.0970,7,1); // C6
    
SFPDC[7]= AddStaticVehicle(597,-1572.4772,718.1763,-5.4672,90.2899,7,1); // C7
    
SFPDC[8]= AddStaticVehicle(597,-1572.5442,714.1923,-5.4672,89.7497,7,1); // C8
    
SFPDC[9]= AddStaticVehicle(597,-1572.5334,710.1553,-5.4674,91.2917,7,1); // C9
    
SFPDC[10]= AddStaticVehicle(597,-1572.5072,706.0652,-5.4672,90.6109,7,1); // C10 
Reply
#10

Quote:
Originally Posted by SaTla
View Post
Why SFPDC1 2 3 ...

new SFPDC[11];

SFPDC[1] = AddStaticVehicle(597,-1572.6292,742.7545,-5.4790,91.7643,7,1); // C1
PHP Code:
    SFPDC[2]= AddStaticVehicle(597,-1572.7528,738.7632,-5.4615,89.8709,7,1); // C2
    
SFPDC[3]= AddStaticVehicle(597,-1572.7487,734.5782,-5.4615,88.6800,7,1); // C3
    
SFPDC[4]= AddStaticVehicle(597,-1572.5511,730.5493,-5.5274,89.4020,7,1); // C4
    
SFPDC[5]= AddStaticVehicle(597,-1572.5724,726.5173,-5.5282,89.7500,7,1); // C5
    
SFPDC[6]= AddStaticVehicle(597,-1572.6974,722.2393,-5.5282,90.0970,7,1); // C6
    
SFPDC[7]= AddStaticVehicle(597,-1572.4772,718.1763,-5.4672,90.2899,7,1); // C7
    
SFPDC[8]= AddStaticVehicle(597,-1572.5442,714.1923,-5.4672,89.7497,7,1); // C8
    
SFPDC[9]= AddStaticVehicle(597,-1572.5334,710.1553,-5.4674,91.2917,7,1); // C9
    
SFPDC[10]= AddStaticVehicle(597,-1572.5072,706.0652,-5.4672,90.6109,7,1); // C10 
Because that is just how I designed it. You're free to change it if you will but mine is a working system, may not be the "best" out there but it is still a working system. If you don't like the way it looks or is done you are free to change it to whatever you wish.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)