User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 7 of 10

Thread: [LuaScript] Equipment Upgrades System

  1. #1
    Enthusiast
    Join Date
    Dec 2013
    Location
    China
    Posts
    33
    XP
    2,410
    Level
    13
    Thanks
    18
    Thanked 18 Times in 5 Posts

    Red face [LuaScript] Equipment Upgrades System

    Write in front... I come from China, my English is poor (T^T) (ο)~


    Code:
    print(">>  Loading EquipmentUpgradesSystem Code by Ayase")
    
    local EquipUpItemEntry = 70000
    local pSelectGos={}
    local clNum = nil
    
    local SlotName = {--is slot name 
    	[0]="|cFF0000FF    头部:|r",		[1]="|cFF0000FF    项链:|r",		[2]="|cFF0000FF    肩膀:|r",	[3]="|cFF0000FF    衬衣:|r",
    	[4]="|cFF0000FF    胸部:|r",		[5]="|cFF0000FF    腰带:|r",		[6]="|cFF0000FF    腿部:|r",	[7]="|cFF0000FF    脚部:|r",
    	[8]="|cFF0000FF    手腕:|r",		[9]="|cFF0000FF    手套:|r",		[10]="|cFF0000FF    戒指A:|r",	[11]="|cFF0000FF    戒指B:|r",
    	[12]="|cFF0000FF    饰品A:|r",		[13]="|cFF0000FF    饰品B:|r",		[14]="|cFF0000FF    背部:|r",	[15]="|cFF0000FF    主手装备:|r",
    	[16]="|cFF0000FF    副手装备:|r",	[17]="|cFF0000FF    远程武器:|r",	[18]="|cFF0000FF    战袍:|r",
    }
    
    local ItemDisplay = {}
    local ItemUpData = {}
    local DBItemData = {}
    
    local function LoadDBItemUP()
    	local query = WorldDBQuery("SELECT * FROM item_up;")
    	local a = 0
    	if (query) then
    		local Time1 = os.clock() * 1000
    		clNum = (query:GetColumnCount()-4)/2
    		repeat 
    			ItemUpData[query:GetUInt32(0)] = {
    				["up"] = query:GetUInt32(1),
    				["jl"] = query:GetUInt32(2),
    				["num"] = query:GetUInt32(3),
    				["cl"] = {}
    				}
    				for i=1,clNum do
    					ItemUpData[query:GetUInt32(0)]["cl"]["id"..i] = query:GetUInt32(2*i+2)
    					ItemUpData[query:GetUInt32(0)]["cl"]["num"..i] = query:GetUInt32(2*i+3)
    				end
    			a = a+1
    		until not query:NextRow()
    		local Time2 = os.clock() * 1000
    		print("     ItemUP->Loading "..a.." ItemUpData in "..Time2-Time1.." ms")
    	end
    end
    
    local function LoadDBItemData()
    	local query = WorldDBQuery("SELECT entry,displayid FROM item_template;")
    	if (query) then
    		local Time1 = os.clock() * 1000
    		repeat 
    			DBItemData[query:GetUInt32(0)] = query:GetUInt32(1)
    		until not query:NextRow()
    		local Time2 = os.clock() * 1000
    		print("     ItemUP->Loading "..#DBItemData.." ItemData in "..Time2-Time1.."ms")
    	end
    end
    
    local function LoadDBItemIcons()
    	local query = WorldDBQuery("SELECT displayid,icon FROM item_icon;")
    	if (query) then
    		local Time1 = os.clock() * 1000
    		repeat
    			ItemDisplay[query:GetUInt32(0)] = query:GetCString(1)
    		until not query:NextRow()
    		local Time2 = os.clock() * 1000
    		print("     ItemUP->Loading "..#ItemDisplay.." ItemIcon in "..Time2-Time1.."ms")
    	end
    end
    
    LoadDBItemUP()
    LoadDBItemData()
    LoadDBItemIcons()
    
    local function EquipmentUpgradeSystemEvent(_, p, _, _)
    	local pGuid = p:GetGUIDLow()
    	pSelectGos[pGuid] = nil
    	EquipmentUpgradeSystem(_,p,_,_)
    end
    
    function EquipmentUpgradeSystem(_,p,_,_)
    	local pGuid = p:GetGUIDLow()
    	p:GossipClearMenu()
    	if pSelectGos[pGuid] == nil then
    		for i=0,18 do
    			local equip = p:GetEquippedItemBySlot(i)
    			if equip then
    				p:GossipMenuAddItem(0,"     "..SlotName[i].."\n|TInterface/ICONS/"..ItemDisplay[equip:GetDisplayId()]..":40:40:-15:12|t"..equip:GetItemLink(),1,i)
    			end
    		end
    		p:GossipSendMenu(1,p,50021)
    	else
    		local equip = p:GetEquippedItemBySlot(pSelectGos[pGuid])
    		if ItemUpData[equip:GetEntry()] == nil or DBItemData[ItemUpData[equip:GetEntry()]["up"]]==nil then
    			p:SendBroadcastMessage("The equipment is not available to upgrade~") 
    			p:GossipComplete()
    		else
    			local UpEntry = ItemUpData[equip:GetEntry()]["up"]
    			p:GossipMenuAddItem(0,"         NewEquipment: \n|TInterface/ICONS/"..ItemDisplay[DBItemData[UpEntry]]..":40:40:-15:12|t"..GetItemLink(UpEntry),1,1000)
    			local TextTem = "|TInterface/ICONS/"..ItemDisplay[equip:GetDisplayId()]..":40:40:-15:12|t"
    			if ItemUpData[equip:GetEntry()]["num"] ~= 0 then 
    				p:GossipMenuAddItem(0,"         |cFF0066CCOldEquipment: |r\n"..TextTem..GetItemLink(equip:GetEntry()).." x "..ItemUpData[equip:GetEntry()]["num"],1,1000)
    			end
    			for i=1,clNum do
    				if ItemUpData[equip:GetEntry()]["cl"]["id"..i] ~=0 then
    					local ItemIcon = "|TInterface/ICONS/"..ItemDisplay[DBItemData[ItemUpData[equip:GetEntry()]["cl"]["id"..i]]]..":40:40:-15:12|t"..GetItemLink(ItemUpData[equip:GetEntry()]["cl"]["id"..i])
    					p:GossipMenuAddItem(0,"         |cFF666699 Material"..i..":|r\n"..ItemIcon.." x "..ItemUpData[equip:GetEntry()]["cl"]["num"..i],1,1000)
    				end
    			end
    			p:GossipMenuAddItem(0,"probability:"..ItemUpData[equip:GetEntry()]["jl"].."%",1,1000)
    			p:GossipMenuAddItem(0,"ye~",1,999)
    			p:GossipSendMenu(1,p,50021)
    		end
    	end
    end
    
    local function EquipmentUpgradeSystem_GossipSelect(event, player, object, sender, intid, code, menu_id)
    	local pGuid = player:GetGUIDLow()
    	if intid == 1000 then
    		player:GossipComplete()
    	elseif intid == 999 then
    		if player:IsInCombat()==false then 
    			local equip = player:GetEquippedItemBySlot(pSelectGos[pGuid])
    			local ItemId = equip:GetEntry()
    			local UpCheck = true
    			if ItemUpData[ItemId]["num"]-1 >0 then
    				if player:HasItem(ItemId,ItemUpData[ItemId]["num"]-1) == false then
    					UpCheck = false
    					player:SendBroadcastMessage("Material:"..GetItemLink(ItemId).."The shortage of raw materials.") 
    				end
    			end
    			for i=1,clNum do
    				if ItemUpData[ItemId]["cl"]["id"..i] ~=0 then
    					if player:HasItem(ItemUpData[ItemId]["cl"]["id"..i],ItemUpData[ItemId]["cl"]["num"..i]) == false then
    						UpCheck = false
    						player:SendBroadcastMessage("Material:"..GetItemLink(ItemUpData[ItemId]["cl"]["id"..i]).."The shortage of raw materials.") 
    					end
    				end
    			end
    			if UpCheck then
    				local jl = math.random(1,100)
    				if jl <= ItemUpData[ItemId]["jl"] then
    					local pEnchantment = {}
    					for i=0,6 do
    						pEnchantment[i] = equip:GetEnchantmentId(i)
    					end
    					player:RemoveItem(equip,1)
    					player:RemoveItem(ItemId,ItemUpData[ItemId].num - 1)
    					player:EquipItem(ItemUpData[ItemId]["up"],pSelectGos[pGuid])
    					local pItem = player:GetEquippedItemBySlot(pSelectGos[pGuid])
    					for i=0,6 do
    						if pEnchantment[i]~= 0 then
    							pItem:SetEnchantment(pEnchantment[i], i)
    						end
    					end
    					pEnchantment=nil
    					player:SendBroadcastMessage("Update Successful。add"..GetItemLink(ItemUpData[ItemId]["up"])) 
    				else
    					player:SendBroadcastMessage("Update failed.") 
    				end
    				for i=1,clNum do
    					if ItemUpData[ItemId]["cl"]["id"..i] ~=0 then
    						player:RemoveItem(ItemUpData[ItemId]["cl"]["id"..i],ItemUpData[ItemId]["cl"]["num"..i])
    					end
    				end
    			end
    		else
    			player:SendBroadcastMessage("Your are in combat! ") 
    		end
    		player:GossipComplete()
    	else
    		for i=0,18 do
    			if intid == i then
    				local item = player:GetEquippedItemBySlot(i)
    					pSelectGos[pGuid] = i
    				return EquipmentUpgradeSystem(event,player,item,_)
    			end
    		end
    	end
    end
    
    RegisterItemEvent(EquipUpItemEntry, 2, EquipmentUpgradeSystemEvent)
    RegisterPlayerGossipEvent(50021,2,EquipmentUpgradeSystem_GossipSelect)


    Attachment 488
    The need to import the world database
    item_icon.sql
    item_up.sql
    --------------------------------
    you can add a new Column in item_up.
    such as
    materialID5,materialCount5
    materialID6,materialCount6
    materialID7,materialCount7
    materialID8,materialCount8
    ...
    ......

    --------------------------------------------------------------
    my english is bad
    The above code is simple to translate into English.
    There may be a lot of mistakes.
    thanks
    Attached Files Attached Files
    Last edited by Ayase; 04-07-2015 at 08:17 AM.
    Achievements:
    Member 1 year registered Level X

  2. The Following 6 Users Say Thank You to Ayase For This Useful Post:


  3. #2
    Enthusiast SkittlesAreFalling's Avatar
    Join Date
    Aug 2013
    Posts
    42
    XP
    2,396
    Level
    13
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Your English is pretty good, keep up the good work :)
    Achievements:
    1 year registered Member Level X

  4. #3
    Super Moderator <span style='color: #FFFF00'><span class='glow_000000'>Kaev</span></span>'s Avatar

    Join Date
    Jan 2014
    Location
    Germany
    Posts
    543
    XP
    2,925,485
    Level
    335
    Thanks
    76
    Thanked 103 Times in 70 Posts
    Awesome to see someone from China here. Nice script!
    Achievements:
    Shopper Member 1 year registered Level XL Level C
    Awards:
    Raffle Winner Member of Staff Support LOL Drunk Donator


    Read the rules before posting.

    Do you have an unsolved issue? Give us more informations about your problem.

    Do you have problems with compiling or installing TrinityCore? Unknown96's Tutorial will help you.

    Visit our other helpful sites:
    EmuDevs SQL Generator

  5. #4
    Lurking Member
    Join Date
    Aug 2016
    Posts
    2
    XP
    6
    Level
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very well! I will check out soon,Thanks!

  6. #5
    Enthusiast
    Join Date
    Mar 2014
    Posts
    17
    XP
    1,878
    Level
    12
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Does not work, put it in, created the npc.

  7. #6
    Emulation Addict
    Join Date
    Apr 2015
    Posts
    11
    XP
    1,262
    Level
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts
    lua_scripts/item_up.lua:60: attempt to call method 'GetCString' (a nil value)
    any idea how I can fix this error?

  8. #7
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,871
    XP
    13,718
    Level
    35
    Thanks
    95
    Thanked 595 Times in 421 Posts
    Quote Originally Posted by titkata View Post
    lua_scripts/item_up.lua:60: attempt to call method 'GetCString' (a nil value)
    any idea how I can fix this error?
    use GetString
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  9. The Following User Says Thank You to Rochet2 For This Useful Post:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •