• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[NPC] Tutor announcement

Grehy

Killroy
Joined
Nov 21, 2008
Messages
2,631
Reaction score
33
Location
United States
I have a script so far, it broadcasts the message, it just can't get the playername to be broadcasted in it. Can someone fix it for me please?

Code:
focus = 1
talk_start = 1
target = 1
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and getPlayerAccess(cid) == 1) then
  		selfSay('Hello, |PLAYERNAME|. Do you want to broadcast that your online?')
  		focus = cid
  		talk_start = os.clock()


	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'stop saying this idiot') then
                                          selfSay('Why I oughta....')
                           elseif msgcontains(msg, 'yes') then
                                          doBroadcastMessage("Our tutor |NAME| is online!",22)
                                          
                           elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
			selfSay('Whatever Man.')
			focus = 0
			talk_start = 0
		end
	end
end


function onCreatureChangeOutfit(creature)

end


if focus == 0 then 
cx, cy, cz = selfGetPosition() 
randmove = math.random(1,25) 
if randmove == 1 then 
nx = cx + 1 
end 
if randmove == 2 then 
nx = cx - 1 
end 
if randmove == 3 then 
ny = cy + 1 
end 
if randmove == 4 then 
ny = cy - 1 
end 
if randmove >= 5 then 
nx = cx 
ny = cy 
end 
moveToPosition(nx, ny, cz) 
--summons = 30 
--summons2 = 30 
end 
if focus == 0 then 
randsay = math.random(1,75) 
if randsay == 1 then 
selfSay('Gonna break me...') 
end 
if randsay == 2 then 
selfSay('The staff here sometimes jeez.') 
end 
end
 
Try this one.. i've changed the |NAME| to |PLAYERNAME|
PHP:
focus = 1
talk_start = 1
target = 1
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and getPlayerAccess(cid) == 1) then
  		selfSay('Hello, |PLAYERNAME|. Do you want to broadcast that your online?')
  		focus = cid
  		talk_start = os.clock()


	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'stop saying this idiot') then
                                          selfSay('Why I oughta....')
                           elseif msgcontains(msg, 'yes') then
                                          doBroadcastMessage("Our tutor |PLAYERNAME| is online!",22)
                                          
                           elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
			selfSay('Whatever Man.')
			focus = 0
			talk_start = 0
		end
	end
end


function onCreatureChangeOutfit(creature)

end


if focus == 0 then 
cx, cy, cz = selfGetPosition() 
randmove = math.random(1,25) 
if randmove == 1 then 
nx = cx + 1 
end 
if randmove == 2 then 
nx = cx - 1 
end 
if randmove == 3 then 
ny = cy + 1 
end 
if randmove == 4 then 
ny = cy - 1 
end 
if randmove >= 5 then 
nx = cx 
ny = cy 
end 
moveToPosition(nx, ny, cz) 
--summons = 30 
--summons2 = 30 
end 
if focus == 0 then 
randsay = math.random(1,75) 
if randsay == 1 then 
selfSay('Gonna break me...') 
end 
if randsay == 2 then 
selfSay('The staff here sometimes jeez.') 
end 
end


Edit: He said on msn mine doesnt work :P
 
Last edited:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                    npcHandler:onThink()                    end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    -- 1 = player, 2 = tutor, 3 = Senior Tutor, 4 = Gamemaster, 5 = Community Manager, 6 = GOD
    if msgcontains(msg, 'yes') and getPlayerAccess(cid) == 2 then          
        doBroadcastMessage("NPC: Our tutor ".. getPlayerName(cid) .." is online!", MESSAGE_STATUS_WARNING)
    else
	npcHandler:say('Only tutors can broad-cast!', cid) 
    end
   return TRUE
end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

PHP:
<npc name="Caster" script="data/npc/scripts/caster.lua" walkinterval="2000" floorchange="0" access="3">
	<health now="150" max="150"/>
	<look type="57" head="115" body="113" legs="31" feet="38" addons="0" corpse="2212"/>
		<parameters>
		<parameter key="message_greet" value="Hello, |PLAYERNAME|. Do you want to broadcast that your online?" />
	</parameters>
</npc>


// tested with TFS 0.3.3

@down u welcome (:
 
Last edited:
LUA:
local delayminutes = 1 -- your minutes here 1 = 1 minute.
local broadcastmessage = 'Your message here that will be broadcasted.'

local timer = os.time ( )
function onThink()

	if ( ( os.time ( ) - timer ) > delayminutes * 60 ) then
		broadcastMessage ( broadcastmessage, 19 )
		timer = os.time ( )
	end
end

Not by me.
 
LUA:
local delayminutes = 1 -- your minutes here 1 = 1 minute.
local broadcastmessage = 'Your message here that will be broadcasted.'

local timer = os.time ( )
function onThink()

	if ( ( os.time ( ) - timer ) > delayminutes * 60 ) then
		broadcastMessage ( broadcastmessage, 19 )
		timer = os.time ( )
	end
end

Not by me.

Read the thread before posting, thanks.
 

Similar threads

  • Question Question
Replies
0
Views
183
Back
Top