SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 09/09/2012, 11:38 AM   #1
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 738
Reputation: 138
Default Creating Custom Class Selection Screen

INTRODUCTION
To get an idea, what we shall be be creating, here is the video : [ame]http://www.youtube.com/watch?v=jTU73Xfhh_Q[/ame]

Custom Class Selection Screen have some advantages, to name few, one may add vehicles, pickups, add custom textdraw.

CODING PART

Before we start coding, we need to create TextDraw's.
I made using Zamaroht's Textdraw Editor

Code :
pawn Code:
new Text:TDClassChooser; //When Player Chooses class [HEADING]
new Text:TDClassChooserBOX; //Box for it
new Text:TDClassChooserAssaulter[MAX_PLAYERS]; //Assaulter Selected
new Text:TDClassChooserSupporter[MAX_PLAYERS];
new Text:TDClassChooserSniper[MAX_PLAYERS];
new Text:TDClassChooserCustom[MAX_PLAYERS];
new Text:TDClassChooserChoosen[MAX_PLAYERS]; //The >  < in class chossing
new Text:TD_HowToSpawn; //Press shift to go up and space to down....

    TDClassChooser = TextDrawCreate(91.000000, 149.000000, "~g~Class ~r~Chooser");
    TextDrawAlignment(TDClassChooser, 2);
    TextDrawBackgroundColor(TDClassChooser, 255);
    TextDrawFont(TDClassChooser, 2);
    TextDrawLetterSize(TDClassChooser, 0.270000, 2.000000);
    TextDrawColor(TDClassChooser, -16776961);
    TextDrawSetOutline(TDClassChooser, 1);
    TextDrawSetProportional(TDClassChooser, 1);
    TextDrawUseBox(TDClassChooser, 1);
    TextDrawBoxColor(TDClassChooser, 255);
    TextDrawTextSize(TDClassChooser, 179.000000, 121.000000);

    TDClassChooserBOX = TextDrawCreate(32.000000, 173.000000, "~n~~n~~n~~n~~n~~n~~n~");
    TextDrawBackgroundColor(TDClassChooserBOX, 255);
    TextDrawFont(TDClassChooserBOX, 1);
    TextDrawLetterSize(TDClassChooserBOX, 0.500000, 1.000000);
    TextDrawColor(TDClassChooserBOX, -1);
    TextDrawSetOutline(TDClassChooserBOX, 0);
    TextDrawSetProportional(TDClassChooserBOX, 1);
    TextDrawSetShadow(TDClassChooserBOX, 1);
    TextDrawUseBox(TDClassChooserBOX, 1);
    TextDrawBoxColor(TDClassChooserBOX, 125);
    TextDrawTextSize(TDClassChooserBOX, 150.000000, 109.000000);

    TD_HowToSpawn                   =TextDrawCreate( 66.000000, 293.000000, "Press ~g~SHIFT ~w~ to go ~g~UP~n~~r~SPACE~w~ to go ~r~DOWN~n~~b~ENTER TO SPAWN");
    TextDrawAlignment           ( TD_HowToSpawn, 2);
    TextDrawBackgroundColor ( TD_HowToSpawn, 255);
    TextDrawFont                ( TD_HowToSpawn, 1);
    TextDrawLetterSize      ( TD_HowToSpawn, 0.300000, 1.300000);
    TextDrawColor               ( TD_HowToSpawn, -1);
    TextDrawSetOutline      ( TD_HowToSpawn, 1);
    TextDrawSetProportional ( TD_HowToSpawn, 1);


    //Under OnPlayerConnect
    TDClassChooserAssaulter[playerid] = TextDrawCreate(55.000000, 174.000000, "~g~Assaulter");
    TextDrawBackgroundColor(TDClassChooserAssaulter[playerid], 255);
    TextDrawFont(TDClassChooserAssaulter[playerid], 2);
    TextDrawLetterSize(TDClassChooserAssaulter[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserAssaulter[playerid], -1);
    TextDrawSetOutline(TDClassChooserAssaulter[playerid], 1);
    TextDrawSetProportional(TDClassChooserAssaulter[playerid], 1);

    TDClassChooserSupporter[playerid] = TextDrawCreate(56.000000, 188.000000, "Supporter");
    TextDrawBackgroundColor(TDClassChooserSupporter[playerid], 255);
    TextDrawFont(TDClassChooserSupporter[playerid], 2);
    TextDrawLetterSize(TDClassChooserSupporter[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserSupporter[playerid], -1);
    TextDrawSetOutline(TDClassChooserSupporter[playerid], 1);
    TextDrawSetProportional(TDClassChooserSupporter[playerid], 1);

    TDClassChooserSniper[playerid] = TextDrawCreate(66.000000, 202.000000, "Sniper");
    TextDrawBackgroundColor(TDClassChooserSniper[playerid], 255);
    TextDrawFont(TDClassChooserSniper[playerid], 2);
    TextDrawLetterSize(TDClassChooserSniper[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserSniper[playerid], -1);
    TextDrawSetOutline(TDClassChooserSniper[playerid], 1);
    TextDrawSetProportional(TDClassChooserSniper[playerid], 1);

    TDClassChooserCustom[playerid] = TextDrawCreate(65.000000, 218.000000, "Custom");
    TextDrawBackgroundColor(TDClassChooserCustom[playerid], 255);
    TextDrawFont(TDClassChooserCustom[playerid], 2);
    TextDrawLetterSize(TDClassChooserCustom[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserCustom[playerid], -1);
    TextDrawSetOutline(TDClassChooserCustom[playerid], 1);
    TextDrawSetProportional(TDClassChooserCustom[playerid], 1);

    TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 175.000000, "~r~>         <");
    TextDrawBackgroundColor(TDClassChooserChoosen[playerid], 255);
    TextDrawFont(TDClassChooserChoosen[playerid], 1);
    TextDrawLetterSize(TDClassChooserChoosen[playerid], 0.500000, 1.000000);
    TextDrawColor(TDClassChooserChoosen[playerid], 9830550);
    TextDrawSetOutline(TDClassChooserChoosen[playerid], 1);
    TextDrawSetProportional(TDClassChooserChoosen[playerid], 1);

    TDGroupClassChooser[playerid] = CreateTDGroup(TDClassChooser,TDClassChooserBOX,TDClassChooserAssaulter[playerid],TDClassChooserSupporter[playerid],TDClassChooserSniper[playerid],TDClassChooserCustom[playerid],TDClassChooserChoosen[playerid],TD_HowToSpawn);

//From my include, TDGrouper, not necessary.
//If using add
//for(new i=0;i<MAX_GROUPS;++i) tdenum[i][count] = -1;
//In OnGameModeInIt

To add vehicles
pawn Code:
AddStaticVehicle(520,1650.1279,-965.3316,63.4298,328.6633,0,0); // Hydra_1
AddStaticVehicle(520,1657.9375,-965.7026,63.4109,13.6602,0,0); // hydra_2

Now that TextDraw's and vehicles are ready, we will need a variable to know if a player has a valid class or not. So we declare a Global variable for it.

pawn Code:
new type[MAX_PLAYERS];
//You may like to add this to your enum instead of making a new global variable

When Player Connects set type to -1.
Found that it may be more usefull when added under OnPlayerRequestClass also.
pawn Code:
public OnPlayerConnect(playerid)
{
    type[playerid] = -1;
}

We wish to skip player from OnPlayerRequestClass ,so we add
pawn Code:
public OnPlayerRequestClass(playerid, classid)
{
     type[playerid] = -1;
    SetSpawnInfo(playerid,0,0,0,0,0,0,0,0,0,0,0,0);
    SpawnPlayer(playerid);
    return 1;
}
This code will simple spawn player as CJ, at (0,0,0) location and no weapons.

When PlayerSpawn, we will send him to our custom class screen,
pawn Code:
public OnPlayerSpawn(playerid)
{
    if(type[playerid]==-1)
    {
        SetPlayerVirtualWorld(playerid,playerid);//Puts player in a virtual world
        ShowCustomClass(playerid);//Stock we are just going to create
        return 0;
    }
//And all other code when he have a valid class
}

Before creating Stock for custom class, we add variables to store id of pickup(since we need to destroy them)
pawn Code:
new Class_pickup[MAX_PLAYERS][3];
pawn Code:
stock ShowCustomClass(playerid)
{
//Since, at starting layer has choosen assaulter as class, so we need to create pickup here.
//___PICKUP____
    Class_pickup[playerid][0] = CreatePickup(356,1,1654.3134,-955.5966,62.6696,playerid);
    Class_pickup[playerid][1] = CreatePickup(348,1,1656.3134,-955.5966,62.6696,playerid);
    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);
    //__TextDraw__
    TDGroupShowForPlayer(playerid,TDGroupClassChooser[playerid]);//Replace by TextDrawShowForPlayer if not using the include.
    //__PLATYER AND CAMERA__

    TogglePlayerControllable(playerid,false);
    SetPlayerInterior(playerid,0);
    SetPlayerPos(playerid,1652.3134,-955.5966,62.6696);
    SetPlayerFacingAngle(playerid,355.7387);
    SetPlayerCameraPos(playerid,1655.4005,-950.2772,62.5974);
    SetPlayerCameraLookAt(playerid,1654.3134,-961.5966,62.6696);
    SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
    SetPlayerSkin(playerid,287);
    SetPVarInt(playerid,"AT",0);
}

Mostly all are self explanatory.I used SetPVarInt to create a player variable which tells us the current choosen class by player, which by default is Assaulter (0).

Now, when a player presses shift, space or enter OnPlayerKeyStateChange is called.
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
}

Add
pawn Code:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
to top
To know about this code : http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange

We must need to ensure that player does not have a valid class
pawn Code:
if(type[playerid]==-1) //This will ensure it.
{
        new at = GetPVarInt(playerid,"AT");
        new bool:create = false;//Should compiler create new pickup?
//To ensure new pickup's are created only when SHIFT or SPACE is Pressed

        if(PRESSED(KEY_SPRINT))//space
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);//Destroy current pickup.
            if(at==3) at=-1;//if layer is at bottom and he pressed space, take him to top.
            ++at;
        }
        else if(PRESSED(KEY_JUMP))//shift
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);
            if(at==0) at=4;
            --at;
        }
        else if(PRESSED(KEY_SECONDARY_ATTACK))//enter
        {
            type[playerid] = at;//0=Assaulter,1==Supported,2=Sniper,3=Custom
            new str[50];
            switch(at)
            {
                case 0:
                {
                    format(str,sizeof(str),"You spawned as Assaulter");
                    SetSpawnInfo(...);      //To give weapons, spawn info
                }
                case 1:
                {
                    format(str,sizeof(str),"You spawned as Supporter");
                    SetSpawnInfo(...);
                }
                case 2:
                {
                    format(str,sizeof(str),"You spawned as Sniper");
                    SetSpawnInfo(...);
                }
                case 4:
                {
                    format(str,sizeof(str),"You spawned as Custom Class");
                    SetSpawnInfo(...);
                }

            }
                          TDGroupHideForPlayer(playerid,TDGroupClassChooser[playerid]); //Hide textDraws
            SCM(playerid,-1,str);
            TogglePlayerControllable(playerid,true);
            ClearAnimations(playerid,1);
            SpawnPlayer(playerid);
            return 1;
        }

