josejunior23
read&read&read
### 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: