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

Monster FriendList

KnightmareZ

New Member
Joined
Feb 3, 2008
Messages
607
Reaction score
4
Location
Sweden/Ljungby
Hello there! I have an event in a Arena where I spawn monsters with Game.createMonster(monster.name, monster.spawnPos ..). Now I would like to add friends(Players) to this monster so he wont target this person. It does add people to this list but still attacks them.

INVESTIGATION RESULT 1. Printer faced this problem where it still tried to steer to the player. Link: https://otland.net/threads/summon-auto-attacking-monster-1-0.211199/ with code examples.

INVESTIGATION RESULT 2.
In monster.cpp at Monster::addTarget (Line 305~)
This process should be:
When addTarget is ran it will update monster friendList first (updateTargetList(I dont know?)).
then right before monster going to add target to his targetList, make it check if its in its friendlist. if it is, dont add it to target.

INVESTIGATION RESULT 3 - Tried to add the 4th line below but any monster never attacked any player
Code:
void Monster::addTarget(Creature* creature, bool pushFront/* = false*/)
{
    assert(creature != this);
    if (std::find(targetList.begin(), targetList.end(), creature) == targetList.end()) {
        if (std::find(friendList.begin(), friendList.end(), creature) != friendList.end()) {
            creature->incrementReferenceCounter();
            if (pushFront) {
                targetList.push_front(creature);
            } else {
                targetList.push_back(creature);
            }
        }
    }
}

INVESTIGATION RESULT 4.
In LUA:
Code:
monster:addFriend(player)
and player can be found in
Code:
monster:getFriendList().
and in monster.cpp:
Code:
if (isOpponent(creature) && isFriend(creature) == false) {[/I][/I][/I][/I][/I]
[I][I][I][I][I]        addTarget(creature, pushFront);
    }
and it still add target to player.


 
Last edited:
local monster = Game.createMonster(name, pos)
monster:addFriend(creature)

You have to use userdata or cid, not name
 
local monster = Game.createMonster(name, pos)
monster:addFriend(creature)

You have to use userdata or cid, not name

Thank you for your quickly response. I have updated my post for clarification. Please take a look at investigation result 2.

Edit: I am in the monsters friendlist but it keeps attacking me. Why is that?
 
Last edited:
try this instead of setTarget
monster:searchTarget()

still no "/

I do
Code:
 for _, c in ipairs(monster:getFriendList()) do
        print(c:getName())
    end
and it return all the playernames...

I do
Code:
monster:getFriendCount()

and it returns 1 or the actual count, but still targetList doesnt updates and attack the player.
 
@UnsineSoft solved my problem in another way - with onTargetCombat instead..

Code:
local creatures_red = "Wolf"
local creatures_blue = "Rat"

function Creature:onTargetCombat(target)
    if self:isMonster() and target:isPlayer() then
        if self:getName() == creatures_red and (target:getStorageValue(26800) == 1) then
            self:searchTarget()
            self:removeTarget(target)
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        elseif self:getName() == creatures_blue and (target:getStorageValue(26800) == 2) then
            self:searchTarget()
            self:removeTarget(target)
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end
    return true
end

also don't forget
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />
 
@UnsineSoft solved my problem in another way - with onTargetCombat instead..

Code:
local creatures_red = "Wolf"
local creatures_blue = "Rat"

function Creature:onTargetCombat(target)
    if self:isMonster() and target:isPlayer() then
        if self:getName() == creatures_red and (target:getStorageValue(26800) == 1) then
            self:searchTarget()
            self:removeTarget(target)
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        elseif self:getName() == creatures_blue and (target:getStorageValue(26800) == 2) then
            self:searchTarget()
            self:removeTarget(target)
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end
    return true
end

also don't forget
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />

<3
 
Back
Top