Lua Function Change Existing Monster Name In-Game

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
922
Best answers
6
Likes
266
Location
Poland
#61
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
3,000
Best answers
11
Likes
1,509
#62
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
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Likes
1,273
Location
Texas
#64
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.
 
Joined
Nov 17, 2011
Messages
32
Best answers
0
Likes
0
#65
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

Well-Known Member
Joined
Dec 23, 2014
Messages
1,363
Best answers
23
Likes
287
#66
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

Well-Known Member
Joined
Dec 23, 2014
Messages
1,363
Best answers
23
Likes
287
#67
Make sure you still add

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