How to make spawn colors

From SA-MP

Jump to: navigation, search

Welcome to this small tutorial about setting colors for spawned players.

Contents

Saving which class the player selects

To set the color to a certain one (e.g. a team-color), we need to save which class has been selected by the player. We can achieve this by a new global variable, which is just for the purpose of saving the class that is selected on the spawn-selection-screen.

new gClass[MAX_PLAYERS]; // This is to remind the class a player did choose

Adding some classes

Of course, you need some classes to set the colors for, we're just adding those two:

public OnGameModeInIt()
{
    AddPlayerClass(106,2512.8611,-1673.2799,13.5104,87.7485,0,0,0,0,0,0); // Class 0
    AddPlayerClass(107,2508.1372,-1656.6781,13.5938,129.4222,0,0,0,0,0,0); // Class 1
    return 1;
}

Saving the player's class

When we want to set the color upon the color later, we need to find out what class has been selected.

public OnPlayerRequestClass(playerid, classid)
{
    // With this you save the chosen class number into gClass[playerid]
    gClass[playerid] = classid;
    return 1;
}

Changing the players colour on spawn

Based upon the class we selected and saved before, we're now going to set the color for the class.

public OnPlayerSpawn(playerid)
{
    // First we need to see what classid a player got
    switch(gClass[playerid])
    {
        case 0:
        {
            // If the player's class is 0 then set it to Orange
            SetPlayerColor(playerid, 0xFF6600AA); // Orange
        }
        case 1:
        {
            // If the player's class is 1 then set it to Red
            SetPlayerColor(playerid, 0xFF0000AA); // Red
        }
    }
    return 1;
}
Personal tools