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

Issues with Weapon Upgrades

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
629
Location
Canada
Hello everyone, I'm using the newest version of TFS (0.3.6 pl1) and I'm trying to use the Weapons Upgrade script made by Slawkens (http://otland.net/f82/upgrade-weapon-killing-monsters-35146/)
There have been some issues, since certain functions are no longer in the C++ files. I was wondering if there's a replacement for onKill... There's no global.lua anymore so that's where I lost it. I'm pretty sure that's the only problem left in the script. Says this in the script:
Code:
function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		return TRUE
	end
All I need is a function to replace it, or the code needed to add it to the server, cause I can do that too.
Thanks in advance <3
 
Try:
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) then
		return true
	end

	local monster = monsters[getCreatureName(target):lower()]
	if not monster then
		return true
	end

	local playerWeapon = getPlayerWeapon(cid, true)
	if playerWeapon.itemid < 1 then
		return true
	end

	local weapon = monster[playerWeapon.itemid]
	if not weapon then
		return true
	end

	local killedMonsters, currentExtraAttack = math.max(1, getPlayerStorageValue(cid, weapon.storage)), math.max(0, playerWeapon.actionid - 100)

	if killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit then
		doItemSetAttribute(playerWeapon.uid, "aid", 100 + math.max(currentExtraAttack, 0) + weapon.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received +" .. weapon.extraAttack .. " attack points and now have total extra damage of +" .. playerWeapon.actionid - 100 .. " points!")
	end

	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return true
end
Untested, and might not work at all or have strange behaviour.
 
That's slawkens' script. onKill is in there. That's the script I'm using. I tested it during the summer when I requested it. I need to replace onKill with something.
 
Do not replace, I modified it to work on 0.3.6 (hopefully, dropped and replaced functions), and once again; onKill works properly on 0.3.6

There is no good reason at all to move the script to onDeath.
 
Have you registered it correctly?
Code:
	<event type="kill" name="Kill" event="script" value="kill.lua"/>
also in login.lua
Code:
	registerCreatureEvent(cid, "Kill")
 
Code:
[06/02/2010 22:05:00] [Error - CreatureScript Interface] 
[06/02/2010 22:05:00] data/creaturescripts/scripts/monster_weapon_upgrade.lua:onKill
[06/02/2010 22:05:00] Description: 
[06/02/2010 22:05:00] ...a/creaturescripts/scripts/monster_weapon_upgrade.lua:58: attempt to compare nil with number
[06/02/2010 22:05:00] stack traceback:
[06/02/2010 22:05:00] 	...a/creaturescripts/scripts/monster_weapon_upgrade.lua:58: in function <...a/creaturescripts/scripts/monster_weapon_upgrade.lua:32>
This is the console error. still saying onkill is the issue.
 
Well the problem is, I've got an updated version, changed by myself back when it worked... Makes it so I can use extraDefense also. so I don't think the actionID is gonna work for extra attack and defense...
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 = {
	["dragon lord"] = {
		[2395] = {
			kills = 1,
			extraAttack = 1,
			extraAttackLimit = 15,
			extraDefense = 1,
			extraDefenseLimit = 15,
			storage = 34000
		}
	},
	["dragon"] = {
		[2383] = {
			kills = 250,
			extraAttack = 1,
			extraAttackLimit = 30,
			extraDefense = 1,
			extraDefenseLimit = 25,
			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 = 	getItemAttribute(playerWeapon.uid, extraAttack)
	if(killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received " .. weapon.extraAttack .. " extra attack points and now has a total extra attack of " .. getItemAttribute(playerWeapon.uid, extraAttack) .. " points!")
		setItemExtraAttack(playerWeapon.uid, currentExtraAttack + weapon.extraAttack)
	end
	
	local currentExtraDefense = getItemAttribute(playerWeapon.uid, extraDefense)
	if(killedMonsters % weapon.kills == 0 and currentExtraDefense < weapon.extraDefenseLimit) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received " .. weapon.extraDefense .. " extra defense points and now has a total extra defense of " .. getItemAttribute(playerWeapon.uid, extraDefense) .. " points!")
		setItemExtraDefense(playerWeapon.uid, currentExtraDefense + weapon.extraDefense)
	end

	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return TRUE
end
 
The problem with TFS 0.3.6 is, its getItemInfo gets info by itemid, not uid .. which basically means that you could only upgrade attack and defense once (+1) - it wouldn't get the extraAttack/Defense from the item correctly later on.

This is the reason why I tried using .. actionids.
 
Do you think you could help me out with a revised, working version of this script that allows for properly checking the extraAttack and extraDefense later, and make everything work the way it's supposed to? I'll recompile to add any functions if needed.
 
Try:
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 = {
	["dragon lord"] = {
		[2395] = {
			kills = 1,
			extraAttack = 1,
			extraAttackLimit = 15,
			extraDefense = 1,
			extraDefenseLimit = 15,
			storage = 34000
		}
	},
	["dragon"] = {
		[2383] = {
			kills = 250,
			extraAttack = 1,
			extraAttackLimit = 30,
			extraDefense = 1,
			extraDefenseLimit = 25,
			storage = 34001
		}
	}
}

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

	local monster = monsters[getCreatureName(target):lower()]
	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 = math.max(1, getPlayerStorageValue(cid, weapon.storage))

	local currentExtraAttack = getItemAttribute(playerWeapon.uid, "extraAttack") or 0
	if(killedMonsters % weapon.kills == 0 and currentExtraAttack < weapon.extraAttackLimit) then
		doItemSetAttribute(playerWeapon.uid, "extraAttack", currentExtraAttack + weapon.extraAttack)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received " .. weapon.extraAttack .. " extra attack points and now has a total extra attack of " .. getItemAttribute(playerWeapon.uid, "extraAttack") .. " points!")
	end
	
	local currentExtraDefense = getItemAttribute(playerWeapon.uid, "extraDefense") or 0
	if(killedMonsters % weapon.kills == 0 and currentExtraDefense < weapon.extraDefenseLimit) then
		doItemSetAttribute(playerWeapon.uid, "extraDefense", currentExtraDefense + weapon.extraDefense)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! Your weapon received " .. weapon.extraDefense .. " extra defense points and now has a total extra defense of " .. getItemAttribute(playerWeapon.uid, "extraDefense") .. " points!")
	end

	setPlayerStorageValue(cid, weapon.storage, killedMonsters + 1)
	return true
end
 
If you come up with something different, I'll test it tomorrow. I was diagnosed with mononucleosis today and that explains my inability to eat or sleep over the last few days... I'm a little sleepy so I'd rather test them tomorrow. I really appreciate the help though, thanks.
 
Back
Top