SA-MP Forums Archive
[Tutorial] Protection from 'Spawn button' - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Protection from 'Spawn button' (/showthread.php?tid=457897)



Protection from 'Spawn button' - RedJohn - 13.08.2013

Intro

This is very simple solution for very annoying problem.

Solution

Few days ago I had a problem like this (this is not my image, found it on the internet):

You see that 'spawn button' at the bottom?

While register dialog or login dialog or whatever is showed you can avoid it if 'spawn button' is visible.

Basically you are playing without registration or login.

So to avoid that I figured simple solution.

Add TogglePlayerSpectating(playerid, 1); under your OnPlayerConnect callback.

pawn Код:
public OnPlayerConnect(playerid)
{
    TogglePlayerSpectating(playerid, 1);
    // Rest of your code goes here.
    return 1;
}
A little explanation:

TogglePlayerSpectating = Toggle a player's spectate mode
playerid = The ID of the player
1 = TogglePlayerSpectating is ENABLED

While TogglePlayerSpectating is enabled 'spawn button' is hidden.

How to disable it?

We are going to disable it at Register dialog or Login dialog or at any dialog which will proceed to player spawning.

Examples:

pawn Код:
case DIALOG_REGISTER:
{
    // Your code goes here
    TogglePlayerSpectating(playerid, 0);
    return 1;
}
pawn Код:
case DIALOG_LOGIN:
{
    // Your code goes here
    TogglePlayerSpectating(playerid, 0);
    return 1;
}
pawn Код:
case DIALOG_WELCOME:
{
    // Your code goes here
    TogglePlayerSpectating(playerid, 0);
    return 1;
}
pawn Код:
case DIALOG_ANYTHING:
{
    // Your code goes here
    TogglePlayerSpectating(playerid, 0);
    return 1;
}
A little explanation:

TogglePlayerSpectating = Toggle a player's spectate mode
playerid = The ID of the player
0 = TogglePlayerSpectating is DISABLED

I prefer putting it at the end of your dialog.

Place it under Register dialog and Login dialog.

So that's it.

Please give a try and post your feedback.


Re: Protection from 'Spawn button' - CyNiC - 13.08.2013

Nice trick.


Re: Protection from 'Spawn button' - RedJohn - 13.08.2013

Yea.


Re: Protection from 'Spawn button' - HyDrAtIc - 13.08.2013

Yeah, a really nice trick, simple, but useful, good job.


Re: Protection from 'Spawn button' - DowDaw - 13.08.2013

Good work, nice tutorial.

Thank you!


Re: Protection from 'Spawn button' - Vince - 13.08.2013

Or just return 0 in OnPlayerRequestSpawn if not logged in. I should also remind you that TogglePlayerSpectating automatically calls OnPlayerSpawn when it's being disabled. This may or may not be useful to different types of server. Not everyone plays roleplay and some servers might actually want the class selection to appear.


Re: Protection from 'Spawn button' - RedJohn - 13.08.2013

Somebody prefer that, somebody prefer TPS.

@Vince:

I can show you my code where TogglePlayerSpectating is being used with class selection. And it's working just great. I'm not saying that your words are wrong I just don't have that problem (using it side by side with class selection).


Re: Protection from 'Spawn button' - Joshswag - 14.08.2013

After you enter your password to log in, my server still requires that you click spawn. I would really like to remove it and allow you to automatically log you in, How can I do this? Thanks.


Re: Protection from 'Spawn button' - RedJohn - 14.08.2013

Can you send me your whole OnDialogResponse please?


Re: Protection from 'Spawn button' - Joshswag - 14.08.2013

My ondialog response is massive, anything inparticular you want?