To change player skin according to the place player is at
pawn Code:
switch(at)
        {
            case 0:
            {
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~g~Assaulter");//Assaulter is green , rest white
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 174.000000, "~g~>         <");//Change location.

                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(356,1,1654.3134,-955.5966,62.6696,playerid);//M4 ASSAULT RIFLE
                    Class_pickup[playerid][1] = CreatePickup(348,1,1656.3134,-955.5966,62.6696,playerid);//Desert EAGLE
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,287);


            }
            case 1:
            {
                TextDrawSetString(TDClassChooserSupporter[playerid],"~g~Supporter");//Supprter is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 188.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(351,1,1654.3134,-955.5966,62.6696,playerid);//Combat Shotgun
                    Class_pickup[playerid][1] = CreatePickup(359,1,1656.3134,-955.5966,62.6696,playerid);//Rocket Launcher
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,282);

            }
            case 2:
            {
                TextDrawSetString(TDClassChooserSniper[playerid],"~g~Sniper");//Sniper is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 202.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);//Sniper
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);//MP5
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,285);
            }
            case 3:
            {
                TextDrawSetString(TDClassChooserCustom[playerid],"~g~Custom");//Custom is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 218.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,163);
            }
        }

And to update Textdraw's and location
pawn Code:
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
        TextDrawBackgroundColor(TDClassChooserChoosen[playerid], 255);
        TextDrawFont(TDClassChooserChoosen[playerid], 1);
        TextDrawLetterSize(TDClassChooserChoosen[playerid], 0.500000, 1.000000);
        TextDrawColor(TDClassChooserChoosen[playerid], 9830550);
        TextDrawSetOutline(TDClassChooserChoosen[playerid], 1);
        TextDrawSetProportional(TDClassChooserChoosen[playerid], 1);
        TextDrawShowForPlayer(playerid,TDClassChooserChoosen[playerid]);
        SetPVarInt(playerid,"AT",at);

