krafttomten
Well-Known Member
I have a custom channel that shows all the loot. When I am playing I have that channel opened all the time.
Everything is great until I get back from my hunt and need to sell all my awesome loot. Because every single time I write:
"Hi" * return * ... wait ... wait... - Oh right! tab into default channel "Hi" npc responds
You with me? I cannot talk to NPCs when I have the loot channel opened. This is annoying. I want to fix it, but I have no idea where to begin.
All the standard functions I've found, like doPlayerSendChannelMessage and sendTextMessage are only used for sending a message to the player, not from the player.
I then looked at the die.lua code, that uses the function say, like player:say(MSG, TALKTYPE_SAY). And it just works.
I was going to make this thread in the support subforum but I didn't need to. So instead I posted this message in tutorials. Because why not, I had to solve it myself and I learned something from doing it.
I found that the "say" function in the die.lua script is more awesome than I previously thought. (Not die as in death, die as in one die, two dice).
I have previously used it for many things, like sending messages before a boss spawns, or for other times when I want to send a message to the player and I did not have access to a player variable, exempli gratia when using AddItem movement events.
So here's some generally applicable knowledge; use the die.lua code whenever you need players or any other creature to say shit. It's great.
And as I said initially, it can also be used to fix annoying problems with loot channels.
Replace all the random stuff, like getName() and the stuff necessary to send the die message, and replace it with whatever you want. Then you can change the range to whatever you see fit.
If you want to use it like I did, with the loot channel, just use:
See? It's easy to use and can be used for so much.
You can also combine it with addEvent() to make an obnoxious advertising sign.
One clever thing about this code is that a creature is necessary to send the message. It's like with the falling tree in the forest. Does it make a sound if nobody hears it? The answer is: maybe, but it doesn't really matter if it does unless somebody hears it. So this brilliant functions inevitably works like that; it is impossible to send a message unless somebody is there to hear it, because you cannot send a message unless you have somebody to send the message. That somebody should be the one who receives the message.
Awesome...
Everything is great until I get back from my hunt and need to sell all my awesome loot. Because every single time I write:
"Hi" * return * ... wait ... wait... - Oh right! tab into default channel "Hi" npc responds
You with me? I cannot talk to NPCs when I have the loot channel opened. This is annoying. I want to fix it, but I have no idea where to begin.
All the standard functions I've found, like doPlayerSendChannelMessage and sendTextMessage are only used for sending a message to the player, not from the player.
I then looked at the die.lua code, that uses the function say, like player:say(MSG, TALKTYPE_SAY). And it just works.
I was going to make this thread in the support subforum but I didn't need to. So instead I posted this message in tutorials. Because why not, I had to solve it myself and I learned something from doing it.
I found that the "say" function in the die.lua script is more awesome than I previously thought. (Not die as in death, die as in one die, two dice).
I have previously used it for many things, like sending messages before a boss spawns, or for other times when I want to send a message to the player and I did not have access to a player variable, exempli gratia when using AddItem movement events.
So here's some generally applicable knowledge; use the die.lua code whenever you need players or any other creature to say shit. It's great.
And as I said initially, it can also be used to fix annoying problems with loot channels.
Lua:
local spectators = Game.getSpectators(position, false, true, 3, 3)
for _, spectator in ipairs(spectators) do
player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, spectator, position)
end
Replace all the random stuff, like getName() and the stuff necessary to send the die message, and replace it with whatever you want. Then you can change the range to whatever you see fit.
If you want to use it like I did, with the loot channel, just use:
Lua:
function onSpeak(player, type, message)
player:say(message, TALKTYPE_SAY)
return
end
See? It's easy to use and can be used for so much.
You can also combine it with addEvent() to make an obnoxious advertising sign.
One clever thing about this code is that a creature is necessary to send the message. It's like with the falling tree in the forest. Does it make a sound if nobody hears it? The answer is: maybe, but it doesn't really matter if it does unless somebody hears it. So this brilliant functions inevitably works like that; it is impossible to send a message unless somebody is there to hear it, because you cannot send a message unless you have somebody to send the message. That somebody should be the one who receives the message.
Awesome...