SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 26/10/2019, 10:05 PM   #1
XoMoX
Little Clucker
 
Join Date: Nov 2018
Posts: 33
Reputation: 0
Default HELP!

i can't save my account in my database when i register it wont save it only shows the "register dialog"

PHP Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <a_mysql>

#define host    "127.0.0.1" //This will be your mysql host. Default for xampp is localhost
#define user    "root" //This will be your mysql . Default for xampp is root
#define db      "samp" //This is your database name. Remember we have created a database called server before.
#define pass    ""

#define    SPAWN_X  10.0
#define    SPAWN_Y  10.0
#define    SPAWN_Z  14.0
#define    SPAWN_A  0.0 

native WP_Hash(buffer[], len, const str[]); 

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Blank Filterscript by your name here");
    print(
"--------------------------------------\n");
    return 
1;
}

public 
OnFilterScriptExit()
{
    return 
1;
}

#else

main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
}

#endif

enum
{
    
LoginDialog,
    
RegisterDialog
}; 

enum PlayerData
{
    
ID,
    
Name[MAX_PLAYER_NAME],
    
Password[129],
    
IP[16],
    
Admin,
    
VIP,
    
Money,
    
Float:posX,
    
Float:posY,
    
Float:posZ,
    
Float:posA
};
new 
Player[MAX_PLAYERS][PlayerData]; 

new 
MySQL:mysql;

public 
OnGameModeInit()
{
    
mysql_log(ERROR DEBUG);
    
mysql mysql_connect(hostuserpassdb);
    if(
mysql_errno() != 0)
    {
        
printf("[MySQL] The connection has failed.");
    }
    else
    {
        
printf("[MySQL] The connection was successful.");
    }
    return 
true;
}

public 
OnGameModeExit()
{
    return 
1;
}

public 
OnPlayerRequestClass(playeridclassid)
{
    
SetPlayerPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraLookAt(playerid1958.37831343.157215.3746);
    return 
1;
}

public 
OnPlayerConnect(playerid)
{
    
TogglePlayerSpectating(playeridtrue);
    new
        
query[128],
        
playername[MAX_PLAYER_NAME];
        
    
GetPlayerName(playeridplayernamesizeof(playername));
    
mysql_format(mysqlquerysizeof(query), "SELECT `Password`, `ID` FROM `users` WHERE `Name` = '%e' LIMIT 1"playername);
    
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    return 
true;
}