So, your full OnPlayerKeyStateChange may look like
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(type[playerid]==-1)
    {
        new at = GetPVarInt(playerid,"AT");
        new bool:create = false;

        if(PRESSED(KEY_SPRINT))
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);
            if(at==3) at=-1;
            ++at;
        }
        else if(PRESSED(KEY_JUMP))
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);
            if(at==0) at=4;
            --at;
        }
        else if(PRESSED(KEY_SECONDARY_ATTACK))
        {
            type[playerid] = at + 1;
            new str[50];
            switch(at)
            {
                case 0:
                {
                    format(str,sizeof(str),"You spawned as Assaulter");
                    SetSpawnInfo(...);
                }
                case 1:
                {
                    format(str,sizeof(str),"You spawned as Supporter");
                    SetSpawnInfo(...);
                }
                case 2:
                {
                    format(str,sizeof(str),"You spawned as Sniper");
                    SetSpawnInfo(...);
                }
                case 4:
                {
                    format(str,sizeof(str),"You spawned as Custom Class");
                    SetSpawnInfo(...);
                }

            }
                         TDGroupHideForPlayer(playerid,TDGroupClassChooser[playerid]);//Hide textdraws
            SCM(playerid,-1,str);
            TogglePlayerControllable(playerid,true);
            ClearAnimations(playerid,1);
            SpawnPlayer(playerid);
            return 1;
        }
        switch(at)
        {
            case 0:
            {
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~g~Assaulter");//Assaulter is green , rest white
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 174.000000, "~g~>         <");//Change location.

                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(356,1,1654.3134,-955.5966,62.6696,playerid);//M4 ASSAULT RIFLE
                    Class_pickup[playerid][1] = CreatePickup(348,1,1656.3134,-955.5966,62.6696,playerid);//Desert EAGLE
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,287);


            }
            case 1:
            {
                TextDrawSetString(TDClassChooserSupporter[playerid],"~g~Supporter");//Supprter is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 188.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(351,1,1654.3134,-955.5966,62.6696,playerid);//Combat Shotgun
                    Class_pickup[playerid][1] = CreatePickup(359,1,1656.3134,-955.5966,62.6696,playerid);//Rocket Launcher
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,282);

            }
            case 2:
            {
                TextDrawSetString(TDClassChooserSniper[playerid],"~g~Sniper");//Sniper is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 202.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);//Sniper
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);//MP5
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,285);
            }
            case 3:
            {
                TextDrawSetString(TDClassChooserCustom[playerid],"~g~Custom");//Custom is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 218.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,163);
            }
        }
        SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
        TextDrawBackgroundColor(TDClassChooserChoosen[playerid], 255);
        TextDrawFont(TDClassChooserChoosen[playerid], 1);
        TextDrawLetterSize(TDClassChooserChoosen[playerid], 0.500000, 1.000000);
        TextDrawColor(TDClassChooserChoosen[playerid], 9830550);
        TextDrawSetOutline(TDClassChooserChoosen[playerid], 1);
        TextDrawSetProportional(TDClassChooserChoosen[playerid], 1);
        TextDrawShowForPlayer(playerid,TDClassChooserChoosen[playerid]);
        SetPVarInt(playerid,"AT",at);
        return 1;
    }
    return 1;
}


