31.07.2011, 19:39
(
Последний раз редактировалось Dudits; 01.08.2011 в 17:46.
)
Better Freezing System
Tutorial
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
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;
}
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
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.