[Tutorial] Login+Register System / Strcmp and ZCMD Commands / Random Messages - Explained !
#1

Introduction
This is my second tutorial at Forum SAMP and hope you all like it.

Content
1) LOGIN+REGISTER system YINI+WHIRLPOOL explained !
2) RANDOM MESSAGES explained !
3) SIMPLE COMMANDS ZCMD and STRCMP explained !

pawn Code:
// ========================================================================
// LOGIN REGISTER SYSTEM Y_INI + WHIRLPOOL explained !
// SIMPLE COMMAND USING STRCMP and ZCMD explained !
// RANDOM MESSAGES explained !
// Credits : Giroud12
// Contact : *******/mrzackysevenfold or forum.sa-mp.com/member.php?u=198770
// Any typo? mistake? bug? and blablabla? please inform to me
// Same as newbienoob tutorial but this explained more thing such as......
// Why do you need to learn from this tutorial?
// 1)lol, why not 2)explained login + register 3)will help newbie
// 4)explained simple commands 5)random message explained
// 6)because this is tutorial 7)will help you to improve your knowledge
// Any suggestion for updates? Just post it :)
// More commands will add in the next update
// ========================================================================
// Pawn compiler 3.2.3664           Copyright © 1997-2006, ITB CompuPhase
// ========================================================================

#include < a_samp >
// credits to Team SAMP
// you need to put this in any script that related to SAMP !!
#include < zcmd >
// credits to ZeeX
// for command
#include < YSI\y_ini >
// credits to Alex Cole aka Y_Less
// this is for LOGIN REGISTER system

native WP_Hash(buffer[],len,const str[]);
// this is whirlpool native
// for hashing

#define as FILTERSCRIPT
// this will define it as filterscript
#define X                         My Server
// this will define "X" to "My Server"
// it means "#X" is same with "My Server"
// I make it short

#define USE_ZCMD_COMMANDS         true  // true / false
#define USE_STRCMP_COMMANDS       false // true / false
// if you make this two define true, the command will not 100% works

#define RED                       0xAA3333AA
#define YELLOW                    0xFFFF00AA
#define PURPLE                    0x9370DBFF
// this is the colour defines, it use when send message

#define DIALOG_REGISTER           2011
#define DIALOG_LOGIN              2012
// this is the dialog define, I put 2011/2012 to prevent the dialog will mix

#define UserPath                  "Users/%s.ini"
// here is the userpath that will be use in saving player data
// "Users" is name of a folder that you need to put in "scriptfiles" folder
// You can change "Users" to any name you want

enum PlayerInfo
{
    Pass[129],
    // pass
    Adminlevel,
    // adminlevel
    VIPlevel,
    // viplevel
    Money,
    // money/cash
    Scores,
    // scores
    Kills,
    // kills
    Deaths
    // deaths
}
// all this enum will be use in saving players data
new pInfo[MAX_PLAYERS][PlayerInfo];
// make the script short/new variable that can be use

new RandomMSG[][] =
{
    "Welcome To "#X" server v0.3x",
    "Visit our website at forum.sa-mp.com",
    "Play fair and dont cheating/hacking",
    "Cheating/hacking will cause you kick/ban"
    // above is all random messages, last random messages dont need to put ","
    // edit or add more if you want
};


stock Path(playerid)
// create new stock for load the user data
{
    new str[128],name[MAX_PLAYER_NAME];
    // new string and name variable
    GetPlayerName(playerid,name,sizeof(name));
    // get player name
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
// forward new function of loadaccount_user
public loadaccount_user(playerid, name[], value[])
// public for loadaccount_user
{
    INI_String("Password", pInfo[playerid][Pass],129);
    // this is a password so we use INI_STRING
    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);
    // this an AdminLevel so we use INI_INT Info:
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);
    // same like above
    INI_Int("Money",pInfo[playerid][Money]);
    // same like above
    INI_Int("Scores",pInfo[playerid][Scores]);
    // same like above
    INI_Int("Kills",pInfo[playerid][Kills]);
    // same like above
    INI_Int("Deaths",pInfo[playerid][Deaths]);
    // same like above
    return 1;
}

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print("TUTORIAL BY GIROUD12 loaded !");
    print("--------------------------------------\n");
    // this will shown in samp-server.exe
    SetTimer("SendMSG", 1000*60*2, true);
    // the timer for random message
    // the timer will send the random message in 2 minutes
    return 1;
}

