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

C++ monster:setPet(true)

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hello folks, I'm wondering if is possible set monster flags to monsters with lua
exemple:
Code:
local monster = Game.createMonster('rat', Position(x, y, z), true, true)
if monster then
      monster:setAttackable(true) -- that line means <flag attackable="1"/>
end
so if is possible, how I should do it?
 
hello folks, I'm wondering if is possible set monster flags to monsters with lua
exemple:
Code:
local monster = Game.createMonster('rat', Position(x, y, z), true, true)
if monster then
      monster:setAttackable(true) -- that line means <flag attackable="1"/>
end
so if is possible, how I should do it?

To set the monsters flags you will need to make functions for that on sources.
No functions to do that exists yet since this was never used/made/requested/needed before.
To me, everything is possible. You need just to find a way to do, no excuses.
But I'm not saying that this is easy, since I think you want functions to customize all flags of monster in real time.
The functions are easy to do, but there is 3957y2957425 flags to do, so probably too much code for you to do.
 
No es necesario, se puede hacer con un simple Lua script, te daré la idea, el detalle es que el monster sumoneara por script. Entonces empiezas creando un creaturescript para el mounstro que sumoneara el pet, el script será onthink, entonces el mounstro estará pensando que tanta vida tiene, cuando le bajen vida entonces sumoneara. El otro script será ontarget quien lo tenga en Target les dará un storage. El otro igual será ontarget pero para el summon quien tenga el storage no podrá atacar al summon.
 
To set the monsters flags you will need to make functions for that on sources.
No functions to do that exists yet since this was never used/made/requested/needed before.
To me, everything is possible. You need just to find a way to do, no excuses.
But I'm not saying that this is easy, since I think you want functions to customize all flags of monster in real time.
The functions are easy to do, but there is 3957y2957425 flags to do, so probably too much code for you to do.
I just need two functions:
setPet(true) -- pet is just a flag that I use internally to monsters walk on pz zones, be teleported to the master when it is away, or down stair etc
setConvinceable(true)
@sirakx sorry but I couldn't understand you, my spanish is bad, but the general I understood, but seems too wierd use onThink on it, or I don't know what is your idea about
 
Last edited:
hello folks, I'm wondering if is possible set monster flags to monsters with lua
exemple:
Code:
local monster = Game.createMonster('rat', Position(x, y, z), true, true)
if monster then
      monster:setAttackable(true) -- that line means <flag attackable="1"/>
end
so if is possible, how I should do it?
The idea is possible but not with the code you posted.
To set the monsters flags you will need to make functions for that on sources.
No functions to do that exists yet since this was never used/made/requested/needed before.
To me, everything is possible. You need just to find a way to do, no excuses.
But I'm not saying that this is easy, since I think you want functions to customize all flags of monster in real time.
The functions are easy to do, but there is 3957y2957425 flags to do, so probably too much code for you to do.
This does not require a source edit, you can do this in lua. Is it difficult? Depends on how you implement it.
 
I'll make it as creature:setHiddenHealth(creature) works... hiden health is a flag, so I can set flags in a monster that already exist

bump !! I couldn't resolve this :/
 
Last edited by a moderator:
monsters.h
Code:
void setPet(MonsterType* monster);
monsters.cpp
Code:
void MonsterType::setPet(MonsterType* monster) {
    monster->isPet = true;
}
luascript.cpp
Code:
int LuaScriptInterface::luaMonsterTypeSetPet(lua_State* L)
{
    // monster:setPet(true)
    MonsterType* monster = getUserdata<MonsterType>(L, 1);
    if (!monster) {
        lua_pushnil(L);
        return 1;
    }
    monster->setPet(monster);
    pushBoolean(L, true);
    return 1;
}
luascript.h
Code:
static int luaMonsterTypeSetPet(lua_State* L);
and ofc isPet is a bool registered in monsters.h as the another flags like "isAttackable"
 
I think you have the wrong idea about what MonsterType is, it is a blue print of a monster type (general), not a specific monster. You shouldn't (not saying you can't) but you shouldn't try to set ownership in MonsterType. Setting a value to true won't do anything for the creature, you need to establish ownership to something.
 
I think you have the wrong idea about what MonsterType is, it is a blue print of a monster type (general), not a specific monster. You shouldn't (not saying you can't) but you shouldn't try to set ownership in MonsterType. Setting a value to true won't do anything for the creature, you need to establish ownership to something.
I guess, cuz I don't understand the different between Monster and MonsterType... so how I should do it ?
 
Lmao. According to this logic (adding the function to Monsters.cpp, i.e, MonsterType), when the function is ran it will make all monsters of a type (sic) belong to a player.

Monster.cpp is where it's at.. Keep at it!
 
Make new bool called isPet in monster.h. Set its value and use it anywhere you want in the source by calling monster->isPet or function that return this value. And then just make checks in what you want to prevent this action. Like for attacking you can just set check in monster::doAttacking()
 
Make new bool called isPet in monster.h. Set its value and use it anywhere you want in the source by calling monster->isPet or function that return this value. And then just make checks in what you want to prevent this action. Like for attacking you can just set check in monster::doAttacking()
I need set the flag, the flag is used to almost everything of the pet system (such as: boost, teleport to master, enter pz)... I need active the flag to especifed monster because I want to use the system generic, to be possible use all monsters without make another monster file, called for exemple: "pet rat"....
@Itutorial it should be to this one monster... as @ScorpionOT and @Linxsis had pointed about the MonsterType, so now I could undertood that difference
 
I need set the flag, the flag is used to almost everything of the pet system (such as: boost, teleport to master, enter pz)... I need active the flag to especifed monster because I want to use the system generic, to be possible use all monsters without make another monster file, called for exemple: "pet rat"....
@Itutorial it should be to this one monster... as @ScorpionOT and @Linxsis had pointed about the MonsterType, so now I could undertood that difference
Yes to one monster, thats how you do it. Like I explained. It will work with monster:setPet() or whatever you want. You cant use global monsterType flags for that. These are for every monster in the game.
 
Is there a reason... monster:getOwner() and monster:setOwner() wont work for what you are doing? Even in C++ codes you can call a monsters owner or check if it has one. It sounds like you are creating something that already exists.
 
Back
Top