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

Lua Help with little modification on script

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
Hello,

I have this AFK system, and I would like it to remove afk status if player moves.

In the original script there was a "doCreatureSetNoMove(cid, true)" when player uses !afk on, but that opens breaches to trap and stuff

Here's my script now, I've removed SetNoMove, but I need to remove AFK status if player walks:

talkactions/afk.lua
LUA:
local time = 3 -- Seconds
local say_events = {}
local function SayText(cid)
    if isPlayer(cid) == TRUE then
         if say_events[getPlayerGUID(cid)] ~= nil then
             if isPlayer(cid) == TRUE then
                 doSendAnimatedText(getPlayerPosition(cid),"AFK", math.random(01,255))
             end
             say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000 / 2, cid)       
         end                                                       
    end
    return TRUE
end
 
local storage = 38417
function onSay(cid, words, param, channel)
local afkCheck = getPlayerStorageValue(cid, storage)
    if(param == "") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
    return TRUE
    end
     if (param == "on") then
        if (afkCheck == -1) then
            if (isPlayer(cid) == TRUE) then
                doSendAnimatedText(getPlayerPosition(cid),"AFK", math.random(01,255))
            end
            say_events[getPlayerGUID(cid)] = addEvent(SayText, time * 1000, cid)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You are now AFK.")
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already AFK.")
        end
     elseif (param == "off") then
        stopEvent(say_events[getPlayerGUID(cid)])
        say_events[getPlayerGUID(cid)] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Welcome Back!")
        setPlayerStorageValue(cid, storage, -1)
    end
    return TRUE
end

creaturescripts/afk.lua
LUA:
function onLogout(cid)
	if getPlayerStorageValue(cid, 38417) > 0 then
		setPlayerStorageValue(cid, 38417, -1)
	end
return TRUE
end

Any suggestions?

Thanks!
 
Actually I've tried to mod creaturescripts/afk.lua like this

LUA:
function onLogout(cid)
	if getPlayerStorageValue(cid, 38417) > 0 then
		setPlayerStorageValue(cid, 38417, -1)
	end
function onMove(cid)
	if getPlayerStorageValue(cid, 38417) > 0 then
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Welcome Back!")
		setPlayerStorageValue(cid, 38417, -1)
	end
return TRUE
end

But didn't work, and I'm afraid of messing with this kind of stuff 'cause I don't want to lag the server, what if when anyone moves it checks if player is afk and stuff, it would lag a lot lolz

My request is simple in fact, there must be an easy to do this but I still don't have the knowledge :s

hoping you guys can help
 
You didnt understand me...
doMoveCreature is a function....
so on !afk script, when it's on, you put something like this:
if doMoveCreature(cid, direction) then
turn off afk mode
xDDDD
Something like that on the script xD
 
lib/050-function.lua
LUA:
say_events = {} -- DON'T TOUCH
timeSayText = 3

function sayText(cid)
	local storage = 85968

	if isPlayer(cid) then
		if say_events[getPlayerGUID(cid)] ~= nil then
			if getPlayerStorageValue(cid, storage) > 0 then
				doSendAnimatedText(getThingPos(cid), 'AFK', math.random(255))			
				say_events[getPlayerGUID(cid)] = addEvent(sayText, timeSayText * 1000 / 2, cid)
			end
		end													   
	end
	return true
end

talkactions/afk.lua
LUA:
local storage = 85968
 
function onSay(cid, words, param, channel)
	local afkCheck, pos = getPlayerStorageValue(cid, storage), getThingPos(cid)
 
	if param == '' then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Command param required.')
		return true
	elseif param:lower() == 'on' then
		if afkCheck < 0 then
			doSendAnimatedText(pos, 'AFK', math.random(255))
			say_events[getPlayerGUID(cid)] = addEvent(sayText, timeSayText * 1000, cid)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You are now AFK.')
			setPlayerStorageValue(cid, storage, 1) 
				setPlayerStorageValue(cid, storage + 1, pos.x)
				setPlayerStorageValue(cid, storage + 2, pos.y)
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You are already AFK.')
		end
	elseif param:lower() == 'off' then
		if afkCheck > 0 then
			stopEvent(say_events[getPlayerGUID(cid)])
			say_events[getPlayerGUID(cid)] = nil
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'Welcome Back!')
			setPlayerStorageValue(cid, storage, -1)
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You are not AFK.')
		end
	end
	return true
end

creaturescripts/afk.lua
LUA:
local storage = 85968
 
function onLogout(cid)
	if getPlayerStorageValue(cid, storage) > 0 then
		setPlayerStorageValue(cid, storage, -1)
	end
	return true
end

function onThink(cid, interval)
	if isPlayer(cid) then	
		if getPlayerStorageValue(cid, storage) > 0 then
			local playerPos = getThingPos(cid)	
			
			if getPlayerStorageValue(cid, storage + 1) ~= playerPos.x or getPlayerStorageValue(cid, storage + 2) ~= playerPos.y then
				stopEvent(say_events[getPlayerGUID(cid)])
				say_events[getPlayerGUID(cid)] = nil
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'Welcome Back!')
				setPlayerStorageValue(cid, storage, -1)
			end
		end
	end
	return true
end







Remember about register onThink and onLogout functions.
 
Last edited:
So, Virrage, I had some issues

First, "attempt to perform arithmetic on global 'time' <a nil value>"

So I've added "local time = 3" to the script

Then: "attempt to index global 'say_events' <a nil value>"

So I've added "local say_events, pPosition = {}, {x = 0, y = 0}" to the script

It eventually works, but does not turn off when walks and stuff... I've added those functions to 050-functions.lua but it didn't recognize, so I've had, as you see, to add it to the script itself

Remember about register onThink and onLogout functions.

login.lua -> registerCreatureEvent(cid, "Afk")

creaturescripts.xml
LUA:
	<event type="logout" name="Afk" event="script" value="afk.lua"/>
	<event type="think" name="Afk" event="script" value="afk.lua"/>

Like this, eh?
 
i know u will get the same errors.... cause they are from the script, not from the .xml..... xD

lol..... i thought a second was 1000 units of time of the server.... but his mathematical operation was time * 1000 / 2
 
Back
Top