[Tutorial] Better Freezing System
#1

Better Freezing System
Tutorial




Introduction
- In this tutorial I will show you how to make a player freezing system, many of you will probably jump to the reply and make "SetPlayerControllable NOOOOOOOOB" posts, if you're one of them either continue reading or just get out of the thread.


Requirements
- Basic Scripting knowledge.
- ZCMD. (Or you can just convert to your own command proccessor)
- SSCANF. (Or you can just use any other way of parameters defining you know)


Why you should use this system instead of using SetPlayerControllable
- This system will allow freezed players to move their screen view freely which has been suggested by many to be supported in future SA-MP scripting versions.



Better Freezing System
Let's get it done



Step 1
Add these variables to the top of your script.
pawn Код:
new Float:FX[MAX_PLAYERS], Float:FY[MAX_PLAYERS], Float:FZ[MAX_PLAYERS]; // X, Y, Z we will store the coordinates at when we freeze someone
new IsFrozen[MAX_PLAYERS]; // The variable we will use to check if a player is frozen or not
new playerb; // Definition for the player we're going to freeze, I like to keep it in public to avoid making new variable under each command

Step 2
Make your freeze and unfreeze commands.
pawn Код:
CMD:freeze(playerid, params[]) // ZCMD Start
{
    if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /freeze [playerid]"); // SSCANF check if we entered an id or not
    if(!IsPlayerConnected(playerb)) return SendClientMessage(playerid, 0xFFFFFFAA, "Invalid player id"); // Check if the player id we entered is valid
    if(IsFrozen[playerb]) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is already frozen."); // Check if the player is frozen already
    IsFrozen[playerb] = 1; // Sets the player's frozen variable to 1
    GetPlayerPos(playerb, FX[playerb], FY[playerb], FZ[playerb]); // Saves the player's coordinates to the variables we defined at the top
    SendClientMessage(playerb, 0xFFFFFFAA, "You have been frozen."); // Sends a message to the player informing him about being frozen
    return 1;
}

CMD:unfreeze(playerid, params[]) // ZCMD Start
{
    if(sscanf(params, "u", playerb)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /unfreeze [playerid]");// SSCANF check if we entered an id or not
    if(!IsPlayerConnected(playerb)) return SendClientMessage(playerid, 0xFFFFFFAA, "Invalid player id"); // Check if the player id we entered is valid
    if(!IsFrozen[playerb]) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is not frozen.");  // Check if the player is not frozen
    IsFrozen[playerb] = 0; // Sets the player's frozen variable to 0
    SendClientMessage(playerb, 0xFFFFFFAA, "You have been unfrozen."); // Sends a message to the player informing him about being unfrozen
    return 1;
}
Step 3
Add this under OnPlayerUpdate.
pawn Код:
if(IsFrozen[playerid]) // Check to make sure the player is frozen
{
    if(GetPlayerWeapon(playerid) != 0) // Check to see if the player is holding a weapon
    {
        SetPlayerArmedWeapon(playerid, 0); // Hides the weapon from player's hand, to prevent shooting while standing still
    }
    new Float:FFX, Float:FFY, Float:FFZ; // Variables we will use to compare to the ones we defined at the top
    GetPlayerPos(playerid, FFX, FFY, FFZ); // Getting the player's current position
    if(FX[playerid] != FFX || FY[playerid] != FFY || FZ[playerid] != FFZ) // Check to see if the player has moved
    {
        SetPlayerPos(playerid, FX[playerid], FY[playerid], FZ[playerid]); // Sets his position back to the coordinates he was frozen at
    }
}


The End
We're Done


FAQ
- If you have any questions, bugs, suggestions reply 'n I will reply ASAP.

Credits
- Dudits


Hope this was helpful to anybody, enjoy.
Reply


Messages In This Thread
Better Freezing System - by Dudits - 31.07.2011, 19:39
Re: Better Freezing System - by LetsOWN[PL] - 31.07.2011, 19:42
Re: Better Freezing System - by Dudits - 31.07.2011, 19:46
Re: Better Freezing System - by [HiC]TheKiller - 31.07.2011, 20:01
Re: Better Freezing System - by Stylock - 31.07.2011, 20:17
Re: Better Freezing System - by Tigerkiller - 31.07.2011, 20:28
Re: Better Freezing System - by Donya - 31.07.2011, 20:33
Re: Better Freezing System - by alpha500delta - 31.07.2011, 21:12
Re: Better Freezing System - by Michael@Belgium - 31.07.2011, 23:14
Re: Better Freezing System - by Karlip - 31.07.2011, 23:41
Re: Better Freezing System - by OleKristian95 - 31.07.2011, 23:56
Re: Better Freezing System - by System64 - 01.08.2011, 13:47
Re: Better Freezing System - by TheArcher - 01.08.2011, 13:57
Re: Better Freezing System - by Dudits - 01.08.2011, 17:46
Re: Better Freezing System - by dowster - 01.08.2011, 17:48
Re: Better Freezing System - by TheArcher - 01.08.2011, 18:48
Re: Better Freezing System - by Dudits - 02.08.2011, 15:37
Re: Better Freezing System - by Calgon - 02.08.2011, 15:52
Re: Better Freezing System - by TheArcher - 02.08.2011, 16:05
Re: Better Freezing System - by Dudits - 02.08.2011, 22:49

Forum Jump:


Users browsing this thread: 2 Guest(s)