SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 11/11/2010, 11:56 PM   #1
Jacob_Venturas
Big Clucker
 
Jacob_Venturas's Avatar
 
Join Date: Nov 2010
Posts: 78
Reputation: 0
Default How to Use Variables to Prevent Abuse

Hello, this is quick tutorial I decided to write because I like to write tutorials. This tutorial will teach you how to use variables to prevent abuse of a command, or restrict a command from other players.


So, first of all, we need to chose a variable name. You can easily do this by choosing anything that relates to the variables role as the name. Mine will be "RestrictCommand1" for I am restricting some players from using the first command in my script. Lets make this variable.
At the top of my script, below the includes, I will add:
pawn Code:
new RestrictCommand1[MAX_PLAYERS];


Now, we will make a command and in this command we will make sure that whoever has this variable set equal to 1, we will allow them to use the command.
pawn Code:
if(!strcmp("/givememoney", cmdtext, true)
{
     if(RestrictCommand1[playerid] == 1) //so if this equals one they're allowed to use it
     {
              GivePlayerMoney(playerid, 50000);  //this is what they are allowed to have/use
      }
      else
      {
               Kick(playerid);    //since they aren't allowed to use this, we'll kick them
      }
      return 1;
}


Now, we can easily set their variable by one or more to make sure they can use that command above by just typing anywhere in your script:
pawn Code:
RestrictCommand1[playerid] = 1;
or if we don't want them to use it after they used it:
pawn Code:
RestrictCommand1[playerid] = 0;

Hopefully this helps some people!
Jacob_Venturas is offline   Reply With Quote
Old 11/11/2010, 11:58 PM   #2
The_Moddler
High-roller
 
The_Moddler's Avatar
 
Join Date: Jan 2010
Location: In my house.
Posts: 1,130
Reputation: 3
Default Re: How to Use Variables to Prevent Abuse

Well, very basic, also, for this types of things, it's better to use booleans, since they are only true or false, and they don't get messed up.

Also, this:

pawn Code:
if (strcmp("/givemeadmin", cmdtext, true, 10) == 0)

Should be:

pawn Code:
if(!strcmp("/givemeadmin", cmdtext, true)
__________________
The_Moddler is offline   Reply With Quote
Old 12/11/2010, 12:00 AM   #3
Hal
High-roller
 
Hal's Avatar
 
Join Date: May 2010
Location: Toronto, Canada
Posts: 1,170
Reputation: 43
Default Re: How to Use Variables to Prevent Abuse

But this just disables the whole command. And to prevent abuse, use if statements such as if(IsPlayerAdmin to prevent 'abuse', but allow a certain player to still use the command.

This should be for disabling commands.
__________________

Wanna start a project thats NOT sa-mp with me? I have a bunch of server space, PM me.
Hal is offline   Reply With Quote
Old 12/11/2010, 12:01 AM   #4
Jacob_Venturas
Big Clucker
 
Jacob_Venturas's Avatar
 
Join Date: Nov 2010
Posts: 78
Reputation: 0
Exclamation Re: How to Use Variables to Prevent Abuse

Quote:
Originally Posted by The_Moddler View Post
Well, very basic, also, for this types of things, it's better to use booleans, since they are only true or false, and they don't get messed up.

Also, this:

pawn Code:
if (strcmp("/givemeadmin", cmdtext, true, 10) == 0)

Should be:

pawn Code:
if(!strcmp("/givemeadmin", cmdtext, true)
Wow, now I think using true or false is better, but GodFather has taught me to use numerical values. I should start using boolean, since I am always getting mixed up and causing so many bugs! Thanks.

Quote:
Originally Posted by Hal View Post
But this just disables the whole command. And to prevent abuse, use if statements such as if(IsPlayerAdmin to prevent 'abuse', but allow a certain player to still use the command.

This should be for disabling commands.
I think you're quite retarded, sir, especially from seeing your last response to my post you made. See, what I am doing is restricting the command to be used by others, unless they have there variable set at one. Of course this command will be disabled for some, or maybe all because they don't have their variables set to 1. Please, read my posts before you start accusing me of false problems in my tutorials.
Jacob_Venturas is offline   Reply With Quote
Old 12/11/2010, 12:11 AM   #5
Steven82
High-roller
 
Join Date: Nov 2009
Posts: 2,431
Reputation: 186
Default Re: How to Use Variables to Prevent Abuse

This is very simple, i would of thought even basic .pawn scripters would know this..oh well good job i guess

6/10 maybe just 5/10
__________________
If you read my old posts; I apologize in advance.
Steven82 is offline   Reply With Quote
Old 12/11/2010, 12:26 AM   #6
Hal
High-roller
 
Hal's Avatar
 
Join Date: May 2010
Location: Toronto, Canada
Posts: 1,170
Reputation: 43
Default Re: How to Use Variables to Prevent Abuse

Quote:
Originally Posted by Jacob_Venturas View Post
I think you're quite retarded, sir, especially from seeing your last response to my post you made. See, what I am doing is restricting the command to be used by others, unless they have there variable set at one. Of course this command will be disabled for some, or maybe all because they don't have their variables set to 1. Please, read my posts before you start accusing me of false problems in my tutorials.
Just unneeded variables that can be replaced with more specific ones.

Don't try to flame me by calling me retarded, you will just loose in a flame war.

Quote:
tutorials.
Correction- Tutorial*
__________________

Wanna start a project thats NOT sa-mp with me? I have a bunch of server space, PM me.
Hal is offline   Reply With Quote
Old 12/11/2010, 05:42 AM   #7
Jacob_Venturas
Big Clucker
 
Jacob_Venturas's Avatar
 
Join Date: Nov 2010
Posts: 78
Reputation: 0
Default Re: How to Use Variables to Prevent Abuse

Quote:
Originally Posted by Steven82 View Post
This is very simple, i would of thought even basic .pawn scripters would know this..oh well good job i guess

6/10 maybe just 5/10
Some basic scripters don't know how to use variables at all. I also said I wanted to write a tutorial because I like to write tutorials. Thanks for the rating but this isn't a contest to see whose tutorial is the best on here.

Quote:
Originally Posted by Hal View Post
Just unneeded variables that can be replaced with more specific ones.

Don't try to flame me by calling me retarded, you will just loose in a flame war.


Correction- Tutorial*
Thank you for your comments. Leave this thread, retard.
Jacob_Venturas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Player Variables vs Normal Variables. Carlton Tutorials 24 09/09/2016 07:19 PM
Global variables or Local variables armyoftwo Help Archive 3 02/10/2010 04:45 PM
Abusers live to abuse. BP13 Help Archive 14 04/03/2010 07:25 AM
Prevent spawning JulesGraus Help Archive 2 12/12/2009 03:31 PM
/handsup abuse killar456 Help Archive 2 13/05/2009 06:49 PM


All times are GMT. The time now is 04:06 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.