[Tutorial] How to use class selection!
#1

How to use class selection!

In this tutorial, you'll learn how to switch between classid's and how to set the camera in the right position.

First off, you'll need a couple of commands that I've put together and used myself to do my class selections, here they are:

pawn Code:
if (strcmp(cmd, "/savepos", true)==0)
    {
        new Float:X, Float:Z, Float:Y, Float:A;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, A);
        new File:pos=fopen("OnFootPos.txt", io_append);
        format(string, sizeof(string), "(%f, %f, %f, %f);\r\n", X, Y, Z, A);
        SendClientMessage(playerid,COLOR_GREY,"OnFootPosition saved to OnFootPos.txt !");
        fwrite(pos, string);
        fclose(pos);
        return 1;
    }
    if (strcmp(cmd, "/savecampos", true)==0)
    {
        new Float:X, Float:Z, Float:Y;
        GetPlayerCameraPos(playerid, X, Y, Z);
        new File:pos=fopen("CameraPos.txt", io_append);
        format(string, sizeof(string), "(%f, %f, %f);\r\n", X, Y, Z);
        SendClientMessage(playerid,COLOR_GREY,"CameraPos saved to CameraPos.txt !");
        fwrite(pos, string);
        fclose(pos);
        return 1;
    }
Place them under:
Code:
public OnPlayerCommandText(playerid, cmdtext[])
What do they do?
"/savepos" saves the players position, and their facing angle.
"/savecampos" saves the position of the camera (very helpful later on).

Now, the first real step is to add the players class, for selection. You'll need to add multiple classes. The function we use is "AddPlayerClass", you can read more information about it here:
This is where the "/savepos" command comes in handy, go in-game, find the position you want the player to spawn after selecting the class and then use the information from the file (OnFootPos.txt - or the file you changed it too) and add it into your AddPlayerClass.

Hint: Don't forget that AddPlayerClass goes under OnGameModeInit.
Hint: The coordinates in AddPlayerClass do not have to be the same for later on, when we do the class selection.


So right about now you should have the players classes setup, if we go in game and navigate through the classes before spawn, then you'll notice they are all in the same position and so on. This is where we are going to change it, and you can even add some TextDraws for different classes.

At the moment, you should have something like this: (feel free to use these as your own!)

pawn Code:
public OnGameModeInit()
{
    //Grove
    AddPlayerClass(105, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 29, 150, 26, 150);
    AddPlayerClass(106, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 29, 150, 30, 150);
    AddPlayerClass(107, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 28, 150, 31, 150);
    AddPlayerClass(270, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 32, 150, 33, 150);
    AddPlayerClass(271, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 28, 150, 34, 150);
    AddPlayerClass(269, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 32, 150, 26, 150);
    //Ballas
    AddPlayerClass(102, 2002.281616, -1123.249633, 26.577611, 269.1425, 22, 150, 28, 150, 30, 150);
    AddPlayerClass(103, 2002.281616, -1123.249633, 26.577611, 269.1425, 23, 150, 29, 150, 31, 150);
    AddPlayerClass(104, 2002.281616, -1123.249633, 26.577611, 269.1425, 24, 150, 32, 150, 27, 150);
    //Los Aztecas
    AddPlayerClass(114, 2785.370361, -1994.306518, 13.382812, 269.1425, 22, 150, 28, 150, 30, 150);
    AddPlayerClass(115, 2785.370361, -1994.306518, 13.382812, 269.1425, 23, 150, 29, 150, 31, 150);
    AddPlayerClass(116, 2785.370361, -1994.306518, 13.382812, 269.1425, 24, 150, 32, 150, 27, 150);
    //Los Santos Vagos
    AddPlayerClass(108, 1882.914916, -2040.028686, 13.390607, 269.1425, 22, 150, 28, 150, 30, 150);
    AddPlayerClass(109, 1882.914916, -2040.028686, 13.390607, 269.1425, 23, 150, 29, 150, 31, 150);
    AddPlayerClass(110, 1882.914916, -2040.028686, 13.390607, 269.1425, 24, 150, 32, 150, 27, 150);
return 1;
}
Alright -- now we're ready to move onto customizing the class selection. We'll be using the callback:
pawn Code:
public OnPlayerRequestClass(playerid, classid)
This is where the command, "/savecampos" will come into place. We will also be using functions such as:
Code:
SetPlayerPos();
SetPlayerCameraPos();
SetPlayerFacingAngle();
SetPlayerCameraLookAt();
First thing is, decide weather you want teams, or individuals. Either way, I'll explain on how to use both. First off, I'll explain how to do it for a team. There's not really much difference anyway.

The first thing we should have under our callback, is this:
pawn Code:
switch(classid)
{

}
Hint: a return is only needed for the callback, nt the switch(classid) function.

Now hopefully you've gone in-game and used the command "/savecampos" because we're about to need the information that was saved. Now we will learn how to switch between the classes. If you're using teams, this is what you should do:

