• 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!

Broadcast message when using an item

haiguri

New Member
Joined
Jun 25, 2012
Messages
18
Reaction score
0
Hi guys, I tried to do a script that whenever a play uses a certain item, the item will be removed and he will be able to send a broadcast message just like a GM.

Can someone help me out with that script? Thanks a lot!
 
No idea if this will work:
Code:
local config = {
msg = "your message",
id = 9999 --your item id.
}

function onUse
    broadcastMessage(config.msg, TALKTYPE_BROADCAST)
    doRemoveItem(config.id)
end

NOTE: Since you failed to provide us with the server information I have used TFS 1.0 functions so if you use 0.4/0.3.x it will not work.
 
What did you had in mind about how people should write their message?
You can do something like this, use a writeable item and then people can write their message on this item, then it will broadcast this message and the item will be removed.

creaturescripts.xml
Code:
<event type="textedit" name="Broadcast" event="script" value="broadcast.lua"/>

login.lua
Code:
registerCreatureEvent(cid, "Broadcast")

broadcast.lua
Code:
function onTextEdit(cid, item, newText)
     if item.itemid == 1951 then
         doBroadcastMessage(getPlayerName(cid)..": "..newText)
         doRemoveItem(item.uid, 1)
     end
     return true
end
 
function onUse should have () (every function should have that) and add the parameters incase people need them.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

The function doRemoveItem works with uid, so you can use item.uid to remove the item people use, or to remove an item from a player: doPlayerRemoveItem(cid, itemid, count)
For the broadcast function use the message types that start with MESSAGE_, like with doPlayerSendTextMessage.
And you forgot return true (above end).
 
Last edited:
Thanks a lot Limos, I got a bit confused to explain what I really wanted.

I was actually looking for a script like a /b message, but for players and using an item when the player sends the message.

Example: !message Hello everyone

And then the item would be removed. But your script is just working fine, thanks then :)
 
Back
Top