• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Upgrade attack/armor every hit

Status
Not open for further replies.

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Reaction score
63
Location
Poland
Hello!

Like in title I looking for script which will upgrade attack/armor every hit.

1. For example I have sword and it have:
Code:
attack: [COLOR="red"]14[/COLOR]
then when I hit 5 times monster/player by this sword after that it will have:
Code:
attack: [COLOR="red"]19[/COLOR]




2. For example I have armor (it can be also shield/legs/head) and it have:
Code:
defense: [COLOR="red"]14[/COLOR]
then when I get hit 5 times from the monster/player this armor after that it will have:
Code:
defense: [COLOR="red"]19[/COLOR]



Thanks and rep for help. :thumbup:
 
Last edited:
yes you should regestire the event name in the login.lua, thpe ough his script will have some errors

first : it is
Code:
type == STATSCHANGE_HEALTHLOSS

Second : You must check for the ip after you have check for if it isPlayer, the the check should be inside the check for isPlayer as if it is monster it will give errors
 
Okay so i registered in login.lua and script is looking that:
LUA:
local weapons = {2400, 2376} -- weapon id's of allowed weapons.
 
function onStatsChange(cid, attacker, type, combat, value)
	if isPlayer(attacker) and type == STATSCHANGE_HEALTHLOSS then
		setItemAttack(CONST_SLOT_RIGHT.uid,getItemAttack(CONST_SLOT_RIGHT.uid) + 1)
	elseif isInArray(weapons,getPlayerSlotItem(attacker,CONST_SLOT_LEFT).itemid) then
		setItemAttack(CONST_SLOT_LEFT.uid,getItemAttack(CONST_SLOT_LEFT.uid) + 1)
	end
return true
end
And don't work :(

When I try to hit player then:

Code:
[12:57:12.343] [Error - CreatureScript Interface]
[12:57:12.343] data/creaturescripts/scripts/sword.lua:onStatsChange
[12:57:12.343] Description:
[12:57:12.343] data/creaturescripts/scripts/sword.lua:5: attempt to index global
 'CONST_SLOT_RIGHT' (a number value)
[12:57:12.343] stack traceback:
[12:57:12.343]  data/creaturescripts/scripts/sword.lua:5: in function <data/crea
turescripts/scripts/sword.lua:3>
 
Last edited:
try this though i am not that sure it would work when u hit monsters :

LUA:
local allowedweps = {2841,5239} -- weapon id's of allowed weapons.
 
function onStatsChange(cid,attacker,type,combat,value)
	if isPlayer(attacker) and isPlayer(cid) then
		if getPlayerIp(attacker) == getPlayerIp(cid) then
			doPlayerSendCancel(attacker,'Can\'t gain weapon upgrade from users with the same IP.')
		end
		return true
	end

	if isPlayer(attacker) then
		local right = getPlayerSlotItem(attacker,CONST_SLOT_RIGHT).uid
		local left = getPlayerSlotItem(attacker,CONST_SLOT_LEFT).uid
			if type == STATSCHANGE_HEALTHLOSS and value > 0 then
				if isInArray(allowedweps,getPlayerSlotItem(attacker,CONST_SLOT_RIGHT).itemid) then 
					setItemAttack(right,getItemAttack(right)+1)
				elseif isInArray(allowedweps,getPlayerSlotItem(attacker,CONST_SLOT_LEFT).itemid) then
					setItemAttack(left,getItemAttack(left)+1)
				end
			end
	end
	return true
end
 
On monster don't work. Also on players too :(

Code:
[14:51:42.562] [Error - CreatureScript Interface]
[14:51:42.562] data/creaturescripts/scripts/sword.lua:onStatsChange
[14:51:42.562] Description:
[14:51:42.562] data/creaturescripts/scripts/sword.lua:11: attempt to call global
 'getItemAttack' (a nil value)
[14:51:42.562] stack traceback:
[14:51:42.562]  data/creaturescripts/scripts/sword.lua:11: in function <data/cre
aturescripts/scripts/sword.lua:3>
 
getItemAttack << It should be a function in tfs , i donno how you dont have it working.


Maybe try to change that
Code:
getItemAttack(right)




Code:
getItemAttribute(right, "attack")

and same with the left one
 
