Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[DEV]MySQL Function ADD ITEMS

Status
Not open for further replies.
Newbie Spellweaver
Joined
Apr 2, 2012
Messages
94
Reaction score
26
Add Function this to loong_db
MySQL Workbench 5.2 CE
PHP:
delimiter $$

CREATE FUNCTION `Add_Items_function`(
Num_ INTEGER,
TypeID_ INTEGER,
Bind_ INTEGER,
OwnerID_ INTEGER,
AccountID_ INTEGER) RETURNS int(11)
BEGIN
DECLARE TEST_ID INTEGER ;
DECLARE LAST_ID INTEGER ;
DECLARE ii,i2,i3 INTEGER ;
SET TEST_ID = 0;  
SET LAST_ID = 19; 
SET ii = 20;
SET i2 = 20;
SET i3 = IFNULL((SELECT
    MAX(`roledata`.`RoleID`)
FROM  
    `loong_db`.`roledata` 
WHERE 
    `roledata`.`RoleID` = OwnerID_ 
AND 
	`roledata`.`AccountID` = AccountID_),-1);
myloop:WHILE TEST_ID <= LAST_ID DO
SET ii = IFNULL((SELECT 
    MAX(`item`.`Suffix`)
FROM
    `loong_db`.`item`
WHERE
    `item`.`Suffix` = TEST_ID
        AND `item`.`OwnerID` = OwnerID_
        AND `item`.`ContainerTypeID` = 3),20);
IF ii = 20 THEN 
SET i2 = TEST_ID;
LEAVE myloop;
END IF;
    SET TEST_ID = TEST_ID + 1;
 
  END WHILE;
IF ((i2 <= 19) AND (i3 <> -1)) THEN 
INSERT INTO `loong_db`.`item`
(
`SerialNum`,
`Num`,
`TypeID`,
`Bind`,
`LockStat`,
`UnlockTime`,
`UseTimes`,
`FirstGainTime`,
`CreateMode`,
`CreateID`,
`CreatorID`,
`CreateTime`,
`OwnerID`,
`AccountID`,
`ContainerTypeID`,
`Suffix`,
`NameID`)
VALUES
(
UNIX_TIMESTAMP(),
Num_, 
TypeID_, 
Bind_, 
0,
0, 
0, 
NOW(), 
0,
4294967295,
4294967295, 
NOW(), 
OwnerID_,
AccountID_,
3, 
i2, 
4294967295
);
 ELSE 
 IF i3 = OwnerID_ THEN
  SET i2 = 255;
 ELSEIF i3 = -1 THEN
  SET i2 = -1;
 END IF;
END IF;
RETURN i2;
END$$

How to use in MySQL Workbench 5.2 CE
PHP:
Use loong_db;
SELECT  Add_Items_function(1,1421453,1,56,52);
/*
Num_ INTEGER, 1-9999 item count
TypeID_ INTEGER, 1421453 Esteemed Thunder Stone equip_name.xml ,item_name.xml
Bind_ INTEGER, 1 2=Lock
OwnerID_ INTEGER, 56 ID charater
AccountID_ INTEGER 52 id account
*/
Use PHP
PHP:
$Q='SELECT  Add_Items_function(1,1421453,1,56,52)';

RETURN 0-19 OK IN INSERT to slot index bag mall +1
RETURN 255 ERROR Bag Full
RETURN -1 ERROR Null RoleID Or AccountID

Thank Seymour

8-16-2013 9-19-18 PM - [DEV]MySQL Function ADD ITEMS - RaGEZONE Forums

use Delphi
PHP:
procedure TForm2.Button15Click(Sender: TObject);
var buttonSelected1,i:integer;
after:string;
begin
buttonSelected1 := MessageDlg('Confirmation',mtError, mbOKCancel, 0);
if buttonSelected1 = mrCancel then exit;
  after  := 'SELECT  `roledata`.`AccountID`, `roledata`.`RoleID` FROM `loong_db`.`roledata` WHERE `roledata`.`RoleName` = :nam';
  ZQuery1.Active:=false;
  ZQuery1.SQL.Clear;
  ZQuery1.SQL.Add(after);
  ZQuery1.ParamByName('nam').AsString:=Edit5.Text;
  ZQuery1.Open;
  ZQuery1.First;
  RoleName:=Edit5.Text;
  while(not ZQuery1.EOF)do begin
   AccountID:=ZQuery1.Fields[0].AsInteger;
   RoleID:= ZQuery1.Fields[1].AsInteger;
   ZQuery1.Next;
  end;



