SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Includes (https://forum.sa-mp.com/forumdisplay.php?f=83)
-   -   [Include] Disable class selection (https://forum.sa-mp.com/showthread.php?t=574072)

Emmet_ 13/05/2015 10:57 AM

Disable class selection
 
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

Crayder 13/05/2015 11:16 AM

Re: Disable class selection
 
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.

ZiGGi 13/05/2015 12:29 PM

Re: Disable class selection
 
Why you call SpawnPlayer(playerid) after TogglePlayerSpectating(playerid, false)? And you did not consider F4 feature.

Emmet_ 13/05/2015 12:32 PM

Re: Disable class selection
 
Quote:

Originally Posted by ZiGGi (Post 3457963)
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
    }
}

ZiGGi 13/05/2015 12:44 PM

Re: Disable class selection
 
Quote:

Originally Posted by Emmet_ (Post 3457967)
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);
    }



Gammix 13/05/2015 01:40 PM

Re: Disable class selection
 
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!

theYiin 24/05/2015 11:36 AM

Re: Disable class selection
 
Quote:

Originally Posted by ZiGGi (Post 3457974)
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.

FplayerGR 24/05/2015 03:24 PM

Re: Disable class selection
 
wow very nice.

ZiGGi 24/05/2015 04:25 PM

Re: Disable class selection
 
Quote:

Originally Posted by theYiin (Post 3467919)
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.

PT 24/05/2015 04:42 PM

Re: Disable class selection
 
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?


All times are GMT. The time now is 10:21 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.