SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 25/01/2017, 01:57 PM   #11
princejeet1510
Big Clucker
 
princejeet1510's Avatar
 
Join Date: Mar 2016
Location: Trying to figure it out.
Posts: 115
Reputation: 4
Default Re: Creating a simple register/save system using R41-2

Well were you there watching him when he was making tutorial and you guessed that it took 5 minutes?
Anyways lol I don't want to spam the thread....So let's keep it going..
__________________
princejeet1510 is offline   Reply With Quote
Old 25/01/2017, 01:59 PM   #12
GhostHacker9
Big Clucker
 
GhostHacker9's Avatar
 
Join Date: Jan 2017
Location: New Zealand
Posts: 105
Reputation: 109
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by princejeet1510 View Post
Well were you there watching him when he was making tutorial and you guessed that it took 5 minutes?
Anyways lol I don't want to spam the thread....So let's keep it going..
Well taking a look @ such an un optmised tutorial with less details its common sense to all that how much he took for this.
GhostHacker9 is offline   Reply With Quote
Old 25/01/2017, 02:03 PM   #13
oMa37
Gangsta
 
Join Date: Feb 2016
Posts: 968
Reputation: 155
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by princejeet1510 View Post
I would still just say good job yup there were some corrections to be made which you already did......
But I would say to oMa37 atleast he made the tutorial which I really haven't seen yet with a update....Why didn't you made that?
Why you didn't get idea on this topic earlier?
Why would I make this when there is a better version? I would say it's the best version, This one.
oMa37 is offline   Reply With Quote
Old 25/01/2017, 02:06 PM   #14
Quinncell
Guest
 
Posts: n/a
Default Re: Creating a simple register/save system using R41-2

Let me clear things up here since I can clearly see that people don't know how to write tutorials.

First off, I made the same mistake when I made my first tutorial so let's avoid calling me a 'hypocrite' here.

Alright, in my opinion, tutorials should be written by people who know everything there is to know about the subject of their tutorial. This section has been made so others can share their knowledge and let other users learn it as well but that has clearly went over board. People make tutorials for a lot of things except the one thing that is the purpose of this section, which is to transfer your knowledge onto others.

People write a lot of bad tutorials, and let me clear this out, making tutorials is really hard. It, however, depends on what kind of tutorial you're writing but it's not easy. People think it is easy and that's why there arent so many good tutorials out here. They got lost in these, don't even have a name for them.

Teaching other people isn't easy, and there are a lot of people that read these bad tutorials and gain false knowledge. That's why this has to stop!
No hate intended to anyone of course but 80% of the tutorials in this board are bad.

Of course, the things I wrote above wont be read by many people and this will still continue but if you did read it please consider it as an option.
  Reply With Quote
Old 25/01/2017, 02:08 PM   #15
Yaa
Banned
 
Join Date: May 2016
Location: = GetPlayerHouse("Yaa", 0.2);
Posts: 598
Reputation: 42
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by oMa37 View Post
Why would I make this when there is a better version? I would say it's the best version, This one.
did this tutorial work ? Yes.

did it's take so much cpu ? No.

so it's fine to use .

Also that GhostHacker just another noob come here to talk about optimizing and he not even know what is optimizing

@oMa37 stop it! it's just a file without any explaintion, i can do that just check my scripts at http://github.com/saplayground

and this is my first tutorial So ?

i was evading creating tutorial but i supposed to do after seeying a lots of ppl cannot update from R39-* to R41-2
Yaa is offline   Reply With Quote
Old 25/01/2017, 02:14 PM   #16
oMa37
Gangsta
 
Join Date: Feb 2016
Posts: 968
Reputation: 155
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by Yaa View Post
@oMa37 stop it! it's just a file without any explaintion, i can do that just check my scripts at http://github.com/saplayground
If you are blind that's not my problem mate.

EDIT:

With integers I meant also the %d specifiers.
oMa37 is offline   Reply With Quote
Old 25/01/2017, 02:28 PM   #17
GhostHacker9
Big Clucker
 
GhostHacker9's Avatar
 
Join Date: Jan 2017
Location: New Zealand
Posts: 105
Reputation: 109
Default Re: Creating a simple register/save system using R41-2