And your full code should look like this
pawn Code:
#include <a_samp>
#include <TDgroup>

new Text:TDClassChooser; //When Player Chooses class [HEADING]
new Text:TDClassChooserBOX; //Box for it
new Text:TDClassChooserAssaulter[MAX_PLAYERS]; //Assaulter Selected
new Text:TDClassChooserSupporter[MAX_PLAYERS];
new Text:TDClassChooserSniper[MAX_PLAYERS];
new Text:TDClassChooserCustom[MAX_PLAYERS];
new Text:TDClassChooserChoosen[MAX_PLAYERS]; //The >  < in class chossing
new Text:TD_HowToSpawn; //Press shift to go up and space to down....
new TDGroupClassChooser[MAX_PLAYERS];
new type[MAX_PLAYERS];
new Class_pickup[MAX_PLAYERS][3];

#define SCM SendClientMessage

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnGameModeInit()
{
    for(new i=0;i<MAX_GROUPS;++i) tdenum[i][count] = -1;

    TDClassChooser = TextDrawCreate(91.000000, 149.000000, "~g~Class ~r~Chooser");
    TextDrawAlignment(TDClassChooser, 2);
    TextDrawBackgroundColor(TDClassChooser, 255);
    TextDrawFont(TDClassChooser, 2);
    TextDrawLetterSize(TDClassChooser, 0.270000, 2.000000);
    TextDrawColor(TDClassChooser, -16776961);
    TextDrawSetOutline(TDClassChooser, 1);
    TextDrawSetProportional(TDClassChooser, 1);
    TextDrawUseBox(TDClassChooser, 1);
    TextDrawBoxColor(TDClassChooser, 255);
    TextDrawTextSize(TDClassChooser, 179.000000, 121.000000);

    TDClassChooserBOX = TextDrawCreate(32.000000, 173.000000, "~n~~n~~n~~n~~n~~n~~n~");
    TextDrawBackgroundColor(TDClassChooserBOX, 255);
    TextDrawFont(TDClassChooserBOX, 1);
    TextDrawLetterSize(TDClassChooserBOX, 0.500000, 1.000000);
    TextDrawColor(TDClassChooserBOX, -1);
    TextDrawSetOutline(TDClassChooserBOX, 0);
    TextDrawSetProportional(TDClassChooserBOX, 1);
    TextDrawSetShadow(TDClassChooserBOX, 1);
    TextDrawUseBox(TDClassChooserBOX, 1);
    TextDrawBoxColor(TDClassChooserBOX, 125);
    TextDrawTextSize(TDClassChooserBOX, 150.000000, 109.000000);
   
    TD_HowToSpawn                   =TextDrawCreate( 66.000000, 293.000000, "Press ~g~SHIFT ~w~ to go ~g~UP~n~~r~SPACE~w~ to go ~r~DOWN~n~~b~ENTER TO SPAWN");
    TextDrawAlignment           ( TD_HowToSpawn, 2);
    TextDrawBackgroundColor ( TD_HowToSpawn, 255);
    TextDrawFont                ( TD_HowToSpawn, 1);
    TextDrawLetterSize      ( TD_HowToSpawn, 0.300000, 1.300000);
    TextDrawColor               ( TD_HowToSpawn, -1);
    TextDrawSetOutline      ( TD_HowToSpawn, 1);
    TextDrawSetProportional ( TD_HowToSpawn, 1);
   
    AddStaticVehicle(520,1650.1279,-965.3316,63.4298,328.6633,0,0); // Hydra_1
    AddStaticVehicle(520,1657.9375,-965.7026,63.4109,13.6602,0,0); // hydra_2
}
public OnPlayerConnect(playerid)
{
    type[playerid] = -1;
     TDClassChooserAssaulter[playerid] = TextDrawCreate(55.000000, 174.000000, "~g~Assaulter");
    TextDrawBackgroundColor(TDClassChooserAssaulter[playerid], 255);
    TextDrawFont(TDClassChooserAssaulter[playerid], 2);
    TextDrawLetterSize(TDClassChooserAssaulter[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserAssaulter[playerid], -1);
    TextDrawSetOutline(TDClassChooserAssaulter[playerid], 1);
    TextDrawSetProportional(TDClassChooserAssaulter[playerid], 1);

    TDClassChooserSupporter[playerid] = TextDrawCreate(56.000000, 188.000000, "Supporter");
    TextDrawBackgroundColor(TDClassChooserSupporter[playerid], 255);
    TextDrawFont(TDClassChooserSupporter[playerid], 2);
    TextDrawLetterSize(TDClassChooserSupporter[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserSupporter[playerid], -1);
    TextDrawSetOutline(TDClassChooserSupporter[playerid], 1);
    TextDrawSetProportional(TDClassChooserSupporter[playerid], 1);

    TDClassChooserSniper[playerid] = TextDrawCreate(66.000000, 202.000000, "Sniper");
    TextDrawBackgroundColor(TDClassChooserSniper[playerid], 255);
    TextDrawFont(TDClassChooserSniper[playerid], 2);
    TextDrawLetterSize(TDClassChooserSniper[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserSniper[playerid], -1);
    TextDrawSetOutline(TDClassChooserSniper[playerid], 1);
    TextDrawSetProportional(TDClassChooserSniper[playerid], 1);

    TDClassChooserCustom[playerid] = TextDrawCreate(65.000000, 218.000000, "Custom");
    TextDrawBackgroundColor(TDClassChooserCustom[playerid], 255);
    TextDrawFont(TDClassChooserCustom[playerid], 2);
    TextDrawLetterSize(TDClassChooserCustom[playerid], 0.239999, 1.299999);
    TextDrawColor(TDClassChooserCustom[playerid], -1);
    TextDrawSetOutline(TDClassChooserCustom[playerid], 1);
    TextDrawSetProportional(TDClassChooserCustom[playerid], 1);

    TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 175.000000, "~r~>         <");
    TextDrawBackgroundColor(TDClassChooserChoosen[playerid], 255);
    TextDrawFont(TDClassChooserChoosen[playerid], 1);
    TextDrawLetterSize(TDClassChooserChoosen[playerid], 0.500000, 1.000000);
    TextDrawColor(TDClassChooserChoosen[playerid], 9830550);
    TextDrawSetOutline(TDClassChooserChoosen[playerid], 1);
    TextDrawSetProportional(TDClassChooserChoosen[playerid], 1);
   
    TDGroupClassChooser[playerid] = CreateTDGroup(TDClassChooser,TDClassChooserBOX,TDClassChooserAssaulter[playerid],TDClassChooserSupporter[playerid],TDClassChooserSniper[playerid],TDClassChooserCustom[playerid],TDClassChooserChoosen[playerid],TD_HowToSpawn);


}

public OnPlayerRequestClass(playerid, classid)
{
    SetSpawnInfo(playerid,0,0,0,0,0,0,0,0,0,0,0,0);
    SpawnPlayer(playerid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(type[playerid]==-1)
    {
        SetPlayerVirtualWorld(playerid,playerid);//Puts player in a virtual world
        ShowCustomClass(playerid);//Stock we are just going to create
        return 0;
    }
    SCM(playerid,-1,"I spawned");
    return 1;
//And all other code when he have a valid class
}
stock ShowCustomClass(playerid)
{
//Since, at starting layer has choosen assaulter as class, so we need to create pickup here.
//___PICKUP____
    Class_pickup[playerid][0] = CreatePickup(356,1,1654.3134,-955.5966,62.6696,playerid);
    Class_pickup[playerid][1] = CreatePickup(348,1,1656.3134,-955.5966,62.6696,playerid);
    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);
    //__TextDraw__
    TDGroupShowForPlayer(playerid,TDGroupClassChooser[playerid]);//Replace by TextDrawShowForPlayer if not using the include.
    //__PLATYER AND CAMERA__

    TogglePlayerControllable(playerid,false);
    SetPlayerInterior(playerid,0);
    SetPlayerPos(playerid,1652.3134,-955.5966,62.6696);
    SetPlayerFacingAngle(playerid,355.7387);
    SetPlayerCameraPos(playerid,1655.4005,-950.2772,62.5974);
    SetPlayerCameraLookAt(playerid,1654.3134,-961.5966,62.6696);
    SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
    SetPlayerSkin(playerid,287);

    SetPVarInt(playerid,"AT",0);
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(type[playerid]==-1)
    {
        new at = GetPVarInt(playerid,"AT");
        new bool:create = false;

        if(PRESSED(KEY_SPRINT))
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);
            if(at==3) at=-1;
            ++at;
        }
        else if(PRESSED(KEY_JUMP))
        {
            create = true;
            for(new i=0;i<3;++i) DestroyPickup(Class_pickup[playerid][i]);
            if(at==0) at=4;
            --at;
        }
        else if(PRESSED(KEY_SECONDARY_ATTACK))
        {
            type[playerid] = at + 1;
            new str[50];
            switch(at)
            {
                case 0:
                {
                    format(str,sizeof(str),"You spawned as Assaulter");
                    SetSpawnInfo(playerid,0,GetPlayerSkin(playerid),1958,95,0,0,1,6,27,300,32,010);
                }
                case 1:
                {
                    format(str,sizeof(str),"You spawned as Supporter");

                }
                case 2:
                {
                    format(str,sizeof(str),"You spawned as Sniper");

                }
                case 4:
                {
                    format(str,sizeof(str),"You spawned as Custom Class");

                }

            }
            TDGroupHideForPlayer(playerid,TDGroupClassChooser[playerid]);
            SCM(playerid,-1,str);
            TogglePlayerControllable(playerid,true);
            ClearAnimations(playerid,1);
            SpawnPlayer(playerid);
            return 1;
        }
        switch(at)
        {
            case 0:
            {
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~g~Assaulter");//Assaulter is green , rest white
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 174.000000, "~g~>         <");//Change location.

                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(356,1,1654.3134,-955.5966,62.6696,playerid);//M4 ASSAULT RIFLE
                    Class_pickup[playerid][1] = CreatePickup(348,1,1656.3134,-955.5966,62.6696,playerid);//Desert EAGLE
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,287);


            }
            case 1:
            {
                TextDrawSetString(TDClassChooserSupporter[playerid],"~g~Supporter");//Supprter is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);

                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 188.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(351,1,1654.3134,-955.5966,62.6696,playerid);//Combat Shotgun
                    Class_pickup[playerid][1] = CreatePickup(359,1,1656.3134,-955.5966,62.6696,playerid);//Rocket Launcher
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,282);

            }
            case 2:
            {
                TextDrawSetString(TDClassChooserSniper[playerid],"~g~Sniper");//Sniper is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserCustom[playerid],"~w~Custom");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 202.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);//Sniper
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);//MP5
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,285);
            }
            case 3:
            {
                TextDrawSetString(TDClassChooserCustom[playerid],"~g~Custom");//Custom is green , rest white
                TextDrawSetString(TDClassChooserAssaulter[playerid],"~w~Assaulter");
                TextDrawSetString(TDClassChooserSupporter[playerid],"~w~Supporter");
                TextDrawSetString(TDClassChooserSniper[playerid],"~w~Sniper");
                TextDrawDestroy(TDClassChooserChoosen[playerid]);


                TDClassChooserChoosen[playerid] = TextDrawCreate(38.000000, 218.000000, "~g~>         <");
                if (create == true)
                {
                    Class_pickup[playerid][0] = CreatePickup(358,1,1654.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][1] = CreatePickup(353,1,1656.3134,-955.5966,62.6696,playerid);
                    Class_pickup[playerid][2] = CreatePickup(342,1,1658.3134,-955.5966,62.6696,playerid);//Grenade
                }
                SetPlayerSkin(playerid,163);
            }
        }
        SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);
        TextDrawBackgroundColor(TDClassChooserChoosen[playerid], 255);
        TextDrawFont(TDClassChooserChoosen[playerid], 1);
        TextDrawLetterSize(TDClassChooserChoosen[playerid], 0.500000, 1.000000);
        TextDrawColor(TDClassChooserChoosen[playerid], 9830550);
        TextDrawSetOutline(TDClassChooserChoosen[playerid], 1);
        TextDrawSetProportional(TDClassChooserChoosen[playerid], 1);
        TextDrawShowForPlayer(playerid,TDClassChooserChoosen[playerid]);
        SetPVarInt(playerid,"AT",at);
        return 1;
    }
    return 1;
}
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money

