- Joined
- Jun 27, 2010
- Messages
- 411
- Reaction score
- 240
Well title says it all. You need to create a new table so the script can track how many hours per player are already paid:
And here's the script:
So why did I post it in the dev section? The script is not tested on a live server, so I'd appreciate feedback.
Code:
USE [CabalCash]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ecoin_by_time](
[UserNum] [int] NOT NULL,
[PlayTimeDepreciate] [int] NULL,
[LastDepreciation] [datetime] NULL,
CONSTRAINT [PK_ecoin_by_time] PRIMARY KEY CLUSTERED
(
[UserNum] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
And here's the script:
Code:
USE [Account]
GO
DECLARE c CURSOR FOR SELECT [UserNum], [PlayTime], [ID] FROM [cabal_auth_table] WHERE AuthType = 1 AND PlayTime > 0
OPEN c
DECLARE @UserNum int, @PlayTime int, @m int, @d int, @uid varchar(50);
FETCH NEXT FROM c INTO @UserNum, @PlayTime, @uid;
WHILE @@Fetch_Status=0
BEGIN
BEGIN TRAN
SELECT [UserNum] FROM [CabalCash].[dbo].[ecoin_by_time] WHERE [UserNum] = @UserNum
IF @@ROWCOUNT = 0
BEGIN
--Account not found, creating a new one;
INSERT INTO [CabalCash].[dbo].[ecoin_by_time]
([UserNum], [PlayTimeDepreciate]) VALUES (@UserNum, 0)
END
SET @m = (@PlayTime - (SELECT [PlayTimeDepreciate] FROM [CabalCash].[dbo].[ecoin_by_time] WHERE [UserNum] = @UserNum)) / 60
SELECT @m AS Multiplikator
SELECT [UserNum] FROM [CabalCash].[dbo].[CashAccount] WHERE [UserNum] = @UserNum
IF @@ROWCOUNT = 0
BEGIN
--Account not found, creating a new one;
INSERT INTO [CabalCash].[dbo].[CashAccount]
([ID]
,[UserNum]
,[Cash]
,[CashBonus])
VALUES
(@uid
,@UserNum
,0
,0)
END
SET @d = (SELECT [Cash] FROM [CabalCash].[dbo].[CashAccount] WHERE [UserNum] = @UserNum) + (@m * 100)
UPDATE [CabalCash].[dbo].[CashAccount]
SET [Cash] = @d WHERE [UserNum] = @UserNum
UPDATE [CabalCash].[dbo].[ecoin_by_time]
SET [PlayTimeDepreciate] = [PlayTimeDepreciate] + (@m * 60) WHERE [UserNum] = @UserNum
COMMIT TRAN
SET @m = 0;
FETCH NEXT FROM c INTO @UserNum, @PlayTime, @uid
END
CLOSE c
DEALLOCATE c
So why did I post it in the dev section? The script is not tested on a live server, so I'd appreciate feedback.
Last edited: