What's new
  • logo_cipsoft
    Latest servers:
    New servers will open on: 19th Feb 2025:
    Noctalia (Open PvP) Ignitera (Open PvP) us_logo Xybra (Open PvP)

Actions Prosty Upgrade Item

Status
Not open for further replies.

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Niech kto? zmieni prefiks na 'Inne'.


PHP:
MELEE = 0
DISTANCE = 1
ARMOR = 2
SHIELD = 3
WAND = 4

AMMO_BOLT = 1
AMMO_ARROW = 2

WEAPON_NONE = 0
WEAPON_TWOHAND = 1
WEAPON_ONEHAND = 2
WEAPON_AXE = 3
WEAPON_SHIELD = 4
WEAPON_DIST = 5
WEAPON_WAND = 6
WEAPON_AMMO = 7
WEAPON_FIST = 8

upgradeConfig = {
				bonusAttrs = {
							[MELEE] = {'attack','extraattack','defense','extradefense',{'Shielding','Sword','Axe','Club'}},
							[DISTANCE] = {'hitChance',{'Distance'}},
							[ARMOR] = {'armor',{'Shielding','Sword','Axe'}},
							[SHIELD] = {'defense',{'Shielding','Sword'}},
							[WAND] = {'magic'}
							},
				[1] = {chanceOnUpgrade = 100, subNameAfterUpgrade = 'upgraded',
						bonusMaxValue = {1,3}, --maksymalny bonus do atrybut?w, czyli losuje od 1 do 10, w tym przypadku
						downrageLevel = 1},
				[2] = {chanceOnUpgrade = 95, subNameAfterUpgrade = 'strengthened',
						bonusMaxValue = {3,6}, --maksymalny bonus do atrybut?w, poprzednie bonusy zostaj? usuwane i nadpisane przez nowe!
						downrageLevel = 1},
				[3] = {chanceOnUpgrade = 95, subNameAfterUpgrade = 'amplified',
						bonusMaxValue = {6,9}, --maksymalny bonus do atrybut?w, poprzednie bonusy zostaj? usuwane i nadpisane przez nowe!
						downrageLevel = 2},
				[4] = {chanceOnUpgrade = 80, subNameAfterUpgrade = 'enhanced',
						bonusMaxValue = {9,12}, --maksymalny bonus do atrybut?w, poprzednie bonusy zostaj? usuwane i nadpisane przez nowe!
						downrageLevel = 3},
				[5] = {chanceOnUpgrade = 85, subNameAfterUpgrade = 'powerful',
						bonusMaxValue = {12,15}, --maksymalny bonus do atrybut?w, poprzednie bonusy zostaj? usuwane i nadpisane przez nowe!
						downrageLevel = 4},
				[6] = {chanceOnUpgrade = 70, subNameAfterUpgrade = 'mightier',
						bonusMaxValue = {15,18}, --maksymalny bonus do atrybut?w, poprzednie bonusy zostaj? usuwane i nadpisane przez nowe!
						downrageLevel = 1},
				}

function getItemType(itemInfo)
return ((isInArray({WEAPON_AXE, WEAPON_SWORD, WEAPON_AXE}, itemInfo.weaponType) and MELEE) or
						(isInArray({AMMO_BOLT,AMMO_ARROW}, itemInfo.ammoType) and DISTANCE) or
						(itemInfo.armor ~= 0 and itemInfo.wieldPosition ~= CONST_SLOT_NECKLACE and ARMOR) or
						(itemInfo.weaponType == WEAPON_SHIELD and SHIELD) or
						(itemInfo.weaponType == WEAPON_WAND and WAND)) or false
end

function getItemAttrInfo(info, itemId)
local itemAttrValue = 0
if info:lower() == 'attack' then
	itemAttrValue = getItemInfo(itemId).attack
elseif info:lower() == 'defense' then
	itemAttrValue = getItemInfo(itemId).defense
elseif info:lower() == 'armor' then
	itemAttrValue = getItemInfo(itemId).armor
