• 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 Error when sending packets

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
Hi,

I am trying to send network message to the client to update name of the summon.

Here is the code so far:
Lua:
function Player.updateName(self, creatureId, creatureName)
    local msg = NetworkMessage()
    msg:addU32(creatureId)
    msg:addString(creatureName)
    msg:sendToPlayer(self)
    msg:delete()
    return true
end

function onCastSpell(cid, var)
    local player = Player(cid)
    local player_position = player:getPosition()
   
    local monster = Game.createMonster("Training Monk", player_position)
    monster:setName("New Monster Name")
    monster:setMaster(player)
   
    player:updateName(monster:getId(), monster:getName())
   
    return true
end

Client Error Debug:
jlbCfaq.png


This is the code from C++ sources I was trying to imitate. It checks whether the creature is known, if so it will not update the name, otherwise it will- so that's the code I need but something is not working and Iam completely stuck & need help

otland/forgottenserver
 
Hello, I do not know how to fix this script for you since I have no knowledge of how these network messages work but I recently added this into my sources
Feature - setCreatureName & monster:setName for TFS 1.2
and it worked good for changing names. (But there is client limitations, read below) I can also provide some input for changing creature's names, since it's something I recently worked alot with on my own otserver.

There's a limitation inside the normal tibia client for changing names, for example, in your script, you're summoning a monster and THEN changing it's name, every player that saw this creature spawn will always see the monsters first name. So even if you get your code to work, it will still be quite buggy, because the players that saw the monster get summoned will see the monsters name as "Training Monk" instead of "New Monsters Name" and players that didn't see the creature spawn will see it as "New Monster Name". A hacky solution could be to spawn the creature first at some random place at the map, then teleport the creature to the player that summoned it after it has changed name.

My suggestion would be to adjust the Game.createMonster inside sources to accept another variable that can be used to make a custom named monster, but it requires kind of many changes and I cannot do this for you. But I guess simplest is, using the hacky solution and implementing setName from the code above.
 
Last edited:
Hello, I do not know how to fix this script for you since I have no knowledge of how these network messages work but I recently added this into my sources
Feature - setCreatureName & monster:setName for TFS 1.2
and it worked good for changing names. (But there is client limitations, read below) I can also provide some input for changing creature's names, since it's something I recently worked alot with on my own otserver.

There's a limitation inside the normal tibia client for changing names, for example, in your script, you're summoning a monster and THEN changing it's name, every player that saw this creature spawn will always see the monsters first name. So even if you get your code to work, it will still be quite buggy, because the players that saw the monster get summoned will see the monsters name as "Training Monk" instead of "New Monsters Name" and players that didn't see the creature spawn will see it as "New Monster Name". A hacky solution could be to spawn the creature first at some random place at the map, then teleport the creature to the player that summoned it after it has changed name.

My suggestion would be to adjust the Game.createMonster inside sources to accept another variable that can be used to make a custom named monster, but it requires kind of many changes and I cannot do this for you.

Yes that's what I had until now. There is no setName function in TFS 1.0 so I had to add that as well XD -> it only changes the name without actually sending any network messages

and that's what I was talking about actually, up there where I mention whenever the creature is known, it will not update its name. And finally I think I know what you mean by others seeing the creature, then actually getting my script to work and then its gonna be buggy. Well in that case, you can just send the network message to every player, that's gonna solve the issue :p
 
Yes that's what I had until now. There is no setName function in TFS 1.0 so I had to add that as well XD -> it only changes the name without actually sending any network messages

and that's what I was talking about actually, up there where I mention whenever the creature is known, it will not update its name. And finally I think I know what you mean by others seeing the creature, then actually getting my script to work and then its gonna be buggy. Well in that case, you can just send the network message to every player, that's gonna solve the issue :p


Ooh! Yeah I saw you added setName already now! :)
I'm still not sure if network message is gonna force players to see the new and updated name (from what I understood its not possible without changing how client works), so I would try what I said in the other post,
just first spawn the creature in a place noone on the map is located, and then after the creatures name has been changed just teleport it to the player then.
 
Ooh! Yeah I saw you added setName already now! :)
I'm still not sure if network message is gonna force players to see the new and updated name (from what I understood its not possible without changing how client works), so I would try what I said in the other post,
just first spawn the creature in a place noone on the map is located, and then after the creatures name has been changed just teleport it to the player then.

It looks like even if I were to change the source files, there is no built-in method in Creature class, which means there is no way to change its name. I did a lot of testing with networking message and it's better to leave it alone and work with the method that creates monsters instead, also did bit of research on that and changed the original method, to something like this:

C++:
bool Game::placeCreature(Creature* creature, const Position& pos, const std::string& newName, bool extendedPos /*=false*/, bool forced /*= false*/)


It worked perfectly when I applied that in luascript.cpp -> Game.createMonster. However it only changed monster's name without updating that in the client, which means that the network message has been sent prior to this. Then I have decided to change the code inside game.cpp->placeCreature and there I couldn't really use setName as its only applicable to Monster class, not Creature class.

