1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Kaip sukurti zaideju sistema?

Discussion in 'C# ir JavaScript pagalba' started by Float, Jan 20, 2017.

  1. Float

    Float Member

    Messages:
    29
    Likes Received:
    2
    Joined:
    Dec 2, 2016
    Sveiki , norejau paklaust gal zinot kaip galeciau sukurt zaidejams sistema?
    Kaip ant SA-MP , tai viskas buvo zymiai paprasciau http://forum.sa-mp.com/showthread.php?t=352703 ,o dabar tai neisivaizduoju kaip tai reiktu padaryt...
     
  2. jedgud

    jedgud New Member

    Messages:
    2
    Likes Received:
    4
    Joined:
    Jan 11, 2017
    Esu pasirases toki kaip service. Bet kaip ka tik is sa-mp busi nuejes nemanau, kad suprasi kas cia yra ir kaip reik naudot :=D
    Code:
    using System;
    using System.Linq;
    using System.IO;
    using System.Collections.Generic;
    using GTANetworkServer;
    using GTANetworkShared;
    using System.Data;
    using System.Globalization;
    
    
    namespace RLResource
    {
        public static class User
        {
            public static void Init()
            {
               API.shared.consoleOutput("User database initialized!");
            }
    
            public static bool DoesAccountExist(string name)
            {
                DataTable result = API.shared.exported.database.executeQueryWithResult(string.Format("SELECT * FROM gta WHERE userName = '{0}'", name));
                if(result.Rows.Count == 0)
                    return false;
                else
                    return true;
            }
    
    
            public static bool currentId(Client player)
            {
                return API.shared.getEntityData(player, "userId");
            }
    
            public static bool IsPlayerLoggedIn(Client player)
            {
                return API.shared.hasEntityData(player, "userId");
            }
    
            public static void CreatePlayerAccount(Client player, string password)
            {
                string query = string.Format("INSERT INTO gta (userName, Password)VALUES('{0}', '{1}')", player.name, password);
                API.shared.exported.database.executeQuery(query);
            }
    
            public static bool TryLoginPlayer(Client player, string password)
            {
                string query = string.Format("SELECT * FROM gta WHERE userName = '{0}' AND Password = '{1}'", player.name, password);
                DataTable result = API.shared.exported.database.executeQueryWithResult(query);
                if(result.Rows.Count == 0)
                    return false;
                if(result.Rows.Count != 0)
                {
                    foreach(DataRow row in result.Rows) //loop through each row
                    {
                        string playerPosX = (string)row["X"];
                        float xpval = float.Parse(playerPosX.Replace(",", "."),
                            CultureInfo.InvariantCulture.NumberFormat);
    
                        string playerPosY = (string)row["Y"];
                        float ypval = float.Parse(playerPosY.Replace(",", "."),
                            CultureInfo.InvariantCulture.NumberFormat);
    
                        string playerPosZ = (string)row["Z"];
                        float zpval = float.Parse(playerPosZ.Replace(",", "."),
                            CultureInfo.InvariantCulture.NumberFormat);
                        Vector3 playerPos = new Vector3(xpval, ypval, zpval);
    
                        API.shared.setEntityPosition(player, playerPos);
    
                        API.shared.setEntityData(player, "Money", row["Money"]);
                        API.shared.setEntityData(player, "userId", row["id"]);
                        API.shared.triggerClientEvent(player, "update_money_display", API.shared.getEntityData(player, "Money"));
                     }
                }
                return true;
            }
    
            public static void SavePlayerAccount(Client player)
            {
                var userId = API.shared.getEntityData(player, "userId");
                Vector3 playerPos = API.shared.getEntityPosition(player);
                string query = string.Format("UPDATE gta SET X = '{0}', Y = '{1}', Z = '{2}', Money = {3} WHERE id = {4}",
                    playerPos.X, playerPos.Y, playerPos.Z, API.shared.getEntityData(player, "Money"), userId);
                API.shared.exported.database.executeQuery();
            }
        }
    }
    
     
    nobody and Osvaldon like this.

Share This Page