Lua Function Change Existing Monster Name In-Game

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
181
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)
 

Shiko Erye

LUA - Scripter
Joined
Dec 7, 2010
Messages
105
Reaction score
8
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:
OP
Scarlet Ayleid

Scarlet Ayleid

Intermediate OT User
Joined
Jul 7, 2007
Messages
4,057
Reaction score
233
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
 

hellpsy

Mapper
Joined
Dec 16, 2008
Messages
299
Reaction score
336
Location
Mexico
i get the following in;
luascript.cpp|2999|error: suggest parentheses around assignment used as truth value|
||=== Build finished: 1 errors, 0 warnings ===|
 
OP
Scarlet Ayleid

Scarlet Ayleid

Intermediate OT User
Joined
Jul 7, 2007
Messages
4,057
Reaction score
233
you did something wrong when adding the code to the sources, try adding it again from scratch
 

Hatsune Miku

Excellent OT User
Joined
Jan 22, 2009
Messages
370
Reaction score
135
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
 
OP
Scarlet Ayleid

Scarlet Ayleid

Intermediate OT User
Joined
Jul 7, 2007
Messages
4,057
Reaction score
233
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
 

hohosanta

Banned User
Joined
Jul 24, 2013
Messages
10
Reaction score
0
what is monster.h where do i find?

- - - Updated - - -

where is monster.h?
 
OP
Scarlet Ayleid

Scarlet Ayleid

Intermediate OT User
Joined
Jul 7, 2007
Messages
4,057
Reaction score
233
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 :)
 
OP
Scarlet Ayleid

Scarlet Ayleid

Intermediate OT User
Joined
Jul 7, 2007
Messages
4,057
Reaction score
233
use the example I made in the first post, then use the convince function to get it as a summon
 

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,442
Reaction score
317
Can this be used in TFS 3.6.0 I don't have C++ scripts
 
Top