17.08.2010, 19:36
Hello. Im trying to do my first GM, and i need ask a question:
Where i place set team color and set team from class.
Please Helpme.
PS: I can map for free if wan't.
Код:
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.
Please Helpme.
PS: I can map for free if wan't.