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

GlobalEvent Summon Auto Attacking Monster [1.0]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,286
Location
Sweden?
Hello, i found this request:
And i gave it a try, also got help from @Dalkon

One problem which i couldn't figure it out, was that how to make it not attack players, now it wont attack player but it will steer on the player. It wants to attack it, but there is a line which prevent it. But i would like to cancel it from even checking on the player, but if there is a monster on the screen it will directly switch focus to the monster instead of the player. Feel free if you have any idea.

Add it on creaturescript:
Code:
<event type="think" name="aA" script="autoAttack.lua"/>

Code:
function onThink(cid, interval)
    local monster = Monster(cid)
    if monster ~= nil then
        local targets = monster:getTargetList()
        local currentTarget = monster:getTarget()
        if not currentTarget then
            return monster:searchTarget()
        end
        if currentTarget ~= nil then
            for i = 1, #targets do
                    local target = targets[i]
                if target:isPlayer() then
                    monster:addFriend(target)
                    monster:removeTarget(target)
                end
            end
            local newTarget = monster:getTargetList()[1]
            monster:setTarget(newTarget)
            monster:setFollowCreature(newTarget)
        end
    end
    return true
end

And here is a example how to register it:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local monster = doSummonCreature("Rattata", getPlayerPosition(cid))
    doConvinceCreature(cid, monster)
    registerCreatureEvent(monster, "aA")
    return true
end
 
Anyone have this for 0.3 or 0.4? Tried to convert it but I don't know it is possible.
 
Excuse me but where do i "register" it? I pasted the first line in under creaturescripts and also made a file named autoAttack.lua, but where do i register that last part?
 
Another thing, would it be possible to enable this to summons in general, like every monster you summon with utevo res will work this way?
 
any chance to use it on tfs 1.3 ?
get no errors but don't work :/
Lua:
function onThink(creature, interval)
    local monster = Monster(creature:getId())
    if monster then
        local targets = monster:getTargetList()
        local currentTarget = monster:getTarget()
        if not currentTarget then
            return monster:searchTarget()
        else
            for indx, target in pairs(targets) do
                if target:isPlayer() then
                    monster:addFriend(target)
                    monster:removeTarget(target)
                end
            end
            local newTarget = monster:getTargetList()[1]
            monster:setTarget(newTarget)
            monster:setFollowCreature(newTarget)
    end
    return true
end

Lua:
function onUse(player, item, fromPos, target, toPos, isHotkey)
    local monster = Game.createMonster("Rattata", player:getPosition())
    if monster then
        doConvinceCreature(monster, player)
        monster:registerEvent("aA")
    end
    return true
end
 
nothing again.
I put the first part of the code on autoattack.lua
and the second part inside the login.lua
but without success in autoattack :x

Lua:
function onThink(creature, interval)
    local monster = Monster(creature:getId())
    if monster then
        local targets = monster:getTargetList()
        local currentTarget = monster:getTarget()
        if not currentTarget then
            return monster:searchTarget()
        else
            for indx, target in pairs(targets) do
                if target:isPlayer() then
                    monster:addFriend(target)
                    monster:removeTarget(target)
                end
            end
            local newTarget = monster:getTargetList()[1]
            monster:setTarget(newTarget)
            monster:setFollowCreature(newTarget)
    end
    return true
end

Lua:
function onUse(player, item, fromPos, target, toPos, isHotkey)
    local monster = Game.createMonster("Rattata", player:getPosition())
    if monster then
        doConvinceCreature(monster, player)
        monster:registerEvent("aA")
    end
    return true
end
 
Back
Top