• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Range for each vocation on one weapon.

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
So basically I'm trying to use getDistanceBetween(firstPosition, secondPosition) to set a range, but when I attack with the weapon it acts as if it's not there, it just trains fist fighting. No errors in console, just not working. I deleted the range="" from items.xml, which could be the reason.
LUA:
function onUseWeapon(cid, var) 
local position = getCreaturePosition(cid)
local target = variantToNumber(var) 
local playerTarget = getCreatureTarget(cid) 
local level = getPlayerLevel(cid) 
	if(target ~= 0) then 	
		if (getPlayerVocation(cid) == 1 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 4) then
			local dmgMin = (300 + (level * 1.5))
			local dmgMax = (350 + (level * 1.8)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_TELEPORT) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_ENERGYBALL)
		end
		if (getPlayerVocation(cid) == 2 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 4) then
			local dmgMin = (300 + (level * 1.5))
			local dmgMax = (350 + (level * 1.8)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_SMALLPLANTS) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_POISON)
		end
		if (getPlayerVocation(cid) == 3 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 7) then
			local dmgMin = (260 + (level * 2.1))
			local dmgMax = (360 + (level * 2.3)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_HOLYDAMAGE) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_SMALLHOLY)
		end
		if (getPlayerVocation(cid) == 4 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 2) then
			local dmgMin = (310 +(level * 2.7))
			local dmgMax = (420 +(level * 3.2)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_GROUNDSHAKER) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_SMALLEARTH)
		end
	end
return ret 
end
 
Try now:

LUA:
function onUseWeapon(cid, var) 
local position = getCreaturePosition(cid)
local target = variantToNumber(var) 
local playerTarget = getCreatureTarget(cid) 
local level = getPlayerLevel(cid) 
	if(target ~= 0) then 	
		if (getPlayerVocation(cid) == 1 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 4)) then
			local dmgMin = (300 + (level * 1.5))
			local dmgMax = (350 + (level * 1.8)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_TELEPORT) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_ENERGYBALL)
		end
		if (getPlayerVocation(cid) == 2 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 4)) then
			local dmgMin = (300 + (level * 1.5))
			local dmgMax = (350 + (level * 1.8)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_SMALLPLANTS) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_POISON)
		end
		if (getPlayerVocation(cid) == 3 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 7)) then
			local dmgMin = (260 + (level * 2.1))
			local dmgMax = (360 + (level * 2.3)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_HOLYDAMAGE) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_SMALLHOLY)
		end
		if (getPlayerVocation(cid) == 4 and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(playerTarget) <= 2)) then
			local dmgMin = (310 +(level * 2.7))
			local dmgMax = (420 +(level * 3.2)) 
			ret = doTargetCombatHealth(cid, playerTarget, COMBAT_PHYSICALDAMAGE, -dmgMin, -dmgMax, CONST_ME_GROUNDSHAKER) and doSendDistanceShoot(position, getCreaturePosition(playerTarget), CONST_ANI_SMALLEARTH)
		end
	end
return ret 
end
 
Ok the first problem, was that error onstartup ive fixed that. Second problem i have no idea try to add prints.
 
before i exited the console out, it was saying something about line 12, which is the end, and it said comparing a table with a number
 
Okay so basically I'm doing a "ghetto" upgrade system lol. Like it's the starting weapon, the item ids 9805, 9806, and 9807 are the same looking. You go to a quest, it takes the 9805, gives you the 9806. The weapon attacks different for each vocation, somewhere within their tibia stereotyped elements. I wanted to make a range for each too.
Here is weapons.xml:
HTML:
	<wand id="9805" script="rusty_weapon.lua">
		<vocation id="1"/>
		<vocation id="2"/>
		<vocation id="3"/>
		<vocation id="4"/>
	</wand>
I made it a wand so it doesn't add skilltries.
Here is items.xml:
HTML:
	<item id="9805" article="a" name="(1/3) rusty weapon">
		<attribute key="weight" value="2800"/>
		<attribute key="weaponType" value="wand"/>
	</item>
 
Back
Top