• Vote in May Mapping Competition to select a winner!
  • 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

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
926
Best answers
8
Reaction score
276
Location
Poland
Does it work for TFS[1.2]?
If not (can't confirm myself, because I never compiled anything) then can someone update it?
 

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,998
Best answers
12
Reaction score
1,538
Does it work for TFS[1.2]?
If not (can't confirm myself, because I never compiled anything) then can someone update it?
Printer said some time ago that it is possible you just need to update the spectators list, however he did not go into much more detail than that.
 

Flatlander

Species Developer
Premium User
Joined
Feb 17, 2009
Messages
2,457
Best answers
3
Reaction score
1,291
Location
Texas
From what I remember, the client saves the creature name when the creature first appears.

This means, the only way to update the creature's name is to have it teleport off screen, and back on screen (Or maybe just teleport at all). Unless you want to edit the client source parse, and tfs protocol, so it can send updated names each time it updates the character.
 

Black123

New Member
Joined
Nov 17, 2011
Messages
32
Best answers
0
Reaction score
0
From what I remember, the client saves the creature name when the creature first appears.

This means, the only way to update the creature's name is to have it teleport off screen, and back on screen (Or maybe just teleport at all). Unless you want to edit the client source parse, and tfs protocol, so it can send updated names each time it updates the character.
I've got errors while compiling.. tried 3 times and everytime errors :/
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,600
Best answers
37
Reaction score
402
For this to work on TFS 1.2

Monster.h

find
Code:
const std::string& getName() const final {
replace the 3 codes with this:
Code:
const std::string& getName() const final {
            return name;
        }
        const std::string& getNameDescription() const final {
            return nameDescription;
        }
        std::string getDescription(int32_t) const final {
            return nameDescription + '.';
        }
Luascript.h

find
Code:
static int luaSetItemOutfit(lua_State* L);
add this under it:
Code:
static int luaSetCreatureName(lua_State* L);
luascript.cpp

find:
Code:
int LuaScriptInterface::luaSetCreatureOutfit(lua_State* L)
{
    //doSetCreatureOutfit(cid, outfit, time)
    Creature* creature = getCreature(L, 1);
    if (!creature) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    Outfit_t outfit = getOutfit(L, 2);
    int32_t time = getNumber<int32_t>(L, 3);
    pushBoolean(L, Spell::CreateIllusion(creature, outfit, time) == RETURNVALUE_NOERROR);
    return 1;
}
Under that paste this:

Code:
int LuaScriptInterface::luaSetCreatureName(lua_State* L)
{
    //setCreatureName(cid, newName, newDescription)
    Creature* creature = getCreature(L, 1);
    if (creature) {
        Monster* monster = (Monster*)creature;
        std::string newName = getString(L, 2);
        std::string newDesc = getString(L, 3);
        monster->name = newName;
        monster->nameDescription = newDesc;
        pushBoolean(L, false);
    }
    else {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
    }
    return 1;
}

find
Code:
//doSetCreatureOutfit(cid, outfit, time)
    lua_register(luaState, "doSetCreatureOutfit", LuaScriptInterface::luaSetCreatureOutfit);
Under add this:
Code:
//setCreatureName(cid, name, description)
    lua_register(luaState, "setCreatureName", LuaScriptInterface::luaSetCreatureName);

Enjoy... Works the same.
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,600
Best answers
37
Reaction score
402
Make sure you still add

Code:
std::string name, nameDescription;
In the same spot.
 

Itutorial

Veteran OT User
Joined
Dec 23, 2014
Messages
1,600
Best answers
37
Reaction score
402
could you help me please?
where should i put this?

thanks in advice!!
Look on the thread owners tutorial and look for where its placed. Put it in the same spot as he did.
 

Ovnyx

Member
Joined
Jul 25, 2017
Messages
155
Best answers
2
Reaction score
8
Look on the thread owners tutorial and look for where its placed. Put it in the same spot as he did.
firstable thanks for your answer, going to take a look, bless!
 
Top