[Tutorial] Making A Class System(Very Simple+Easy+Dialogs+Texts)
#1

CLASS SYSTEM TUTORIAL

Hi guys!

I am getting lots of queries from users and my friend, how to make a class system, how to make its commands for different classes and they get lots of problems with them. So i m making a tutorial for all those who wants a class system for their server. Lets get started:

First of all, lets me tell you what includes i gonna use, Just add these in the top most section of your pawn or gamemode or filterscript:
pawn Code:
#include < a_samp >
Now lets define some classes, your wish if you want more classes, i have added 6 classes, add this after includes:Note: If you want to add new class then define it with a value(e.g. #define Your class Value/Number)
pawn Code:
#define SOLDIER 1
#define SNIPER 2
#define ENGINEER 3
#define JETTROOPER 4
#define PILOT 5
#define SPY 6
Now when you have added these, now you have to add the variables which defines several functions:
These variables are usefull for class functioning.

pawn Code:
new gPlayerClass[MAX_PLAYERS];// for defining classes
new PickedClass[MAX_PLAYERS];// this variable can be used in many functions
Now define the colors, there are 5-6 colors offered by me, add these after the below part:
Colours are used to define the class colours, dilogs, lot more. Add more if you want.

pawn Code:
#define COLOR_WHITE 0xFFFFFFFF
#define COL_GREEN          "{6EF83C}"
#define COL_WHITE          "{FFFFFF}"
#define COLOR_RED          0xAA3333AA
#define COLOR_GREEN        0x33AA33AA
Now this is the main function, the dialog part for selecting classes. You can put this dialog in many public functions, like: public OnPlayerRequestSpawn(playerid), public OnPlayerRequestClass(playerid, Classid) or
public OnPlayerConnect(playerid). I had put it in OnPlayerRequestClass(playerid).
Note: This is for Team Death Match Severs. If you have added new class with define then you have to add the class section here also(Put \nYour class name).

pawn Code:
public OnPlayerRequestSpawn(playerid)
{
    ShowPlayerDialog(playerid, 999, DIALOG_STYLE_LIST, "{6EF83C}Choose A Class:", "Soldier Class\nSniper Class\nEngineer Class\nJet-Trooper Class\nPilot Class\nSpy Class", "Choose","");//this is the class dialog, you can change it if you want but dont forget to define the class also
    return 1;
}
Now this is OnPlayerSpawn(playerid) section. Its used here to save your selected class(like if you have selected class soldier and spawned in OnPlayerRequestSpawn, then OnPlayerSpawn it will give you the same weapons and class bonouses that you get OnPlayerRequestSpawn. ).
Note: If you defined and added a new class then add it here also.


pawn Code:
public OnPlayerSpawn(playerid)
{
    if(gPlayerClass[playerid] == SOLDIER)//This is for the First soldier class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 31, 200);//m4
        GivePlayerWeapon(playerid, 25, 100);//mp5
        GivePlayerWeapon(playerid, 24, 70);//deagle
    }
    else if(gPlayerClass[playerid] == SNIPER)//This is for the Second Sniper class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 34, 250);//sniper
        GivePlayerWeapon(playerid, 29, 250);//mp5
        GivePlayerWeapon(playerid, 4, 1);//knife
    }
    else if(gPlayerClass[playerid] == ENGINEER)//This is for the Second Engineer class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 27, 200);//spas12
        GivePlayerWeapon(playerid, 23, 200);//silent pistol
        GivePlayerWeapon(playerid, 35, 2);//rpg
        GivePlayerWeapon(playerid, 16, 2);//grenade
    }
    else if(gPlayerClass[playerid] == JETROOPER)//This is for the Second Jetrooper class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 32, 500);//tec-9
        GivePlayerWeapon(playerid, 22, 500);//colt
        GivePlayerWeapon(playerid, 4, 1);//knife
    }
    else if(gPlayerClass[playerid] == PILOT)//This is for the Second Pilot class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 24, 200);//deagle
        GivePlayerWeapon(playerid, 17, 4);//moltove
        GivePlayerWeapon(playerid, 25, 100);//shotgun
    }
    else if(gPlayerClass[playerid] == SPY)//This is for the Second Spy class.
    {
        TogglePlayerControllable(playerid, 1);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 29, 200);//mp5
        GivePlayerWeapon(playerid, 23, 200);//silent pistol
        GivePlayerWeapon(playerid, 4, 1);//knife
        GivePlayerWeapon(playerid, 18, 2);//moltove
    }
    return 1;
}
Now we can define the classes commands here, There is a command for 2 classes here:
JETTOOPER: theres a command for it i.e. /jetpack through which we can spawn a jet pack if we are jet trooper class.
SPY: theres 4 commands for spy i.e. /dis: used to see the disguize feature kit, /team<1-3> : this is used to disguize to a specific team by which or skin and colour gets changed but we remains the same team.

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/jetpack", true))//jetpack spawn command
        {
       
        if(gPlayerClass[playerid] == JETTROOPER)//if the player is jettrooper
        {
             SetPlayerSpecialAction(playerid,2);//This is command for the jet trooper, he  can spawn jetpack by /jp command
             return 1;
        }
    }
   
    if(!strcmp(cmdtext, "/dis", true))//dialog which tells u about the spy class disguises
        {

        if(gPlayerClass[playerid] == SPY)
        {
             ShowPlayerDialog(playerid, 88, DIALOG_STYLE_MSGBOX, "{6EF83C}Spy Disguise  Kit:", "/team1\n/team2\n/team3", "Disguise ","Exit");//Replace the team1,2,3 to your game teams name and colors, by /team1 or /team2 or / team3 the player gets disguise to enemy soldier but don't changes its team
             return 1;
        }
    }

        if(!strcmp(cmdtext, "/team1", true))//This is for disguise to team 1
        {

        if(gPlayerClass[playerid] == SPY)//if player class spy
        {
             ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Disguised to Team1:", "Team: Team1\nColor: Red\nSkin: 285\nDisguised Class: Soldier", "Ok ","");
             SetPlayerSkin(playerid,285);//skin set to S.W.A.T, can change to ur team skin
             SetPlayerColor(playerid,COLOR_RED)//Color Red
             return 1;
        }
    }
   
    if(!strcmp(cmdtext, "/team2", true))//This is for disguise to team 2
        {

        if(gPlayerClass[playerid] == SPY)//if player class spy
        {
             ShowPlayerDialog(playerid, 22, DIALOG_STYLE_MSGBOX, "{6EF83C}Disguised to Team2:", "Team: Team2\nColor: White\nSkin: 287\nDisguised Class: Soldier", "Ok ","");
             SetPlayerSkin(playerid,287);//skin set to Military, can change to ur team skin
             SetPlayerColor(playerid,COL_WHITE)//Color white
             return 1;
        }
    }
   
    if(!strcmp(cmdtext, "/team3", true))//This is for disguise to team 1
        {

        if(gPlayerClass[playerid] == SPY)//if player class spy
        {
             ShowPlayerDialog(playerid, 33, DIALOG_STYLE_MSGBOX, "{6EF83C}Disguised to Team3:", "Team: Team3\nColor: Green\nSkin: 181\nDisguised Class: Soldier", "Ok ","");
             SetPlayerSkin(playerid,181);//skin set to Rockstar, can change to ur team skin
             SetPlayerColor(playerid,COLOR_GREEN)//Color green
             return 1;
        }
    }
    return 0;
}

