Help a fellow Newbie Programmer..
#1

What's up guys!

I been working on learning the basics of Pawn with some tutorials, etc. Today i started checking out tutorials for Registration Systems with Whirpool and MySQL (Turned out to be great, learned alot of it). Myself as a Web Developer have some experience on the field plus i find Pawn easy to learn on some parts.

However, i still have a long way to learn (like all of you did at some point) and i have this huge problem (Probably a really dumb problem)

Im using this code: https://sampforum.blast.hk/showthread.php?tid=574714

The problem is that i want to set the player skin after registration and save the skin on my database, just like: Name, Password, IP, SkinID, Admin, VIP, etc.

My real question is: how i achieve this?

If somebody doesn't mind explaining how to make this code set the player skin on sign up, i would appreciate.
Reply
#2

After you save the skin ID to a database, load it into a variable under 'OnAccountLoad' and use SetPlayerSkin under OnPlayerSpawn, like so:
Код:
public OnPlayerSpawn(playerid)
{
    if (Player[playerid][ID] > 0) // check if player is registered
    {
        SetPlayerSkin(playerid, Player[playerid][SkinID]);
    }
    return 1;
}
Or use it directly as the third parameter in SetSpawnInfo defines with which skin ID they spawn.

Edit: I admit, I half-misread what you wanted there.
To let players have some way of selecting a skin, you have two options: use the old way, or the new way.

The old way is maybe more complicated, but you still have to use some part of it.
The old way consisted of this: you add the classes (skins with predefined weapons as they spawn etc.) under OnGameModeInit (when the server loads) then under OnPlayerRequestClass (when they get to choose the skin) you set their camera position to look at the skin to select and they choose it with '<<' '>>' buttons. I can't explain it to you any better, go take a look at the 'grandlarc.pwn' (Grand Larceny) game mode included with the server.

The new way is with text draws. You show the player a text draw menu with skin models and they choose which one they want with a simple mouse click! See here.
Reply
#3

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
After you save the skin ID to a database, load it into a variable under 'OnAccountLoad' and use SetPlayerSkin under OnPlayerSpawn, like so:
Код:
public OnPlayerSpawn(playerid)
{
    if (Player[playerid][ID] > 0) // check if player is registered
    {
        SetPlayerSkin(playerid, Player[playerid][SkinID]);
    }
    return 1;
}
Or use it directly as the third parameter in SetSpawnInfo defines with which skin ID they spawn.

Edit: I admit, I half-misread what you wanted there.
To let players have some way of selecting a skin, you have two options: use the old way, or the new way.

The old way is maybe more complicated, but you still have to use some part of it.
The old way consisted of this: you add the classes (skins with predefined weapons as they spawn etc.) under OnGameModeInit (when the server loads) then under OnPlayerRequestClass (when they get to choose the skin) you set their camera position to look at the skin to select and they choose it with '<<' '>>' buttons. I can't explain it to you any better, go take a look at the 'grandlarc.pwn' (Grand Larceny) game mode included with the server.

The new way is with text draws. You show the player a text draw menu with skin models and they choose which one they want with a simple mouse click! See here.
I seem to have missed a few things/points that are vital for such Support Request:

Im working on a Roleplay gamemode, we all know that Skin Selection isn't a thing on most RP servers since we (Developers), choose to have the backpacker as default skin. The problem is that i have no single clue on how to integrate part of that stuff on my MySQL Query.

My Enum:

