Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help MySQL DataBase saving kills
#1
Hey I need some help for my plugin. I want to save kills of all player in the database.
Could someone give me the code for connecting to a database and saving kills of each player in it?
[Image: b_560_95_1.png]
Reply

#2
l2please, please... lol.
Stop asking for code, *I think* no one will give/make it for you.
Just use msql system from EpicZombie/Moonlight shop and put adding line to OnPlayerDamaged when player getting killed.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
Whats the reference for
Code:
using System.Data.SQLite;
[Image: b_560_95_1.png]
Reply

#4
When you download the files do you see a file with name: "System.Data.SQLite" add that to your refrence!
Reply

#5
Which files do you mean?
[Image: b_560_95_1.png]
Reply

#6
(12-13-2013, 19:54)SailorMoon Wrote: l2please, please... lol.
Stop asking for code, *I think* no one will give/make it for you.
Just use msql system from EpicZombie/Moonlight shop and put adding line to OnPlayerDamaged when player getting killed.

one of these
Reply

#7
http://www.itsmods.com/forum/Thread-Rele...Suite.html

Logs kills and other stuff. Doesn't have the code available but can at least record who killed who.

Anyways if you want the code:

Onplayerdamaged

if damage > victim health
do sql stuff here that commits to a database
catch mysqlexception (do nothing, print to server)

return damage
Reply

#8
Do you think this will work?
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Data.SQLite;
using Addon;

namespace NS_LevelSystem
{
    class Main : CPlugin
    {
        public struct StatElem
        {
            public String XUID;
            public int Kills;
        }

        public class Statistics
        {
            public Dictionary<String, StatElem> Stats = new Dictionary<string, StatElem>();
            SQLiteConnection connection;

            public Statistics()
            {
                connection = new SQLiteConnection("Data Source=" + Directory.GetCurrentDirectory() + "/plugins/stats_ns.stat");
                connection.Open();

                SQLiteCommand command = new SQLiteCommand("CREATE TABLE IF NOT EXISTS Statistics (XUID varchar(20),Kills integer)", connection);
                command.ExecuteNonQuery();
                command.Dispose();
                read();
            }

            ~Statistics()
            {
                connection.Close();
            }

            private void read()
            {
                SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Statistics", connection);
                SQLiteDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                    while (reader.Read())
                    {
                        StatElem newEntry = new StatElem();
                        newEntry.XUID = reader.GetString(reader.GetOrdinal("XUID"));
                        newEntry.Kills = reader.GetInt32(reader.GetOrdinal("Kills"));
                        Stats.Add(newEntry.XUID, newEntry);
                    }
                cmd.Dispose();
            }

            public void insertNewPerson(ServerClient c)
            {
                SQLiteCommand cmd = new SQLiteCommand("INSERT IGNORE INTO Statistics (XUID, Kills)" +
                                                      "VALUES (\'" + c.XUID + "\', 1,0)", connection);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                StatElem insert = new StatElem();
                insert.XUID = c.XUID;
                Stats.Add(c.XUID, insert);
            }

            public void updateKills(int Kills, ServerClient c)
            {
                StatElem updated = Stats[c.XUID];
                updated.Kills += Kills;
                SQLiteCommand cmd = new SQLiteCommand("UPDATE Statistics SET Kills=" + updated.Kills + " WHERE XUID=\'" + updated.XUID + "\'", connection);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                Stats[c.XUID] = updated;
            }


        }

        Statistics stats;
        int kill = 1;

        public override int OnPlayerDamaged(ServerClient Attacker, ServerClient Victim, string Weapon, int Damage)
        {
            if (Damage >= Victim.Other.Health && Attacker.Team != Victim.Team)
            {
                UpdateKills(kill, Victim);
            }

            return base.OnPlayerDamaged(Attacker, Victim, Weapon, Damage);
        }

        public void UpdateKills(int inc, ServerClient c)
        {
            stats.updateKills(inc, c);
        }

        public int getKills(String XUID)
        {
            return stats.Stats[XUID].Kills;
        }

        public override void OnPlayerConnect(ServerClient Client)
        {
            base.OnPlayerConnect(Client);
            if (Client.Team == Teams.Allies)
            {
            }
        }

        public override void OnPlayerSpawned(ServerClient Client)
        {
            base.OnPlayerSpawned(Client);
            if (Client.Team == Teams.Allies)
            {
            }
        }

        public override ChatType OnSay(string Message, ServerClient Client)
        {
            if (Message.StartsWith("!kills"))
            {
                int k = Client.Stats.Kills;
                iPrintLnBold("^1You have got ^2" + k + "^1 kills", Client);
                return ChatType.ChatNone;
            }
            return base.OnSay(Message, Client);
        }
    

    }
}
[Image: b_560_95_1.png]
Reply

#9
I think it doesn't work, if I do !kills nothing happens.
How can I check if it works?
[Image: b_560_95_1.png]
Reply

#10
Why nobody answer?
[Image: b_560_95_1.png]
Reply



Forum Jump:


Users browsing this thread:
3 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.