So, to fix that, either create another function such as Game:placeMonster... < that will take a lot of unecessary space in your source files

or re-write the current function Game::placeCreature, to the one provided above. But for that to work, setName method taken from the other thread has to be applied in Creatures not monsters then maybe I could've fixed it :confused:
 
Hello, I do not know how to fix this script for you since I have no knowledge of how these network messages work but I recently added this into my sources
Feature - setCreatureName & monster:setName for TFS 1.2
and it worked good for changing names. (But there is client limitations, read below) I can also provide some input for changing creature's names, since it's something I recently worked alot with on my own otserver.

There's a limitation inside the normal tibia client for changing names, for example, in your script, you're summoning a monster and THEN changing it's name, every player that saw this creature spawn will always see the monsters first name. So even if you get your code to work, it will still be quite buggy, because the players that saw the monster get summoned will see the monsters name as "Training Monk" instead of "New Monsters Name" and players that didn't see the creature spawn will see it as "New Monster Name". A hacky solution could be to spawn the creature first at some random place at the map, then teleport the creature to the player that summoned it after it has changed name.

My suggestion would be to adjust the Game.createMonster inside sources to accept another variable that can be used to make a custom named monster, but it requires kind of many changes and I cannot do this for you. But I guess simplest is, using the hacky solution and implementing setName from the code above.
I wrote that code ;) Maybe i'll update it :) been soo busy :(
 
I wrote that code ;) Maybe i'll update it :) been soo busy :(

That would be awesome if you could do that, monsters -> creatures update

then I am almost sure I will be able to finish the project

if we look in game.cpp at the game:placeCreature there is a comment line: (That was in TFS 1.0, it's different in 1.2 as there is some info about spectators. It should still work though, maybe)
// TODO: Move this code to Player::eek:nCreatureAppear where creature == this.

This means that network messages must be sending after this line. So if I were to add simple if statement there. It should be possible to adjust monster name, in theory. Before sending the packets

If you don't have time, I will try and do it myself :D
 
I didn't read the previous posts, but since you didn't mark any as a Best Answer. Here is a few tips.

1) Is your networking packet correct?
Lua:
function Player.updateName(self, creatureId, creatureName)
    local msg = NetworkMessage()
    -- here you are missing the packet type..
    msg:addU32(creatureId)
    msg:addString(creatureName)
    msg:sendToPlayer(self)
    msg:delete()
    return true
end

This code you wrote will end up unreached or causing OTC to parse something incorrectly which may really end up badly on the client-side.

2) Is namechange really allowed in Tibia Client?
If you want to change the name, you'd probably have to you OTClient, changing the name in the default client isn't as trivial as this code.

A propper example of that, is defining your own packet type (in protocolcodes.h) and then updating the creatures (m_name and m_cacheName or w/e related to name)
If you want help about OTClient you'd better open another cleaner support thread so that people can help you.

3) But I want to use normal client to do the job.
It's clearly not possible, Tibia doesn't allow you to re-send the player again to the screen with another name(creature is known). Even if you changed the ID, you would just be allowed to change other creatures' names BUT not yourself.
Using OTC is better as it will give you full power of optimizing your own custom things.

Good luck!
 
I didn't read the previous posts, but since you didn't mark any as a Best Answer. Here is a few tips.

1) Is your networking packet correct?
Lua:
function Player.updateName(self, creatureId, creatureName)
    local msg = NetworkMessage()
    -- here you are missing the packet type..
    msg:addU32(creatureId)
    msg:addString(creatureName)
    msg:sendToPlayer(self)
    msg:delete()
    return true
end

This code you wrote will end up unreached or causing OTC to parse something incorrectly which may really end up badly on the client-side.

2) Is namechange really allowed in Tibia Client?
If you want to change the name, you'd probably have to you OTClient, changing the name in the default client isn't as trivial as this code.

A propper example of that, is defining your own packet type (in protocolcodes.h) and then updating the creatures (m_name and m_cacheName or w/e related to name)
If you want help about OTClient you'd better open another cleaner support thread so that people can help you.

3) But I want to use normal client to do the job.
It's clearly not possible, Tibia doesn't allow you to re-send the player again to the screen with another name(creature is known). Even if you changed the ID, you would just be allowed to change other creatures' names BUT not yourself.
Using OTC is better as it will give you full power of optimizing your own custom things.

Good luck!

Hi, Thank you for your contribution

Writing a network message in lua to change monster name was REALLY a bad idea and would require a lot more than just this little function.

There is no need for OTClient to change monster name. and yes everything is possible if you plan everything beforehand

I just did it after a lot of compilation errors. (FYI, there is no need to update bayview method to creature, you can still use monster class)

Right after creating a monster:

qO1kjpI.png


Here is the code used:

Lua:
local monster = Game.createMonster("Training Monk", player_position, "newName")

Now, to further improve the code I want to make the third parameter optional, (it's a string) I will try and do it :p
 
Back
Top