Jump to content
RAGE Multiplayer Community

Need help with a MySQL Query


Asznee
 Share

Recommended Posts

Hey, 

 

so I wanted to create a MySQL Query where something in one table gets updated and something gets created in another table.

That works so far, but I want to send a Error Message to the player, if `name1` already exists.

 

public static int CreatePlayerSkin(Client player, AccountModel account, SkinModel skin)
        {
            NAPI.Util.ConsoleOutput("Debug 1");
            int playerId = 0;
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                NAPI.Util.ConsoleOutput("Debug 2");
                try
                {
                    NAPI.Util.ConsoleOutput("Debug 3");
                    connection.Open();

                    MySqlCommand command = connection.CreateCommand();
                    command.CommandText = "UPDATE accounts SET sex = @sex, name = @name WHERE socialName = @socialName LIMIT 1";
                    command.Parameters.AddWithValue("@sex", account.sex);
                    command.Parameters.AddWithValue("@name", account.realName);
                    command.Parameters.AddWithValue("@socialName", account.socialName);
                    command.ExecuteNonQuery();

                    player.SetData(EntityData.PLAYER_SEX, account.sex);

                    NAPI.Util.ConsoleOutput("Debug 4");
                    playerId = (int)command.LastInsertedId;

                    command.CommandText = "INSERT INTO `skins` (`name1`, `socialName`, `firstHeadShape`, `secondHeadShape`, `firstSkinTone`, `secondSkinTone`, `headMix`, `skinMix`, ";
                    command.CommandText += "`hairModel`, `firstHairColor`, `secondHairColor`, `beardModel`, `beardColor`, `chestModel`, `chestColor`, `blemishesModel`, ";
                    command.CommandText += "`ageingModel`, `complexionModel`, `sundamageModel`, `frecklesModel`, `noseWidth`, `noseHeight`, `noseLength`, `noseBridge`, `noseTip`, `noseShift`, ";
                    command.CommandText += "`browHeight`, `browWidth`, `cheekboneHeight`, `cheekboneWidth`, `cheeksWidth`, `eyes`, `lips`, `jawWidth`, `jawHeight`, `chinLength`, ";
                    command.CommandText += "`chinPosition`, `chinWidth`, `chinShape`, `neckWidth`, `eyesColor`, `eyebrowsModel`, `eyebrowsColor`, `makeupModel`, `blushModel`, `blushColor`, ";
                    command.CommandText += "`lipstickModel`, `lipstickColor`) VALUES (@name1, @socName, @firstHeadShape, @secondHeadShape, @firstSkinTone, @secondSkinTone, @headMix, @skinMix, ";
                    command.CommandText += "@hairModel, @firstHairColor, @secondHairColor, @beardModel, @beardColor, @chestModel, @chestColor, @blemishesModel, @ageingModel, ";
                    command.CommandText += "@complexionModel, @sundamageModel, @frecklesModel, @noseWidth, @noseHeight, @noseLength, @noseBridge, @noseTip, @noseShift, @browHeight, ";
                    command.CommandText += "@browWidth, @cheekboneHeight, @cheekboneWidth, @cheeksWidth, @eyes, @lips, @jawWidth, @jawHeight, @chinLength, @chinPosition, @chinWidth, ";
                    command.CommandText += "@chinShape, @neckWidth, @eyesColor, @eyebrowsModel, @eyebrowsColor, @makeupModel, @blushModel, @blushColor, @lipstickModel, @lipstickColor)";

                    command.Parameters.AddWithValue("@name1", account.realName);
                    command.Parameters.AddWithValue("@socName", player.SocialClubName);
                    command.Parameters.AddWithValue("@firstHeadShape", skin.firstHeadShape);
                    command.Parameters.AddWithValue("@secondHeadShape", skin.secondHeadShape);
                    command.Parameters.AddWithValue("@firstSkinTone", skin.firstSkinTone);
                    command.Parameters.AddWithValue("@secondSkinTone", skin.secondSkinTone);
                    command.Parameters.AddWithValue("@headMix", skin.headMix);
                    command.Parameters.AddWithValue("@skinMix", skin.skinMix);
                    command.Parameters.AddWithValue("@hairModel", skin.hairModel);
                    command.Parameters.AddWithValue("@firstHairColor", skin.firstHairColor);
                    command.Parameters.AddWithValue("@secondHairColor", skin.secondHairColor);
                    command.Parameters.AddWithValue("@beardModel", skin.beardModel);
                    command.Parameters.AddWithValue("@beardColor", skin.beardColor);
                    command.Parameters.AddWithValue("@chestModel", skin.chestModel);
                    command.Parameters.AddWithValue("@chestColor", skin.chestColor);
                    command.Parameters.AddWithValue("@blemishesModel", skin.blemishesModel);
                    command.Parameters.AddWithValue("@ageingModel", skin.ageingModel);
                    command.Parameters.AddWithValue("@complexionModel", skin.complexionModel);
                    command.Parameters.AddWithValue("@sundamageModel", skin.sundamageModel);
                    command.Parameters.AddWithValue("@frecklesModel", skin.frecklesModel);
                    command.Parameters.AddWithValue("@noseWidth", skin.noseWidth);
                    command.Parameters.AddWithValue("@noseHeight", skin.noseHeight);
                    command.Parameters.AddWithValue("@noseLength", skin.noseLength);
                    command.Parameters.AddWithValue("@noseBridge", skin.noseBridge);
                    command.Parameters.AddWithValue("@noseTip", skin.noseTip);
                    command.Parameters.AddWithValue("@noseShift", skin.noseShift);
                    command.Parameters.AddWithValue("@browHeight", skin.browHeight);
                    command.Parameters.AddWithValue("@browWidth", skin.browWidth);
                    command.Parameters.AddWithValue("@cheekboneHeight", skin.cheekboneHeight);
                    command.Parameters.AddWithValue("@cheekboneWidth", skin.cheekboneWidth);
                    command.Parameters.AddWithValue("@cheeksWidth", skin.cheeksWidth);
                    command.Parameters.AddWithValue("@eyes", skin.eyes);
                    command.Parameters.AddWithValue("@lips", skin.lips);
                    command.Parameters.AddWithValue("@jawWidth", skin.jawWidth);
                    command.Parameters.AddWithValue("@jawHeight", skin.jawHeight);
                    command.Parameters.AddWithValue("@chinLength", skin.chinLength);
                    command.Parameters.AddWithValue("@chinPosition", skin.chinPosition);
                    command.Parameters.AddWithValue("@chinWidth", skin.chinWidth);
                    command.Parameters.AddWithValue("@chinShape", skin.chinShape);
                    command.Parameters.AddWithValue("@neckWidth", skin.neckWidth);
                    command.Parameters.AddWithValue("@eyesColor", skin.eyesColor);
                    command.Parameters.AddWithValue("@eyebrowsModel", skin.eyebrowsModel);
                    command.Parameters.AddWithValue("@eyebrowsColor", skin.eyebrowsColor);
                    command.Parameters.AddWithValue("@makeupModel", skin.makeupModel);
                    command.Parameters.AddWithValue("@blushModel", skin.blushModel);
                    command.Parameters.AddWithValue("@blushColor", skin.blushColor);
                    command.Parameters.AddWithValue("@lipstickModel", skin.lipstickModel);
                    command.Parameters.AddWithValue("@lipstickColor", skin.lipstickColor);
                    command.ExecuteNonQuery();

                    NAPI.Util.ConsoleOutput("Character created");

                    player.TriggerEvent("cancelCharacterCreation2");
                    player.SetData(EntityData.PLAYER_TUTORIAL, 2);
                    Globals.OnPlayerSpawn(player);
                }
                catch (Exception ex)
                {
                    NAPI.Util.ConsoleOutput("[EXCEPTION CreateCharacter] " + ex.Message);
                    NAPI.Util.ConsoleOutput("[EXCEPTION CreateCharacter] " + ex.StackTrace);
                    player.TriggerEvent("characterNameDuplicated");
                }
            }

            return playerId;
        }

So, If `name1` already exists in the table `skins` I want that "catch (Exception ex)" gets called, where it triggers the Event "characterNameDuplicated", but Idk how I should do that.

 

Maybe somebody here has some idea.

Btw. that's the WiredPlayers-RP Gamemode from the resource on this forum here.

 

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...