[Include] Disable class selection
#1

Disable class selection

This include allows you to disable class selection with ease, without playing around with the spectator functions.

You can also use this include to hide the class selection buttons without spawning the player.

Usage
All you need to do is include it after a_samp:

pawn Code:
#include <a_samp>
#include <noclass>
This works by enabling spectator mode in OnPlayerRequestClass() to hide the class selection buttons. There is one callback available:

pawn Code:
// Called when a player has fully connected to the server.
public OnPlayerFullyConnected(playerid);
After OnPlayerRequestClass has been called and the buttons have been hidden, the callback above will be called.

It can be used to show the login dialog, spawn the player, or set the player's camera.

Spawning the player
Use SpawnPlayer() to simply spawn the player after they are done logging in or whatever.

pawn Code:
public OnPlayerLogin(playerid)
{
    if (cache_get_row_count(gConnection))
    {
        SetSpawnInfo(playerid, NO_TEAM, 255, 1280.0, -1024.0, 20.0, 180.0, 0, 0, 0, 0, 0, 0);
        SpawnPlayer(playerid);
    }
}
There is a bug in SA-MP where using SpawnPlayer after TogglePlayerSpectating will kick you. In this instance, you can safely spawn a player without any problems.

Disable class selection
If you want to completely disable class selection and spawn the player after they connect, do this:

pawn Code:
public OnPlayerFullyConnected(playerid)
{
    SpawnPlayer(playerid);
}
Download
https://www.dropbox.com/s/eawh6oo8z7...class.inc?dl=1
Reply
#2

Simple, nice. I was thinking of doing a series of little scripts like this. The series would cover a lot of the small things newbies have trouble with such as skipping class selection.
Reply
#3

Why you call SpawnPlayer(playerid) after TogglePlayerSpectating(playerid, false)? And you did not consider F4 feature.
Reply
#4

Quote:
Originally Posted by ZiGGi
View Post
Why you call SpawnPlayer(playerid) after TogglePlayerSpectating(playerid, false)? And you did not consider F4 feature.
SpawnPlayer() doesn't work if the player is spectating. It bugs or kicks the player.

No way to detect F4, but for now I would just do something like:

pawn Code:
public OnPlayerFullyConnected(playerid)
{
    if (IsPlayerLoggedIn(playerid))
    {
        SpawnPlayer(playerid);
    }
    else
    {
        // Show register/login dialog, set camera, etc
    }
}
Reply
#5

Quote:
Originally Posted by Emmet_
View Post
SpawnPlayer() doesn't work if the player is spectating. It bugs or kicks the player.
I know, but TogglePlayerSpectating(playerid, false) will automatically spawns player.
Maybe this variant is better:
PHP Code:
stock CS_SpawnPlayer(playerid)
{
    if (
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        
TogglePlayerSpectating(playeridfalse);
    }
    else
    {
        
SpawnPlayer(playerid);
    }

Reply
#6

Here is my version:
pawn Code:
/*
FUNCTIONS:
native TogglePlayerClassSelection(playerid, bool:toggle);
native IsPlayerClassSelectionToggled(playerid);
*/


static bool:gPlayerClassSelection[MAX_PLAYERS] = true;

public OnPlayerRequestClass(playerid, classid)
{
    if(! gPlayerClassSelection[playerid])
    {
        TogglePlayerSpectating(playerid, true);

        SetTimerEx("OnPlayerSkipClassSelection", (GetPlayerPing(playerid) + 50), false, "i", playerid);
    }
    return CallLocalFunction("CLASS_OnPlayerRequestClass", "i", playerid);
}
#if defined _ALS_OnPlayerRequestClass
    #undef OnPlayerRequestClass
#else
    #define _ALS_OnPlayerRequestClass
#endif
#define OnPlayerRequestClass CLASS_OnPlayerRequestClass
forward CLASS_OnPlayerRequestClasst(playerid, classid);

forward OnPlayerSkipClassSelection(playerid);
public OnPlayerSkipClassSelection(playerid) return (TogglePlayerSpectating(playerid, false), SpawnPlayer(playerid));

stock TogglePlayerClassSelection(playerid, bool:toggle) return (gPlayerClassSelection[playerid] = toggle);

stock IsPlayerClassSelectionToggled(playerid) return gPlayerClassSelection[playerid];
Having functions for enabling or disabling class selection would be much meaningful according to the thread name!
Reply
#7

Quote:
Originally Posted by ZiGGi
View Post
I know, but TogglePlayerSpectating(playerid, false) will automatically spawns player.
Actually, few days ago I ran into strange bug, where calling TogglePlayerSpectating(playerid, false) would kick the player from server if he wasn't spawned before, but calling SpawnPlayer(playerid) right after toggling spectating off fixed it, and player spawned properly without getting kicked. That was one hell of a bug to track down.
Reply
#8

wow very nice.
Reply
#9

Quote:
Originally Posted by theYiin
View Post
Actually, few days ago I ran into strange bug, where calling TogglePlayerSpectating(playerid, false) would kick the player from server if he wasn't spawned before, but calling SpawnPlayer(playerid) right after toggling spectating off fixed it, and player spawned properly without getting kicked. That was one hell of a bug to track down.
Better solution is calling SetSpawnInfo before TogglePlayerSpectating.
Reply
#10

Well the problem is if you use TogglePlayerSpectating and SpawnPlayer will call the OnPlayerSpawn twice...


@ Emmet do you advice any good way to disapear that arrows ( << & >> ) and dont be called the OnPlayerSpawn twice?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)