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

[0.4] Monster wont attack player with storage

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
583
Solutions
2
Reaction score
60
Location
México
hello, otlanders. i got an idea but i dont know how to execute it:
I want to create a quest, when u done that quest u got a storage value, if u have that storage dwarves wont attack you.

its something like a mining quest, if u complete it u can gather resources without getting attacked by the dwarves :)

hope u could help me, im using tfs 0.4
 
hello, otlanders. i got an idea but i dont know how to execute it:
I want to create a quest, when u done that quest u got a storage value, if u have that storage dwarves wont attack you.

its something like a mining quest, if u complete it u can gather resources without getting attacked by the dwarves :)

hope u could help me, im using tfs 0.4
Requires a source edit to have them not attack you.

But if you just want them to not damage you, you could do onStatsChange, and just return false the damage of those monsters.

Lua:
local monsters = {"dwarf", "dwarf guard", "dwarf geomancer"}

function onStatsChange(cid, attacker, type, combat, value)
    if not isMonster(attacker) then
        return true
    end
    if isInArray(monsters, getCreatureName(attacker):lower()) then
        if getPlayerStorageValue(cid, storage) == 11111 then
            if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then
                return false
            end
        end
    end
    return true
end
 
Hi,
Where I should put this script? Creaturescripts?
Yup. Just like you think you would.

data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="script_name" event="script" value="script_name.lua"/>
data/creaturescripts/scripts/login.lua [down near bottom of script with other registered events]
Lua:
registerCreatureEvent(cid, "script_name")
data/creaturescripts/scripts/script_name.lua
Lua:
script from above.
 
monster.cpp
C++:
bool Monster::isFriend(const Creature* creature)
{
    if(creature->getMonster() == this) return true;
    const Player* player = creature->getPlayer();
    if (player) {
        std::string value;
        getStorage(123123, value)
        if (value != "-1") {
            return true;
        }
    }
    NameList::iterator it = std::find(namelist.begin(), namelist.end(), creature->getName()); //MS
    if(it != namelist.end())
        return false; 
 
    if(player && !targetPlayers)
        return true; 
 
    if(!isSummon() || !master->getPlayer())
        return creature->getMonster() && !creature->isSummon();

    const Player* tmpPlayer = NULL;
    if(creature->getPlayer())
        tmpPlayer = creature->getPlayer();
    else if(creature->getPlayerMaster())
        tmpPlayer = creature->getPlayerMaster();

    const Player* masterPlayer = master->getPlayer();
    return tmpPlayer && (tmpPlayer == masterPlayer || masterPlayer->isPartner(tmpPlayer) || masterPlayer->isAlly(tmpPlayer));
}

change storage 123123 to whatever storage id you use
 
Last edited:
monster.cpp
C++:
bool Monster::isFriend(const Creature* creature)
{
    if(creature->getMonster() == this) return true;
    const Player* player = creature->getPlayer()
    if (player) {
        std::string value;
        getStorage(123123, value)
        if (value != "-1") {
            return true;
        }
    }
    NameList::iterator it = std::find(namelist.begin(), namelist.end(), creature->getName()); //MS
    if(it != namelist.end())
        return false;
 
    if(player && !targetPlayers)
        return true;
 
    if(!isSummon() || !master->getPlayer())
        return creature->getMonster() && !creature->isSummon();

    const Player* tmpPlayer = NULL;
    if(creature->getPlayer())
        tmpPlayer = creature->getPlayer();
    else if(creature->getPlayerMaster())
        tmpPlayer = creature->getPlayerMaster();

    const Player* masterPlayer = master->getPlayer();
    return tmpPlayer && (tmpPlayer == masterPlayer || masterPlayer->isPartner(tmpPlayer) || masterPlayer->isAlly(tmpPlayer));
}

change storage 123123 to whatever storage id you use
i need just to paste this in wathever place of monster.cpp? (outside of any function)

if so, i got this error
 

Attachments

Last edited:
now it compiled, but how do i use it?
i want to make dwarves friendly if player has the storage
Code:
getStorage(123123, value);
    if (value != "-1") {
I believe != means 'not equal to'
So, just add storage 123123 to the player however you want to, as any value not -1 should work.
 
Code:
getStorage(123123, value);
    if (value != "-1") {
I believe != means 'not equal to'
So, just add storage 123123 to the player however you want to, as any value not -1 should work.
yeah, i tried that to test the function using /storage but, i think i need something more on creaturescripts maybe (?
 
thank
idk i gave it my best try, i don't work with 0.4 so my answer was my best guess to make it work
thank you very much boi, im gonna try to figure out how to realize this via lua :)

maybe creating a flag that makes player invisible to monster in that area (?
 
it's impossible to do through lua that's why my first thought was through sources
i've done something similar in my server with 1.3 inside of Monster::selectTarget to make it not target me on a specific condition, but i'm not entirely sure about 0.4
maybe you can find something like selectTarget in 0.4 but i couldn't (maybe i didn't check enough) and use the code snippet i gave inside of that function instead
 
Back
Top