• 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!

CreatureEvent Upgrade weapon by killing monsters!

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,665
Solutions
125
Reaction score
1,111
Location
Germany
GitHub
slawkens
Idea by: Cocoamonkey

Works only with TFS 0.3!

How it looks in game:
monsterhunter.jpg


How it works.
Player must kill specified monsters. For every x kills with specified weapon, weapon gets additional extra attack points. :)
Max extra attack can be limited, so players wont get to much powerful weapons!

1. data/creaturescripts/scripts/monster_weapon_upgrade.lua
Code:
--[[
	** Monster weapon upgrader by slawkens **

	kills - how much monsters must be killed
	extraAttack - how much extraAttack points will this weapon get
	extraAttackLimit - you can set limit of extraAttack points added
]]--

local monsters = {
	["rat"] = {
		[2395] = {
			kills = 30,
			extraAttack = 1,
			extraAttackLimit = 3,
			storage = 34000
		}
	},
	["dragon"] = {
		[2383] = {
			kills = 500,
			extraAttack = 1,
			extraAttackLimit = 20,
			storage = 34001
		}
	}
}

if(not getItemExtraAttack) then
	if(not getItemAttribute) then
		print("ERROR: (monster_weapon_upgrade.lua) your distribution is not supported!")
		return false
	end
	function getItemExtraAttack(uid)
		return getItemAttribute(uid, "extraattack")
	end
	function setItemExtraAttack(uid, extraAttack)
		doItemSetAttribute(uid, "extraattack", extraAttack)
		return true
	end
end

function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		return TRUE
	end

	local monster = monsters[string.lower(getCreatureName(target))]
	if(not monster) then
		return TRUE
	end

	local playerWeapon = getPlayerWeapon(cid, TRUE)
	if(playerWeapon.itemid == 0) then
		return TRUE
	end

	local weapon = monster[playerWeapon.itemid]
	if(not weapon) then
		return TRUE
	end

	local killedMonsters = getPlayerStorageValue(cid, weapon.storage)
	if(not killedMonsters or killedMonsters == -1) then
		killedMonsters = 1
	end

	local currentExtraAttack = getItemExtraAttack(playerWeapon.uid)
	if(killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit) then
		setItemExtraAttack(playerWeapon.uid, currentExtraAttack + weapon.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. weapon.extraAttack .. " attack points and now have total extra damage of +" .. (currentExtraAttack + weapon.extraAttack) .. " points!")
	end

	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return TRUE
end

2. data/creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="MonstersWeaponUpgrade" event="script" value="monster_weapon_upgrade.lua"/>

3. Add this at bottom of your login.lua (before return TRUE)
Code:
registerCreatureEvent(cid, "MonstersWeaponUpgrade")
 
Last edited:
Code:
--[[
	** Monster weapon upgrader by slawkens **
        ** Extra Defense added by Cocoamonkey **


	kills - how much monsters must be killed
	extraAttack - how much extraAttack points will this weapon get
	extraAttackLimit - you can set limit of extraAttack points added
	extraDefense - how much extraDefense points will this weapon get
	extraDefenseLimit - you can set limit of extraDefense points added
]]--

local monsters = {
	["demon"] = {
		[7382] = {
			kills = 1,
			extraAttack = 50,
			extraAttackLimit = 800,
			extraDefense = 50,
			extraDefenseLimit = 800,
			storage = 34000
	},
			[2400] = {
			kills = 30,
			extraAttack = 1,
			extraAttackLimit = 25,
			extraDefense = 50,
			extraDefenseLimit = 800,
			storage = 34001
		}
	},
	["dragon"] = {
		[7407] = {
			kills = 2,
			extraAttack = 2,
			extraAttackLimit = 20,
			extraDefense = 2,
			extraDefenseLimit = 30,
			storage = 34003
		}
	}
}

function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		return TRUE
	end

	local monster = monsters[string.lower(getCreatureName(target))]
	if(not monster) then
		return TRUE
	end

	local playerWeapon = getPlayerWeapon(cid, TRUE)
	if(playerWeapon.itemid == 0) then
		return TRUE
	end

	local weapon = monster[playerWeapon.itemid]
	if(not weapon) then
		return TRUE
	end

	local killedMonsters = getPlayerStorageValue(cid, weapon.storage)
	if(killedMonsters == -1) then
		killedMonsters = 1
	end

	local currentExtraAttack = getItemExtraAttack(playerWeapon.uid)
	if(killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit) then
		setItemExtraAttack(playerWeapon.uid, currentExtraAttack + weapon.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. weapon.extraAttack .. " attack points and now have total extra damage of +" .. getItemExtraAttack(playerWeapon.uid) .. " points!")
	end
	
		local currentExtraDefense = getItemExtraDefense(playerWeapon.uid)
		if(killedMonsters % weapon.kills == 0 and currentExtraDefense < weapon.extraDefenseLimit) then
		setItemExtraDefense(playerWeapon.uid, currentExtraDefense + weapon.extraDefense)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. weapon.extraDefense .. " defense points and now have total extra defense of +" .. getItemExtraDefense(playerWeapon.uid) .. " points!")
	end
	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return TRUE
end
 
Last edited:
Great script. Nicely done, clean, tabbed and optimised.

I just want to notice, there are lots of possibilities of usages of this script. For example you can make weapon's description include amount of killed monsters with it or do same thing as attack but with extra defense, attackspeed, even character stats.
 
This is very true. ^_^ I think that's a good idea, wanna add it slawkey? ^_^ Mind if I call you slawkey? xD
I like the description part. "Haha, my knife killed more rats than yours!"
 
I just tested it and I can't get it to work... :(

Code:
[07/06/2009  15:45:53] Lua Script Error: [CreatureScript Interface] 
[07/06/2009  15:45:53] data/creaturescripts/scripts/monster_weapon_upgrade.lua:onKill

[07/06/2009  15:45:54] ...a/creaturescripts/scripts/monster_weapon_upgrade.lua:19: attempt to call global 'getPlayerWeapon' (a nil value)
[07/06/2009  15:45:54] stack traceback:
[07/06/2009  15:45:54] 	...a/creaturescripts/scripts/monster_weapon_upgrade.lua:19: in function <...a/creaturescripts/scripts/monster_weapon_upgrade.lua:10>
 
I just tested it and I can't get it to work... :(

Code:
[07/06/2009  15:45:53] Lua Script Error: [CreatureScript Interface] 
[07/06/2009  15:45:53] data/creaturescripts/scripts/monster_weapon_upgrade.lua:onKill

[07/06/2009  15:45:54] ...a/creaturescripts/scripts/monster_weapon_upgrade.lua:19: attempt to call global 'getPlayerWeapon' (a nil value)
[07/06/2009  15:45:54] stack traceback:
[07/06/2009  15:45:54] 	...a/creaturescripts/scripts/monster_weapon_upgrade.lua:19: in function <...a/creaturescripts/scripts/monster_weapon_upgrade.lua:10>

Ah, works only with 0.3 [; (Included in first post now)
 
Why thank you. Gawsh now I gotta get 0.3. D: Unless you could make it work with 0.2? D:?
 
It's cool and working, but how do i make it work for multiple monsters and weapons? And it could be like, more configurable. For example 500 kills for +1, but 1000 for +2, 2000 kills for +3 and so on. What about it? Like percentage grow, need 100% more kills for next damage level.
 
-- Hey friend this is a great script and great ideia, but, don't work for me, but don't make errors on console... I'm using TFS 0.3.4 pl2... Can you help me??? Many thx
 
TY all for your opinios :)

As you requested, here is an updated version, which supports more monsters aswell (Not tested, can someone confirm if it works?)
Code:
--[[
	** Monster weapon upgrader by slawkens **

	* HELP
		kills - how much monsters must be killed
		weapon - which weapon player must use
		extraAttack - how much extraAttack points will this weapon get
		extraAttackLimit - you can set limit of extraAttack points added
]]--

local monsters = {
	["rat"] = {
		kills = 30,
		weapon = 2395,
		extraAttack = 1,
		extraAttackLimit = 3,
		storage = 34000
	},
	["dragon"] = {
		kills = 500,
		weapon = 2383,
		extraAttack = 1,
		extraAttackLimit = 20,
		storage = 34001
	}
}

function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		return TRUE
	end

	local monster = monsters[string.lower(getCreatureName(target))]
	if(not monster) then
		return TRUE
	end

	local playerWeapon = getPlayerWeapon(cid, TRUE)
	if(isInArray({0, monster.weapon}, playerWeapon.itemid) ~= TRUE) then
		return TRUE
	end

	local killedMonsters = getPlayerStorageValue(cid, monster.storage)
	if(killedMonsters == -1) then
		killedMonsters = 1
	end

	local currentExtraAttack = getItemExtraAttack(playerWeapon.uid)
	if(killedMonsters % monster.kills == 0 and currentExtraAttack < monster.extraAttackLimit) then
		setItemExtraAttack(playerWeapon.uid, currentExtraAttack + monster.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. monster.extraAttack .. " attack points and now have total extra damage of +" .. getItemExtraAttack(playerWeapon.uid) .. " points!")
	end

	setPlayerStorageValue(cid, monster.storage, killedMonsters + 1)
	return TRUE
end
 
@Slawkens

-- Hey man work fine and its great (you new update work too), many thx for you and congratulations... REP++ for you... now how to add many weapons on this???
 
@Slawkens

-- Hey man work fine and its great (you new update work too), many thx for you and congratulations... REP++ for you... now how to add many weapons on this???

hm.. ok will be added :thumbup:

#Edit

Updated
Code:
--[[
	** Monster weapon upgrader by slawkens **

	kills - how much monsters must be killed
	extraAttack - how much extraAttack points will this weapon get
	extraAttackLimit - you can set limit of extraAttack points added
]]--

local monsters = {
	["rat"] = {
		[2395] = {
			kills = 30,
			extraAttack = 1,
			extraAttackLimit = 3,
			storage = 34000
		}
	},
	["dragon"] = {
		[2383] = {
			kills = 500,
			extraAttack = 1,
			extraAttackLimit = 20,
			storage = 34001
		}
	}
}

function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		return TRUE
	end

	local monster = monsters[string.lower(getCreatureName(target))]
	if(not monster) then
		return TRUE
	end

	local playerWeapon = getPlayerWeapon(cid, TRUE)
	if(playerWeapon.itemid == 0) then
		return TRUE
	end

	local weapon = monster[playerWeapon.itemid]
	if(not weapon) then
		return TRUE
	end

	local killedMonsters = getPlayerStorageValue(cid, weapon.storage)
	if(killedMonsters == -1) then
		killedMonsters = 1
	end

	local currentExtraAttack = getItemExtraAttack(playerWeapon.uid)
	if(killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit) then
		setItemExtraAttack(playerWeapon.uid, currentExtraAttack + weapon.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. weapon.extraAttack .. " attack points and now have total extra damage of +" .. getItemExtraAttack(playerWeapon.uid) .. " points!")
	end

	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return TRUE
end
 
Last edited:
Back
Top