02.09.2011, 16:43
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:
Place them under: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;
}
Code:
public OnPlayerCommandText(playerid, cmdtext[])
"/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;
}
pawn Code:
public OnPlayerRequestClass(playerid, classid)
Code:
SetPlayerPos(); SetPlayerCameraPos(); SetPlayerFacingAngle(); SetPlayerCameraLookAt();
The first thing we should have under our callback, is this:
pawn Code:
switch(classid)
{
}
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:
{
}
}
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);
Code:
(2785.370361, -1994.306518, 13.382812, 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);
pawn Code:
switch(classid)
{
case 0 .. 5:
{
SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
}
}
Code:
SetPlayerFacingAngle(playerid, 176.249954);
pawn Code:
switch(classid)
{
case 0 .. 5:
{
SetPlayerPos(playerid, 2481.010253, -1654.001953, 13.317111);
SetPlayerFacingAngle(playerid, 176.249954);
}
}
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);
}
}
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;
}
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);
}
}
pawn Code:
public OnPlayerRequestClass(playerid, classid)
{
return 1;
}
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);
Code:
case 0 .. 5:
Code:
case 0: