need alot of help :D
#1

hi im new to scripting before u say im using wiki but i need to know how to add groups e.g police,arms dealer and that i cant find it on wiki please help if there is a site that can help me better please let me know
Reply
#2

Quote:
Originally Posted by madmatty
hi im new to scripting before u say im using wiki but i need to know how to add groups e.g police,arms dealer and that i cant find it on wiki please help if there is a site that can help me better please let me know
Making a team deathmatch
OK, now you know how to make classes and place them about we will show you how to set teams, this will be the first bit of real coding but is fairly easy. I will just be using the two classes described on this page so if you have more remove them for now or start a new mode and make sure only those two are in. Classes are numbered in order from 0, so the first class in your file is 0, the second is 1 and so on (computers and programs nearly always start from 0 in counting (you will find that your playerid in a test game is 0)). We want to set the team based on which class they choose (either Grove or Balla), you may look at the callbacks and think that this would go in the OnPlayerRequestClass function, and you would be correct. When the select their class you want to set the team based on that, we can't do it in the OnPlayerSpawn function as at that point we don't know the class they have selected (that is a parameter and only parameters we are passed or which are global in your script (we will cover this later) can be used in any function). First we need to define our teams, under the "#include" line(s) at the top of your file add these lines:

#define TEAM_GROVE 1
#define TEAM_BALLA 2
#define TEAM_GROVE_COLOR 0x00FF00AA // Bright Green (in RGBA format)
#define TEAM_BALLA_COLOR 0xFF00FFAA // Bright PurpleIf you want to alter the colors, that's fine, just remember that the last two digits are the alpha and the lower that is the less you can see the color. Defines are purely replacements, now if you ever want to use the number 1 in your script you can use TEAM_GROVE instead, this is not a good idea for normal calculations as it makes them harder to read, but for using to denote teams, which are only denoted by a number, it makes it a lot clearer what's going on (and makes it very easy to change the teams around or modify later as you need only change the 1 in the define rather than all the instances of it throughout the code. When the code is compiled, all the "TEAM_GROVE"s will be replaced by 1, it is not like a variable, it is a constant, it doesn't change. Now under those lines add:

new gTeam[MAX_PLAYERS];This is called a global array. An array is basically lots of variables (places you store data to read and write) clumped together to store lots of data at once. The "MAX_PLAYERS" is a pre-defined constant (done in exactly the same way as we did our defines. MAX_PLAYERS is actually set at 200 in SA-MP 0.2, so this means that our array can store up to 200 pieces of data. The g on the name means global, but that doesn't make it global (it just makes it easier to tell what variables do what, defining it outside a function means it is global and can be used by all our functions. Any variable defined in a function is local to that function and it can't have the same name as another variable in the same function or a global variable (which is also why the g is useful), it can however have the same name as another variable in another function. All the "playerid" variables in your blank script are in fact all independent variables, each local to a different function, however they are all passed the same data, but just remember that any functions you make won't automatically have that data. Now we have that set up we can set the teams:

SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}
else
{
gTeam[playerid] = TEAM_BALLA;
}
}Place that code OUTSIDE a function in your code (as it is a new function) and put these lines as the first things after the open curly braces in your OnPlayerRequestClass callback (notice the way the variables are not global so we are having to pass them to out function too):

SetPlayerTeamFromClass(playerid, classid);This will save the players team to an array through our new function. Data in an array is referenced by a number, so array[0] is the first item of data, array[1] is the second and so on, as we are using gTeam[playerid], depending on which playerid we are passed will define where in the array to store the data, so for player 5 their data will be stored at array position 5 (remember, this is the 6th piece of data). Now copy this function:

SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}
else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}
}And add the following line to OnPlayerSpawn:

SetPlayerToTeamColor(playerid);We now have our teams, but what have we actually done?

if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}In our first function, we check which class they chose (remember we said that the first class defined in your file was class 0?) "==" means "is equal to", a single equals sign simply sets the variable to the number given (as seen on the next line but one). The curly braces separate the functions between them from the rest of the code, bits in there are only executed if the selected class is 0 (cj), if it isn't, the else command comes into play and executes instead (this executes whenever the "if" command is false (i.e. the class isn't 0)), since we only have two classes to choose from this must mean we're Balla:

else
{
gTeam[playerid] = TEAM_BALLA;
}We don't need a return here as there is no data to return.



The second half set the players' color when they spawn, so you can tell who's on which team. As we saved their team to a global array, we can still access the data even though it is in a separate function.

if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}Hopefully you can see what this is doing now, if the player who just spawned (as referenced by playerid) is in TEAM_GROVE, we set their color to TEAM_GROVEs color.

else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}This next section is a little different, it could easilly have been done like this:

else
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}But the way it is done allows you to set their color to TEAM_BALLAs color only if the first part is false (as sorted by the ELSE) AND if they are in TEAM_BALLA, this allows you to add more options by adding more "else if ()" blocks to the end as one will only be executed if all the blocks before it weren't.
Reply
#3

Take a SFTDM.pwn as an example.
Reply
#4