elseif info:lower() == 'hitchance' then
	itemAttrValue = getItemInfo(itemId).hitChance
end
return itemAttrValue
end

function checkAttrName(bonusAttr)
return bonusAttr == 'attack' and 'Attack' or bonusAttr == 'defense' and 'Defense' or bonusAttr == 'extraattack' and 'Extra Attack' or
		bonusAttr == 'extradefense' and 'Extra Defense' and bonusAttr == 'hitChance' and 'Hit Chance' or 
		bonusAttr == 'magic' and 'Magic Level' or bonusAttr
end


function onUse(cid, item, frompos, itemEx, topos)
if not getItemType(getItemInfo(itemEx.itemid)) then
	return false
end
local effect, message, description, itemLevel = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE), 'Congratulation! Upgraded was successful, your item has become stronger!', '', getItemAttribute(itemEx.uid, 'upgradeLevel') or 1
if not upgradeConfig[itemLevel] then
	return false
end
doChangeTypeItem(item.uid, item.type-1)
if math.random(100000) > upgradeConfig[itemLevel].chanceOnUpgrade * 1000 then
	effect = CONST_ME_POFF
	itemLevel = upgradeConfig[itemLevel].downrageLevel
	message = 'Argh! Upgrading fail... you item lost some of strong!'
else
	itemLevel = itemLevel + 1
end
doItemSetAttribute(itemEx.uid, 'upgradeLevel', itemLevel)
local itemType = getItemType(getItemInfo(itemEx.itemid))
doItemSetAttribute(itemEx.uid, 'description', '')
doItemSetAttribute(itemEx.uid, 'name', upgradeConfig[itemLevel].subNameAfterUpgrade .. ' ' .. getItemInfo(itemEx.itemid).name .. '['..itemLevel..']')
for i = 1, #upgradeConfig.bonusAttrs[itemType] do
	local bonusAttr, newBonusValue = upgradeConfig.bonusAttrs[itemType][i], math.random(upgradeConfig[itemLevel].bonusMaxValue[1],upgradeConfig[itemLevel].bonusMaxValue[2])
	if type(bonusAttr) == 'table' then
		normalValue = true
		bonusAttr = bonusAttr[math.random(#bonusAttr)]
	end
	local oldStat = getItemAttrInfo(bonusAttr, itemEx.itemid)
	local newStat = oldStat == 0 and newBonusValue or oldStat + math.ceil((oldStat * newBonusValue) / 100)
	doItemSetAttribute(itemEx.uid, bonusAttr, (normalValue and newBonusValue or newStat))
	description = description .. checkAttrName(bonusAttr) .. ' ' .. (newBonusValue < 0 and newBonusValue or '+' .. newBonusValue) .. (normalValue and '' or '%') .. '\n'
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, message)
doSendMagicEffect(getThingPos(itemEx.uid), effect)
return doItemSetAttribute(itemEx.uid, 'description', description)
end

Skrypt jest prosty, cho? pisa?em go dawno temu.
Skrypt ulepsza item o warto?ci: attack, defense, armor, hitChance.
Jedyne co zmieniamy w skrypcie to:
PHP:
				[1] = {chanceOnUpgrade = 100, subNameAfterUpgrade = 'upgraded',
						bonusMaxValue = {1,3}, --maksymalny bonus do atrybut?w, czyli losuje od 1 do 10, w tym przypadku
						downrageLevel = 1},
Gdzie indeks to poziom itema, chanceOnUpgrade to szansa na udany upgrade, subNameAfterUpgrade to przydomek itema po ulepszeniu (np. upgraded fire axe), bonusMaxValue to przedzia? procentowy o ile ma zosta? ulepszony item oraz downrageLevel, kt?ry m?wi nam, na jaki poziom spadnie item, gdy nie uda si? na ulepszy?.
Znalaz?em w folderze actions to wam go daj?.
 
Status
Not open for further replies.
Top