after  := 'SELECT  Add_Items_function(:cou, :typ, :bid, :rid, :uid)';
  ZQuery1.Active:=false;
  ZQuery1.SQL.Clear;
  ZQuery1.Params.Clear;
  ZQuery1.SQL.Add(after);
  ZQuery1.ParamByName('cou').AsInteger:=Strtoint(Edit3.Text);
  ZQuery1.ParamByName('typ').AsInteger:=Strtoint(ComboBox6.Text);
  ZQuery1.ParamByName('bid').AsInteger:=ComboBox8.ItemIndex;
  ZQuery1.ParamByName('rid').AsInteger:=RoleID;
  ZQuery1.ParamByName('uid').AsInteger:=AccountID;

     ZQuery1.Open;
   ZQuery1.First;
   while(not ZQuery1.EOF)do begin

    i  := ZQuery1.Fields[0].AsInteger;

    ZQuery1.Next;
   end;
   if i=-1 then
    after:='Char Name Wong!'
   else if i=255 then
    after:='Bag Full!'
   else
   after:='OK Add item to slot bag '+inttostr(i+1);
   Label26.Caption:='MSG:'+after;
end;
8-17-2013 8-09-23 AM - [DEV]MySQL Function ADD ITEMS - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Last edited by a moderator:
Newbie Spellweaver
Joined
Apr 2, 2012
Messages
94
Reaction score
26
iononline - [DEV]MySQL Function ADD ITEMS - RaGEZONE Forums

What version do you use?
Latest
Chinese translation to Thailand.

Update
PHP:
DELIMITER $$

CREATE FUNCTION `Add_Items_function`(
Num_ INTEGER,
TypeID_ INTEGER,
Bind_ INTEGER,
OwnerID_ INTEGER,
AccountID_ INTEGER,
IfEquip BOOLEAN) RETURNS int(11)
BEGIN
DECLARE TEST_ID INTEGER ;
DECLARE LAST_ID INTEGER ;
DECLARE ii,i2,i3 INTEGER ;
DECLARE TI INTEGER;
DECLARE MMM INTEGER;
SET MMM =0;
SET TEST_ID = 0;  
SET LAST_ID = 19; 
SET ii = 20;
SET i2 = 20;
SET TI =(SELECT UNIX_TIMESTAMP());
SET i3 = IFNULL((SELECT
    MAX(`roledata`.`RoleID`)
FROM  
    `loong_db`.`roledata` 
WHERE 
    `roledata`.`RoleID` = OwnerID_ 
AND 
	`roledata`.`AccountID` = AccountID_),-1);
myloop:WHILE TEST_ID <= LAST_ID DO
SET ii = IFNULL((SELECT 
    MAX(`item`.`Suffix`)
FROM
    `loong_db`.`item`
WHERE
    `item`.`Suffix` = TEST_ID
        AND `item`.`AccountID` = AccountID_
        AND `item`.`ContainerTypeID` = 3),20);
IF ii = 20 THEN 
SET i2 = TEST_ID;
LEAVE myloop;
END IF;
    SET TEST_ID = TEST_ID + 1;
 
  END WHILE;
IF ((i2 <= 19) AND (i3 <> -1)) THEN 
INSERT INTO `loong_db`.`item`
(
`SerialNum`,
`Num`,
`TypeID`,
`Bind`,
`LockStat`,
`UnlockTime`,
`UseTimes`,
`FirstGainTime`,
`CreateMode`,
`CreateID`,
`CreatorID`,
`CreateTime`,
`OwnerID`,
`AccountID`,
`ContainerTypeID`,
`Suffix`,
`NameID`)
VALUES
(
TI,
Num_, 
TypeID_, 
Bind_, 
0,
0, 
0, 
NOW(), 
7,
4294967295,
4294967295, 
NOW(), 
OwnerID_,
AccountID_,
3, 
i2, 
4294967295
);
 ELSE 
 IF i3 = OwnerID_ THEN
  SET i2 = 255;
 ELSEIF i3 = -1 THEN
  SET i2 = -1;
 END IF;
END IF;
IF IfEquip = TRUE THEN
INSERT INTO `loong_db`.`equip`
(`SerialNum`,
`Quality`,
`WuHun`,
`MinDmg`,
`MaxDmg`,
`Armor`,
`PotVal`)
VALUES
(
TI,
255,
227,
826,
7246,
826,
5600);
UPDATE `loong_db`.`equip`
SET
`Quality` = 255,
`WuHun` = 227,
`MinDmg` = 826,
`MaxDmg` = 7246,
`Armor` = 826,
`PotVal` = 5600
WHERE `equip`.`SerialNum` = TI;

END IF;
IF i2 = -1 THEN
SET TI = i2;
ELSEIF i2 = 255 THEN
SET TI = i2;
END IF;
 
RETURN TI;
END

RETURN >255 OK IN INSERT RETURN=SerialNum
RETURN 255 ERROR Bag Full
RETURN -1 ERROR Null RoleID Or AccountID

Use sent items
$Q='SELECT Add_Items_function(1,1421453,1,56,52,false)';
Use sent Equip
$Q='SELECT Add_Items_function(1,1421453,1,56,52,true)';

Work More.:junglejane:
 
Status
Not open for further replies.
Back
Top