• 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 in Channels

Syntax

Developer
Joined
Oct 10, 2007
Messages
2,890
Reaction score
458
Location
Texas
Somehow I need to broadcast to all players in X channel, just that channel, not default or others...
 
This function works for the newer distros.

Lua:
doPlayerSendChannelMessage(cid, AuthorName, message, talktype, channelNumber) -- example 4 = gamachat

If you have an older version paste this into your sources.

In Luascript.cpp
Code:
//doPlayerSendChannelMessage(cid, author, message, SpeakClasses, channel)
	lua_register(m_luaState, "doPlayerSendChannelMessage", LuaScriptInterface::luaDoPlayerSendChannelMessage);
Code:
int32_t LuaScriptInterface::luaDoPlayerSendChannelMessage(lua_State* L)
{
	//doPlayerSendChannelMessage(cid, author, message, SpeakClasses, channel)
	uint16_t channelId = popNumber(L);
	uint32_t speakClass = popNumber(L);
	std::string text = popString(L), name = popString(L);

	ScriptEnviroment* env = getScriptEnv();
	Player* player = env->getPlayerByUID(popNumber(L));
	if(!player)
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushboolean(L, LUA_ERROR);
		return 1;
	}

	player->sendChannelMessage(name, text, (SpeakClasses)speakClass, channelId);
	lua_pushboolean(L, LUA_NO_ERROR);
	return 1;
}

Luascript.h
Code:
static int32_t luaDoPlayerSendChannelMessage(lua_State* L);

kind regards, Evil Hero
 
Last edited:
Channels:
Code:
CHANNEL_GUILD = 0
CHANNEL_STAFF = 1
CHANNEL_COUNSELOR = 2
CHANNEL_RVR = 3
CHANNEL_GAMECHAT = 4
CHANNEL_TRADE = 5
CHANNEL_RLCHAT = 6
CHANNEL_TRADEROOK = 7
CHANNEL_PARTY = 8
CHANNEL_HELP = 9
Talktypes:
Code:
TALKTYPE_SAY = 1
TALKTYPE_WHISPER = 2
TALKTYPE_YELL = 3
TALKTYPE_PRIVATE_PN = 4
TALKTYPE_PRIVATE_NP = 5
TALKTYPE_PRIVATE = 6
TALKTYPE_CHANNEL_Y = 7
TALKTYPE_CHANNEL_W = 8
TALKTYPE_RVR_CHANNEL = 9
TALKTYPE_RVR_ANSWER = 10
TALKTYPE_RVR_CONTINUE = 11
TALKTYPE_BROADCAST = 12
TALKTYPE_CHANNEL_R1 = 13
TALKTYPE_PRIVATE_RED = 14
TALKTYPE_CHANNEL_O = 15
TALKTYPE_CHANNEL_R2 = 17
TALKTYPE_ORANGE_1 = 19
TALKTYPE_ORANGE_2 = 20
Example:
Code:
doPlayerSendChannelMessage(cid, AuthorName, "Hello World", TALKTYPE_CHANNEL_Y, CHANNEL_GAMECHAT)
 
It broadcasts in the channel, so this works fine for me, probably use another talktype that might solve your problem.
 
Use a loop to broadcast in all channels to all players online: Example:

Lua:
local players = getPlayersOnline()
for k, v in ipairs(players) do
doPlayerSendChannelMessage(pid, AuthorName, "Hello World", TALKTYPE_CHANNEL_Y, CHANNEL_GAMECHAT)
end
 
thankyou Pitufo, I was thinking of somehow doing that but I couldn't think of a way. I'll try that. Ill rep you if works
[21/06/2009 20:36:00] luaDoPlayerSendChannelMessage(). Player not found

[21/06/2009 20:36:00] Lua Script Error: [CreatureScript Interface]
[21/06/2009 20:36:00] data/creaturescripts/scripts/deathBroadcast.lua:eek:nDeath

Script:

Lua:
  local config = {
        killStorageValue = 3943,
        deathStorageValue = 3944,

        -- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
        rewardItem = {
                use = false,
                itemid = 8698,
                minLevel = 100, -- false if you don't want any level req
                minLevelDiff = 20, -- false if you don't want any level diff req (negative numbers allowed).
                text = "This is a gift to |KILLERNAME| [|KILLERLEVEL|] for killing |TARGETNAME| [|TARGETLEVEL|]"
        },
       
        killMessage = {
                use = false,
                text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
                messageClass = MESSAGE_STATUS_CONSOLE_BLUE
        },
       
        broadcastMessage = {
                use = true,
                minLevel = false, -- false if you don't want any level req
                minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
                text = "|KILLERNAME| [|KILLERLEVEL|] killed |TARGETNAME| [|TARGETLEVEL|]!",
                messageClass = MESSAGE_STATUS_CONSOLE_ORANGE			
        },
       
        killerAnimation = {
                use = true,
                text = "Frag!", -- Only 9 letters! No "commands" here.
                color = 215
        },
       
        targetAnimation = {
                use = true,
                text = "Owned!", -- Only 9 letters! No "commands" here.
                color = 215
        }
}

function onDeath(cid, corpse, killer)
        if(isPlayer(killer) == TRUE) then
                local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
                local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
               
                local killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
                local killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
               
                setPlayerStorageValue(killer, config.killStorageValue, targetKills)
                setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)

                local killerLevel = getPlayerLevel(killer)
                local targetLevel = getPlayerLevel(cid)
                local levelDiff = targetLevel - killerLevel

                local values = {
                        ["KILLERKILLS"]         = killerKills,
                        ["KILLERDEATHS"]        = killerDeaths,
                        ["KILLERNAME"]          = getCreatureName(killer),
                        ["KILLERLEVEL"]         = killerLevel,
                       
                        ["TARGETKILLS"]         = targetKills,
                        ["TARGETDEATHS"]        = targetDeaths,
                        ["TARGETNAME"]          = getCreatureName(cid),
                        ["TARGETLEVEL"]         = targetLevel
                }

                function formateString(str)
                        return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
                end
               
                if(config.rewardItem.use and (not config.rewardItem.minLevel or targetLevel >= config.rewardItem.minLevel) and (not config.rewardItem.minLevelDiff or levelDiff >= config.rewardItem.minLevelDiff)) then
                        local uid = doPlayerAddItem(killer, config.rewardItem.itemid, 1)
                        doSetItemSpecialDescription(uid, formateString(config.rewardItem.text))
                end
                if(config.killMessage.use) then
                        doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
                end
                if(config.broadcastMessage.use and (not config.broadcastMessage.minLevel or getPlayerLevel(cid) >= config.broadcastMessage.minLevel) and (not config.broadcastMessage.minLevelDiff or levelDiff >= config.broadcastMessage.minLevelDiff)) then
                        broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
						  local players = getPlayersOnline()
							for k, v in ipairs(players) do
						doPlayerSendChannelMessage(pid, "Notice", formateString(config.broadcastMessage.text), 7, 7)
					end						
                end
                if(config.killerAnimation.use) then
                        doSendAnimatedText(getCreaturePosition(killer), config.killerAnimation.text, config.killerAnimation.color)
                end
                if(config.targetAnimation.use) then
                        doSendAnimatedText(getCreaturePosition(cid), config.targetAnimation.text, config.targetAnimation.color)
                end
        end
       
        return TRUE
end
 
Last edited:
Lol i was wrong in one part, here you go:

Lua:
  local config = {
        killStorageValue = 3943,
        deathStorageValue = 3944,

        -- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
        rewardItem = {
                use = false,
                itemid = 8698,
                minLevel = 100, -- false if you don't want any level req
                minLevelDiff = 20, -- false if you don't want any level diff req (negative numbers allowed).
                text = "This is a gift to |KILLERNAME| [|KILLERLEVEL|] for killing |TARGETNAME| [|TARGETLEVEL|]"
        },
       
        killMessage = {
                use = false,
                text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
                messageClass = MESSAGE_STATUS_CONSOLE_BLUE
        },
       
        broadcastMessage = {
                use = true,
                minLevel = false, -- false if you don't want any level req
                minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
                text = "|KILLERNAME| [|KILLERLEVEL|] killed |TARGETNAME| [|TARGETLEVEL|]!",
                messageClass = MESSAGE_STATUS_CONSOLE_ORANGE                   
        },
       
        killerAnimation = {
                use = true,
                text = "Frag!", -- Only 9 letters! No "commands" here.
                color = 215
        },
       
        targetAnimation = {
                use = true,
                text = "Owned!", -- Only 9 letters! No "commands" here.
                color = 215
        }
}

function onDeath(cid, corpse, killer)
        if(isPlayer(killer) == TRUE) then
                local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
                local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
               
                local killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
                local killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
               
                setPlayerStorageValue(killer, config.killStorageValue, targetKills)
                setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)

                local killerLevel = getPlayerLevel(killer)
                local targetLevel = getPlayerLevel(cid)
                local levelDiff = targetLevel - killerLevel

                local values = {
                        ["KILLERKILLS"]         = killerKills,
                        ["KILLERDEATHS"]        = killerDeaths,
                        ["KILLERNAME"]          = getCreatureName(killer),
                        ["KILLERLEVEL"]         = killerLevel,
                       
                        ["TARGETKILLS"]         = targetKills,
                        ["TARGETDEATHS"]        = targetDeaths,
                        ["TARGETNAME"]          = getCreatureName(cid),
                        ["TARGETLEVEL"]         = targetLevel
                }

                function formateString(str)
                        return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
                end
               
                if(config.rewardItem.use and (not config.rewardItem.minLevel or targetLevel >= config.rewardItem.minLevel) and (not config.rewardItem.minLevelDiff or levelDiff >= config.rewardItem.minLevelDiff)) then
                        local uid = doPlayerAddItem(killer, config.rewardItem.itemid, 1)
                        doSetItemSpecialDescription(uid, formateString(config.rewardItem.text))
                end
                if(config.killMessage.use) then
                        doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
                end
                if(config.broadcastMessage.use and (not config.broadcastMessage.minLevel or getPlayerLevel(cid) >= config.broadcastMessage.minLevel) and (not config.broadcastMessage.minLevelDiff or levelDiff >= config.broadcastMessage.minLevelDiff)) then
                        broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
                                                  local players = getPlayersOnline()
                                                        for k, v in ipairs(players) do
                                                doPlayerSendChannelMessage(v, "Notice", formateString(config.broadcastMessage.text), 7, 7)
                                        end                                            
                end
                if(config.killerAnimation.use) then
                        doSendAnimatedText(getCreaturePosition(killer), config.killerAnimation.text, config.killerAnimation.color)
                end
                if(config.targetAnimation.use) then
                        doSendAnimatedText(getCreaturePosition(cid), config.targetAnimation.text, config.targetAnimation.color)
                end
        end
       
        return TRUE
end
 
Lua:
local players = getPlayersOnline()
	for _, pid in ipairs(players) do
	doPlayerSendChannelMessage(pid, "OtLand", "Visit otland.net", TALKTYPE_CHANNEL_W, CHANNEL_TRADE)
	end
 
Back
Top