Lua Function Change Existing Monster Name In-Game

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Best answers
0
Likes
180
#42
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
Best answers
0
Likes
8
#44
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:

Scarlet Ayleid

Well-Known Member
Joined
Jul 7, 2007
Messages
4,057
Best answers
0
Likes
232
#45
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
 
Joined
Dec 16, 2008
Messages
290
Best answers
0
Likes
331
Location
Mexico
#47
i get the following in;
luascript.cpp|2999|error: suggest parentheses around assignment used as truth value|
||=== Build finished: 1 errors, 0 warnings ===|
 

Hatsune Miku

Active Member
Joined
Jan 22, 2009
Messages
370
Best answers
0
Likes
135
#50
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
 

Scarlet Ayleid

Well-Known Member
Joined
Jul 7, 2007
Messages
4,057
Best answers
0
Likes
232
#51
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
 

Scarlet Ayleid

Well-Known Member
Joined
Jul 7, 2007
Messages
4,057
Best answers
0
Likes
232
#55
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 :)
 

Scarlet Ayleid

Well-Known Member
Joined
Jul 7, 2007
Messages
4,057
Best answers
0
Likes
232
#59
use the example I made in the first post, then use the convince function to get it as a summon
 
Top