[HowTo] Activate Variable W/ PassWord.
#1

Indtroduction
Allright, so, i've seen topics before, where some people ask how to make for an example, a skin 'passworded' or, make simple passwords that logs you in as an administrator. (i asked that question alot before :P), so i decided, now that i realise how to do so, i could might aswell share some of it for those in need.

Target / Goal.
The Goal of this tutorial is to teach you how to create custom variables which you could use to restrict either commands, or skins, or anything you would like, as long as it can be scripted in PAWN of course.

Let's Begin.
Ok, so let's get started shall we.?

Part I: Creating a New .PWN file.
Okay, now, open up Pawno.exe, (note: if you are a vista user, you should Open As Administrator to skip the Error messages.), after opening up Pawno, you should either open a Already existing script (pre-made), or you could create your own new script, how to do so, look in the top left corner, it says: "File", press it, and you will see New, and Open, along with some other stuff, now choose what you wish to do.

Now go to line ONE, and enter this


pawn Код:
#include <a_samp>
This will load all the Natives & Functions and all the stuff inside of that file. Making it possible to script SA:MP servers. , After doing this, go to part II.

Part II: Creating the Variables.
Allright, you have opened a script, and you are ready to modify, so let's start out by finding out what we want our variable to be named, hmm... AdminPW? or SkinPW?, i'll pick this time, you will pick next time. So, let's create the variable.

Scroll down some lines, and enter this code:


pawn Код:
new Admin[MAX_PLAYERS]; // this is the ADMIN variable itself, this will be needed when you are asking for the player's Admin status. (I.E if (Admin[playerid] == 0) return 1; )
new AdminPW = 1234; // this is the password you will be asking for later. OF COURSE, you can change it. :P
There, you have now defined the 2 variables that is needed to complete this tutorial. Go to part III.

Part III: Creating the Command. /AUTH.
So, after doing the Variables, you are ready to perform the Command coding, now, to do this, you must have defined DCMD, you will be able to find that code on the SA:MP wiki, by searching for "fast command".

Let's jump some lines down, and create our public function; OnPlayerCommandText.


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(auth, 4, cmdtext); // this will add the /auth command to the CommandText processor. So once you execute it, the script will understand what to do with it.
    return 1; // returning a true value.
}
You have created the OnPlayerCommandText function now, you are ready to do the final lines of this tutorial, by now, you have: Made Custom Vars, Defined DCMD, Added /Auth To Be Processed. Go to Part IV for the final lines.

Part IV: The Final Lines. /Dun Duun Duuun!
Allright! you're almost done. Now all you need to do, is to jump some lines down, (not inside the OnPlayerCommandText) but outside of it. When you have skipped some lines and are ready for the code, insert this. :

pawn Код:
dcmd_auth(playerid, params[])
{
    if (!strlen(params)) return SendClientMessage(playerid, 0xFFFFFFAA ,"Error: No Input."); // this will scan the player's parameters (params), if he didn't put anything after the /auth, it will send him a message telling him he did not put an Input.
    if(strval(params) != AdminPW) return SendClientMessage(playerid, 0xFFFFFFAA ,"Error: Wrong Input."); // now we will scan the length of his parameters, and if they did not match the AdminPW Variable, it will send him a message telling him he did not write the correct password (input).
    {
        Admin[playerid] = 1; // this is if his parameters were correct, it will activate the ADMIN Variable, giving him Administrator status.
        SendClientMessage(playerid, 0xFFFFFFAA,"You Have Logged As: Admin."); // sending him a little message saying HAI UR NAO ADMIN.
    }
    return 1; // this just returns a true value.
}
If things goes as planned in this tutorial everything should be fine, if it didnt, well, you can post your problems here, i shall check it from time to time. Congratulations, you have finished this tutorial.

Reply
#2

Very good & nice
Reply
#3

Quote:
Originally Posted by russiany
Very good & nice
Thanks mate. Hope you learned something .
Reply
#4

This will only work if the password is composed of solely numbers.
Reply
#5

Why use strval? You could use strcmp and then the password could be numbers, letters, ascii characters...
Reply
#6

Quote:
Originally Posted by Weirdosport
Why use strval? You could use strcmp and then the password could be numbers, letters, ascii characters...
Well, i just never did that, only did it this way .
Reply
#7

thanks, for tutorial! i'll definitely use it!
Reply
#8

Here is the documentation if you would like to adapt it. Remember, the parameters with equal signs are OPTIONAL.

strcmp(const string1[], const string2[], bool: ignorecase=false, length=cellmax)

string1 - The first string in the comparison.
string2 - The first string in the comparison.
ignorecase - If logically “true”, case is ignored during the comparison.
length - The maximum number of characters to consider for comparison.

The return value is:
−1 if string1 comes before string2,
1 if string1 comes after string2, or
0 if the strings are equal (for the matched length).
Reply
#9

Quote:
Originally Posted by samgreen
Here is the documentation if you would like to adapt it. Remember, the parameters with equal signs are OPTIONAL.

strcmp(const string1[], const string2[], bool: ignorecase=false, length=cellmax)

string1 - The first string in the comparison.
string2 - The first string in the comparison.
ignorecase - If logically “true”, case is ignored during the comparison.
length - The maximum number of characters to consider for comparison.

The return value is:
−1 if string1 comes before string2,
1 if string1 comes after string2, or
0 if the strings are equal (for the matched length).
So something along with this?

I removed the AdminPW because you could just use the STRCMP line for both the password and the variable?

pawn Код:
dcmd_auth(playerid, params[])
{
    if (!strlen(params)) return SendClientMessage(playerid, COLOR_MSG ,"Error: No Input.");
    if(strcmp(params, "testpass", true))
    {
        Admin[playerid] = 1;
        SendClientMessage(playerid, COLOR_MSG,"You Have Logged As: Admin.");
        SendClientMessage(playerid, COLOR_MSG,"/Kick(id), /Ban(id), /Slap(id), Launch(id),/Explode(id)");
        SendClientMessage(playerid, COLOR_MSG,"/Goto(id), /Get(id), /Stfu(id),");
    }
    return 1;
}
?
Reply
#10

Quote:
Originally Posted by sbґ
So something along with this?

I removed the AdminPW because you could just use the STRCMP line for both the password and the variable?

pawn Код:
dcmd_auth(playerid, params[])
{
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_MSG ,"Error: No Input.");

  if(strcmp(params, "testpass", true) == 0)
  {
    Admin[playerid] = 1;
    SendClientMessage(playerid, COLOR_MSG,"You Have Logged As: Admin.");
    SendClientMessage(playerid, COLOR_MSG,"/Kick(id), /Ban(id), /Slap(id), Launch(id),/Explode(id)");
    SendClientMessage(playerid, COLOR_MSG,"/Goto(id), /Get(id), /Stfu(id),");
  }

  return 1;
}
Very close! Watch your return values, remember the function returns zero if the strings are equal. You were correct in removing the additional password declaration, and just using strcmp.

I changed the fourth line if you are having difficulty finding the alteration.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)