SQL - PK and Heroes store unlimited.

Results 1 to 1 of 1
  1. #1
    Proficient Member Matias65 is offline
    MemberRank
    Nov 2013 Join Date
    182Posts

    idea SQL - PK and Heroes store unlimited.

    Copy/Paste Español

    Hola muchachos, la idea de este sistema es poder almacenar el PK mas alla del "99" o "-1" que esta permitido en las versiones viejas (nose si aun se presenta este problema en versiones nuevas), ademas como plus le agregamos para que guarde valores en 2 columnas mas llamadas PkMensual y PkSemanal.

    El sistema lo probe muy a grandes rasgos, nunca con un servidor online, en el caso de los pks no me preocupa el funcionamiento, es un 99% seguro que funcione como se espera, pero en el caso de los heroes podria llegar a variar, bueno, sin mas rodeos, les dejo los pasos a seguir.

    Primero que nada, todo se realiza a traves del "Analizador de Consultas" y tienen que seleccionar la db en la cual van a correr las consultas (yo seleccione "MuOnline" porque es una db con la que pruebo estas pequeñeces)





    1- Crear las tablas en la base de datos:

    Code:
    USE MuOnline
    ALTER TABLE dbo.[Character] add PkTotal int not null default 0
    ALTER TABLE dbo.[Character] add PkMensual int not null default 0
    ALTER TABLE dbo.[Character] add PkSemanal int not null default 0

    2- Creamos el trigger:

    Code:
    CREATE TRIGGER [dbo].[RankingPK] ON [dbo].[Character]
    FOR Update
    AS
    BEGIN
    
    
    SET NOCOUNT ON;
    
    
    -- =============================================
    -- Author:   <kind>
    -- Create date: <09/07/2015>
    -- Description:   <Obtiene los valores de PkCount y los guarda en otras columnas>
    -- =============================================
    
    
    DECLARE @accountid varchar(10)
    DECLARE @Ranknew int
    DECLARE @Rankold int
    DECLARE @Rankdif int
    DECLARE @name varchar(10)
    
    
    SELECT @Ranknew = PkCount, @name = Name, @accountid = AccountID FROM INSERTED
    SELECT @Rankold = PkCount, @name = Name, @accountid = AccountID FROM DELETED
    END
    IF  @Ranknew != @Rankold)
    BEGIN
    SET @Rankdif =  @Ranknew - @Rankold
    UPDATE  Character SET PkTotal = PkTotal + @Rankdif, PkSemanal = PkSemanal +  @Rankdif, PkMensual = PkMensual + @Rankdif WHERE Name = @name
    IF @Ranknew = -3
    BEGIN
    UPDATE character SET PkCount = 0 WHERE Name = @name
    END
    IF @Ranknew = 100
    BEGIN
    UPDATE character SET PkCount = 0 WHERE Name = @name
    END
    END
    Solamente eso es necesario para aumentar el limite de kills almacenadas en la db, basicamente lo que hace el script es tomar los valores del PkCount ni bien se actualiza la tabla, y los agrega a las tablas creadas (PkTotal,PkMensual y PkSemanal). En el caso de que el personaje sea Heroe y tenga ya "-3" (el limite que se guarda), vuelve el valor de PkCount a 0, para poder seguir almacenando los kills de los heroes.


    Para verificar que el script funciona basta con editar el PkCount de algun personaje, o entrar al juego y matar a alguien:

    Code:
    UPDATE Character SET PkCount = 3 WHERE Name = 'NombrePj'

    Y luego la siguiente para ver si sumo o no los kills :

    Code:
    SELECT TOP 10 Name,PkTotal,PkSemanal,PkMensual FROM Character ORDER BY PkTotal DESC

    Para mostrarlos despues en la pagina web, basta alterar todos los campos donde figure PkCount por PkTotal. Ya si quieren crear un sistema de rankings mensuales y semanales tendran que crear tareas que se ejecuten mensualmente/semanalmente borrando los valores de las tablas PkMensual y PkTotal.


    Si se lo piensan llevar a otro foro, por favor respeten creditos.

    CREDITOS :

    kind

    English :

    Hello boys, the idea of this system is to store the PK beyond the "99" or "-1" that is allowed in older versions (nose if even this problem is presented in new versions), plus as a bonus we added to to save values in 2 columns and more calls PkMensual PkSemanal.

    The system will probe very broadly ever with an online server, in the case of pks'm not worried about the operation, it is 99% sure that it works as expected, but in the case of the heroes could vary, well, without further ado, I leave the steps.

    First of all, everything is done through the "Query Analyzer" and have to select the db which will run queries (I choose "MuOnline" because it is a db with which I try these little)

    Only it is necessary to increase the limit stored in the db kills, basically what the script is taking PkCount values as soon as the table is updated, and added to the created tables (PkTotal, PkMensual and PkSemanal). In the case of the character is the hero and has already "-3" (the limit that is stored), returns the value of PkCount to 0, to continue storing the kills of heroes.





    To show later on the website, simply alter all fields where PkCount by PkTotal figure. And if they want to create a system of monthly and weekly rankings will have to create jobs running monthly / weekly erasing values and PkTotal PkMensual tables.

    Google Traslate.







Advertisement