Now this step is optional, If you want Score requirement to drive such vehicles then add this:
Its used for vechile entrace, it defines that if you are a specific class then you can drive that vechile which you have mentioned for that class. I mean to say that pilot can drive vehicles like hunter, hydra etc but if you are a soldier then you will be removed from the hunter, hydra, etc.

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);//variable to get vehicle ids
    if(GetVehicleModel(vehicleid) == 425 && gPlayerClass[playerid] == SOLDIER && gPlayerClass[playerid] == SNIPER && gPlayerClass[playerid] == ENGINEER && gPlayerClass[playerid] == JETTROOPER && gPlayerClass[playerid] == SPY)//if player is pilot then he can drive
    {
        SendClientMessage(playerid, COLOR_RED, "You Need to  be a Pilot to fly Hunter");//messages goes to the player that he can't drive the hunter
        RemovePlayerFromVehicle(playerid);//get u off from the hunter
    }

    if(GetVehicleModel(vehicleid) == 425 && gPlayerClass[playerid] == SOLDIER && gPlayerClass[playerid] == SNIPER && gPlayerClass[playerid] == ENGINEER && gPlayerClass[playerid] == JETTROOPER && gPlayerClass[playerid] == SPY)//if player is pilot then he can drive
    {
        SendClientMessage(playerid, COLOR_RED, "You Need to  be a Pilot to fly Hydra");//messages goes to the player that he can't drive the hydra
        RemovePlayerFromVehicle(playerid);//get u off from the hydra
    }

    if(GetVehicleModel(vehicleid) == 425 && gPlayerClass[playerid] == PILOT && gPlayerClass[playerid] == SNIPER && gPlayerClass[playerid] == ENGINEER && gPlayerClass[playerid] == JETTROOPER && gPlayerClass[playerid] == SPY)//if player is Soldier then he can drive
    {
        SendClientMessage(playerid, COLOR_RED, "You Need to  be a Soldier to drive Tank");//messages goes to the player that he can't drive the tank or rhino
        RemovePlayerFromVehicle(playerid);//get u off from the tank or rhino
    }

    if(GetVehicleModel(vehicleid) == 425 && gPlayerClass[playerid] == SOLDIER && gPlayerClass[playerid] == SNIPER && gPlayerClass[playerid] == ENGINEER && gPlayerClass[playerid] == JETTROOPER && gPlayerClass[playerid] == SPY)//if player is pilot then he can drive
    {
        SendClientMessage(playerid, COLOR_RED, "You Need to  be a Pilot to fly Sea Sparrow");/messages goes to the player that he can't drive the tank or sea sparrow
        RemovePlayerFromVehicle(playerid);//get u off from the sea sparrow
    }
}
Now the main feature, about the dialog response, the class system dialog functions, add the in public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{ , heres the code:
Note: if you have defined new class and added to the dialog for class selection, then you have to make it responce, you have to put the functioning of it in a listitem.

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 999)//dialog id response
            {
                if(response)
                    {
                if(listitem == 0)//the listitem0, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Soldier as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Soldier Class:", "{F81414}Abilities:\n{FFFFFF}A Solo class, good in infantry attacks.\n\n{F81414}Weapons:\n\n{FFFFFF}M4\n{FFFFFF}Shotgun\n{FFFFFF}Deagle", "Play","");
                        gPlayerClass[playerid] = SOLDIER;//setting the class to soldier
                        PickedClass[playerid] = 1;
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 31, 200);//m4
                        GivePlayerWeapon(playerid, 25, 100);//mp5
                        GivePlayerWeapon(playerid, 24, 70);//deagle
                        }
                    }

                if(listitem == 1)//the listitem1, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Sniper as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Sniper Class:", "{F81414}Abilities:\n{FFFFFF}A Locater class, Always invisible on map.\n\n{F81414}Weapons:\n\n{FFFFFF}Sniper Rifle\n{FFFFFF}Mp5\n{FFFFFF}Knife", "Play","");
                        gPlayerClass[playerid] = SNIPER;//setting the class to Sniper
                        PickedClass[playerid] = 1;
                        RemovePlayerMapIcon(playerid, 0);
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 34, 250);//sniper
                        GivePlayerWeapon(playerid, 29, 250);//mp5
                        GivePlayerWeapon(playerid, 4, 1);//knife
                        }
                    }

                if(listitem == 2)//the listitem2, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Engineer as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Engineer Class:", "{F81414}Abilities:\n{FFFFFF}A Strong class, Good in both land and air\nCan drive tanks.\n\n{F81414}Weapons:\n\n{FFFFFF}Spas12\n{FFFFFF}Silent Pistol\n{FFFFFF}RPG\n{FFFFFF}Grenade", "Play","");
                        gPlayerClass[playerid] = ENGINEER;//setting the class to engineer
                        PickedClass[playerid] = 1;
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 27, 200);//spas12
                        GivePlayerWeapon(playerid, 23, 200);//silent pistol
                        GivePlayerWeapon(playerid, 35, 2);//rpg
                        GivePlayerWeapon(playerid, 16, 2);//grenade
                        }
                    }
                   
                if(listitem == 3)//the listitem3, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Jetrooper as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Jetrooper Class:", "{F81414}Abilities:\n{FFFFFF}A Solo class, cna spawn jetpack by /jetpack.\n\n{F81414}Weapons:\n\n{FFFFFF}Tec-9\n{FFFFFF}Colt\n{FFFFFF}Knife", "Play","");
                        gPlayerClass[playerid] = JETTROOPER;//setting the class to jettrooper
                        PickedClass[playerid] = 1;
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 32, 500);//tec-9
                        GivePlayerWeapon(playerid, 22, 500);//colt
                        GivePlayerWeapon(playerid, 4, 1);//knife
                        }
                    }

                if(listitem == 4)//the listitem4, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Pilot as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Pilot Class:", "{F81414}Abilities:\n{FFFFFF}A Airforce class, Can drive hunter, hydra & sea sparrow.\n\n{F81414}Weapons:\n\n{FFFFFF}Deagle\n{FFFFFF}Tear Gas\n{FFFFFF}Shotgun", "Play","");
                        gPlayerClass[playerid] = PILOT;//setting the class to pilot
                        PickedClass[playerid] = 1;
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 24, 200);//deagle
                        GivePlayerWeapon(playerid, 17, 4);//moltove
                        GivePlayerWeapon(playerid, 25, 100);//shotgun
                        }
                    }
                   
                if(listitem == 5)//the listitem5, defines the number one option of the dialog
                    {
                    if(GetPlayerScore(playerid) >= 0)//if player have 0 score then  he can choose this class
                        {
                        SendClientMessage(playerid, COLOR_WHITE, "You chose the Spy as your class.");
                        ShowPlayerDialog(playerid, 11, DIALOG_STYLE_MSGBOX, "{6EF83C}Spy Class:", "{F81414}Abilities:\n{FFFFFF}A Victim class, Can Disguise to enemy assaults by /dis\n\n{F81414}Weapons:\n\n{FFFFFF}Mp5\n{FFFFFF}Silent Pistol\n{FFFFFF}Knife\n{FFFFFF}Moltove", "Play","");
                        gPlayerClass[playerid] = SPY;//setting the class to Spy
                        PickedClass[playerid] = 1;
                        SetPlayerVirtualWorld(playerid, 0);
                        TogglePlayerControllable(playerid, 1);
                        ResetPlayerWeapons(playerid);
                        GivePlayerWeapon(playerid, 29, 200);//mp5
                        GivePlayerWeapon(playerid, 23, 200);//silent pistol
                        GivePlayerWeapon(playerid, 4, 1);//knife
                        GivePlayerWeapon(playerid, 18, 2);//moltove
                        }
                }
                return 1;
        }