Last edited:
I've made you the basics, you just need to extend it to your wish.
LUA:
local maxWorth = {attack = 100, defense = 200, armor = 150} -- the worth of an item can't go higher then the worth in the table.
function onStatsChange(cid,attacker,type,combat,value)
	if isPlayer(attacker) then
		if type == STATSCHANGE_HEALTHLOSS and value > 0 then
			for i = CONST_SLOT_RIGHT,CONST_SLOT_LEFT do
				local item = getPlayerSlotItem(attacker, i)
				if item.uid == nil then
					return true
				end
				local checkAttack = getItemAttribute(item.uid, "attack") or getItemInfo(item.itemid).attack
				if checkAttack > 0 and checkAttack < maxWorth.attack then
					doItemSetAttribute(item.uid, "attack", (checkAttack + 1))
				end
			end
		end
	end
	if isPlayer(cid) then
		if type == STATSCHANGE_HEALTHLOSS and value > 0 then
			for i = CONST_SLOT_FIRST,CONST_SLOT_LAST do
				local item = getPlayerSlotItem(cid, i)
				if item.uid == nil then
					return true
				end
				local checkDefense = getItemAttribute(item.uid, "defense") or getItemInfo(item.itemid).defense
				local checkArmor = getItemAttribute(item.uid, "armor") or getItemInfo(item.itemid).armor
				if checkDefense > 0 and checkDefense < maxWorth.defense then
					doItemSetAttribute(item.uid, "defense", (checkDefense + 1))
				end
				if checkArmor > 0 and checkArmor < maxWorth.armor then
					doItemSetAttribute(item.uid, "armor", (checkArmor + 1))
				end
			end
		end
	end
	return true
end


kind regards, Evil Hero.
 
Last edited:
Yeah but it not working (when I attack then nothing is changing also when I get damage it showing in TFS):
Code:
[17:11:04.968] [Error - CreatureScript Interface]
[17:11:04.968] data/creaturescripts/scripts/sword.lua:onStatsChange
[17:11:04.968] Description:
[17:11:04.968] (luaGetItemAttribute) Item not found

[17:11:04.968] [Error - CreatureScript Interface]
[17:11:04.968] data/creaturescripts/scripts/sword.lua:onStatsChange
[17:11:04.968] Description:
[17:11:04.968] data/creaturescripts/scripts/sword.lua:23: attempt to index a boo
lean value
[17:11:04.968] stack traceback:
[17:11:04.968]  data/creaturescripts/scripts/sword.lua:23: in function <data/cre
aturescripts/scripts/sword.lua:2>


Also yours Doggynub script don't work (there isn't any bugs or something else :()
 
Last edited:
I dont think there is a way to make it work on monsters as i think you need to regestire all monsters to this event if you want it to work

[players only]
LUA:
local max_attack = 120				-- max upgrade value

function exist(cid)
	local n = { uid = nil, itemid = nil }
	for i = 5,6 do
		local e = getPlayerSlotItem(cid,i)
			if e.uid > 0 and getItemInfo(e.itemid).attack then
				if getItemAttribute(e.uid, "attack") == nil or (getItemAttribute(e.uid, "attack") < max_attack and getItemInfo(e.itemid).attack < max_attack) then
					n.uid = e.uid
					n.itemid = e.itemid
				end
			end
	end
	return n
end

function onStatsChange(cid, attacker, type, combat, value)
	if type == STATSCHANGE_HEALTHLOSS and value > 0 then
		if isPlayer(attacker) then
			if exist(attacker).uid ~= nil then
				doItemSetAttribute(exist(attacker).uid, "attack", (getItemAttribute(exist(attacker).uid, "attack") ~= nil and (getItemAttribute(exist(attacker).uid, "attack")) +1 or (getItemInfo(exist(attacker).itemid).attack) +1))
				doPlayerSendTextMessage(attacker,19,"Weapon upgraded +1 ")
			end
		end
	end		
	return true
end
 
Last edited:
Evil Hero: when nothing is changing when I attack but when I het hit then it's showing:
Code:
[14:19:10.359] [Error - CreatureScript Interface]
[14:19:10.359] data/creaturescripts/scripts/sword.lua:onStatsChange
[14:19:10.359] Description:
[14:19:10.359] data/creaturescripts/scripts/sword.lua:24: attempt to index a boo
lean value
[14:19:10.359] stack traceback:
[14:19:10.359]  data/creaturescripts/scripts/sword.lua:24: in function <data/cre
aturescripts/scripts/sword.lua:2>


Doggynub
your script not work nothing is showing. :(




#Can someone try this scripts?? Maybe for me it isn't working.
 
ye i tryed my script it is working on players, if you want it to work on monsters then you need to regestire this event in each monster file

put script regestire event in login, restart server, hold a sword not more than max_value , and hit a player, the hit must deal damadge.
 
Why don't you try using...

Code:
function onAttack(cid, target)

Upgrade weapon on attack, sounds like this should be used.
 
to check for value of damadge if more than 0(if he dealt any damadge) , but rather than that onAttack would be better ye.
 
Yeah it's working thanks. :thumbup:

But you can try to make that I won't must to register this event in each monster???
I will be very thankful
 
No way to make that. Like what it would take you like 30 min to make all monsters :p
 
Last edited:
Status
Not open for further replies.
Back
Top