[quote=Mr_FinnigaN ]
Quote:
Originally Posted by madmatty
hi im new to scripting before u say im using wiki but i need to know how to add groups e.g police,arms dealer and that i cant find it on wiki please help if there is a site that can help me better please let me know
thx i managed to set up my teams i think like so
SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_COP;
}
if (classid == 1)
{
gTeam[playerid] = TEAM_ARMSDEALER;
}
if (classid == 2)
{
gTeam[playerid] = TEAM_MEDIC;
}
if (classid == 3)
{
gTeam[playerid] = TEAM_KIDNAPPER;
}
else if (classid == 4)
{
gTeam[playerid] = TEAM_CARJACKER;
}
}

SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_COP)
{
SetPlayerColor(playerid, TEAM_COP_COLOR);
}
if (gTeam[playerid] == TEAM_ARMSDEALER)
{
SetPlayerColor(playerid, TEAM_ARMSDEALER_COLOR);
}
if (gTeam[playerid] == TEAM_MEDIC)
{
SetPlayerColor(playerid, TEAM_MEDIC_COLOR);
}
if (gTeam[playerid] == TEAM_KIDNAPPER)
{
SetPlayerColor(playerid, TEAM_KIDNAPPER_COLOR);
}
else if (gTeam[playerid] == TEAM_CARJACKER)
{
SetPlayerColor(playerid, TEAM_CARJACKER_COLOR);
}
}
#define TEAM_COP 1
#define TEAM_ARMSDEALER 2
#define TEAM_MEDIC 3
#define TEAM_KIDNAPPER 4
#define TEAM_CARJACKER 5
#define TEAM_CARJACKER_COLOR 0xFFFFFFAA // white
#define TEAM_KIDNAPPER_COLOR 0xFFFFFFAA // white
#define TEAM_MEDIC_COLOR 0x800080FF // purple
#define TEAM_COP_COLOR 0x0000FFFF // Blue
#define TEAM_ARMSDEALER_COLOR 0xFFFFFFAA // white

how do i add commands to a certain group so i can sell guns if im a dealer or heal people if im a medic and so on please
Reply
#5

Quote:
Originally Posted by Don Correlli
Take a SFTDM.pwn as an example.
i can't find it
Reply
#6

Quote:
Originally Posted by madmatty
Quote:
Originally Posted by Don Correlli
Take a SFTDM.pwn as an example.
i can't find it
http://files.sa-mp.com/samp02Xserver.win32.zip
You have it in here.
Reply
#7

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by madmatty
Quote:
Originally Posted by Don Correlli
Take a SFTDM.pwn as an example.
i can't find it
http://files.sa-mp.com/samp02Xserver.win32.zip
You have it in here.
thx buddy thats so simple is there an easy 1 to show me how to add commands to them groups then again it dont recognise half of its own commands so it no good coz it dont even work PLEASE HELP HOW WOULD A ADD A COMMAND TO A CERTAIN CLASS
Reply
#8

Quote:
Originally Posted by madmatty
Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by madmatty
Quote:
Originally Posted by Don Correlli
Take a SFTDM.pwn as an example.
i can't find it
http://files.sa-mp.com/samp02Xserver.win32.zip
You have it in here.
thx buddy thats so simple is there an easy 1 to show me how to add commands to them groups then again it dont recognise half of its own commands so it no good coz it dont even work PLEASE HELP HOW WOULD A ADD A COMMAND TO A CERTAIN CLASS
please somebody help i got at mo don't know if it right
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerTeamFromClass(playerid, classid);
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);

return 1;
}

SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_COP;
}
if (classid == 1)
{
gTeam[playerid] = TEAM_ARMSDEALER;
}
if (classid == 2)
{
gTeam[playerid] = TEAM_MEDIC;
}
if (classid == 3)
{
gTeam[playerid] = TEAM_KIDNAPPER;
}
else if (classid == 4)
{
gTeam[playerid] = TEAM_CARJACKER;
}
}

SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_COP)
{
SetPlayerColor(playerid, TEAM_COP_COLOR);
}
if (gTeam[playerid] == TEAM_ARMSDEALER)
{
SetPlayerColor(playerid, TEAM_ARMSDEALER_COLOR);
}
if (gTeam[playerid] == TEAM_MEDIC)
{
SetPlayerColor(playerid, TEAM_MEDIC_COLOR);
}
if (gTeam[playerid] == TEAM_KIDNAPPER)
{
SetPlayerColor(playerid, TEAM_KIDNAPPER_COLOR);
}
else if (gTeam[playerid] == TEAM_CARJACKER)
{
SetPlayerColor(playerid, TEAM_CARJACKER_COLOR);
}
}
new gTeam[MAX_PLAYERS];

#define TEAM_COP 1
#define TEAM_ARMSDEALER 2
#define TEAM_MEDIC 3
#define TEAM_KIDNAPPER 4
#define TEAM_CARJACKER 5
#define TEAM_CARJACKER_COLOR 0xFFFFFFAA // white
#define TEAM_KIDNAPPER_COLOR 0xFFFFFFAA // white
#define TEAM_MEDIC_COLOR 0x800080FF // purple
#define TEAM_COP_COLOR 0x0000FFFF // Blue
#define TEAM_ARMSDEALER_COLOR 0xFFFFFFAA // white
if so how do i make the class to that team, like cop class from 280 to 289 i want them as team_cop how do i do it please
Reply


Forum Jump:


Users browsing this thread: