USE [MuOnline]
GO

CREATE TRIGGER [dbo].[RANK_BC] ON [dbo].[RankingBloodCastle]
AFTER UPDATE
AS

SET NOCOUNT ON
SET XACT_ABORT ON

DECLARE @rank int
DECLARE @valor int
DECLARE @char varchar(10)

SELECT @valor = Score FROM DELETED
SELECT @rank = Score, @char = Name FROM INSERTED

IF (@rank > 0) and (@rank > @valor)
begin
UPDATE [dbo].[RankingBloodCastle]
SET Score_semanal = Score_semanal + (@rank-@valor)
WHERE Name = @char

UPDATE Character SET eventos=eventos+200,eventos_mensal=eventos_mensal+200,eventos_semanal=eventos_semanal+200 WHERE Name=@char

end

SET NOCOUNT OFF
SET XACT_ABORT OFF

GO


CREATE TRIGGER [dbo].[RANK_CC] ON [dbo].[RankingChaosCastle]
AFTER UPDATE
AS

SET NOCOUNT ON
SET XACT_ABORT ON

DECLARE @rank int
DECLARE @valor int
DECLARE @char varchar(10)

SELECT @valor = Score FROM DELETED
SELECT @rank = Score, @char = Name FROM INSERTED

IF (@rank > 0) and (@rank > @valor)
begin
UPDATE [dbo].[RankingChaosCastle]
SET Score_semanal = Score_semanal + (@rank-@valor)
WHERE Name = @char

UPDATE Character SET eventos=eventos+200,eventos_mensal=eventos_mensal+200,eventos_semanal=eventos_semanal+200 WHERE Name=@char

end

SET NOCOUNT OFF
SET XACT_ABORT OFF

GO


USE [MuOnline]
GO

/****** Object:  Trigger [dbo].[RANK_DS]    Script Date: 01/18/2017 11:28:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[RANK_DS] ON [dbo].[RankingDevilSquare]
AFTER UPDATE
AS

SET NOCOUNT ON
SET XACT_ABORT ON

DECLARE @rank int
DECLARE @valor int
DECLARE @char varchar(10)

SELECT @valor = Score FROM DELETED
SELECT @rank = Score, @char = Name FROM INSERTED

IF (@rank > 0) and (@rank > @valor)
begin
UPDATE [dbo].[RankingDevilSquare]
SET Score_semanal = Score_semanal + (@rank-@valor)
WHERE Name = @char

UPDATE Character SET eventos=eventos+200,eventos_mensal=eventos_mensal+200,eventos_semanal=eventos_semanal+200 WHERE Name=@char
end

SET NOCOUNT OFF
SET XACT_ABORT OFF

GO



Create TRIGGER [dbo].[RANK_DUEL] ON [dbo].[RankingDuel]
AFTER UPDATE
AS

SET NOCOUNT ON
SET XACT_ABORT ON

DECLARE @rank int
DECLARE @valor int
DECLARE @char varchar(10)

SELECT @valor = WinScore FROM DELETED
SELECT @rank = WinScore, @char = Name FROM INSERTED

IF (@rank > 0) and (@rank > @valor)
UPDATE [dbo].[RankingDuel]
SET WinScore_semanal = WinScore_semanal + (@rank-@valor)
WHERE Name = @char

SET NOCOUNT OFF
SET XACT_ABORT OFF

GO


CREATE TRIGGER [dbo].[News create] ON [dbo].[Character] 
FOR INSERT
AS

DECLARE @newName VARCHAR(10)

SELECT @newName = (SELECT top 1 Inserted.Name FROM Inserted)

INSERT INTO MK_murkut_news (Nome,tipo) valueS (@newName, 1)

GO

CREATE TRIGGER [dbo].[News delete] ON [dbo].[Character] 
FOR DELETE
AS
DECLARE @newNameD VARCHAR(10)
DECLARE @newacc VARCHAR(10)

SELECT @newNameD = (SELECT top 1 deleted.Name FROM deleted)
SELECT @newacc = (SELECT top 1 deleted.accountid FROM deleted)

INSERT INTO MK_Murkut_News (Nome,tipo,valor) valueS (@newNameD, 2,@newacc)

GO


CREATE TRIGGER [dbo].[Z_PK_HERO] ON [dbo].[Character]
AFTER UPDATE
AS

SET NOCOUNT ON
SET XACT_ABORT ON

DECLARE @rank int
DECLARE @valor int
DECLARE @char varchar(10)

SELECT @valor = PkCount FROM DELETED
SELECT @rank = PkCount, @char = Name FROM INSERTED

IF (@rank > 0) and (@rank > @valor)
UPDATE [dbo].[Character]
SET Z_RankPK = Z_RankPK + (@rank-@valor),Z_RankPK_semanal = Z_RankPK_semanal + (@rank-@valor), Z_RankPK_mensal = Z_RankPK_mensal + (@rank-@valor)
WHERE Name = @char
ELSE
IF (@rank < 0) and (@rank < @valor)
UPDATE [dbo].[Character]
SET Z_RankHR = Z_RankHR + (@valor-@rank), Z_RankHR_semanal = Z_RankHR_semanal + (@valor-@rank), Z_RankHR_mensal = Z_RankHR_mensal + (@valor-@rank)
WHERE Name = @char

SET NOCOUNT OFF
SET XACT_ABORT OFF

GO