Everyone who has never used our Bots before, can test each one for 2 days without any limitation.
The trial is given automatically when you login on the Bot, but in some cases it wouldn't work (security reasons).
If this happens, send me a private message and i will be checking the failed trials manually and adding it for those who didn't get it.
We are looking for resellers who may accept payment methods different from ours, including classictibia's cash, realesta's cash, mastercores' cash, etc. Interested? Click here at anytime.



Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spawn and attack Trainer
#1
Souls of Elysium

I am fishing on a dock in Souls of Elysium and with the command !train I can spawn a 'Trainer'.
The problem is, the Trainer sometimes gets killed by Quara's or whatever monster, so I need to respawn it.

I made a script which writes !train if there is no Trainer right next to me, but the problem is, I use targeting to attack Trainer.
I want to make sure I am always attacking my own Trainer, and not someone elses trainer, because if I attack my own trainer, it attacks me back and thus I will train shielding as well.
If I attack the Trainer of someone else, I will not skill Shielding.

I tried to make something with the function isattackingme and the function attack to keep searching for a Trainer which attacks me back, but I didn't succeed.

I now have this, but perhaps you can make something better:

local trainerName = 'Trainer'
local checkInterval = 60000

local function checkTrainers()
    local trainerCount = maround(1, trainerName)

    if trainerCount < 1 then
        print('Trainer Spawned')
        say('!train')
end
end

while true do
    checkTrainers()
    wait(checkInterval)
end
Reply

#2
Hello.

This script will attack a "Trainer" creature that is attacking you when you are not attacking creatures.
if connected() and attacked().id == 0 then
    local creatures = getcreatures('mfs')
    for _, creature in ipairs(creatures) do
        if creature.name == 'Trainer' and (creature.isattackme or creature.dist <= 2) then
            attack(creature.id)
            return
        end
    end
end
Reply

#3
|Only Registered members can see download links. | Click here to buy subscription or here to register.
Hi, thanks for the reply
Problem is, it does only start attacking me after I initate the attack.

So if I spawn it, it doesn't attack me, it waits until I attack it, and then it attacks me back
Reply

#4
I just changed the script, so this script will attack a "Trainer" creature that is attacking you OR it's withing 2 sqm from you when you are not attacking creatures.
If Trainer spawns around you (1 sqm) than change "creature.dist <= 2" to "creature.dist <= 1".
Reply

#5
It is indeed 1 SQM, but despite changing that it will not work as intended.

if creature.name == 'Trainer' and (creature.isattackme or creature.dist <= 1) then

This will attack a Trainer, if it's either attacking me OR if it's <=1 SQM.
But it will not keep checking for the correct Trainer (my Trainer). As, only MY own trainer will attack me back.

Let's assume I am RED
Let's assume Trainer = Player left of me.
Let's assume I spawn Trainer with command !train, it will probably spawn NE or NW of me (or if north was free it could also spawn there).

With the above script, it will just attack one of the two+ available trainer. But what it should do is:
Attack one, check if it then attackme, if not attackme, then search for another Trainer within 1 SQM range.
If can not find Trainer attackme, then say "!train" and again try to find a Trainer which attackme (after I attack it)

|Only Registered members can see download links. | Click here to buy subscription or here to register.
|Only Registered members can see download links. | Click here to buy subscription or here to register.loading="lazy" alt="[Image: OMmS1PX.png]" class="mycode_img" />

Edit: If it's too much work, then just ignore this request. I tried a lot of different approaches to this issue, but couldn't be creative enough to find out.


I came with this logic, but I won't be able to test at the moment - will test it later:
Added some debug prints, but perhaps you can already tell this will succeed or fail XD
local trainerName = 'Trainer'
local checkInterval = 60000
-- Function to check if a creature is attacking me
local function isCreatureAttackingMe(creature)
    return creature.isattackme
end
-- Function to check if a Trainer is mine
local function isMyTrainer(trainer)
    return trainer.name == trainerName and isCreatureAttackingMe(trainer) and maround(1, trainerName) >= 1
end
-- Function to find the next Trainer to attack
local function findNextTrainer()
    local trainers = getcreatures('mfs')
    local targetTrainer = target()
    for _, trainer in ipairs(trainers) do
        if trainer.name == trainerName then
            local distanceX = trainer.posx - targetTrainer.posx
            local distanceY = trainer.posy - targetTrainer.posy
            if (math.abs(distanceX) == 1 and distanceY == 0) or (math.abs(distanceY) == 1 and distanceX == 0) then
                -- Trainer is adjacent to the previous target
                return trainer
            end
        end
    end
    return nil
end
-- Function to attack the next Trainer
local function attackNextTrainer()
    local targetTrainer = findNextTrainer()
    while targetTrainer and not isMyTrainer(targetTrainer) do
        stopattack()
        attack(targetTrainer.id)
        wait(2000)  -- Wait for the attack to register
        -- Check if the Trainer is attacking back
        if isCreatureAttackingMe(targetTrainer) then
            print('Attacking my own Trainer')
            return
        else
            print('This Trainer is not attacking me. Continuing the search...')
            targetTrainer = findNextTrainer()
        end
    end
    print('Unable to find a Trainer that is attacking back.')
    say('!train')
end
while true do
    if isMyTrainer(target()) then
        print('Already attacking my Trainer. Doing nothing.')
    else
        attackNextTrainer()
    end
    wait(checkInterval)
end
Reply

#6
Hello.

I didn't tested, but i think code below should work.
local trainerName = 'Trainer'
local intervalCheckAfterAttack = 2000 -- In milliseconds. How long should wait after attacking to find out if the trainer is yours.

if LAST_TRAINER_ID == nil then
    LAST_TRAINER_ID = 0
end

if connected() and attacked().id ~= LAST_TRAINER_ID then
    if LAST_TRAINER_ID > 0 and findcreature(LAST_TRAINER_ID) >= 0 then
        attack(LAST_TRAINER_ID)
    else
        local creatures = getcreatures('mfs')
        for _, creature in ipairs(creatures) do
            if creature.name:lower() == trainerName:lower() and creature.dist <= 1 then
                attack(creature.id)

                local startCheck = runningtimems()
                while runningtimems() <= (startCheck + intervalCheckAfterAttack) do
                    wait(100, 200)

                    local attackedCreature = attacked()
                    if attackedCreature.id > 0 and attackedCreature.id == creature.id and attackedCreature.isattackme then
                        LAST_TRAINER_ID = creature.id
                        return
                    end
                end
            end
        end
    end
end
Reply

#7
That one looks nice
Only thing which is missing is that it doesn't say "!train" to spawn a new Trainer if it died or disappeared for another reason
Reply

#8
Maybe this...
local trainerName = 'Trainer'
local intervalCheckAfterAttack = 2000 -- In milliseconds. How long should wait after attacking to find out if the trainer is yours.

if checkTrainer == nil then
    function checkTrainer(trainerId)
        attack(trainerId)

        local startCheck = runningtimems()
        while runningtimems() <= (startCheck + intervalCheckAfterAttack) do
            wait(100, 200)

            local attackedCreature = attacked()
            if attackedCreature.id > 0 and attackedCreature.id == trainerId and attackedCreature.isattackme then
                return true
            end
        end

        stopattack()

        return false
    end
end

if connected() and (LAST_TRAINER_ID == nil or attacked().id ~= LAST_TRAINER_ID) then
    if LAST_TRAINER_ID ~= nil and LAST_TRAINER_ID > 0 and findcreature(LAST_TRAINER_ID) >= 0 then
        attack(LAST_TRAINER_ID)
    else
        LAST_TRAINER_ID = nil

        local creatures = getcreatures('mfs')
        for _, creature in ipairs(creatures) do
            if creature.name:lower() == trainerName:lower() and creature.dist <= 1 and checkTrainer(creature.id) then
                LAST_TRAINER_ID = creature.id
                return
            end
        end

        if LAST_TRAINER_ID == nil then
            local NEAR_TRAINERS = { }
            local creatures = getcreatures('mfs')
            for _, creature in ipairs(creatures) do
                if creature.name:lower() == trainerName:lower() and creature.dist <= 1 then
                    table.insert(NEAR_TRAINERS, creature.id)
                end
            end

            say('!train')
            wait(1000, 2000)

            local creatures = getcreatures('mfs')
            for _, creature in ipairs(creatures) do
                if creature.name:lower() == trainerName:lower() and creature.dist <= 1 and table.find(NEAR_TRAINERS, creature.id) == nil and checkTrainer(creature.id) then
                    LAST_TRAINER_ID = creature.id
                    return
                end
            end
        end
    end
end
Reply

#9
I don't want to frustrate you, but nope it's not working.
I changed !trainer to !train because that's the command

But still it doesn't work, it doesn't spawn a !train (trainer)

If it's too hard, just get over it - i am also clueless how to make it work
Reply

#10
|Only Registered members can see download links. | Click here to buy subscription or here to register.
Try again, i just updated the script.

It's not hard, just had to fix the logic approach.
Reply



Forum Jump:



Forum software by © MyBB Theme © iAndrew 2016