Page 2 of 2
Re: Scripting: Monster only gets demaged by one special weap
Posted: Sat Mar 15, 2014 10:28 pm
by Leki
to complicated I guess...
I prefer method to make clone party with onAttack hook, and on attack check tile(s) by entitiesAt(party.level, party.x+party.dir, party.y+party.dir) - in front of the party and compare used weapon with monster(objects) on tile(s). You can define weapons in array, if you wanna make more effective weapons. If it does not match, return false, so weapon/item is unefective. If it mach, do damage.
In other word, on attack, get monster in front of party, then interate through ifs with monsters and if it matches, check if one of defined weapons matches weapon used onAttack, then return true. No isues with death effects, skills, exp etc.
You can do the same in onUseItem hook, for special items (I mean no weapons - to break walls etc.) You can also check party.x+party.dir, party.y+party.dir, to check if item/weapon is used on right dungeon position etc. In hooks designed in this way, you can define all combinations you need.
btw, monster:destroy(); does not call "monster death particle effect" - it removes monster from game and thats all - so you must use damageTile or play with invisible projectiles to achieve what you need.
Please someone write the party script I described, I'm in hurry.
Re: Scripting: Monster only gets demaged by one special weap
Posted: Mon Mar 17, 2014 6:49 pm
by THOM
I am still not sure, if I got everything right.
My biggest question at the moment is, how to do a damage-script. What I want is to reduce health-points by a certain amount (lets say 100). Not killing immediatly.
Re: Scripting: Monster only gets demaged by one special weap
Posted: Mon Mar 17, 2014 10:47 pm
by Leki
forget that "-100 HP damage idea", it's not good solution, because propper method to calculate damage is mix of weapon power, character stats and skills, monster defence etc... use smth like this for melee weapons in custom party definition, in onAttack hook:
Code: Select all
function party_onAttack(champion, weapon)
-- weapon efficiencies tests
-- define locals
local dx,dy = 0,0
local usedWeapon
-- manage case that attack is unarmed
if weapon == nil then usedWeapon = "unarmed"
else usedWeapon = weapon.name
end
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check what is in front of the party
local checkedCell = entitiesAt(party.level, party.x + dx, party.y + dy)
-- interate through all objects on cell
for object in checkedCell do
if object.class == "Monster" then -- it will do test only for monsters
if monster.name == "snail" then -- here you can define monsters (you can use OR, or define array for more monsters and go through the array)
if usedWeapon == "long_sword" then -- here is test if champion used effextive weapon (you can use OR, or array for more weapons)
return true -- weapons is effective, attack will by computed (weapon power, character skills, monster defence etc)
else
return false -- weapon is uneffective, you can write
end
end
else
return true
end
end
end
for ranged weapons use onProjectileHit hook in monster definition: check the projectile which hits the monster and if it's name is i.e. "poison_arrow", then return true, else false and you have what you need.
P.S I wrote that script without tests, so guys, if you can, please chcek it for sure or rewrite it etc...[/color]
Re: Scripting: Monster only gets demaged by one special weap
Posted: Thu Mar 20, 2014 12:36 am
by THOM
Nope.
I made a clone party object. What I get is, that I can use a weapon on other monsters, but when I attack my special-monster with
some weapon (not my special weapon) the whole editor crashes...
The same, when I
use my weapon on my monster...
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onAttack = function (champion, weapon)
-- weapon efficiencies tests
-- define locals
local dx,dy = 0,0
local usedWeapon
-- manage case that attack is unarmed
if weapon == nil then usedWeapon = "unarmed"
else usedWeapon = weapon.name
end
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check what is in front of the party
local checkedCell = entitiesAt(party.level, party.x + dx, party.y + dy)
-- interate through all objects on cell
for object in checkedCell do
if object.class == "Monster" then -- it will do test only for monsters
if monster.name == "ghost" then
if usedWeapon == "dm_vorpalblade" then
return true -- weapons is effective, attack will by computed
else
return false -- weapon is uneffective, you can write
end
end
else
return true
end
end
end,
}
Re: Scripting: Monster only gets demaged by one special weap
Posted: Thu Mar 20, 2014 10:16 am
by Leki
As I said, it was not tested and the bug is typo. Sorry for that -but you should find it by yourself
replace:
with
in general, use
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion, weapon)
return hooks.party_onAttack(champion, weapon);
end,
}
and then add script_entity named
hooks into editor with
function party_onAttack(champion, weapon) , it will stop in script entity and prevent crashes. If it works, then you can move script into clone party.
[/color]
Re: Scripting: Monster only gets demaged by one special weap
Posted: Thu Mar 20, 2014 12:57 pm
by THOM
yep - it works.
I've added a sound effect to the false-case and now it's a cool game-part.
thanx - i would never had figured that out by my own...