SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 13/05/2015, 10:57 AM   #1
Emmet_
Guest
 
Posts: n/a
Default 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
  Reply With Quote
Old 13/05/2015, 11:16 AM   #2
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default 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.
Crayder is offline   Reply With Quote
Old 13/05/2015, 12:29 PM   #3
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,659
Reputation: 356
Default Re: Disable class selection

Why you call SpawnPlayer(playerid) after TogglePlayerSpectating(playerid, false)? And you did not consider F4 feature.
ZiGGi is offline   Reply With Quote
Old 13/05/2015, 12:32 PM   #4
Emmet_
Guest
 
Posts: n/a
Default Re: Disable class selection

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 With Quote
Old 13/05/2015, 12:44 PM   #5
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,659
Reputation: 356
Default Re: Disable class selection

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);
    }

ZiGGi is offline   Reply With Quote
Old 13/05/2015, 01:40 PM   #6
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 858
Default 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!
__________________

Follow me on Github: Donate on Paypal:


Last edited by Gammix; 17/05/2015 at 06:36 AM.
Gammix is offline   Reply With Quote
Old 24/05/2015, 11:36 AM   #7
theYiin
Big Clucker
 
theYiin's Avatar
 
Join Date: Aug 2013
Location: Lithuania
Posts: 84
Reputation: 53
Default Re: Disable class selection

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.
theYiin is offline   Reply With Quote
Old 24/05/2015, 03:24 PM   #8
FplayerGR
Big Clucker
 
FplayerGR's Avatar
 
Join Date: May 2015
Location: Greece!
Posts: 83
Reputation: 5
Default Re: Disable class selection

wow very nice.
FplayerGR is offline   Reply With Quote
Old 24/05/2015, 04:25 PM   #9
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,659
Reputation: 356
Default Re: Disable class selection

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.
ZiGGi is offline   Reply With Quote
Old 24/05/2015, 04:42 PM   #10
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Europe
Posts: 7,180
Reputation: 803
Default 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?
PT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] [TUT] Disable Class Selection aqu Tutorials 8 09/06/2012 11:48 AM
Disable class selection on GF Mr.Carson Clay Scripting Help 8 03/02/2012 10:43 AM
Disable class selection TaMeD Help Archive 8 26/06/2011 08:53 AM
disable class selection? HondaCBR Help Archive 6 21/04/2011 11:15 AM
Disable Class selection falor Help Archive 2 21/04/2010 10:32 AM


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


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