[Tutorial] Mysql Register/Login system!
#6

Well,

pawn Код:
#include <a_samp>
#include <streamer>
#include <a_mysql>
#include <sscanf2>

#define mysql_host                                              "YourHostIp"
#define mysql_user                                              "YourMysqlUser"
#define mysql_password                                          "YourUserPassword"
#define mysql_database                                          "YourDatabaseName"

main()
{
    printf("Hi");
}

enum PlayerInfo
{
    Username[23],
    Password[24],
    Money
}
new PInfo[MAX_PLAYERS][PlayerInfo]

public OnGameModeInit()
{
    mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
    SetGameModeText("Motel RP");
    CreateDynamicObject(14783,2217.31860352,-1143.14697266,1023.42614746,0.00000000,0.00000000,358.00000000); //object(int3int_kbsgarage) (1)
    CreateDynamicObject(14834,2214.42968750,-1155.06799316,1025.02209473,0.00000000,0.00000000,0.00000000); //object(lm_stripplant) (1)
    CreateDynamicObject(977,2243.01464844,-1160.77770996,1029.68249512,0.00000000,0.00000000,101.75000000); //object(newtowerdoor1) (1)
    CreateDynamicObject(977,2239.39501953,-1160.78808594,1029.68249512,0.00000000,0.00000000,101.74987793); //object(newtowerdoor1) (2)
    CreateDynamicObject(977,2239.33544922,-1171.72338867,1029.68249512,0.00000000,0.00000000,101.74987793); //object(newtowerdoor1) (3)
    CreateDynamicObject(977,2226.59301758,-1186.72668457,1030.40075684,0.00000000,0.00000000,191.74987793); //object(newtowerdoor1) (4)
    CreateDynamicObject(977,2210.59814453,-1190.60839844,1030.40075684,0.00000000,0.00000000,191.74438477); //object(newtowerdoor1) (5)
    CreateDynamicObject(977,2195.11621094,-1174.09912109,1030.30810547,0.00000000,0.00000000,101.24438477); //object(newtowerdoor1) (6)
    CreateDynamicObject(977,2195.09887695,-1158.02233887,1030.30810547,0.00000000,0.00000000,101.23901367); //object(newtowerdoor1) (7)
    CreateDynamicObject(977,2191.23999023,-1157.99169922,1030.30810547,0.00000000,0.00000000,101.23901367); //object(newtowerdoor1) (8)
    CreateDynamicObject(1723,2217.68945312,-1155.00512695,1024.79687500,0.00000000,0.00000000,180.00000000); //object(mrk_seating1) (1)
    CreateDynamicObject(1723,2219.15283203,-1152.37744141,1024.79687500,0.00000000,0.00000000,269.99450684); //object(mrk_seating1) (2)
    CreateDynamicObject(1723,2215.73437500,-1152.02197266,1024.79687500,0.00000000,0.00000000,359.98901367); //object(mrk_seating1) (3)
    CreateDynamicObject(2008,2215.69946289,-1144.85717773,1025.42248535,0.00000000,0.00000000,180.00000000); //object(officedesk1) (1)
    CreateDynamicObject(2166,2215.11059570,-1140.28161621,1025.14624023,0.00000000,0.00000000,0.00000000); //object(med_office_desk_2) (1)
    CreateDynamicObject(1670,2216.16308594,-1153.43225098,1025.35156250,0.00000000,0.00000000,0.00000000); //object(propcollecttable) (1)
    CreateDynamicObject(18028,2240.63012695,-1154.72802734,1024.30493164,0.00000000,0.00000000,90.00000000); //object(smllbarinterior) (1)
    CreateDynamicObject(14651,2241.39306641,-1163.84631348,1024.21655273,0.00000000,0.00000000,88.00000000); //object(trukstp05) (1)
    return 1;
}