return 1;
}
return true;
}
You are done now with your class system and congrats, you have a new class system added in your server or gamemode or filterscript.

DOWNLOADS:
Team death match class system: Coming soon (by $$insane)
Roleplay Class System: Coming soon (by $$insane)
Death Match class system: Download Here (by naruto)
Reply


Messages In This Thread
Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 08.05.2012, 15:46
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 08.05.2012, 16:04
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by iOmar - 08.05.2012, 17:02
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 09.05.2012, 08:55
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by JaKe Elite - 09.05.2012, 09:18
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 09.05.2012, 09:28
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by BigETI - 09.05.2012, 11:40
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by iOmar - 09.05.2012, 12:19
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Rudy_ - 09.05.2012, 12:25
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 09.05.2012, 15:07
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by iOmar - 09.05.2012, 17:17
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 10.05.2012, 08:49
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by [ABK]Antonio - 10.05.2012, 09:45
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Slix_ - 10.05.2012, 09:48
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by iOmar - 10.05.2012, 10:21
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 10.05.2012, 13:47
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 14.05.2012, 11:13
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Gangs_Rocks - 19.05.2012, 15:30
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 19.05.2012, 16:08
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by ℓмяαη_кнαη - 19.05.2012, 16:51
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 19.05.2012, 17:12
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 21.05.2012, 09:05
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by [GF]Logic - 23.05.2012, 12:56
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Luis- - 23.05.2012, 14:20
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Coder_ - 04.07.2012, 17:55
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 07.07.2012, 09:33
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 07.07.2012, 14:00
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Lordzy - 07.07.2012, 14:09
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 07.07.2012, 14:13
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Biess - 26.08.2012, 10:47
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by DeadLy™ - 26.08.2012, 17:26
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by JimmyCh - 24.06.2013, 10:43
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Chrisis - 01.07.2013, 07:32
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Mckarlis - 30.07.2013, 22:45
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by qazwsx - 02.08.2013, 09:07
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by qazwsx - 12.08.2013, 04:58
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by usamahifi - 07.02.2015, 18:01
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 09.02.2015, 08:51
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 25.07.2015, 08:42
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Hemeei - 25.07.2015, 09:55
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Snipa - 26.07.2015, 17:12
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by $$inSane - 27.07.2015, 10:09
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Glossy42O - 27.07.2015, 10:18
Re: Making A Class System(Very Simple+Easy+Dialogs+Texts) - by Snipa - 28.07.2015, 01:11

Forum Jump:


Users browsing this thread: 2 Guest(s)