Код:
enum PlayerData 
{ 
    ID, 
    Name[MAX_PLAYER_NAME], 
    Password[129], 
    IP[16], 
    Admin, 
    VIP, 
    Money,  
    SkinID,
    Float:PosX, 
    Float:PosY, 
    Float:PosZ, 
    Float:PosA
}; 
new Player[MAX_PLAYERS][PlayerData];
My SQL Query:

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
    switch(dialogid) 
    { 
        case LoginDialog: 
        { 
            if(!response) Kick(playerid); 
             
            new 
                hashpass[129], 
                query[100], 
                playername[MAX_PLAYER_NAME]; 

            GetPlayerName(playerid, playername, sizeof(playername)); 
            WP_Hash(hashpass, sizeof(hashpass), inputtext); 
            if(!strcmp(hashpass, Player[playerid][Password])) 
            { 
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername); 
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid); 
            } 
            else 
            { 
                SendClientMessage(playerid, -1, "Incorrect Password, try again."); 
                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Sign in", "You seem to have an account on our server. \nPlease, type your password to log in:", "Login", "Quit"); 
            } 
        } 
        case RegisterDialog: 
        { 
            if(!response) return Kick(playerid); 
            if(strlen(inputtext) < 5) 
            { 
                SendClientMessage(playerid, -1, "Your password needs to have more than 4 characters."); 
                return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Sign up", "Mmm.. seems like you don't have an account. \nPlease, type a password:", "Next", "Quit");  
            } 
            new 
                query[512], 
                playername[MAX_PLAYER_NAME], 
                playerip[16]; 
                 

            GetPlayerName(playerid, playername, sizeof(playername)); 
            GetPlayerIp(playerid, playerip, sizeof(playerip)); 
            WP_Hash(Player[playerid][Password], 129, inputtext); 
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)", playername, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A); 
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid); 
        } 
    } 
    return 0; // 
}
OnPlayerDisconnect (Saving stuff after disconnect)
Код:
public OnPlayerDisconnect(playerid, reason) 
{ 
    new 
        query[128], 
        Float:Pos[4]; 
         
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]); 
    GetPlayerFacingAngle(playerid, Pos[3]); 
     
    mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` 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, query, "", ""); 
     
    return 1; 
}
Also, i want to make use of a defined variable (like it has been done with the SPAWN_Z, etc), in this case for my Default Skin set for new accounts on registration:

Код:
#define DEFAULT_SKIN (26)
If anybody knows how to achieve that, i will (again) appreciate that.
Reply
#4

Well, what i can get from your explanation i can give this example out;

Set a playervar under the response of register dialog when player just gets registered.

PHP код:
SetPVarInt(playerid"JustRegistered"1); 
And when player spawns, check if the variable is 1 or not, if it is 1 then execute the query to insert the player's skin id into the table cause when they spawn, skin is already set so you can fetch the skin id using GetPlayerSkin(playerid); function;

PHP код:
public OnPlayerSpawn(playerid)
{
    if (
GetPVarInt(playerid"JustRegistered") == 1)
    {
        new
            
query[128];
            
        
mysql_format(mysqlquerysizeof(query), "UPDATE `...` SET `SkinID`='%d' WHERE `uniqueid`='%d'"GetPlayerSkin(playerid), uniqueidhere); // Change the unique id with yours
        
mysql_tquery(mysqlquery"""");
        
DeletePVar(playerid"JustRegistered"); // Deleting this so query won't be executed next time the player spawns
    
}
    return 
1;

I know there are more better ways than this but this is what i can think of so far.
Reply
#5

I don't know why but I just loved the way you asked for help and I'll try to make this a little tutorial as much as I can, and hope It helps you

Okay, one by one.
MySQL has a default parameter you could set, this is (in my opinion) better, as you don't have to even insert the value or have to define a default for it in the script, you just insert everything except it and it automatically takes the default value in the database, so, how do you do this ?




Also, MySQL has a great few hashing methods, so you don't have to actually use Whirpool, I think the most popular one is SHA256, but that's just if you want
Quote:
Originally Posted by Jay_
Посмотреть сообщение
These are SA-MP gamemodes, not banks. Stating that "Whirlpool is a more secure hash" may not necessarily be incorrect, however, for the data that is stored by a SA-MP server, a salted SHA-256 encryption is more than enough.
And about the skin saving, I just edited the two queries in here and noted what I changed
pawn Код:
#define DEFAULT_SKIN (26)

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case LoginDialog:
        {
            if(!response) Kick(playerid);

            new
                hashpass[129],
                query[100],
                playername[MAX_PLAYER_NAME];

            GetPlayerName(playerid, playername, sizeof(playername));
            WP_Hash(hashpass, sizeof(hashpass), inputtext);
            if(!strcmp(hashpass, Player[playerid][Password]))
            {
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                SendClientMessage(playerid, -1, "Incorrect Password, try again.");
                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Sign in", "You seem to have an account on our server. \nPlease, type your password to log in:", "Login", "Quit");
            }
        }
        case RegisterDialog:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) < 5)
            {
                SendClientMessage(playerid, -1, "Your password needs to have more than 4 characters.");
                return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Sign up", "Mmm.. seems like you don't have an account. \nPlease, type a password:", "Next", "Quit");
            }
            new
                query[512],
                playername[MAX_PLAYER_NAME],
                playerip[16];


            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerIp(playerid, playerip, sizeof(playerip));
            WP_Hash(Player[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`, `SkinID`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f, %d)", playername, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, DEFAULT_SKIN);//Added "`SkinID`", "%d" and "DEFAULT_SKIN"
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
        }
    }
    return 0;
}