stock LoginPlayer(playerid,const password[])
{
    new string[165],EscapedText[60];
    new Query[200],pName[24];
    GetPlayerName(playerid,pName,24);
    mysql_real_escape_string(password, EscapedText);
    format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",pName,EscapedText);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        SendClientMessage(playerid,green,"You have been logged in!");
        LoadStats(playerid);
    }
    else
    {
            SendClientMessage(playerid,red,"Wrong password!");
        Kick(playerid);
    }
    mysql_free_result();
    return 1;
}
stock LoadStats(playerid)
{
    new pName[24];
    GetPlayerName(playerid,pName,24);
    format(Query, sizeof(Query), "SELECT `Username` = '%s' FROM `Users`", pName);
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_row_format(Query, "|");
    sscanf(Query, "e<p<|>s[24]s[23]i>", PInfo[playerid]);
    mysql_free_result();
    GivePlayerMoney(playerid,PInfo[playerid][Money]);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new pName[24];
    GetPlayerName(playerid,pName,24);
    format(Query,sizeof(Query),"SELECT `Username` = '%s' FROM `Users`",pName);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
        ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Log in",string,"Login","");
    }
    else
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","");
    }
    mysql_free_result();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1)
    {
        new string[220];
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password"cblue" for it! \n","Register!","");
        }
        else
        {
            new EscapedText[60];
            mysql_real_escape_string(inputtext, EscapedText);
            format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText);
            mysql_query(Query);
            SendClientMessage(playerid,green,"You have been successfully registered!");
            GivePlayerMoney(playerid,5000);
            SetPlayerScore(playerid,100);
        }
    }
    if(dialogid == Logindialog)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
        }
        else
        {
            LoginPlayer(playerid,inputtext);
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Here is my script and Uhm .. The errors:

pawn Код:
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(24) : error 001: expected token: ";", but found "public"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(60) : error 017: undefined symbol "green"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(65) : error 017: undefined symbol "red"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(66) : warning 217: loose indentation
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(51) : warning 204: symbol is assigned a value that is never used: "string"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 017: undefined symbol "Query"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 017: undefined symbol "Query"
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\My Documents\Downloads\samp03dsvr_R2_win32\gamemodes\mrp.pwn(75) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


7 Errors.
I can fix some errors
Reply


Messages In This Thread
Mysql Register/Login system! - by FireCat - 24.12.2011, 17:37
Re: Mysql Register/Login system! - by PlayHard - 24.12.2011, 19:02
Re: Mysql Register/Login system! - by Coffeemonster - 24.12.2011, 19:12
Re: Mysql Register/Login system! - by PlayHard - 24.12.2011, 19:16
Re: Mysql Register/Login system! - by Kar - 24.12.2011, 19:24
Re: Mysql Register/Login system! - by PlayHard - 24.12.2011, 19:28
Re: Mysql Register/Login system! - by BetaLaxx - 24.12.2011, 19:32
Re: Mysql Register/Login system! - by FireCat - 24.12.2011, 19:38
Re: Mysql Register/Login system! - by [HiC]TheKiller - 24.12.2011, 19:53
Re: Mysql Register/Login system! - by FireCat - 24.12.2011, 20:06
Re: Mysql Register/Login system! - by [HiC]TheKiller - 24.12.2011, 20:20
Re: Mysql Register/Login system! - by Gazmull - 25.12.2011, 02:39
Re: Mysql Register/Login system! - by #marcus. - 25.12.2011, 09:08
Re: Mysql Register/Login system! - by Niko_boy - 26.12.2011, 17:14
Re: Mysql Register/Login system! - by =WoR=G4M3Ov3r - 27.12.2011, 01:03
Re: Mysql Register/Login system! - by [HiC]TheKiller - 27.12.2011, 03:52
Re: Mysql Register/Login system! - by FireCat - 27.12.2011, 10:03
Re: Mysql Register/Login system! - by HyperZ - 27.12.2011, 15:57
Re: Mysql Register/Login system! - by FireCat - 27.12.2011, 16:01
Re: Mysql Register/Login system! - by suhrab_mujeeb - 27.12.2011, 16:11
Re: Mysql Register/Login system! - by [DOG]irinel1996 - 29.12.2011, 04:40
Respuesta: Mysql Register/Login system! - by [Nikk] - 29.12.2011, 04:42
Re: Respuesta: Mysql Register/Login system! - by [DOG]irinel1996 - 29.12.2011, 04:53
Re: Respuesta: Mysql Register/Login system! - by FireCat - 29.12.2011, 09:54
Re: Respuesta: Mysql Register/Login system! - by FarSe. - 29.12.2011, 11:36
Respuesta: Mysql Register/Login system! - by [Nikk] - 29.12.2011, 13:49
Re: Respuesta: Mysql Register/Login system! - by Konstantinos - 29.02.2012, 17:01
Re: Mysql Register/Login system! - by FireCat - 29.02.2012, 19:14
Re: Mysql Register/Login system! - by fadhilkab - 15.03.2012, 21:00
Re: Mysql Register/Login system! - by logoster - 06.05.2012, 19:00
Re: Mysql Register/Login system! - by SwiftKidZ - 08.05.2012, 08:46
Re: Mysql Register/Login system! - by vIBIENNYx - 26.05.2012, 21:15
Re: Mysql Register/Login system! - by Mustang[GTS] - 02.08.2012, 19:13
Re: Mysql Register/Login system! - by PawnFox - 10.08.2012, 09:35
Re: Mysql Register/Login system! - by FireCat - 10.08.2012, 09:46
Re: Mysql Register/Login system! - by PawnFox - 10.08.2012, 09:50
Re: Mysql Register/Login system! - by Zilvinass - 10.12.2012, 18:06
Re: Mysql Register/Login system! - by KingPilot - 19.12.2012, 23:41
Re: Mysql Register/Login system! - by DJTunes - 21.12.2012, 18:38
Re: Mysql Register/Login system! - by kamzaf - 21.12.2012, 22:37
Re: Mysql Register/Login system! - by XMoonBladerX - 24.12.2012, 10:09
Re: Mysql Register/Login system! - by michaelcosyns - 18.04.2013, 19:07
Re: Mysql Register/Login system! - by x96664 - 29.06.2013, 20:46
Re: Mysql Register/Login system! - by Alazam - 11.07.2013, 17:26
Re: Mysql Register/Login system! - by Dugzor - 11.09.2013, 18:45
Re: Mysql Register/Login system! - by Yves - 21.12.2013, 19:12
Re: Mysql Register/Login system! - by anou1 - 04.01.2014, 00:58
Re: Mysql Register/Login system! - by anou1 - 05.01.2014, 14:16
Re: Mysql Register/Login system! - by anou1 - 05.01.2014, 21:07
Re: Mysql Register/Login system! - by Ramin - 05.12.2014, 03:02
Re: Mysql Register/Login system! - by cyberlord - 10.12.2014, 22:47
Re: Mysql Register/Login system! - by Vadyanga - 11.12.2015, 01:13
Re: Mysql Register/Login system! - by AndreiWow - 21.04.2016, 18:14

Forum Jump:


Users browsing this thread: 1 Guest(s)