public OnFilterScriptExit()
{
    print("\n----------------------------------");
    print("TUTORIAL BY GIROUD12 unloaded !");
    print("----------------------------------\n");
    // this will shown in samp-server.exe
    return 1;
}

forward SendMSG();
// forward to send the random messages
public SendMSG()
// new public for send the random messages
{
    new randMSG = random(sizeof(RandomMSG));
    // new randMSG = the random messages that we write
    SendClientMessageToAll(YELLOW, RandomMSG[randMSG]);
    // will send the random messages
}

public OnPlayerConnect(playerid)
// when player connect
{
    new name[MAX_PLAYER_NAME], str[128];
    // new variable called "name"
    GetPlayerName(playerid,name,sizeof(name));
    // get player name
    format(str, sizeof(str), "Welcome %s to "#X" server v0.3x", name);
    SendClientMessage(playerid, YELLOW, str);
    // will send player welcome message
    if(fexist(Path(playerid)))
    // check the player registered or not
    {
        INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid);
        // load user data
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");
        // if they registered, show login dialog
    }
    else
    {
        ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        // if they not register, show register dialog
        return 1;
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
// when player response to dialog
{
    if(dialogid == DIALOG_REGISTER)
    // if dialog id is register dialog
    {
        if(!response) return Kick(playerid);
        // if they click 2nd button, then automatically they will be kicked
        if(response)
        // if they click 1st button
        {
            if(!strlen(inputtext))
            // if they didnt put password
            {
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                // show register dialog
                return 1;
            }
            // if they succesfull put their new password
            new hashpass[129];
            // new variable for hashing
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            // whirlpool will has their password
            new INI:file = INI_Open(Path(playerid));
            // open new file to save their data
            INI_SetTag(file,"Player's Data");
            // set title in the player data file
            INI_WriteString(file,"Password",hashpass);
            // this will right the hashed password
            INI_WriteInt(file,"AdminLevel",0);
            // set his admin level to 0 when he registered
            INI_WriteInt(file,"VIPLevel",0);
            // same like above
            INI_WriteInt(file,"Money",0);
            // same like above
            INI_WriteInt(file,"Scores",0);
            // same like above
            INI_WriteInt(file,"Kills",0);
            // same like above
            INI_WriteInt(file,"Deaths",0);
            // same like above
            INI_Close(file);
            // will close file
            SendClientMessage(playerid,YELLOW,"You have been successfully registered");
            // send player message that they sucessfully registered
        }
    }
    if(dialogid == DIALOG_LOGIN)
    // if dialog id is dialog login
    {
        if(!response) return Kick(playerid);
        // if they click 2nd button, then automatically they will be kicked
        if(response)
        // if they kicked 1st button
        {
            new hashpass[129];
            // new variable to hashing
            WP_Hash(hashpass,sizeof(hashpass),inputtext);
            // whirlpool will hash their password
            if(!strcmp(hashpass,pInfo[playerid][Pass]))
            // if they insert correct password
            {
                INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);
                // this will load player data
                SetPlayerScore(playerid,pInfo[playerid][Scores]);
                // will set his score to the score in their files
                GivePlayerMoney(playerid,pInfo[playerid][Money]);
                // same as above
                SendClientMessage(playerid,YELLOW,"Welcome back! You have successfully logged in");
                // send player message that they have succesfully login
            }
            else
            // if they put the wrong password
            {
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                // show login dialog
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
        new INI:file = INI_Open(Path(playerid));
        // open their file
        INI_SetTag(file,"Player's Data");
        // set the title in player dile
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]);
        // get latest adminlevel
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);
        // same as above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
        // same as above
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
        // same as above
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
        // same as above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
        // same as above
        INI_Close(file);
        // close file
        return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;
    // will add 1 kill to the killer
    pInfo[playerid][Deaths]++;
    // will add 1 death to the dead player
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    #if USE_STRCMP_COMMANDS == true
    // if u make it true on top of the script
    if (strcmp("/kill", cmdtext, true, 4) == 0)
    {
        if(GetPlayerMoney(playerid) <1000) return SendClientMessage(playerid,RED, "ERROR: You don't have $1000 !");
        // if player money below 1000 then it will send player message
        SetPlayerHealth(playerid, 0.0);
        // set player health to 0/die
        SendClientMessage(playerid, RED, "You just killed yourself");
        // send player message
        SendClientMessageToAll(RED, "Someone using /kill and kill him/herself and paid $1000 !");
        // send message to all player in server
        GivePlayerMoney(playerid, -1000);
        // minus 1000 from player money
        return 1;
    }
    if (strcmp("/heal", cmdtext, true, 4) == 0)
    // /heal is the command/4 is how many letter in the command/true is to make the command work
    {
        if(GetPlayerMoney(playerid) <500) return SendClientMessage(playerid,RED, "ERROR: You don't have $500 !");
        // if player money below 500 then it will send player message
        SetPlayerHealth(playerid, 100.0);
        // set player health to 100/full
        SendClientMessage(playerid, RED, "You just healed yourself");
        // send player message
        SendClientMessageToAll(RED, "Someone using /heal and heal him/herself and paid $500 !");
        // send message to all player
        GivePlayerMoney(playerid, -500);
        // minus -500 from player money
        return 1;
    }
    if (strcmp("/spawnme", cmdtext, true, 7) == 0)
    // /spawnme is the command/7 is how many letter in the command/true is to make the command work
    {
        SpawnPlayer(playerid);
        // spawn player
        SendClientMessage(playerid, RED, "You have been spawned");
        // send player message
        return 1;
    }
    if (strcmp("/kickme", cmdtext, true, 6) == 0)
    // /kickme is the command/6 is how many letter in the command/true is to make the command work
    {
        SendClientMessageToAll(RED, "1 of the player has been kicked | Reason: He/She want it");
        // send message to all player in server
        Kick(playerid);
        // kick player
        return 1;
    }
    if (strcmp("/banme", cmdtext, true, 5) == 0)
    // /banme is the command/5 is how many letter in the command/true is to make the command work
    {
        SendClientMessageToAll(RED, "1 of the player has been banned | Reason: He/She want it");
        // send message to all player in server
        BanEx(playerid, "You're banned !");
        // send player message with ban player
        return 1;
    }
    if (strcmp("/godon", cmdtext, true, 5) == 0)
    // /godon is the command/5 is how many letter in the command/true is to make the command work
    {
        if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED,"ERROR: You are'nt Rcon Admin");
        // check if the player is rcon admin or not
        // if not it will send message
        SetPlayerHealth(playerid, 99999999999.0);
        // set player health to infinite
        SetPlayerArmour(playerid, 99999999999.0);
        // set player armour to infinite
        SendClientMessageToAll(RED, "Rcon Admin has turned on his God Mode");
        // send message to all player in server
        return 1;
    }
    if (strcmp("/godoff", cmdtext, true, 6) == 0)
    // /godon is the command/5 is how many letter in the command/true is to make the command work
    {
        if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED,"ERROR: You are'nt Rcon Admin");
        // check if the player is rcon admin or not
        // if not it will send message
        SetPlayerHealth(playerid, 100.0);
        // set player health to 100/full
        SetPlayerArmour(playerid, 100.0);
        // set player armour to 100/full
        SendClientMessageToAll(RED, "Rcon Admin has turned off his God Mode");
        // send message to all player in server
        return 1;
    }
    #endif
    // if you put #if so you need to put #endif to prevent errors
    return SendClientMessage(playerid, RED, "ERROR: Unknown Command");
    // if player make /troll but the command not exist in your server then it will send player message
}

