[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
#2

Smart :]
It seems to be usefull, cuz some cheats has anti admin-freeze system.
Well done

Greetz,
Lets
Reply
#3

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Smart :]
It seems to be usefull, cuz some cheats has anti admin-freeze system.
Well done

Greetz,
Lets
They have NOP SetPlayerPos too, but this would be exactly what someone would need if he wants people to be able to move their screen view while being frozen.


Thank you
Reply
#4

I have noticed a few errors in your code

pawn Код:
GetPlayerPos(playerb, FX, FY, FZ); // Saves the player's coordinates to the variables we defined at the top
Should be changed to

pawn Код:
GetPlayerPos(playerb, FX[playerb], FY[playerb], FZ[playerb]); // Saves the player's coordinates to the variables we defined at the top
Also, if you make a check on OnPlayerUpdate like that, it's not the best idea because it will be called quite a few times per second if you constantly check it.
Reply
#5

Or you could just freeze player with animation.
pawn Код:
ClearAnimations(playerid);
ApplyAnimation(playerid, "PED", "XPRESSscratch", 0.0, 1, 1, 1, 1, 0);
Got that from Slice's anti 2-shot FS.
Reply
#6

it will be better when you check is player frozen then check theyre pos if !inrangeoffpoint then ban him because off hacks
Reply
#7

better ≥ https://sampforum.blast.hk/showthread.php?tid=184118
Reply
#8

Also, under /freeze you use:

pawn Код:
IsFrozen[playern] = 1;
and under /unfreeze you use:

pawn Код:
if(IsFrozen[playerb]) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is not frozen.");  // Check if the player is not frozen
So you can't unfreeze the person... Did you even test this before posting?
Reply
#9

You forgot something:

pawn Код:
new playerb; //in both cmds ^^
Reply
#10

https://sampforum.blast.hk/showthread.php?tid=184118

This topic also has a solution to the incomplete freeze system.
Reply
#11

Would be cool if you explained what this and that does. and not only write the codes.
Reply
#12

nice but you should use u not i in the sscanf and not use IsPlayerConnected than INVALID_PLAYER_ID
Reply
#13

Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
You forgot something:

pawn Код:
new playerb; //in both cmds ^^
No he made it in public that means playerb will call that player.

Anyways this is not the best way to create a freeze/unfreeze system beacuse OnPlayerUpdate calls that code everysecond. and what is the best way making it on OnPlayerUpdate
Reply
#14

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
I have noticed a few errors in your code

pawn Код:
GetPlayerPos(playerb, FX, FY, FZ); // Saves the player's coordinates to the variables we defined at the top
Should be changed to

pawn Код:
GetPlayerPos(playerb, FX[playerb], FY[playerb], FZ[playerb]); // Saves the player's coordinates to the variables we defined at the top
Also, if you make a check on OnPlayerUpdate like that, it's not the best idea because it will be called quite a few times per second if you constantly check it.
Done.

Quote:
Originally Posted by YJIET
Посмотреть сообщение
Or you could just freeze player with animation.
pawn Код:
ClearAnimations(playerid);
ApplyAnimation(playerid, "PED", "XPRESSscratch", 0.0, 1, 1, 1, 1, 0);
Got that from Slice's anti 2-shot FS.
There are commands that clear the animation

Quote:
Originally Posted by Tigerkiller
Посмотреть сообщение
it will be better when you check is player frozen then check theyre pos if !inrangeoffpoint then ban him because off hacks
The system isn't about detecting if the player is hacking or not, it's about freezing someone and making him able to move his camera, + packetloss makes people appear like hackers sometimes.

Quote:
Originally Posted by alpha500delta
Посмотреть сообщение
Also, under /freeze you use:

pawn Код:
IsFrozen[playern] = 1;
and under /unfreeze you use:

pawn Код:
if(IsFrozen[playerb]) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is not frozen.");  // Check if the player is not frozen
So you can't unfreeze the person... Did you even test this before posting?
I tested it and deleted the code, then decided to make a tutorial here so I've missed few stuff, fixed.

Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
You forgot something:

pawn Код:
new playerb; //in both cmds ^^
It's defined on the top AKA can be usedi n any cmd ^^


Quote:
Originally Posted by OleKristian95
Посмотреть сообщение
Would be cool if you explained what this and that does. and not only write the codes.
Would be cool if you read every green line besides the commands.

Quote:
Originally Posted by System64
Посмотреть сообщение
nice but you should use u not i in the sscanf and not use IsPlayerConnected than INVALID_PLAYER_ID
Done, and IsPlayerConnected works good ye?
Everybody has his own scripting style.

Quote:
Originally Posted by Anthony_prince
Посмотреть сообщение
No he made it in public that means playerb will call that player.

Anyways this is not the best way to create a freeze/unfreeze system beacuse OnPlayerUpdate calls that code everysecond. and what is the best way making it on OnPlayerUpdate
OnPlayerUpdate prevents you from moving totally, making a timer will make someone able to move for like a second then get TPed back, would do the trick but OnPlayerUpdate makes it more accurate.
Reply
#15

Good job, i was wondering how to freeze a player but still allow him to move the view, going to make a security camera application in the gamemode im helping out on
Reply
#16

Quote:
Originally Posted by Dudits
Посмотреть сообщение
OnPlayerUpdate prevents you from moving totally, making a timer will make someone able to move for like a second then get TPed back, would do the trick but OnPlayerUpdate makes it more accurate.
Often the people dont know what they doing OnPlayerUpdate. Like sometime array and cells. So i dont think is a good idea put this code on OnPlayerUpdate only beacuse you move 1 sec and TPed again. But i think that happen if someone got 200ms. I will do some tests about it.
Reply
#17

Quote:
Originally Posted by Anthony_prince
Посмотреть сообщение
Often the people dont know what they doing OnPlayerUpdate. Like sometime array and cells. So i dont think is a good idea put this code on OnPlayerUpdate only beacuse you move 1 sec and TPed again. But i think that happen if someone got 200ms. I will do some tests about it.
It prevents you from moving totally and allows you to be shot, making a 1 sec timer will making shooting the freezed person harder, can be used for tazers or tying someone you know..
Reply
#18

It's an extremely common misconception that OnPlayerUpdate should only be used for single lines of code - which is generally wrong. As long as you don't abuse intensive functions inside the callback, you're fine - and you should refine your code to be as minimal as possible, but I'd generally say the amount of code in the callback here is pretty much fine...

Anyhow, what's "better" about this? And what is this in comparison to?
Reply
#19

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
It's an extremely common misconception that OnPlayerUpdate should only be used for single lines of code - which is generally wrong. As long as you don't abuse intensive functions inside the callback, you're fine - and you should refine your code to be as minimal as possible, but I'd generally say the amount of code in the callback here is pretty much fine...

Anyhow, what's "better" about this? And what is this in comparison to?
Fully agree with you.
Reply
#20

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
It's an extremely common misconception that OnPlayerUpdate should only be used for single lines of code - which is generally wrong. As long as you don't abuse intensive functions inside the callback, you're fine - and you should refine your code to be as minimal as possible, but I'd generally say the amount of code in the callback here is pretty much fine...

Anyhow, what's "better" about this? And what is this in comparison to?
Here's a very simple comparison.

TogglePlayerControllable.......................... ..........Better Freezing System

Prevents camera movement................................Allows camera movement
Prevents health/armor drain....(When being shot)....Allows health/armor drain
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)