#include <a_samp>
#define TEAM_ONE 3
// You can rename 'TEAM_ONE' to anything, of course.
// '3' is the Team ID used to identify them, you can change this, too!
#define TEAM_TWO 6
main() { print( "- Team Example by 2KY" ); }
// Just a simple print.. Don't feel like I have to explain this..
public OnGameModeInit( )
{
AddPlayerClass( 169, 255.0, 0.0, 10.0, 69.0, 0,0, 0,0, 0,0 ); // TEAM_ONE
AddPlayerClass( 119, 0.0, 255.0, 10.0, 69.0, 0,0, 0,0, 0,0 ); // TEAM_TWO
// Later on under OnPlayerRequestClass, we are going to assign their teams.
return true;
}
public OnPlayerRequestClass(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);
// Blah, blah, generic new.pwn camera position code.
switch( classid ) // Goes through all of the classid's, this is faster than an if statement!
{
case 0: // 'classid' zero is our first class, which is going to be assigned to 'TEAM_ONE'
{
SetPlayerTeam( playerid, TEAM_ONE );
// Since TEAM_ONE is defined as '3', this is the same thing as doing:
// SetPlayerTeam( playerid, 3 );
}
case 1: // Let's do the same thing again, but this time, we're assigning it to 'TEAM_TWO'
{
SetPlayerTeam( playerid, TEAM_TWO );
// Once again, this is like doing:
// SetPlayerTeam( playerid, 6 );
}
}
/*
Alternatively, you could do something with if statements like so:
if( classid == 0 )
{
}
But this method would be slower than using a switch statement.
Remember switch > if statement, if it's between using multiple if statements or a simple switch statement.
*/
return 1;
}
public OnPlayerSpawn(playerid)
{
switch( GetPlayerTeam( playerid ) )
{
case TEAM_ONE:
{
// They are a member of 'TEAM_ONE'
// Since we can put two-and-two together, we can also find out that they chose classid zero without
// needing to create an extra variable!
SendClientMessage( playerid, -1, GetTeamName( TEAM_ONE ) );
// GetTeamName is a custom function I created. If you scroll down, you will find more on it.
}
case TEAM_TWO:
{
// They are a member of 'TEAM_TWO'
// Like above, they chose classid one!
SendClientMessage( playerid, -1, GetTeamName( TEAM_TWO ) );
}
}
return true;
}
public OnPlayerCommandText( playerid, cmdtext[] )
{
// Although I recommend the use of ZCMD, I will be using strcmp for this tutorial.
if( strcmp( "/myteam", cmdtext, true, 7 ) == 0 )
{
new
tStr [ 50 ];
format( tStr, sizeof( tStr ), "* You are currently a %s!", GetTeamName ( GetPlayerTeam( playerid ) ) );
return SendClientMessage( playerid, -1, tStr );
}
return false;
}
stock GetTeamName ( TeamID )
{
new
tName [ 64 ];
// We probably don't even need 64 cells for this, but we will just in case.
switch( TeamID )
{
case TEAM_ONE:
{
tName = "Attackers";
// If their Team ID is TEAM_ONE, then GetTeamName will return "Attackers"
}
case TEAM_TWO:
{
tName = "Defenders";
// If their Team ID is TEAM_TWO, then GetTeamName will return "Defenders"
}
default: // Anything but TEAM_ONE or TEAM_TWO.
{
tName = "Unknown";
// If it's unknown ( I'm not sure how this would happen, but I'm sure it's possible.. )
}
}
return tName;
}
Nice :/ mostly its a copy and paste right ? >if its not sorry< it just seems like it
but nice anyway rep+ |
Good job 2KY, this will surely help some newbies in starting their own server
![]() |
Good job 2KY, this will surely help some newbies in starting their own server
![]() |
Yes ! You are right
![]() ![]() ![]() |