|
You last visited: Today at 22:48
Advertisement
[RELEASE] Usefull SQL statements - for GM's
Discussion on [RELEASE] Usefull SQL statements - for GM's within the Shaiya PServer Development forum part of the Shaiya Private Server category.
01/07/2011, 18:20
|
#1
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
[RELEASE] Usefull SQL statements - for GM's
This one lists all items that can drop from any particular monster. The one I post here will return MobName, ItemName, Grade, DropChance. You can add more if you want to.
To make it work type the monster name between the percent signs (red colour). It doesn't have to be the full name. Partial names will work too, i.e. '%Ruined Wolf%', '%Cryptic%':
Code:
DECLARE @MobName varchar(60);
SET @MobName = [COLOR=Red]'%%'[/COLOR];
SELECT M.MobName, I.ItemName, MI.Grade, MI.DropRate
FROM PS_GameDefs.dbo.Mobs AS M INNER JOIN PS_GameDefs.dbo.MobItems AS MI
ON M.MobID = MI.MobID AND MI.Grade<>0 LEFT OUTER JOIN PS_GameDefs.dbo.Items AS I
ON MI.Grade = I.Grade
WHERE M.MobName LIKE @MobName
ORDER BY I.Grade, I.ItemName;
To get more detailed results simply add the column names you want to be returned with proper alias in-front of it.
SQL Version of Deleting Player
This is one heck of a statement if you ask me, but I didn't want to start another thread. This is a complete procedure to wipe existence of any player from a server. It only needs a CharName, then it goes by itself acquiring all the necessary data. Read the comments when you are lost. Post any errors if you get them.
Code:
USE [PS_GameData]
GO
/****** Object: StoredProcedure [dbo].[ausp_Delete_Player] Script Date: 07/07/2010 00:41:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ausp_Delete_Player]
@CharName varchar(50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @UserUID int, @CharID int;
-- temporary table to store basic information about to be deleted characters
DECLARE @del_chars TABLE (UserUID int, UserID varchar(40), CharID int PRIMARY KEY CLUSTERED, CharName varchar(50));
-- get UserUID of the player
SELECT @UserUID=UM.UserUID
FROM PS_GameData.dbo.Chars AS C INNER JOIN PS_UserData.dbo.Users_Master AS UM
ON C.UserUID = UM.UserUID
WHERE C.CharName = @CharName AND C.Del=0;
-- no rows returned? player doesn't exist or invalid character name
IF @@ROWCOUNT=0
BEGIN
PRINT 'Character not found.';
return;
END
-- get all characters belonging to player and insert their CharID into temp table
INSERT INTO @del_chars
SELECT UserUID, UserID, CharID, CharName
FROM PS_GameData.dbo.Chars
WHERE UserUID=@UserUID;
BEGIN TRANSACTION;
begin TRY
-- all needed information gathered, it's time to delete
-- let's begin with less important data
DELETE FROM PS_GameData.dbo.CharItems WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.CharQuests WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.CharQuickSlots WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.CharSavePoint WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.CharSkills WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.UserStoredItems WHERE UserUID = @UserUID;
DELETE FROM PS_GameData.dbo.UserMaxGrow WHERE UserUID = @UserUID;
DELETE FROM PS_GameData.dbo.GuildChars WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.FriendChars WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.FriendChars WHERE FriendID IN (SELECT CharID FROM @del_chars);
DELETE PS_GameData.dbo.MarketItems
FROM PS_GameData.dbo.MarketItems AS MID INNER JOIN PS_GameData.dbo.Market AS M
ON M.MarketID = MID.MarketID
WHERE M.CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.Market WHERE CharID IN (SELECT CharID FROM @del_chars);
DELETE FROM PS_GameData.dbo.Chars WHERE UserUID = @UserUID
DELETE FROM PS_UserData.dbo.Users_Detail WHERE UserUID = @UserUID
DELETE FROM PS_UserData.dbo.Users_Master WHERE UserUID = @UserUID
-- save changes to database
COMMIT TRANSACTION;
end TRY
begin CATCH
-- rollback on error
ROLLBACK TRANSACTION;
-- Raise the error with the appropriate message and error severity
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int;
SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY();
PRINT @ErrMsg;
PRINT @ErrSeverity;
end CATCH
SET NOCOUNT OFF;
END
SET QUOTED_IDENTIFIER OFF;
SET ANSI_NULLS OFF;
There's a lot of recurring DELETE and (CharID IN (SELECT CharID FROM @del_chars)) statements. I didn't know how to replace the latter. I hope someone with more knowledge and experience can optimize the procedure.
List players equipped items
I created this procedure to check player's equipment, what lapis is linked and how much it adds to basic status points. I had my doubts about some people 'cheating' their way to become stronger. I think I found myself in error, anyway it is still useful if you want to allow players to use it.
What it does:
- selects all equipped items the player has,
- ignores items in inventory (for now),
- checks what lapis is linked,
- and which stats and by how much it increases,
- sums it up with basic stats and prints everything.
I couldn't come up with any use for this procedure when it turned out to be useless. Then I thought you can actually integrate it with a website and allow players to list their equipment. Might be hard on the DB side though. Still it is worth considering.
Procedure:
Code:
USE [PS_GameData]
GO
/****** Object: StoredProcedure [dbo].[ausp_Check_PlayersEquipment] Script Date: 06/13/2010 12:24:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tomasz Wiącek
-- Create date: <Create Date,,>
-- Description: Lists equipment, lapis linked, current and added status points of a given character.
-- =============================================
CREATE PROCEDURE [dbo].[ausp_Check_PlayersEquipment]
@CharName varchar(50) = '',
@CharID int = 0
AS
BEGIN
SET NOCOUNT ON;
-- variables to store Status Points
-- variables without _p - characters current status points
-- variables with _p - status points added by lapis
DECLARE @Str smallint, @Dex smallint, @Rec smallint, @Int smallint, @Wis smallint, @Luc smallint,
@Str_p smallint, @Dex_p smallint, @Rec_p smallint, @Int_p smallint, @Wis_p smallint, @Luc_p smallint;
-- variables for sp_executesql
DECLARE @stmt nvarchar(1000), @variables nvarchar(500)
-- these variables with hold lapis name and an item it was linked to
DECLARE @ItemName varchar(50),
@GemName1 varchar(50),@GemName2 varchar(50),@GemName3 varchar(50),@GemName4 varchar(50),
@GemName5 varchar(50),@GemName6 varchar(50);
-- variables to hold lapis properties
-- first set is TypeID selected from PS_GameData.dbo.CharItems
-- second set (Const***) holds what lapis adds
DECLARE @Gem1 tinyint,@Gem2 tinyint,@Gem3 tinyint,@Gem4 tinyint,@Gem5 tinyint,@Gem6 tinyint
DECLARE @ConstStr tinyint, @ConstDex tinyint, @ConstRec tinyint, @ConstInt tinyint, @ConstWis tinyint,
@ConstLuc tinyint, @ConstHP tinyint, @ConstMP tinyint, @ConstSP tinyint;
DECLARE @ItemID int
-- let's prepare statements for sp_executesql procedure
SET @stmt = N'
SELECT @GemName=ItemName, @ConstStr=ConstStr, @ConstDex=ConstDex, @ConstRec=ConstRec, @ConstInt=ConstInt,
@ConstWis=ConstWis, @ConstLuc=ConstLuc, @ConstHP=ConstHP, @ConstMP=ConstMP, @ConstSP=ConstSP
FROM PS_GameDefs.dbo.Items WHERE [Type]=30 AND TypeID=@Gem';
SET @variables = N'
@GemName varchar(50) output, @Gem tinyint, @ConstStr tinyint output, @ConstDex tinyint output,
@ConstRec tinyint output, @ConstInt tinyint output, @ConstWis tinyint output, @ConstLuc tinyint output,
@ConstHP tinyint output, @ConstMP tinyint output, @ConstSP tinyint output';
-- and initialize variables
SET @Str_p = 0
SET @Dex_p = 0
SET @Rec_p = 0
SET @Int_p = 0
SET @Wis_p = 0
SET @Luc_p = 0
IF @CharID = 0
SELECT @CharID = CharID FROM PS_GameData.dbo.Chars WHERE CharName=@CharName;
ELSE
SELECT @CharName = CharName FROM PS_GameData.dbo.Chars WHERE CharID=@CharID;
-- let see if the character exists and there are no typing errors
IF @@ROWCOUNT>0
BEGIN
-- setting up a cursor to process characters items (equiped)
DECLARE item_cursor CURSOR FAST_FORWARD FOR
SELECT CI.ItemID, I.ItemName, CI.Gem1, CI.Gem2, CI.Gem3, CI.Gem4, CI.Gem5, CI.Gem6
FROM PS_GameData.dbo.CharItems AS CI INNER JOIN PS_GameDefs.dbo.Items AS I
ON CI.ItemID = I.ItemID
WHERE CI.CharID = @CharID AND CI.Bag=0 --AND Gem1<>0 AND (Gem2<>0 or Gem3<>0 or Gem4<>0 or Gem5<>0 or Gem6<>0);
SELECT ItemID, Gem1, Gem2, Gem3, Gem4, Gem5, Gem6
FROM PS_GameData.dbo.CharItems WHERE CharID=@CharID AND Bag=0
-- initialize cursor and fetch first row
OPEN item_cursor;
FETCH NEXT FROM item_cursor INTO
@ItemID,@ItemName,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6;
-- now let's put it all together and print what items this character has
PRINT '-----------------------------'
PRINT 'Items of: ' + @CharName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' '
print '----------------------------------------';
print 'Item name: ' + @ItemName;
print '----------------------------------------';
-- if this is an old player not all slots can be taken and some lapis might have been extracted
-- let's make sure we don't process such slots
if @Gem1 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName1 output, @Gem1, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem1: ' + @GemName1
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
if @Gem2 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName2 output,@Gem2, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem2: ' + @GemName2
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
if @Gem3 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName3 output,@Gem3, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem3: ' + @GemName3
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
if @Gem4 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName4 output,@Gem4, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem4: '+@GemName4
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
if @Gem5 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName5 output,@Gem5, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem5: '+@GemName5
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
if @Gem6 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName6 output,@Gem6, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem6: ' + @GemName6
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
-- get new row from the cursor
FETCH NEXT FROM item_cursor INTO
@ItemID,@ItemName,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6
END
-- the cursor is no longer needed, time to close it and free memory
CLOSE item_cursor
DEALLOCATE item_cursor
/* now let's see how many status points the character has */
SELECT @Str = [Str], @Dex = Dex, @Rec = Rec, @Int = [Int], @Wis = Wis, @Luc = Luc
FROM PS_GameData.dbo.Chars WHERE CharName=@CharName
PRINT '----------------------------------------';
PRINT 'Players status points: ';
PRINT 'Str: ' + cast(@Str AS char(3)) + ' (' + cast(@Str_p as char(3)) + ') = ' + cast(@Str + @Str_p as Char(4))
PRINT 'Dex: ' + cast(@Dex AS char(3)) + ' (' + cast(@Dex_p as char(3)) + ') = ' + cast(@Dex + @Dex_p as Char(4))
PRINT 'Rec: ' + cast(@Rec AS char(3)) + ' (' + cast(@Rec_p as char(3)) + ') = ' + cast(@Rec + @Rec_p as Char(4))
PRINT 'Int: ' + cast(@Int AS char(3)) + ' (' + cast(@Int_p as char(3)) + ') = ' + cast(@Int + @Int_p as Char(4))
PRINT 'Wis: ' + cast(@Wis AS char(3)) + ' (' + cast(@Wis_p as char(3)) + ') = ' + cast(@Wis + @Wis_p as Char(4))
PRINT 'Luc: ' + cast(@Luc AS char(3)) + ' (' + cast(@Luc_p as char(3)) + ') = ' + cast(@Luc + @Luc_p as Char(4))
PRINT '----------------------------------------';
END
ELSE
BEGIN
PRINT 'Character ' + @CharName + ' does not exists.'
END
END
New Version
Version II of the above procedure. It does the same thing but is entirely different. You can integrate it with your website as the results are sent to PHP or whatever you are using. I am planing to write a PHP website which will sort all the information.
To remind beginners. It is up to you to implement it. I will not provide any assistance in doing so.
I tested the procedure and it works. It works with PHP as well. I was able to receive, switch between results and print the data. I haven't noticed any errors, but if you get one post it here. Any optimizations are welcome.
Procedure Ver.2
Code:
USE [PS_GameData]
GO
/****** Object: StoredProcedure [dbo].[ausp_Check_PlayersEquipment] Script Date: 06/13/2010 12:24:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tomasz Wiącek
-- Create date: 12.I.2011
-- Description: Lists equipment, lapis linked, current and added status points of a given character.
-- =============================================
CREATE PROCEDURE [dbo].[ausp_Read_PlayersEquipment_V2]
@CharID int
AS
BEGIN
SET NOCOUNT ON;
-- first get player UserUID
DECLARE @UserUID int;
SELECT @UserUID = UserUID FROM PS_GameData.dbo.Chars WHERE CharID = @CharID;
-- temp tables to store player items - equipped, in backpack, in warehouse
DECLARE @items_equipped TABLE (ItemID int, ItemName varchar(30), Gem1 varchar(30), Gem2 varchar(30),
Gem3 varchar(30), Gem4 varchar(30), Gem5 varchar(30), Gem6 varchar(30));
DECLARE @items_backpack TABLE (ItemID int, ItemName varchar(30));
DECLARE @items_warehouse TABLE (ItemID int, ItemName varchar(30));
-- temp table to store lapis properties
DECLARE @lapis_props TABLE (TypeID smallint, ItemName varchar(30), ConstStr tinyint, ConstDex tinyint,
ConstRec tinyint, ConstInt tinyint, ConstWis tinyint, ConstLuc tinyint, ConstHP tinyint,
ConstMP tinyint, ConstSP tinyint);
/*
Now get all needed information about player's items and lapis linked in equipped gear.
- get player's equiped items
*/
INSERT @items_equipped
SELECT CI.ItemID, I.ItemName, CI.Gem1, CI.Gem2, CI.Gem3, CI.Gem4, CI.Gem5, CI.Gem6
FROM PS_GameData.dbo.CharItems AS CI INNER JOIN PS_gamedefs.dbo.Items AS I
ON CI.ItemID = I.ItemID AND CI.Bag=0
WHERE CI.CharID = @CharID
ORDER BY CI.Bag, CI.Slot;
-- get player's items from backpack
INSERT INTO @items_backpack
SELECT CI.ItemID, I.ItemName
FROM PS_GameData.dbo.CharItems AS CI INNER JOIN PS_gamedefs.dbo.Items AS I
ON CI.ItemID = I.ItemID
WHERE CI.CharID = @CharID AND CI.Bag IN (1,2,3,4,5)
ORDER BY CI.Bag, I.Slot;
-- get player's items from warehouse
INSERT INTO @items_warehouse
SELECT USI.ItemID, I.ItemName
FROM PS_GameData.dbo.UserStoredItems AS USI INNER JOIN PS_gamedefs.dbo.Items AS I
ON USI.ItemID = I.ItemID
WHERE USI.UserUID = @UserUID
ORDER BY USI.Slot;
/*
Get lapis properties for each lapis linked to equipped gear.
Info is stored by TypeID of lapis.
*/
INSERT INTO @lapis_props
SELECT TypeID, ItemName, ConstStr, ConstDex, ConstRec, ConstWis, ConstInt, ConstLuc, ConstHP, ConstMP, ConstSP
FROM PS_gamedefs.dbo.Items
WHERE [Type]=30 AND TypeID IN ( SELECT DISTINCT Gem.Gem1 FROM
(SELECT DISTINCT Gem1 FROM @items_equipped UNION ALL Select DISTINCT Gem2 FROM @items_equipped UNION ALL
SELECT DISTINCT Gem3 FROM @items_equipped UNION ALL SELECT DISTINCT Gem4 FROM @items_equipped UNION ALL
SELECT DISTINCT Gem5 FROM @items_equipped UNION ALL SELECT DISTINCT Gem6 FROM @items_equipped) AS Gem)
/*
Create table to store player's status information.
- without _p - characters current status points
- with _p - status points added by lapis (summed)
*/
DECLARE @player_stats TABLE (
CharName varchar(60),
[Str] smallint, Dex smallint, Rec smallint, [Int] smallint, Wis smallint, Luc smallint,
Str_p smallint DEFAULT(0), Dex_p smallint DEFAULT(0), Rec_p smallint DEFAULT(0),
Int_p smallint DEFAULT(0), Wis_p smallint DEFAULT(0), Luc_p smallint DEFAULT(0));
-- fill above table with player's status information
INSERT INTO @player_stats (CharName, [Str], Dex, Rec, [Int], Wis, Luc)
SELECT CharName, [Str], Dex, Rec, [Int], Wis, Luc
FROM PS_GameData.dbo.Chars
WHERE CharID=@CharID;
/*
Add points added by lapis and store the result in _p fields in @player_stats table.
Variables found below are used to collect data about the amount of status points added
by lapis. It is used then to update @player_stats table _p fields.
*/
DECLARE @Str smallint, @Dex smallint, @Rec smallint, @Int smallint, @Wis smallint, @Luc smallint,
@Str_p smallint, @Dex_p smallint, @Rec_p smallint, @Int_p smallint, @Wis_p smallint, @Luc_p smallint;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem1 = LP.TypeID
SET @Str_p=@Str;
SET @Dex_p=@Dex;
SET @Rec_p=@Rec;
SET @Int_p=@Int;
SET @Wis_p=@Wis;
SET @Luc_p=@Luc;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem2 = LP.TypeID
SET @Str_p = @Str_p + @Str;
SET @Dex_p = @Dex_p + @Dex;
SET @Rec_p = @Rec_p + @Rec;
SET @Int_p = @Int_p + @Int;
SET @Wis_p = @Wis_p + @Wis;
SET @Luc_p = @Luc_p + @Luc;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem3 = LP.TypeID
SET @Str_p = @Str_p + @Str;
SET @Dex_p = @Dex_p + @Dex;
SET @Rec_p = @Rec_p + @Rec;
SET @Int_p = @Int_p + @Int;
SET @Wis_p = @Wis_p + @Wis;
SET @Luc_p = @Luc_p + @Luc;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem4 = LP.TypeID
SET @Str_p = @Str_p + @Str;
SET @Dex_p = @Dex_p + @Dex;
SET @Rec_p = @Rec_p + @Rec;
SET @Int_p = @Int_p + @Int;
SET @Wis_p = @Wis_p + @Wis;
SET @Luc_p = @Luc_p + @Luc;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem5 = LP.TypeID
SET @Str_p = @Str_p + @Str;
SET @Dex_p = @Dex_p + @Dex;
SET @Rec_p = @Rec_p + @Rec;
SET @Int_p = @Int_p + @Int;
SET @Wis_p = @Wis_p + @Wis;
SET @Luc_p = @Luc_p + @Luc;
SELECT @Str = SUM(LP.ConstStr), @Dex = SUM(LP.ConstDex), @Rec = SUM(LP.ConstRec),
@Int = SUM(LP.ConstInt), @Wis = SUM(LP.ConstWis), @Luc = SUM(LP.ConstLuc)
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem6 = LP.TypeID
SET @Str_p = @Str_p + @Str;
SET @Dex_p = @Dex_p + @Dex;
SET @Rec_p = @Rec_p + @Rec;
SET @Int_p = @Int_p + @Int;
SET @Wis_p = @Wis_p + @Wis;
SET @Luc_p = @Luc_p + @Luc;
UPDATE @player_stats SET Str_p=@Str_p, Dex_p=@Dex_p, Rec_p=@Rec_p, Int_p=@Int_p, Wis_p=@Wis_p, Luc_p=@Luc_p;
/*
Because of small error when declaring @items_equipped table (Gem1-6 is varchar instead of tinyint),
all TypeID's of lapis will be updated to LapisName.
*/
UPDATE @items_equipped SET Gem1 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem1=LP.TypeID
UPDATE @items_equipped SET Gem2 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem2=LP.TypeID
UPDATE @items_equipped SET Gem3 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem3=LP.TypeID
UPDATE @items_equipped SET Gem4 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem4=LP.TypeID
UPDATE @items_equipped SET Gem5 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem5=LP.TypeID
UPDATE @items_equipped SET Gem6 = LP.ItemName
FROM @items_equipped AS IE INNER JOIN @lapis_props AS LP
ON IE.Gem6=LP.TypeID
/*
Select all the data for the PHP script to process.
*/
SELECT CharName, [Str], Dex, Rec, [Int], Wis, Luc, Str_p, Dex_p, Rec_p, Int_p, Wis_p, Luc_p FROM @player_stats;
SELECT ItemName, Gem1, Gem2, Gem3, Gem4, Gem5, Gem6 FROM @items_equipped;
SELECT ItemName FROM @items_backpack;
SELECT ItemName FROM @items_warehouse;
SET NOCOUNT OFF;
END
SET ANSI_NULLS OFF;
SET QUOTED_IDENTIFIER OFF;
|
|
|
01/07/2011, 22:35
|
#2
|
elite*gold: 0
Join Date: Aug 2010
Posts: 136
Received Thanks: 343
|
If you changed the Set to
Code:
SET @MobName = [COLOR="Red"]'%%'[/COLOR];
and the Where to
Code:
WHERE M.MobName like @MobName
Or (with the original SET)
Code:
where MobName like '%@MobName%'
(Abrasive suggested this might work)
Will it find partial mob names?
I'm not currently at home so I couldn't test it.
I usually search for partial mob names because I can never remember the full thing, and sometimes it is hard to get the exact name, like CTI.
Also, if you can do partial names, it would make it more robust.
|
|
|
01/07/2011, 23:32
|
#3
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
Didn't think of that. Added.
|
|
|
01/07/2011, 23:45
|
#4
|
elite*gold: 0
Join Date: Mar 2010
Posts: 2,334
Received Thanks: 1,777
|
# added to my collection of guides.^^
|
|
|
01/08/2011, 12:54
|
#5
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
Added something new.
|
|
|
01/09/2011, 01:27
|
#6
|
elite*gold: 0
Join Date: Aug 2010
Posts: 136
Received Thanks: 343
|
Quote:
Originally Posted by ProfNerwosol
There's a lot of recurring DELETE and (CharID IN (SELECT CharID FROM @del_chars)) statements. I didn't know how to replace the latter. I hope someone with more knowledge and experience can optimize the procedure.
|
Abrasive can probably do it, he is much better at writing queries than I am. I'm only good at finding exploits
Quote:
Originally Posted by ProfNerwosol
This is one heck of a statement if you ask me, but I didn't want to start another thread. This is a complete procedure to wipe existence of any player from a server. It only needs a CharName, then it goes by itself acquiring all the necessary data. Read the comments when you are lost. Post any errors if you get them.
|
I think it would be safer supplying the UserUID or UserID.
But, if you still what to do it based on character name, you should add a check to see if that character has not been deleted. I believe it is possible to have two characters in the database with the same name, only one of them will be active however.
I think the way it stands, it could accidently grab the UserUID of somebody that had that char name and deleted the character, then proceed to delete all his data.
I didn't see where this deleted your friend list as well as take your characters off of anybody that friended you. (This sounds really complex).
Abrasive and I were talking and thought it would be good to add a 'BEGIN TRAN'/'ROLLBACK' to this also. That way if any part had an error it wouldn't fragment the data.
|
|
|
01/09/2011, 17:26
|
#7
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
There would be a problem with UserID or UserUID. You don't normally know them when you are in game. However it can be easily changed and the procedure made available to players who want to delete their account. UserUID or UserID would be known then.
You might be right with the two char names in DB. I think the server doesn't include deleted chars in check for duplicate names. I'll add check for it.
EDIT:
Added TRY...CATCH to test for errors and TRANSACTION.
Deleting friend list and those chars from others friend lists was easier than I thought. CharID's of friends are stored in one table so basically you need to delete every record with your CharID and every record where your CharID appears in FriendID column.
|
|
|
01/10/2011, 01:34
|
#8
|
elite*gold: 0
Join Date: Jun 2010
Posts: 84
Received Thanks: 65
|
Very nice addition. Certainly makes the process much quicker, as well as easier to keep db's clean and minimal. Thank you.
|
|
|
01/11/2011, 22:33
|
#9
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
Another addition to first post.
|
|
|
01/12/2011, 14:00
|
#10
|
elite*gold: 0
Join Date: Aug 2010
Posts: 241
Received Thanks: 254
|
In the Player equipments SQL I got an small error
Code:
Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.
To avoid this just remove the calls to I.Itemname near cursor declaration, and also from fetch next statement. To get the itemname use the ItemID and get from items table seperatly.
|
|
|
01/12/2011, 14:34
|
#11
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
Quote:
Originally Posted by zargon05
In the Player equipments SQL I got an small error
Code:
Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.
To avoid this just remove the calls to I.Itemname near cursor declaration, and also from fetch next statement. To get the itemname use the ItemID and get from items table seperatly.
|
You got the error because I didn't add variable @ItemName to the FETCH inside the loop. No need to remove I.ItemName from cursor declaration. I used JOIN to limit the number of queries.
|
|
|
01/12/2011, 14:59
|
#12
|
elite*gold: 0
Join Date: Aug 2010
Posts: 241
Received Thanks: 254
|
Ok ty, fixed.
Here I modifiedt so instead just displaying the charitems table, It displays the entire item list in tabular form.
Code:
USE [PS_GameData]
GO
/****** Object: StoredProcedure [dbo].[ausp_Check_PlayersEquipment] Script Date: 06/13/2010 12:24:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tomasz Wiacek
-- Create date: <Create Date,,>
-- Description: Lists equipment, lapis linked, current and added status points of a given character.
-- =============================================
CREATE PROCEDURE [dbo].[ausp_Check_PlayersEquipment]
@CharName varchar(50) = '',
@CharID int = 0
AS
BEGIN
SET NOCOUNT ON;
DECLARE @tempitems TABLE (
ItemName varchar(30),
Gem1 varchar(30),
Gem2 varchar(30),
Gem3 varchar(30),
Gem4 varchar(30),
Gem5 varchar(30),
Gem6 varchar(30) )
-- variables to store Status Points
-- variables without _p - characters current status points
-- variables with _p - status points added by lapis
DECLARE @Str smallint, @Dex smallint, @Rec smallint, @Int smallint, @Wis smallint, @Luc smallint,
@Str_p smallint, @Dex_p smallint, @Rec_p smallint, @Int_p smallint, @Wis_p smallint, @Luc_p smallint;
-- variables for sp_executesql
DECLARE @stmt nvarchar(1000), @variables nvarchar(500)
-- these variables with hold lapis name and an item it was linked to
DECLARE @ItemName varchar(50),
@GemName1 varchar(50),@GemName2 varchar(50),@GemName3 varchar(50),@GemName4 varchar(50),
@GemName5 varchar(50),@GemName6 varchar(50);
-- variables to hold lapis properties
-- first set is TypeID selected from PS_GameData.dbo.CharItems
-- second set (Const***) holds what lapis adds
DECLARE @Gem1 tinyint,@Gem2 tinyint,@Gem3 tinyint,@Gem4 tinyint,@Gem5 tinyint,@Gem6 tinyint
DECLARE @ConstStr tinyint, @ConstDex tinyint, @ConstRec tinyint, @ConstInt tinyint, @ConstWis tinyint,
@ConstLuc tinyint, @ConstHP tinyint, @ConstMP tinyint, @ConstSP tinyint;
DECLARE @ItemID int
-- let's prepare statements for sp_executesql procedure
SET @stmt = N'
SELECT @GemName=ItemName, @ConstStr=ConstStr, @ConstDex=ConstDex, @ConstRec=ConstRec, @ConstInt=ConstInt,
@ConstWis=ConstWis, @ConstLuc=ConstLuc, @ConstHP=ConstHP, @ConstMP=ConstMP, @ConstSP=ConstSP
FROM PS_GameDefs.dbo.Items WHERE [Type]=30 AND TypeID=@Gem';
SET @variables = N'
@GemName varchar(50) output, @Gem tinyint, @ConstStr tinyint output, @ConstDex tinyint output,
@ConstRec tinyint output, @ConstInt tinyint output, @ConstWis tinyint output, @ConstLuc tinyint output,
@ConstHP tinyint output, @ConstMP tinyint output, @ConstSP tinyint output';
-- and initialize variables
SET @Str_p = 0
SET @Dex_p = 0
SET @Rec_p = 0
SET @Int_p = 0
SET @Wis_p = 0
SET @Luc_p = 0
IF @CharID = 0
SELECT @CharID = CharID FROM dbo.Chars WHERE CharName=@CharName;
ELSE
SELECT @CharName = CharName FROM dbo.Chars WHERE CharID=@CharID;
-- let see if the character exists and there are no typing errors
IF @@ROWCOUNT>0
BEGIN
-- setting up a cursor to process characters items (equiped)
DECLARE item_cursor CURSOR FAST_FORWARD FOR
SELECT CI.ItemID,CI.ItemName, CI.Gem1, CI.Gem2, CI.Gem3, CI.Gem4, CI.Gem5, CI.Gem6
FROM dbo.CharItems AS CI INNER JOIN PS_GameDefs.dbo.Items AS I
ON CI.ItemID = I.ItemID
WHERE CI.CharID = @CharID AND CI.Bag=0 ORDER BY CI.slot --AND Gem1<>0 AND (Gem2<>0 or Gem3<>0 or Gem4<>0 or Gem5<>0 or Gem6<>0);
SELECT ItemID, Gem1, Gem2, Gem3, Gem4, Gem5, Gem6
FROM PS_GameData.dbo.CharItems WHERE CharID=@CharID AND Bag=0
-- initialize cursor and fetch first row
OPEN item_cursor;
FETCH NEXT FROM item_cursor INTO
@ItemID,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6,@ItemName;
-- now let's put it all together and print what items this character has
PRINT '-----------------------------'
PRINT 'Items of: ' + @CharName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' '
print '----------------------------------------';
print 'Item name: ' + @ItemName;
print '----------------------------------------';
-- if this is an old player not all slots can be taken and some lapis might have been extracted
-- let's make sure we don't process such slots
if @Gem1 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName1 output, @Gem1, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem1: ' + @GemName1
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName1 = ''
end
if @Gem2 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName2 output,@Gem2, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem2: ' + @GemName2
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName2 = ''
end
if @Gem3 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName3 output,@Gem3, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem3: ' + @GemName3
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName3 = ''
end
if @Gem4 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName4 output,@Gem4, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem4: '+@GemName4
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName4 = ''
end
if @Gem5 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName5 output,@Gem5, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem5: '+@GemName5
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName5 = ''
end
if @Gem6 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName6 output,@Gem6, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem6: ' + @GemName6
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName6 = ''
end
INSERT INTO @tempitems (itemname,gem1,gem2,gem3,gem4,gem5,gem6)
VALUES (@itemname,@gemname1,@gemname2,@gemname3,@gemname4,@gemname5,@gemname6)
-- get new row from the cursor
FETCH NEXT FROM item_cursor INTO
@ItemID,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6,@ItemName
END
-- the cursor is no longer needed, time to close it and free memory
CLOSE item_cursor
DEALLOCATE item_cursor
/* now let's see how many status points the character has */
SELECT @Str = [Str], @Dex = Dex, @Rec = Rec, @Int = [Int], @Wis = Wis, @Luc = Luc
FROM dbo.Chars WHERE CharName=@CharName
SELECT * FROM @tempitems
PRINT '----------------------------------------';
PRINT 'Players status points: ';
PRINT 'Str: ' + cast(@Str AS char(3)) + ' (' + cast(@Str_p as char(3)) + ') = ' + cast(@Str + @Str_p as Char(4))
PRINT 'Dex: ' + cast(@Dex AS char(3)) + ' (' + cast(@Dex_p as char(3)) + ') = ' + cast(@Dex + @Dex_p as Char(4))
PRINT 'Rec: ' + cast(@Rec AS char(3)) + ' (' + cast(@Rec_p as char(3)) + ') = ' + cast(@Rec + @Rec_p as Char(4))
PRINT 'Int: ' + cast(@Int AS char(3)) + ' (' + cast(@Int_p as char(3)) + ') = ' + cast(@Int + @Int_p as Char(4))
PRINT 'Wis: ' + cast(@Wis AS char(3)) + ' (' + cast(@Wis_p as char(3)) + ') = ' + cast(@Wis + @Wis_p as Char(4))
PRINT 'Luc: ' + cast(@Luc AS char(3)) + ' (' + cast(@Luc_p as char(3)) + ') = ' + cast(@Luc + @Luc_p as Char(4))
PRINT '----------------------------------------';
END
ELSE
BEGIN
PRINT 'Character ' + @CharName + ' does not exists.'
END
END
|
|
|
01/12/2011, 18:02
|
#13
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
How will you go about adding the players status information to the table or are you planing not to? I was thinking to do it this way but couldn't come up with any idea how to combine everything in one table.
Btw, minor bug in CURSOR declaration "CI.ItemName" should be "I.ItemName" or you'll get an error. Plus remember to add @ItemName to FETCH's. There are two of them. One is right under whole CURSOR thing and the other is at the end of WHILE loop.
|
|
|
01/13/2011, 00:05
|
#14
|
elite*gold: 0
Join Date: Oct 2009
Posts: 449
Received Thanks: 644
|
*BUMP*
Added another version of equipment listing procedure.
|
|
|
01/13/2011, 14:13
|
#15
|
elite*gold: 0
Join Date: Aug 2010
Posts: 241
Received Thanks: 254
|
o.O sorry I posted a untested version instead of the one in my DB. I never intented to add a seperate table for stats but here is one anyway. The last row of the items table is used for stats
Code:
USE [PS_GameData]
GO
/****** Object: StoredProcedure [dbo].[ausp_Check_PlayersEquipment] Script Date: 01/13/2011 19:04:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tomasz Wiacek
-- Create date: <Create Date,,>
-- Description: Lists equipment, lapis linked, current and added status points of a given character.
-- =============================================
CREATE PROCEDURE [dbo].[ausp_Check_PlayersEquipment]
@CharName varchar(50) = '',
@CharID int = 0
AS
BEGIN
SET NOCOUNT ON;
DECLARE @tempitems TABLE (
ItemName varchar(50),
Gem1 varchar(50),
Gem2 varchar(50),
Gem3 varchar(50),
Gem4 varchar(50),
Gem5 varchar(50),
Gem6 varchar(50) )
-- variables to store Status Points
-- variables without _p - characters current status points
-- variables with _p - status points added by lapis
DECLARE @Str smallint, @Dex smallint, @Rec smallint, @Int smallint, @Wis smallint, @Luc smallint,
@Str_p smallint, @Dex_p smallint, @Rec_p smallint, @Int_p smallint, @Wis_p smallint, @Luc_p smallint;
-- variables for sp_executesql
DECLARE @stmt nvarchar(1000), @variables nvarchar(500)
-- these variables with hold lapis name and an item it was linked to
DECLARE @ItemName varchar(50),
@GemName1 varchar(50),@GemName2 varchar(50),@GemName3 varchar(50),@GemName4 varchar(50),
@GemName5 varchar(50),@GemName6 varchar(50);
-- variables to hold lapis properties
-- first set is TypeID selected from PS_GameData.dbo.CharItems
-- second set (Const***) holds what lapis adds
DECLARE @Gem1 tinyint,@Gem2 tinyint,@Gem3 tinyint,@Gem4 tinyint,@Gem5 tinyint,@Gem6 tinyint
DECLARE @ConstStr tinyint, @ConstDex tinyint, @ConstRec tinyint, @ConstInt tinyint, @ConstWis tinyint,
@ConstLuc tinyint, @ConstHP tinyint, @ConstMP tinyint, @ConstSP tinyint;
DECLARE @ItemID int
-- let's prepare statements for sp_executesql procedure
SET @stmt = N'
SELECT @GemName=ItemName, @ConstStr=ConstStr, @ConstDex=ConstDex, @ConstRec=ConstRec, @ConstInt=ConstInt,
@ConstWis=ConstWis, @ConstLuc=ConstLuc, @ConstHP=ConstHP, @ConstMP=ConstMP, @ConstSP=ConstSP
FROM PS_GameDefs.dbo.Items WHERE [Type]=30 AND TypeID=@Gem';
SET @variables = N'
@GemName varchar(50) output, @Gem tinyint, @ConstStr tinyint output, @ConstDex tinyint output,
@ConstRec tinyint output, @ConstInt tinyint output, @ConstWis tinyint output, @ConstLuc tinyint output,
@ConstHP tinyint output, @ConstMP tinyint output, @ConstSP tinyint output';
-- and initialize variables
SET @Str_p = 0
SET @Dex_p = 0
SET @Rec_p = 0
SET @Int_p = 0
SET @Wis_p = 0
SET @Luc_p = 0
IF @CharID = 0
SELECT @CharID = CharID FROM dbo.Chars WHERE CharName=@CharName;
ELSE
SELECT @CharName = CharName FROM dbo.Chars WHERE CharID=@CharID;
-- let see if the character exists and there are no typing errors
IF @@ROWCOUNT>0
BEGIN
-- setting up a cursor to process characters items (equiped)
DECLARE item_cursor CURSOR FAST_FORWARD FOR
SELECT CI.ItemID,I.ItemName, CI.Gem1, CI.Gem2, CI.Gem3, CI.Gem4, CI.Gem5, CI.Gem6
FROM dbo.CharItems AS CI INNER JOIN PS_GameDefs.dbo.Items AS I
ON CI.ItemID = I.ItemID
WHERE CI.CharID = @CharID AND CI.Bag=0 ORDER BY CI.slot --AND Gem1<>0 AND (Gem2<>0 or Gem3<>0 or Gem4<>0 or Gem5<>0 or Gem6<>0);
-- initialize cursor and fetch first row
OPEN item_cursor;
FETCH NEXT FROM item_cursor INTO
@ItemID,@ItemName,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6;
-- now let's put it all together and print what items this character has
PRINT '-----------------------------'
PRINT 'Items of: ' + @CharName
WHILE @@FETCH_STATUS = 0
BEGIN
--SELECT @ItemName=Itemname from PS_GameDefs.dbo.items where itemid=@itemid
PRINT ' '
print '----------------------------------------';
print 'Item name: ' + @ItemName;
print '----------------------------------------';
-- if this is an old player not all slots can be taken and some lapis might have been extracted
-- let's make sure we don't process such slots
if @Gem1 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName1 output, @Gem1, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem1: ' + @GemName1
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName1 = ''
end
if @Gem2 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName2 output,@Gem2, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem2: ' + @GemName2
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName2 = ''
end
if @Gem3 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName3 output,@Gem3, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem3: ' + @GemName3
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName3 = ''
end
if @Gem4 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName4 output,@Gem4, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem4: '+@GemName4
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName4 = ''
end
if @Gem5 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName5 output,@Gem5, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem5: '+@GemName5
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName5 = ''
end
if @Gem6 <> 0
begin
exec sp_executesql @stmt,@variables,@GemName6 output,@Gem6, @ConstStr output,
@ConstDex output, @ConstRec output, @ConstInt output, @ConstWis output,
@ConstLuc output, @ConstHP output, @ConstMP output, @ConstSP output;
print 'Gem6: ' + @GemName6
if @ConstStr <> 0 SET @Str_p = @Str_p + @ConstStr;
if @ConstDex <> 0 SET @Dex_p = @Dex_p + @ConstDex;
if @ConstRec <> 0 SET @Rec_p = @Rec_p + @ConstRec;
if @ConstInt <> 0 SET @Int_p = @Int_p + @ConstInt;
if @ConstWis <> 0 SET @Wis_p = @Wis_p + @ConstWis;
if @ConstLuc <> 0 SET @Luc_p = @Luc_p + @ConstLuc;
end
else
begin
SET @GemName6 = ''
end
INSERT INTO @tempitems (itemname,gem1,gem2,gem3,gem4,gem5,gem6)
VALUES (@itemname,@gemname1,@gemname2,@gemname3,@gemname4,@gemname5,@gemname6)
-- get new row from the cursor
FETCH NEXT FROM item_cursor INTO
@ItemID,@ItemName,@Gem1,@Gem2,@Gem3,@Gem4,@Gem5,@Gem6
END
-- the cursor is no longer needed, time to close it and free memory
CLOSE item_cursor
DEALLOCATE item_cursor
/* now let's see how many status points the character has */
SELECT @Str = [Str], @Dex = Dex, @Rec = Rec, @Int = [Int], @Wis = Wis, @Luc = Luc
FROM dbo.Chars WHERE CharName=@CharName
INSERT INTO @tempitems (itemname,gem1,gem2,gem3,gem4,gem5,gem6)
VALUES ('Stats',
cast(@Str as char(4))+'+'+cast(@Str_p as char(4)),
cast(@Dex as char(4))+'+'+cast(@Dex_p as char(4)),
cast(@Rec as char(4))+'+'+cast(@Rec_p as char(4)),
cast(@Int as char(4))+'+'+cast(@Int_p as char(4)),
cast(@Wis as char(4))+'+'+cast(@Wis_p as char(4)),
cast(@Luc as char(4))+'+'+cast(@Luc_p as char(4)))
SELECT * FROM @tempitems
PRINT '----------------------------------------';
PRINT 'Players status points: ';
PRINT 'Str: ' + cast(@Str AS char(3)) + ' (' + cast(@Str_p as char(3)) + ') = ' + cast(@Str + @Str_p as Char(4))
PRINT 'Dex: ' + cast(@Dex AS char(3)) + ' (' + cast(@Dex_p as char(3)) + ') = ' + cast(@Dex + @Dex_p as Char(4))
PRINT 'Rec: ' + cast(@Rec AS char(3)) + ' (' + cast(@Rec_p as char(3)) + ') = ' + cast(@Rec + @Rec_p as Char(4))
PRINT 'Int: ' + cast(@Int AS char(3)) + ' (' + cast(@Int_p as char(3)) + ') = ' + cast(@Int + @Int_p as Char(4))
PRINT 'Wis: ' + cast(@Wis AS char(3)) + ' (' + cast(@Wis_p as char(3)) + ') = ' + cast(@Wis + @Wis_p as Char(4))
PRINT 'Luc: ' + cast(@Luc AS char(3)) + ' (' + cast(@Luc_p as char(3)) + ') = ' + cast(@Luc + @Luc_p as Char(4))
PRINT '----------------------------------------';
END
ELSE
BEGIN
PRINT 'Character ' + @CharName + ' does not exists.'
END
END
|
|
|
Similar Threads
|
[Release] Some Usefull Tools
12/23/2014 - Aion Guides & Strategies - 8 Replies
Well, i see there is not much traffic going here , and anyway there aren't a lot of releases for aion.so i guess those will help you a bit.
All credits go to the releasers.
Make Max level 60 (34.87 KB) Multiupload.com - upload your files to multiple file hosting sites!
Fixed Gatherable Templates (6.34 KB) Multiupload.com - upload your files to multiple file hosting sites!
|
[RELEASE] Usefull Server Scripts
03/02/2010 - EO PServer Guides & Releases - 9 Replies
Hey everyone as there isnt many admin type releases i thought id put some up to help out the newer server developers out there.
here is a list of the scripts to follow:
Palladin Potion Soul bug fix,
Set players gear to full bonus,
Bot jail a player,
Open all totems,
Staff ep and pp award,
banned player and cheat log table' (php web page for it soon)
|
All times are GMT +2. The time now is 22:48.
|
|