31.10.2010, 16:37
(
Последний раз редактировалось Kwarde; 01.11.2010 в 06:27.
Причина: Some BBcode wrong ([b][/pawn) + End Script Error (line 27) fixed
)
Hi!
I'm bored, so I've decided to make a tutorial: How do you make your own SIMPLE anti-cheat system
This anti-cheat system includes:
- Anti Money Cheat
- Anti Weapon Cheat
It isn't supposed to use as an filterscript. It's recommended to use it in your gamemode (you need to integrate it -> Or you can make an include
Whatever. First we're gonna begin at the top of the script.
We only need the "a_samp" include (the standard stuff for PAWN scripting)
If you didn't know you must do that, I recommend you to learn scripting :P (TIP: https://sampforum.blast.hk/showthread.php?tid=177490 )
Whatever. We're gonna use the 'COLOR_RED' define (Just the red color for showing messages).
The code for it is: 0xFF0000AA (I am always using 'AA' at the end: It makes standard colors better). And whatever, you need to place that under #include <a_samp>:
Now we are gonna make the variable for the money cheat: pMoney[playerid]. The anti cheat system will work like this: If the player has more money then the string says, he'll be banned
Place the following code under the COLOR_RED define:
Ok. That wasn't very hard, was it? (If it was hard, I really recommend you to learn scripting (A) )
So we now have: The a_samp include: Basic script stuff, the COLOR_RED define: for showing messages in red color, and the pMoney[playerid]: for the money cheat detector.
We're now gonna use the 'OnPlayerConnect' and the 'OnPlayerDisconnect' callbacks. This will only set the pMoney string of the player to '0'. This is to prevent eventually bugs (loosing connection)
That was easy... again!
And now there'll come one of the important things (everything was important... nvm)
We're gonna check if the player has more money then the string (money cheat!) (I'll do the anti weapon cheat later.. Just scroll down)
It seems like this: if("Money that the player currently has" "is more then" "the pMoney string") //Ban the player
To get the money that a player has, use: GetPlayerMoney(playerid);. For the 'Is more then' you use '>' . You will have this:
And now.. Where to put it? In OnPlayerUpdate ofcourse! We don't use the laggy timers
The OnPlayerUpdate will detect updates of a player (switching weapon... getting less/more money.. etc...)
In the callback, we'll make a "string" again: pName[playerid]. This is for the player's name. And a 'string[128]' to show the message. Call the player name with: GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
Here'll come the whole script:
Easy :O
But about the pMoney[playerid]. Does this mean, when you use "GivePlayerMoney" that the player will be banned? The answer is: YES
That's why we aren't going to use "GivePlayerMoney". We're gonna make our own function: a_GivePlayerMoney.
What this function does: Give's the player money, and it will increase the 'money' in the string (just a number)
I'll give it:
I told you it was easy! And simple. That's why the topic's title is: ~~~ own SIMPLE ~~~
You can make your own a_SetPlayerMoney of course. Here it is:
That was the anti money cheat system!
Now the anti weapon cheat system! [b]NOTE: You need to give your own forbidden weapon ID's. I only'll forbid the minigun, the RPG and the heatseeking RPG
We already have the "#include <a_samp>" and the "#define COLOR_RED 0xFF0000AA".
We are gonna make a array string, with the weapon ID's you don't want ingame!
Eaaasy
Now we only need the "OnPlayerUpdate". We still have got the 'pName' and the 'string'. We are gonna make an 'w' too : 'new w = 0;'. That's all
What we're gonna do is the next: We are gonna look if the player got a weapon ID that is in the 'ForbiddenWeapons' array. We're gonna use the function while: while(w < (sizeof(ForbiddenWeapons))){
That's not all. We need to check if the player've got a weapon ID from it, using 'GetPlayerWeapon'. If the weapon ID is "w" the player will be banned.
Here it is:
And that was the anti weapon cheat script! You can make it MUCH better of course, but this is just a basic.
Now, here's the whole script, it should look like this (without the comments)
Good luck with it
Maybe I'll add more soon.
Kind Regards,
Kevin aka Kwarde
I'm bored, so I've decided to make a tutorial: How do you make your own SIMPLE anti-cheat system
This anti-cheat system includes:
- Anti Money Cheat
- Anti Weapon Cheat
It isn't supposed to use as an filterscript. It's recommended to use it in your gamemode (you need to integrate it -> Or you can make an include
Whatever. First we're gonna begin at the top of the script.
We only need the "a_samp" include (the standard stuff for PAWN scripting)
pawn Код:
#include <a_samp>
Whatever. We're gonna use the 'COLOR_RED' define (Just the red color for showing messages).
The code for it is: 0xFF0000AA (I am always using 'AA' at the end: It makes standard colors better). And whatever, you need to place that under #include <a_samp>:
pawn Код:
#define COLOR_RED 0xFF0000AA
Place the following code under the COLOR_RED define:
pawn Код:
new pMoney[MAX_PLAYERS];
So we now have: The a_samp include: Basic script stuff, the COLOR_RED define: for showing messages in red color, and the pMoney[playerid]: for the money cheat detector.
We're now gonna use the 'OnPlayerConnect' and the 'OnPlayerDisconnect' callbacks. This will only set the pMoney string of the player to '0'. This is to prevent eventually bugs (loosing connection)
pawn Код:
public OnPlayerConnect(playerid)
{
pMoney[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid) //Or: OnPlayerDisconnect(playerid, reason)
{
pMoney[playerid] = 0;
return 1;
}
And now there'll come one of the important things (everything was important... nvm)
We're gonna check if the player has more money then the string (money cheat!) (I'll do the anti weapon cheat later.. Just scroll down)
It seems like this: if("Money that the player currently has" "is more then" "the pMoney string") //Ban the player
To get the money that a player has, use: GetPlayerMoney(playerid);. For the 'Is more then' you use '>' . You will have this:
pawn Код:
if(GetPlayerMoney(playerid) > pMoney[playerid]) //Ban the player
The OnPlayerUpdate will detect updates of a player (switching weapon... getting less/more money.. etc...)
In the callback, we'll make a "string" again: pName[playerid]. This is for the player's name. And a 'string[128]' to show the message. Call the player name with: GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
Here'll come the whole script:
pawn Код:
public OnPlayerUpdate(playerid) //The player changed something
{
new pName[MAX_PLAYER_NAME], string[128]; //I already explained it. Too much explaination for one line
if(GetPlayerMoney(playerid) > pMoney[playerid]) //The player has more money then the string says (more 'bout that later)
{
GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Will get the player's name
format(string, sizeof(string), "* %s has been banned: MONEY CHEAT", pName); //Format's a script: "* 'pName' has been banned: MONEY CHEAT"
SendClientMessageToAll(COLOR_RED, string); //Send an message to ALL the active players with the formatted string: "* 'pName' has been banned: MONEY CHEAT" in an RED COLOR
BanEx(playerid, "Money Cheat"); //Bans the player with the reason "Money Cheat"
}
return 1;
}
But about the pMoney[playerid]. Does this mean, when you use "GivePlayerMoney" that the player will be banned? The answer is: YES
That's why we aren't going to use "GivePlayerMoney". We're gonna make our own function: a_GivePlayerMoney.
What this function does: Give's the player money, and it will increase the 'money' in the string (just a number)
I'll give it:
pawn Код:
stock a_GivePlayerMoney(playerid, money)
{
pMoney[playerid] += money; //Will increase the string: "+="
GivePlayerMoney(playerid, money); //Give's the player money... DUH :P Don't use "a_GivePlayerMoney" here.
}
You can make your own a_SetPlayerMoney of course. Here it is:
pawn Код:
stock a_SetPlayerMoney(playerid, money)
{
pMoney[playerid] = money; //Will set the string to the money ammount
ResetPlayerMoney(playerid); //Reset's player money
GivePlayerMoney(playerid); //Will give the player money. no a_GivePlayerMoney needed!
}
Now the anti weapon cheat system! [b]NOTE: You need to give your own forbidden weapon ID's. I only'll forbid the minigun, the RPG and the heatseeking RPG
We already have the "#include <a_samp>" and the "#define COLOR_RED 0xFF0000AA".
We are gonna make a array string, with the weapon ID's you don't want ingame!
pawn Код:
new ForbiddenWeapons[][] = {
38, //Minigun
35, //RPG
36 //Heatseeking RPG
};
Now we only need the "OnPlayerUpdate". We still have got the 'pName' and the 'string'. We are gonna make an 'w' too : 'new w = 0;'. That's all
What we're gonna do is the next: We are gonna look if the player got a weapon ID that is in the 'ForbiddenWeapons' array. We're gonna use the function while: while(w < (sizeof(ForbiddenWeapons))){
That's not all. We need to check if the player've got a weapon ID from it, using 'GetPlayerWeapon'. If the weapon ID is "w" the player will be banned.
Here it is:
pawn Код:
public OnPlayerUpdate(playerid)
{
new w = 0;
while(w < (sizeof(ForbiddenWeapons))){ //Loop through the weapon ID's in the ForbiddenWeapons array
if(GetPlayerWeapon(playerid) == w){ //Does the player has a wapon that's in the array? Then...
GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get player name
format(string, sizeof(string), "* %s has been banned: WEAPON CHEAT", pName); //Format's a script: "* 'pName' has been banned: WEAPON CHEAT"
SendClientMessageToAll(COLOR_RED, string); //Send an message to ALL the active players with the formatted string: "* 'pName' has been banned: WEAPON CHEAT" in an RED COLOR
BanEx(playerid, "Weapon Cheat"); //Bans the player with the reason "Weapon Cheat"
}
return 1;
}
Now, here's the whole script, it should look like this (without the comments)
pawn Код:
#include <a_samp>
#define COLOR_RED 0xFF0000AA
new pMoney[MAX_PLAYERS];
new ForbiddenWeapons[][] = {
38,
35,
36
};
public OnPlayerConnect(playerid)
{
pMoney[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
pMoney[playerid] = 0;
return 1;
}
public OnPlayerUpdate(playerid)
{
new pName[MAX_PLAYER_NAME],
w = 0,
string[128];
if(GetPlayerMoney(playerid) > pMoney[playerid]){
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string), "* %s has been banned: MONEY CHEAT", pName);
SendClientMessageToAll(COLOR_RED, string);
BanEx(playerid, "Money Cheat");
}
while(w < (sizeof(ForbiddenWeapons))){
if(GetPlayerWeapon(playerid) == w){
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string), "* %s has been banned: WEAPON CHEAT", pName);
SendClientMessageToAll(COLOR_RED, string);
BanEx(playerid, "Weapon Cheat");
}
}
return 1;
}
stock a_GivePlayerMoney(playerid, money)
{
pMoney[playerid] += money;
GivePlayerMoney(playerid, money);
}
stock a_SetPlayerMoney(playerid, money)
{
pMoney[playerid] = money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, money);
}
Maybe I'll add more soon.
Kind Regards,
Kevin aka Kwarde