Okay Mr Pro scripter i will tell you what exactly is optmisation is.It is not actually reducing no of lines in a script.It how you hacks with compiler and machine.Also overdoing an optmisation is also bad programming do the optmisation where ever necessary and never should it compromise it with readability.
Lets take a tiny portion of your script.
Code:
public OnPlayerConnect(playerid) 
{ 
    new query[50], pname[MAX_PLAYERS_NAME]; 
    GetPlayerName(playerid, pname, sizeof(pname)); // gets player name on connect 
    mysql_format(MHandle, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e'", pname); 
    mysql_tquery(MHandle, query, "OnPlayerAccountCheck", "i", playerid); // in this step the server checks if player registered or not using the callback up ^^ 
    return 1; 
}
Now this
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
    switch(dialogid) 
    {    
        case Login: 
        { 
            static loginattemp, buf[129], pname[MAX_PLAYERS_NAME]; 
            GetPlayerName(playerid, pname, sizeof(pname)); 

            if(!response) Kick(playerid);  
            if(isnull(PlayerInfo[playerid][Password])) // checks if password correctly loaded else check below :) 
            { 
                SendClientMessage(playerid, -1,"[MYSQL]: Sorry, we have some problems on database right now, Come back later !"); 
                Kick(playerid); 
                print("[MYSQL]: Password Value 'PlayerInfo[playerid][Password]' not correctly loaded! please check OnPlayerAccountCheck callback"); 
                print("[SA-MP Server]: Server shutdown.."); 
                SendRconCommand("exit"); 
                return 1; 
            } 
            WP_Hash(buf, sizeof(buf), inputtext); 
            if(!strcmp(buf, PlayerInfo[playerid][Password], true)) // comparing the passwords (database & entrerd) 
            {  
                new query[70], Cache:GetCache; 
                mysql_format(MHandle, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", pname); 
                GetCache = mysql_query(MHandle, query); 
                
                // Importing data after beigning sure he is the right user 
                new rows;  
                cache_get_row_count(rows); 
                if(rows == 1)  
                { 
                    cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][Admin]);  
                    cache_get_value_name_int(0, "Deaths", PlayerInfo[playerid][Deaths]);  
                    cache_get_value_name_int(0, "Kills", PlayerInfo[playerid][Kills]); 
                } 
                SendClientMessage(playerid, -1, "You have successfully logged in.");  
                cache_delete(GetCache); 
            }  
            else // if he entred an wrrong password 
            {  
                if(loginattemp == 3) return Kick(playerid); // if he entred the same wrrong password 3 times he got kicked 
                SendClientMessage(playerid, -1, "You have specified an incorrect password!");  
                ShowPlayerDialog(playerid, Login, DIALOG_STYLE_PASSWORD, "Login", "Welcome Back !\nWe miss you here !\nPlease fill you password here to get stats back!", "Login", "Cancel"); 
                loginattemp++; // adding +1 for every attemp 
            }  
        } 
        case Register: 
        { 
            if(!response) return Kick(playerid);  
            if(strlen(inputtext) < 5)  
            {  
                SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");  
                return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_PASSWORD, "Register", "Welcome to our server! \nthis account not register at the database \nPlease fill a password to register your account", "Register", "Cancel"); 
            }  
            new  
                query[287],  
                playername[MAX_PLAYER_NAME],  
                playerip[16], 
                buf[129] 
            ; 
            WP_Hash(buf, sizeof(buf), inputtext); // hashing password using Whirlpool engine 
            GetPlayerName(playerid, playername, sizeof(playername));  
            GetPlayerIp(playerid, playerip, sizeof(playerip));  
            mysql_format(MHandle, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`,`Deaths`, `Kills`) VALUES ('%e', '%e', '%e', 0, 0, 0)", playername, buf, playerip);  
            mysql_query(MHandle, query); // here inserting the player account in the database as a registered player 
        } 
    } 
    return 0; 
}
You are creating 3 variables to hold the player name in 3 different situations thats just fucking stupidness.
if i were you i will do create an global array to hold the player name,if its thats case i will add it in player enum

Also take a look @ here

Code:
static loginattemp
what the hell? You know what you actually doing ? Your code never going to work even. The code will not allow any player to login if one of the player failed the attempt.Because you are using a static variable whose copy will be created only once in the stack.
Now you can use char arrays instead of plain arrays which will much more memory efficient.
Code:
array_name[size char];
i can go even more and you can get more chilled.
Needless to say 1 star from me.Keep trying.....
GhostHacker9 is offline   Reply With Quote
Old 25/01/2017, 02:33 PM   #18
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,083
Reputation: 2655
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by Yaa View Post
did this tutorial work ? Yes.

did it's take so much cpu ? No.

so it's fine to use .
That's not the point. A tutorial should teach the best method. People reading a tutorial assume that what you've written is the best method to achieve the desired result. I'm sure all that you've written here will work, but as long as you don't understand the concept of keys in SQL you shouldn't write an SQL related tutorial.
__________________
Vince is offline   Reply With Quote
Old 25/01/2017, 02:39 PM   #19
Yaa
Banned
 
Join Date: May 2016
Location: = GetPlayerHouse("Yaa", 0.2);
Posts: 598
Reputation: 42
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by GhostHacker9 View Post
Okay Mr Pro scripter i will tell you what exactly is optmisation is.It is not actually reducing no of lines in a script.It how you hacks with compiler and machine.Also overdoing an optmisation is also bad programming do the optmisation where ever necessary and never should it compromise it with readability.




Quote:
Originally Posted by GhostHacker9 View Post
^^ another bad habit a good programmer cares about data structure rather than code. Instead creating an overhead to this function every time its better to have per player array to hold name on connection and not to mention your database arrangement it also need to normalized.


kill me no ?


Quote:
Originally Posted by Vince View Post
That's not the point. A tutorial should teach the best method. People reading a tutorial assume that what you've written is the best method to achieve the desired result. I'm sure all that you've written here will work, but as long as you don't understand the concept of keys in SQL you shouldn't write an SQL related tutorial.
thank you
Yaa is offline   Reply With Quote
Old 25/01/2017, 02:42 PM   #20
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,949
Reputation: 504
Default Re: Creating a simple register/save system using R41-2

Quote:
Originally Posted by Yaa View Post






kill me no ?

That's completely immature behaviour man what he said is 100% right.You should take a look @ your login attempts part again and consider the optmisation tricks he mentioned.
SyS 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] [TUT] Creating a Register System using Dini Eazy_Efolife Tutorials 192 20/08/2014 04:26 PM
Register System not creating file. rangerxxll Scripting Help 4 05/03/2013 09:09 PM
[Tutorial] Creating a dialog register/login system using Dini [NWA]Hannes Tutorials 3 17/06/2012 05:35 PM
Y_ini Register System Not Creating Files LeetModz Scripting Help 10 02/05/2012 09:04 PM
[Tutorial] Creating a simple register and login system. AcId n RaPiD Help Archive 0 21/11/2009 02:23 PM


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


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