[RELEASE] Upgrade System

03/23/2015 10:05 Syloxx#1
Procedure:

Code:
/**
version : 1
author : syloxx
created date : 2015-03-23
description : upgrade your items.
return value :
0 = There is no error.
-1 = The transaction is in an uncommittable state. Rolling back transaction.
-2 = Slot 13 is emptry.
-3 = Item in slot 13 is not in upgrade table.
**/

CREATE PROCEDURE dbo._UpgradeItem
      @CharID int
    , @Scroll varchar(129)
AS
SET NOCOUNT ON;
SET XACT_ABORT ON;

DECLARE @ReturnValue int
    , @ItemID bigint
    , @BeforeRefID int
    , @BeforeOptLevel tinyint
    , @UpgradeRefID int
    , @UpgradeOptLevel tinyint;

IF XACT_STATE() = -1
BEGIN
    SET @ReturnValue = -1;
    GOTO ErrorHandler;
END

BEGIN TRY
    /**_# Get ItemID of item in slot 13.*/
    SELECT @ItemID = ItemID
    FROM dbo._Inventory WITH (NOLOCK)
    WHERE CharID = @CharID
    AND Slot = 13;

    /**_# Check if slot 13 is empty.*/
    IF @ItemID IS NULL OR @ItemID = 0
    BEGIN
        SET @ReturnValue = -2;
        GOTO ErrorHandler;
    END

    /**_# Get RefID and OptLevel of item in slot 13.*/
    SELECT @BeforeRefID = RefItemID
        , @BeforeOptLevel = OptLevel
    FROM dbo._Items WITH (NOLOCK)
    WHERE ID64 = @ItemID;

    /**_# Get all required informations to upgrade the item.*/
    SELECT TOP 1 @UpgradeRefID = UpgradeRefID
        , @UpgradeOptLevel = UpgradeOptLevel
    FROM _RefUpgradeConfig WITH (NOLOCK)
    WHERE Service = 1
    AND BeforeRefID = @BeforeRefID
    AND BeforeOptLevel <= @BeforeOptLevel
    ORDER BY BeforeOptLevel DESC;

    /**_# Check if item in slot 13 exsits in upgrade table.*/
    IF @UpgradeRefID IS NULL OR @UpgradeRefID = 0
    BEGIN
        SET @ReturnValue = -3;
        GOTO ErrorHandler;
    END

    BEGIN TRANSACTION;

    /**_# Upgrade your item.*/
    UPDATE _Items
    SET RefItemID = @UpgradeRefID
        , OptLevel = @UpgradeOptLevel
    WHERE ID64 = @ItemID;

    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    GOTO ErrorHandler;
END CATCH;

RETURN 0;

ErrorHandler:
IF XACT_STATE() <> 0
    ROLLBACK TRANSACTION;

DECLARE @CharName varchar(16);

SELECT @CharName = CharName16
FROM _Char WITH (NOLOCK)
WHERE CharID = @CharID;

EXEC _ADD_ITEM_EXTERN @CharName, @Scroll, 1, 0;

RETURN @ReturnValue;
Table:
Code:
CREATE TABLE _RefUpgradeConfig
(
  Service bit NOT NULL
, BeforeRefID int NOT NULL
, BeforeOptLevel tinyint NOT NULL
, UpgradeRefID int NOT NULL
, UpgradeOptLevel tinyint NOT NULL
);
i didn't tested this system so if something is wrong please lemme know.

TUTORIAL
you have to config the upgrade system first.
means you have to insert stuff in the _RefUpgradeConfig table in following format:

Service, BeforeRefID (olditem), BeforeOptLevel (required plus), UpgradeRefID (new item), UpgradeOptLevel (new plus)

the rest should be self explain
03/23/2015 10:34 DeaDeployment#2
tkz men pt wh pen en azs sw mne :)
03/23/2015 10:35 CrystalCoder#3
Great Job Syloxx
03/23/2015 10:35 DeaDeployment#4
[Only registered and activated users can see links. Click Here To Register...]

Hacker :)
03/23/2015 20:28 Syloxx#5
Quote:
Originally Posted by Exo View Post
Don't use Codes or ObjCommon for such stuff. Just don't!
why? its a one time use and only _RefObjCommon know the CodeName?
03/23/2015 21:17 Aaron*#6
Quote:
Originally Posted by Exo View Post
dafuq, that was a query to fill yo ur table :facepalm: my bad then..
Read the query before you post.. :p
03/23/2015 23:32 _Miss_AngeL_#7
Quote:
Originally Posted by Exo View Post
dafuq, that was a query to fill yo ur table :facepalm: my bad then..
hahahaha. can you tell me who explained for you that this query will fill the table and it's not a procedure for upgrade ?
don't try to lie. i knew that you don't have any idea about sql coding.
03/24/2015 00:32 Crue*#8
Quote:
Originally Posted by Exo View Post
We're talking about the procedure Aeron posted

btw, do I know you? I never saw you or heard about you before, can you stop acting like if you know me?
know you ? who are you i didn't hear about you also lel
03/24/2015 01:01 Eslam Galull#9
why every dam thread turning to a fight thread .. can you calm down ppl !! #Please !!
03/24/2015 01:17 AhmedKasin#10
one thing to say i like your work good luck in that you do and we wait for you all new..
03/24/2015 13:22 terawly#11
Great Job Syloxx
04/01/2015 09:00 X-Vortex#12
Nice :D
04/03/2015 15:21 TheRunner#13
useful thanks bro
04/19/2015 00:23 raptter#14
added procedure succ + config table and i fill it with items codes + OPT level
now could anyone tell me how to use it to upgrade my weapons anyone answer please cuze i don't know how to do it
04/19/2015 10:26 Syloxx#15
place the item you wanna uprade on slot 13 (1 in inventory).
Execute the procedure (can be executed by a scroll aswell).
Teleport!

I won't explain you how to execute this procedure by scroll.