pawn Code:
switch(classid)
{
    case 0 .. 5:
    {
           
    }
}
This will choose the first 5 classes to customize.
Hint: the count starts from 0, not 1.

If you're using my AddPlayerClass's, case 0 .. 5 will effect these classes:
Code:
	//Grove
	AddPlayerClass(105, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 29, 150, 26, 150);
	AddPlayerClass(106, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 29, 150, 30, 150);
	AddPlayerClass(107, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 28, 150, 31, 150);
	AddPlayerClass(270, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 32, 150, 33, 150);
	AddPlayerClass(271, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 28, 150, 34, 150);
	AddPlayerClass(269, 2478.777832, -1661.156738, 13.343750, 269.1425, 24, 150, 32, 150, 26, 150);
Alright -- so now we're ready to change the camera position! Again I'll use mine as an example, and you are free to use it in your script. First, we need to go back to the information that was saved when you done "/savepos" - because we need to grab the players angle. The angle is the last number, example:
Code:
(2785.370361, -1994.306518, 13.382812, 89.249145);
Hint: the facing angle for this one is 89.249145

First off, set your players position for the class selection. This is mine, and is located at Grove St:
Code:
SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
Now your code should look like:
pawn Code:
switch(classid)
{
    case 0 .. 5:
    {
        SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);      
    }
}
After setting the position of the player, let's turn his facing angle around. Again, I'm using the code out of mine.
Code:
SetPlayerFacingAngle(playerid, 176.249954);
pawn Code:
switch(classid)
{
    case 0 .. 5:
    {
        SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
        SetPlayerFacingAngle(playerid, 176.249954);    
    }
}
But that still won't be okay, because the camera won't be facing the player!
Hint: /savecampos

Code:
SetPlayerCameraPos(playerid, 2482.577880, -1661.032836, 14.404399);
pawn Code:
switch(classid)
{
    case 0 .. 5:
    {
        SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
        SetPlayerFacingAngle(playerid, 176.249954);
        SetPlayerCameraPos(playerid, 2482.577880, -1661.032836, 14.404399);    
    }
}
In some cases, this still wont' work because the cameras facing look at won't be facing the player, it really depends on the position of everything else. Although, I've also made a command that may help that:
pawn Code:
if(strcmp(cmd, "/savecamface", true) == 0)
    {
        new Float:X,Float:Y,Float:Z;
        GetPlayerCameraFrontVector(playerid, X, Y, Z);
        new File:pos=fopen("CameraFace.txt", io_append);
        format(string, sizeof(string), "SetPlayerCameraLookAt(playerid, %f, %f, %f);\r\n", X, Y, Z);
        fwrite(pos, string);
        SendClientMessage(playerid,COLOR_GREY,"CameraFace saved to CameraFace.txt !");
        fclose(pos);
        return 1;
    }
Hint: This is SetPlayerCameraLookAt();

Now, we should have a code that looks like this:
pawn Code:
switch(classid)
{
    case 0 .. 5:
    {
        SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
        SetPlayerFacingAngle(playerid, 176.249954);
        SetPlayerCameraPos(playerid, 2482.577880, -1661.032836, 14.404399);  
        SetPlayerCameraLookAt(playerid, 2201.6306,1217.2319,10.8128);  
    }
}
And that code should be placed under:
pawn Code:
public OnPlayerRequestClass(playerid, classid)
{

return 1;
}
Warning: there must be data before the switch(classid), leave the default data there!
Incase you deleted it, just use:
pawn Code:
SetPlayerPos(playerid, 2201.6306,1217.2319,10.8128);
SetPlayerFacingAngle(playerid,178.6062);
SetPlayerCameraPos(playerid, 2202.2537,1210.6444,10.8128);
SetPlayerCameraLookAt(playerid, 2201.6306,1217.2319,10.8128);
That was for teams, now to use individuals just change:
Code:
case 0 .. 5:
To:
Code:
case 0:
Now you should have a class selection at your own location! (I hope so anyway!).
This concludes my very first tutorial. I'll be releasing more and each one will get more advanced, I just wanted to do something simple and see if it helped anyone! Hope this helped you... and if it didn't, well better luck next time
Reply
#2

thanks awesome work now i can make easly
Reply
#3

To be honest it's better to assign the class ID's to variables. So you don't have to rely on ID's (which, afaik, is how GF does it's class system. Not sure though since I haven't seen it's source code). Making it this way will create problems when you want to edit it at a later point unless you add new skins at the bottom of the other ones.
Reply
#4

eeehm it's asking for string? and other shit: F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(130 : error 017: undefined symbol "cmd"
F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(1314) : error 017: undefined symbol "string"
F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(1314) : error 017: undefined symbol "string"
F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(1314) : error 029: invalid expression, assumed zero
F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(1314) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#5

eehm think i've fixed it but now i got this warnings: F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(1399) : warning 219: local variable "string" shadows a variable at a preceding level
F:\program files\my own drifting gamemode\gamemodes\NYD_Drifting.pwn(2137) : warning 219: local variable "string" shadows a variable at a preceding level
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Warnings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)