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

Lua Function Change Existing Monster Name In-Game

Well..

I was making a pet system, and i prefereed to use a doCreateCreatureEx() like the item thing. So pet created virtually and i edit everything then add it, to replace current i just removed the current, created another one in same place with different name same hp. (Idea)
 
hi, Scarlet Ayleid... srr if now u off thread, but
when i add ur code to my source, monster in my tfs don't respawn
and in server log: You dealt 1000 damage to .
I'm using TFS 0.3.6

srr for my bad
 
Last edited:
then you did something wrong, I and many other people have already done this with no problem, try doing it again, maybe u messed something up last time
 
i get the following in;
luascript.cpp|2999|error: suggest parentheses around assignment used as truth value|
||=== Build finished: 1 errors, 0 warnings ===|
 
you did something wrong when adding the code to the sources, try adding it again from scratch
 
Lol this can be used to check if someone is botting :D If someone bots at demon you can call the monster "Botting?" and the bot won't attack it :D Botting? would still be a demon just name is different so a bot can't attack it :D
I like this /bookmarked :D
 
yeah, it can work like that, but remember that if the player sees the demon before you change the name, nothing will happen, you have to change the name before anyone sees it
 
what is monster.h where do i find?

- - - Updated - - -

where is monster.h?
 
How i can make it without "new description"?
monster.h
find
Code:
class Monster : public Creature
then add this under public:
Code:
std::string name;
find
Code:
virtual const std::string& getName() const {return mType->name;}
replace with
Code:
virtual const std::string& getName() const {return name;}

monster.cpp
find
Code:
Monster::Monster(MonsterType* _mType):
then add the following code right above isIdle = true;
Code:
    name = _mType->name;

luascript.h
add near the similar lines
Code:
static int32_t luaSetCreatureName(lua_State* L);

luascript.cpp
add near similar lines
Code:
//setCreatureName(cid, name)
lua_register(m_luaState, "setCreatureName", LuaInterface::luaSetCreatureName);
add near similar lines
Code:
int32_t LuaInterface::luaSetCreatureName(lua_State* L)
{
    //setCreatureName(cid, newName)
    std::string newName = popString(L);
    ScriptEnviroment* env = getEnv();
    Creature* creature;
    if(creature = env->getCreatureByUID(popNumber(L))){
        Monster* monster = (Monster*)creature;
        monster->name = newName;
        lua_pushboolean(L, true);
    }
    else{
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

An example for this would be:

Code:
function createFakeTroll(spawnPos) 
   local farAwayPos = {x = 100, y = 100, z = 7} --Change This!! 
   local monster = doCreateMonster("Troll", farAwayPos) 
   setCreatureName(monster, "FakeTroll") 
   doTeleportThing(monster, spawnPos) 
end
Done :)
 
use the example I made in the first post, then use the convince function to get it as a summon
 
Can this be used in TFS 3.6.0 I don't have C++ scripts
 
Back
Top