Last edited by [MM]RoXoR[FS]; 09/09/2012 at 03:45 PM.
[MM]RoXoR[FS] is offline   Reply With Quote
Old 09/09/2012, 11:46 AM   #2
Black Wolf
Gangsta
 
Join Date: Mar 2009
Location: On the bed with your sister.
Posts: 505
Reputation: 166
Default Re: Creating Custom Class Selection Screen

wow man great tutorial and awesome script.Fuck yeah its really very very usefull.
__________________
<not allowed>
Black Wolf is offline   Reply With Quote
Old 09/09/2012, 12:00 PM   #3
[HK]Ryder[AN]
High-roller
 
[HK]Ryder[AN]'s Avatar
 
Join Date: Jan 2012
Location: New Delhi, India
Posts: 1,195
Reputation: 365
Default Re: Creating Custom Class Selection Screen

Awesome script..Thanks for sharing.
__________________


[HK]Ryder[AN] is offline   Reply With Quote
Old 09/09/2012, 12:07 PM   #4
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 738
Reputation: 138
Default Re: Creating Custom Class Selection Screen

Earlier I thought of using Arrow keys instead of Shift and Space, but since it required the use on OnPlayerUpdate, I moved to other keys.
In another version I used arrow keys, but in that one could choose Team as well as class (Left - Right swaps team || Up-Down swaps Class)
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 09/09/2012, 12:29 PM   #5
xMCx
Huge Clucker
 
