How to password protect skins

From SA-MP Wiki

Jump to: navigation, search


Welcome to the Passworded Skins tutorial.

This tutorial will assist in lockin certain classes on class selection. It's quite easy, just watch and learn!


Contents


Variable

First off, we must have some variables;

new Locked[MAX_PLAYERS];

This creates a new variable that determines if a player is viewing a locked skin. Make sure you put it outside of all callbacks, preferably at the top of your script.

Add Classes

Now lets add some classes.

public OnGameModeInit()
{
    AddPlayerClass(221, 0, 0, 0, 130, 24, 300, 0, 0, 0, 0); //Class 0 - Not passworded
    AddPlayerClass(212, 0, 0, 0, 130, 24, 300, 0, 0, 0, 0); //Class 1 - Not passworded
    AddPlayerClass(199, 0, 0, 0, 130, 24, 300, 0, 0, 0, 0); //Class 2 - Passworded
    return 1;
}

Okay great, now we have some player classes to protect.

Determining if a class is locked

Remember that 'Locked[MAX_PLAYERS]' variable we created earlier? Time to use it! If a player views a protected skin, we will set 'Locked[playerid]' to 1. If the skin they see isn't protected, we can set it to 0.

public OnPlayerRequestClass(playerid, classid)
{
    switch(classid)
    {
	case 0: Locked[playerid] = 0; //this one DOESNT.
	case 1: Locked[playerid] = 0; //this one too
	case 2: Locked[playerid] = 1; //this is going to be locked, right?
    }
    return 1;
}

Locked[playerid] will now be set to 1 if they are viewing a passworded skin.

Stopping the player from spawning

Now lets make it so they can't spawn with a protected skin.

public OnPlayerRequestSpawn(playerid)
{
    if(Locked[playerid]) return 0;
    //If player's current class is passworded, stop them from spawning
    return 1;
}

Now we have that done, we need a way to unprotect a class by entering a password.

Unlock command

Let's make the command '/unlock [password]'.

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/unlock YOUR_PASS"))
    {
        Locked[playerid] = 0;
        SendClientMessage(playerid, COLOR_GREEN, "Skins unlocked!");
    }
    return 1;
}

So now, when a player types '/unlock YOUR_PASS' they will be able to use those protected skins!

Tutorial finished

Congratulations, you now know how to password protect a skin.

Personal tools
Navigation
Toolbox