leonardo ramos
Veteran OT User
- Joined
- Dec 7, 2016
- Messages
- 190
- Reaction score
- 369
I am trying to take advantage of a 0.36 / 0.4 script I found in another forum, but in version 1.x of TFS there is no attack / onAttack function. This script would be very useful to me, but I do not know how to solve this problem and I count on your help.
the script quoted is as follows:
Lib:
Creaturescript:
Code:
<event type = "think" name = "monsters" event = "script" value = "monsters.lua" />
<event type = "attack" name = "monstersatt" event = "script" value = "monsters.lua" />
Code:
[Error - CreatureEvent::configureEvent] Invalid type for creature event: monstersatt
[Warning - BaseEvents::loadFromXml] Failed to configure event
the script quoted is as follows:
Lib:
Code:
local config = {
storages = {time = 5553, tgt = 5554},
away_dist = 2,
}
function verifyTarget(cid, target)
if not isCreature(target) and not isCreature(cid) then
return false
end
if target == cid then
return false
end
return true
end
function attack(cid, target, att_distance)
if not isCreature(cid) and not isCreature(target) then
return false
end
local dir = getDirectionTo(getCreaturePosition(cid), getCreaturePosition(target))
if getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(target)) > att_distance then
if (getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(target)) > att_distance + config.away_dist) then
doCreatureSetStorage(cid, config.storages.tgt, -1)
return false
end
doCreatureSetNoMove(cid, false)
local toPos = getPosByDir(getCreaturePosition(cid), dir, 1)
toPos.stackpos = 253
if getThingFromPos(toPos).uid == 0 then
doMoveCreature(cid, dir)
end
else
doCreatureSetNoMove(cid, true)
doCreatureSetLookDirection(cid, dir)
setDamage(cid, target)
end
end
doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -5, -20, CONST_ME_DRAWBLOOD)
Creaturescript:
Code:
local config = {
storages = {tempo = 5553, tgt = 5554},
attRange = 1,
}
function onThink(cid)
if not isCreature(cid) then
return false
end
if getCreatureStorage(cid, config.storages.tgt) == -1 then
setTarget(cid)
else
if isCreature(getCreatureStorage(cid, config.storages.tgt)) then
if getCreatureStorage(cid, config.storages.tempo) - os.time() <= 0 then
doCreatureSetStorage(cid, config.storages.tempo, os.time() + 1)
attack(cid, getCreatureStorage(cid, config.storages.tgt), config.attRange)
end
else
doCreatureSetStorage(cid, config.storages.tgt, -1)
end
end
end
function onAttack(cid, target) if isPlayer(target) then if getCreatureStorage(cid, config.storages.tgt) ~= target then return false end end return true end