public OnPlayerDisconnect(playerid, reason)
{
    new
        query[128],
        Float:Pos[4];

    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    GetPlayerFacingAngle(playerid, Pos[3]);

    mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f, `SkinID` = %d WHERE `ID` = %d",
    GetPlayerMoney(playerid), Pos[0], Pos[1], Pos[2], Pos[3], GetPlayerSkin(playerid), Player[playerid][ID]);//Added "`SkinID` = %d" and "GetPlayerSkin(playerid)" which returns the skin id
    mysql_tquery(mysql, query, "", "");

    return 1;
}
One step messing though, which is actually setting the skin to the player, using "SetPlayerSkin(playerid, skinid);" under "OnAccountLoad" but you didn't post this function and I think you can do it.
Don't forget to add the "SkinID" to the database manually and to the creation query(If you got one) in the script.
Reply
#6

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
-snipp-
I wouldn't mind a hand on that one, i seem to got stuck in that part. Learning pawn is getting easier with every thing i do, wasn't expecting it to be easy lol
Reply
#7

Which exactly, the loading and setting ?
If so just show me the current "OnAccountLoad" function and I will do it for you, I just can't magically expect what's in there.
Reply
#8

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Which exactly, the loading and setting ?
If so just show me the current "OnAccountLoad" function and I will do it for you, I just can't magically expect what's in there.
Oh, sorry my bad:
Код:
forward OnAccountLoad(playerid); 
public OnAccountLoad(playerid) 
{ 
    Player[playerid][Admin] = cache_get_field_content_int(0, "Admin"); 
    Player[playerid][VIP] = cache_get_field_content_int(0, "VIP"); 
    Player[playerid][Money] = cache_get_field_content_int(0, "Money");
    Player[playerid][PosX] = cache_get_field_content_float(0, "PosX"); 
    Player[playerid][PosY] = cache_get_field_content_float(0, "PosY"); 
    Player[playerid][PosZ] = cache_get_field_content_float(0, "PosZ"); 
    Player[playerid][PosA] = cache_get_field_content_float(0, "PosA"); 
    Player[playerid][SkinID] = cache_get_field_content_float(0, "SkinID"); 
  
    TogglePlayerSpectating(playerid, false); 

    GivePlayerMoney(playerid, Player[playerid][Money]); 

    SetSpawnInfo(playerid, 0, 23, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], 0, 0, 0, 0, 0, 0); 
    SpawnPlayer(playerid); 

    SendClientMessage(playerid, COLOR_WHITE, "{FFFFFF}Welcome to {FFBB00}Placeholder.");
 
    return 1; 
}
Reply
#9

Good, you're actually already getting the skin from the database, just messing setting the skin to the player, here you go
pawn Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
    Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
    Player[playerid][Money] = cache_get_field_content_int(0, "Money");
    Player[playerid][PosX] = cache_get_field_content_float(0, "PosX");
    Player[playerid][PosY] = cache_get_field_content_float(0, "PosY");
    Player[playerid][PosZ] = cache_get_field_content_float(0, "PosZ");
    Player[playerid][PosA] = cache_get_field_content_float(0, "PosA");
    Player[playerid][SkinID] = cache_get_field_content_float(0, "SkinID");//This gets the skin and saves it in "Player[playerid][SkinID]"

    TogglePlayerSpectating(playerid, false);

    GivePlayerMoney(playerid, Player[playerid][Money]);

    SetSpawnInfo(playerid, 0, 23, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);

    SetPlayerSkin(playerid, Player[playerid][SkinID]);//Set his skin to the saved variable.

    SendClientMessage(playerid, COLOR_WHITE, "{FFFFFF}Welcome to {FFBB00}Placeholder.");

    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)