• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction News system

josejunior23

read&read&read
Joined
Apr 13, 2008
Messages
760
Solutions
3
Reaction score
90
Location
Portugal
### NEWS SYSTEM ###​

credits: josejunior23
ps: tested with 0.3.4PL2
-------------------

first, make a file:
news.txt and move it.
(where's config.lua)

-------------------


-------------------
to add news, just type:
/addnews Welcome to |SERVERNAME|, have fun!.

read news:
/news

auto-broadcast news:
add news, and it will broad cast
your news to online players.
-------------------



ADD NEWS

talkactions.xml

PHP:
	<talkaction log="yes" words="/addnews" access="3" event="script" value="addnews.lua"/>

addnews.lua

Lua:
function onSay(cid, words, param, channel)
    if(param == "") then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
		return TRUE
    end

	local file = io.open("news.txt", "w+")
	file:write("\n    ### SERVER NEWS ###\n - ".. os.date("%d / %B / %Y - %X ", os.time()) .."-\n\n--> "..param.."\n\n### POSTED BY " .. getPlayerName(cid) .." ###\n") 
	file:close()
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "NEWS ADDED!\n ".. param .."")
	return TRUE
end

READ NEWS


talkactions.xml

PHP:
	<talkaction log="no" words="/news" event="script" value="news.lua"/>

news.lua

Lua:
function onSay(cid, words, param, channel)
    local file = io.open('news.txt','r')
    doPlayerSendTextMessage(cid, TALKTYPE_BROADCAST, file:read(-1))
	file:close()	
    return TRUE
end

AUTO-BROADCAST NEWS

globalevents.xml

PHP:
	<globalevent name="news" interval="4000" event="script" value="autonews.lua"/>

autonews.lua

Lua:
function onThink(interval, lastExecution)
    local file = io.open('news.txt','r')
    for _, name in ipairs(getOnlinePlayers()) do
	    local player = getPlayerByName(name)
        doPlayerSendTextMessage(player, TALKTYPE_BROADCAST, file:read(-1))
    end
	file:close()
    return TRUE
end
 
Last edited:
I can't get this to work. It doesn't write anything to the file :s
 
Nice work,
great idea...
:thumbup:
 
Well nice done. I wanted to make a similar script and searched the function io.open, because I lost the name xD.

But I am a bit disappointed.

How can I do that if I write: /addnews Hi\nWelcome Guys
The \n isn't written and does a new line.
 
[Warning - TalkAction::configureEvent] Duplicate registered talkaction with words: /addnews
[Warning - TalkAction::configureEvent] Duplicate registered talkaction with words: /news

://////////////////////////
 
Back
Top