xMCx's Avatar
 
Join Date: May 2012
Location: Mars.
Posts: 250
Reputation: 23
Default Re: Creating Custom Class Selection Screen

Nice really cool! thanks
xMCx is offline   Reply With Quote
Old 06/10/2012, 09:46 PM   #6
Ghost_Boii
Huge Clucker
 
Ghost_Boii's Avatar
 
Join Date: Sep 2012
Location: Don of Dubai :)
Posts: 311
Reputation: 42
Default Re: Creating Custom Class Selection Screen

Nice
__________________
My Works

Ghost_Boii is offline   Reply With Quote
Old 08/10/2012, 12:52 PM   #7
[HK]Ryder[AN]
High-roller
 
[HK]Ryder[AN]'s Avatar
 
Join Date: Jan 2012
Location: New Delhi, India
Posts: 1,195
Reputation: 365
Default Re: Creating Custom Class Selection Screen

Now theres a better thing.
We can use clickable textdraws. But this is also good
__________________


[HK]Ryder[AN] is offline   Reply With Quote
Old 08/10/2012, 01:35 PM   #8
Hoss
Big Clucker
 
Join Date: Sep 2010
Posts: 186
Reputation: 85
Default Re: Creating Custom Class Selection Screen

Good job.
Hoss is offline   Reply With Quote
Old 09/10/2012, 04:41 AM   #9
Psymetrix
Huge Clucker
 
Join Date: Oct 2011
Posts: 292
Reputation: 104
Default Re: Creating Custom Class Selection Screen

Nice copy and paste!
Seriously, though. This is more like a release than anything. I suggest you read this, especially the part about explanations.

Nice try, though. I'm sure if you spend some more time explaining, it will become a good tutorial.

P.s.
Code:
#define SCM SendClientMessage
Disgusting
Psymetrix is offline   Reply With Quote
Old 09/10/2012, 07:53 AM   #10
RenSoprano
Huge Clucker
 
Join Date: Oct 2011
Location: Bansko, Bulgaria
Posts: 437
Reputation: 44
Default Re: Creating Custom Class Selection Screen

This an amazing work. Good Job +REP from me
__________________
RenSoprano is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Selection screen Ilan321 Help Archive 2 01/01/2011 11:42 AM
class selection screen armyoftwo Help Archive 10 20/11/2010 04:26 PM
Bypass Class Selection Screen Hot Help Archive 4 07/03/2010 07:24 PM
Can't get to class selection screen Celson Client Support 7 10/06/2009 01:50 AM
Delay class selection screen mascii Help Archive 8 03/03/2009 11:41 AM


All times are GMT. The time now is 06:01 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.