#if USE_ZCMD_COMMANDS == true
// if u make it true on top of the script
CMD:kill(playerid, params[])
// the cmd is /kill
{
    if(GetPlayerMoney(playerid) <1000) return SendClientMessage(playerid,RED, "ERROR: You don't have $1000 !");
    // if player money below 1000 then it will send player message
    SetPlayerHealth(playerid, 0.0);
    // set player health to 0/die
    SendClientMessage(playerid, RED, "You just killed yourself");
    // send player message
    SendClientMessageToAll(RED, "Someone using /kill and kill him/herself and paid $1000 !");
    // send message to all player in server
    GivePlayerMoney(playerid, -1000);
    // minus 1000 from player money
    return 1;
}
CMD:heal(playerid, params[])
// the cmd is /heal
{
   if(GetPlayerMoney(playerid) <500) return SendClientMessage(playerid,RED, "ERROR: You don't have $500 !");
   // if player money below 500 then it will send player message
   SetPlayerHealth(playerid, 100.0);
   // set player health to 100/full
   SendClientMessage(playerid, RED, "You just healed yourself");
   // send player message
   SendClientMessageToAll(RED, "Someone using /heal and heal him/herself and paid $500 !");
   // send message to all player in server
   GivePlayerMoney(playerid, -500);
   // minus 500 from player money
   return 1;
}
CMD:spawnme(playerid, params[])
// the cmd is /spawnme
{
   SpawnPlayer(playerid);
   // spawn player
   SendClientMessage(playerid, RED, "You have been spawned");
   // send player message
   return 1;
}
CMD:kickme(playerid, params[])
// the cmd is /kickme
{
   SendClientMessageToAll(RED, "1 of the player has been kicked | Reason: He/She want it");
   // send player message
   Kick(playerid);
   // kick player
   return 1;
}
CMD:banme(playerid, params[])
// the cmd is /banme
{
   SendClientMessageToAll(RED, "1 of the player has been banned | Reason: He/She want it");
   // send player message
   BanEx(playerid, "You're banned !");
   // send player message and ban the player
   return 1;
}
CMD:godon(playerid, params[])
// the cmd is /godon
{
   if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED,"ERROR: You are'nt Rcon Admin");
   // check if the player is rcon admin or not
   // if not it will send message
   SetPlayerHealth(playerid, 99999999999.0);
   // set player health to infinite
   SetPlayerArmour(playerid, 99999999999.0);
   // set player armour to infinite
   SendClientMessageToAll(RED, "Rcon Admin has turned on his God Mode");
   // send message to all player in server
   return 1;
}
CMD:godoff(playerid, params[])
// the cmd is /godoff
{
   if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED,"ERROR: You are'nt Rcon Admin");
   // check if the player is rcon admin or not
   // if not it will send message
   SetPlayerHealth(playerid, 100.0);
   // set player health to 100/full
   SetPlayerArmour(playerid, 100.0);
   // set player armour to 100/full
   SendClientMessageToAll(RED, "Rcon Admin has turned off his God Mode");
   // send message to all player in server
   return 1;
}
#endif
// if you put #if so you need to put #endif to prevent errors

Last But Not Least

Any typo? error? bug? Please inform me.
Any problem? Post your problem here.
Reply
#2

nice
Reply
#3

Explaining it all into a script, is pretty stupid. In my opinion, but okay.
Reply
#4

Hahahah okey, tq for the comment
Reply
#5

nice rep+
Reply
#6

Thanks, im going to study this, i want to start learning to script so i feel this would be a good aide
Reply
#7

thx all
Reply
#8

....
Reply
#9

Thanks
Reply
#10

Good job!
Reply
#11

Great Job!! You did there
I agree with Swyft™ Explaining It in the script is Just Awful
It makes it harder to read and understand
+rep
Reply
#12

Awesome!! +reped
Reply
#13

nice tutorial
Really helped...
Reply
#14

its good but to much i easy just can copy all that. try better next time.
Reply
#15

very nice tutorial
Reply
#16

--delete--
Reply
#17

Very nice and helpfull.
Reply
#18

thx all
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)