script : return throwing : bad object error
Posted: Sun Apr 21, 2013 5:04 pm
I try to create a script that return throwing weapons on the player when it is thrown on a monster.
I am inspired by viewtopic.php?f=14&t=3796
monster.lua
With only rock, no problem
But I have a "bad object" error when I add more throwing weapon in the Projectile function:
With "elseif", no error but the script doesn't run.
And I have try to simplify the script with a
but it is worse.
I am inspired by viewtopic.php?f=14&t=3796
monster.lua
Code: Select all
cloneObject{
name = "crowern_red",
baseObject = "crowern",
onProjectileHit = function(monster, weapon)
return return_throw_script.Projectile(monster,weapon)
end,
}Code: Select all
thrower_ord = 1
function getDistance(obj1,obj2)
local distance = 0
local XNumber = math.max(obj1.x,obj2.x) - math.min(obj1.x,obj2.x)
local YNumber = math.max(obj1.y,obj2.y) - math.min(obj1.y,obj2.y)
distance = XNumber + YNumber
return distance
end
function Projectile(monster,weapon)
if weapon.name == "rock" then
if findEntity(weapon.id) ~= nil then
weapon:destroy()
local distance = getDistance(party,monster)
local facing = (party.facing + 2)%4
local dx,dy = getForward(facing)
shootProjectile("rock", party.level, monster.x+dx, monster.y+dy, facing, distance, 1, 1, 0, 0, 0, 0, false, false)
end
end
endBut I have a "bad object" error when I add more throwing weapon in the Projectile function:
Code: Select all
function Projectile(monster,weapon)
if weapon.name == "rock" then
if findEntity(weapon.id) ~= nil then
weapon:destroy()
local distance = getDistance(party,monster)
local facing = (party.facing + 2)%4
local dx,dy = getForward(facing)
shootProjectile("rock", party.level, monster.x+dx, monster.y+dy, facing, distance, 1, 1, 0, 0, 0, 0, false, false)
end
end
if weapon.name == "shuriken" then
if findEntity(weapon.id) ~= nil then
weapon:destroy()
local distance = getDistance(party,monster)
local facing = (party.facing + 2)%4
local dx,dy = getForward(facing)
shootProjectile("shuriken", party.level, monster.x+dx, monster.y+dy, facing, distance, 1, 1, 0, 0, 0, 0, false, false)
end
end
if weapon.name == "throwing_axe" then
if findEntity(weapon.id) ~= nil then
weapon:destroy()
local distance = getDistance(party,monster)
local facing = (party.facing + 2)%4
local dx,dy = getForward(facing)
shootProjectile("throwing_axe", party.level, monster.x+dx, monster.y+dy, facing, distance, 1, 1, 0, 0, 0, 0, false, false)
end
end
if weapon.name == "throwing_knife" then
if findEntity(weapon.id) ~= nil then
weapon:destroy()
local distance = getDistance(party,monster)
local facing = (party.facing + 2)%4
local dx,dy = getForward(facing)
shootProjectile("throwing_knife", party.level, monster.x+dx, monster.y+dy, facing, distance, 1, 1, 0, 0, 0, 0, false, false)
end
end
endAnd I have try to simplify the script with a
Code: Select all
local itemList = {"rock", "throwing_knife", "throwing_axe", "shuriken"}
for i= 1,4 do
if weapon.name == itemList [i]
...
end
end