public 
OnPlayerDisconnect(playeridreason)
{
    new
        
query[128],
        
Float:pos[4];
        
    
GetPlayerPos(playeridpos[0], pos[1], pos[2]);
    
GetPlayerFacingAngle(playeridpos[3]);
    
    
mysql_format(mysqlquerysizeof(query), "UPDATE `users` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
    
GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
    
mysql_tquery(MySQL:mysqlquery"""");
    
    return 
true;
}

public 
OnPlayerSpawn(playerid)
{
    return 
1;
}

public 
OnPlayerDeath(playeridkilleridreason)
{
    return 
1;
}

public 
OnVehicleSpawn(vehicleid)
{
    return 
1;
}

public 
OnVehicleDeath(vehicleidkillerid)
{
    return 
1;
}

public 
OnPlayerText(playeridtext[])
{
    return 
1;
}

public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
// Do something here
        
return 1;
    }
    return 
0;
}

public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    return 
1;
}

public 
OnPlayerExitVehicle(playeridvehicleid)
{
    return 
1;
}

public 
OnPlayerStateChange(playeridnewstateoldstate)
{
    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(playeridobjectid)
{
    return 
1;
}

public 
OnPlayerPickUpPickup(playeridpickupid)
{
    return 
1;
}

public 
OnVehicleMod(playeridvehicleidcomponentid)
{
    return 
1;
}

public 
OnVehiclePaintjob(playeridvehicleidpaintjobid)
{
    return 
1;
}

public 
OnVehicleRespray(playeridvehicleidcolor1color2)
{
    return 
1;
}

public 
OnPlayerSelectedMenuRow(playeridrow)
{
    return 
1;
}

public 
OnPlayerExitedMenu(playerid)
{
    return 
1;
}

public 
OnPlayerInteriorChange(playeridnewinterioridoldinteriorid)
{
    return 
1;
}

public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    return 
1;
}

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

public 
OnPlayerUpdate(playerid)
{
    return 
1;
}

public 
OnPlayerStreamIn(playeridforplayerid)
{
    return 
1;
}

public 
OnPlayerStreamOut(playeridforplayerid)
{
    return 
1;
}

public 
OnVehicleStreamIn(vehicleidforplayerid)
{
    return 
1;
}

public 
OnVehicleStreamOut(vehicleidforplayerid)
{
    return 
1;
}

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
LoginDialog:
        {
            if(!
responseKick(playerid);
            
            new
                
hashpass[129],
                
query[100],
                
playername[MAX_PLAYER_NAME];

            
GetPlayerName(playeridplayernamesizeof(playername));
            
WP_Hash(hashpasssizeof(hashpass), inputtext);
            if(!
strcmp(hashpassPlayer[playerid][Password]))
            {
                
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `users` WHERE `Name` = '%e' LIMIT 1"playername);
                
mysql_tquery(mysqlquery"OnAccountLoad""i"playerid);
            }
            else
            {
                
SendClientMessage(playerid, -1"You have specified an incorrect password!");
                
ShowPlayerDialog(playeridLoginDialogDIALOG_STYLE_INPUT"Login""Welcome player!\nYour account has been found in our database. Please fill in your password:""Login""Quit");
            }
        }
        case 
RegisterDialog:
        {
            if(!
response) return Kick(playerid);
            if(
strlen(inputtext) < 5)
            {
                
SendClientMessage(playerid, -1"Your password must at least contain more than 4 characters.");
                return 
ShowPlayerDialog(playeridRegisterDialogDIALOG_STYLE_INPUT"Register""Welcome player!\nYour account has not been registered yet. Please fill in your desired password:""Register""Quit");
            }
            new
                
query[512],
                
playername[MAX_PLAYER_NAME],
                
playerip[16];
            
GetPlayerName(playeridplayernamesizeof(playername));
            
GetPlayerIp(playeridplayeripsizeof(playerip));
            
WP_Hash(Player[playerid][Password], 129inputtext);
            
mysql_format(MySQL:mysqlquerysizeof(query), "INSERT INTO `users` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)"playernamePlayer[playerid][Password], playeripSPAWN_XSPAWN_YSPAWN_ZSPAWN_A);
            
mysql_tquery(MySQL:mysqlquery"OnAccountRegister""i"playerid);
        }
    }
    return 
false// For filterscripts..
}

public 
OnPlayerClickPlayer(playeridclickedplayeridsource)
{
    return 
1;
}

forward OnAccountCheck(playerid);
public 
OnAccountCheck(playerid)
{
    new 
rowsfields;
    
cache_get_row_count(rows);
    
cache_get_field_count(fields);
    if(
rows)
    {    
        new 
int_dest;
        
cache_get_value_name(0"Password"Player[playerid][Password], 129);
        
Player[playerid][ID] = cache_get_value_name_int(0"ID"int_dest);
        
ShowPlayerDialog(playeridLoginDialogDIALOG_STYLE_PASSWORD"Login""Welcome player!\nYour account has been found in our database. Please fill in your password:""Login""Quit");
    }
    else
    {
        
ShowPlayerDialog(playeridRegisterDialogDIALOG_STYLE_PASSWORD"Register""Welcome player!\nYour account has not been registered yet. Please fill in your desired password:""Register""Quit");
    }
    return 
true;


forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    new 
int_dest;
    new 
Float:float_dest;
    
Player[playerid][Admin] = cache_get_value_name_int(0"Admin"int_dest);
    
Player[playerid][VIP] = cache_get_value_name_int(0"VIP"int_dest);
    
Player[playerid][Money] = cache_get_value_name_int(0"Money"int_dest);
    
Player[playerid][posX] = cache_get_value_name_float(0"PosX"float_dest);
    
Player[playerid][posY] = cache_get_value_name_float(0"PosY"float_dest);
    
Player[playerid][posZ] = cache_get_value_name_float(0"PosZ"float_dest);
    
Player[playerid][posA] = cache_get_value_name_float(0"PosA"float_dest);
 
    
TogglePlayerSpectating(playeridfalse);

    
GivePlayerMoney(playeridPlayer[playerid][Money]);

    
SetSpawnInfo(playerid023Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 000000);
    
SpawnPlayer(playerid);

    
SendClientMessage(playerid, -1"You have successfully logged in.");
    return 
true;

forward OnAccountRegister(playerid);
public 
OnAccountRegister(playerid)
{
    
Player[playerid][ID] = cache_insert_id();
    
printf("[Registration] New account registered. Database ID: [%d]"Player[playerid][ID]);

    
TogglePlayerSpectating(playeridfalse);

    
SetSpawnInfo(playerid023SPAWN_XSPAWN_YSPAWN_ZSPAWN_A000000);
    
SpawnPlayer(playerid);
    return 
true;

XoMoX is offline   Reply With Quote
Old 26/10/2019, 11:34 PM   #2
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,234
Reputation: 1004
Default Re: HELP!

What version of the MySQL plugin are you using?

It looks to me like you aren’t loading values correctly for the new MySQL plugin API: https://forum.sa-mp.com/showthread.php?t=616103
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 27/10/2019, 04:32 AM   #3
XoMoX
Little Clucker
 
Join Date: Nov 2018
Posts: 33
Reputation: 0
Default Re: HELP!

i have the latest one which line i should update but for my compiler i have none warnings nor errors
__________________
𝓧𝓸𝓶𝓸𝓧.𝓧𝓸𝓶𝓸𝓧.𝓧𝓸𝓶𝓸𝓧
XoMoX is offline   Reply With Quote
Old 27/10/2019, 07:09 AM   #4
SiaReyes
Gangsta
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 614
Reputation: 57
Default Re: HELP!

check mysql_log. Make sure mysql connection is established and also did you load Whirlpool plugin?
SiaReyes is offline   Reply With Quote
Old 27/10/2019, 07:19 AM   #5
XoMoX
Little Clucker
 
Join Date: Nov 2018
Posts: 33
Reputation: 0
Default Re: HELP!

NVM i fixed it PROBLEM:the amx file in gamemodes is the old one the new one is in the filterscripts
__________________
𝓧𝓸𝓶𝓸𝓧.𝓧𝓸𝓶𝓸𝓧.𝓧𝓸𝓶𝓸𝓧
XoMoX 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



All times are GMT. The time now is 06:11 PM.


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