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

GarQet

Own3d!
Joined
Feb 10, 2009
Messages
1,381
Solutions
14
Reaction score
81
Hello, I don't know what's wrong with my script and why tfs spits by errors.

So, I have this script:
Lua:
local c = {
	p = 1234
}
function onSay(cid, words, param, channel)
	while (getPlayerStorageValue(cid, c.p) == 1) do
		addEvent(g, cid)
	end
	return true
end

function g(cid)
	doPlayerSendTextMessage(cid, 4, "".. getCreaturePosition(cid) .."")
	return true
end
Error:
[21:0:00.436] [Error - TalkAction Interface]
[21:0:00.436] In a timer event called from:
[21:0:00.436] data/talkactions/scripts/test.lua:eek:nSay
[21:0:00.436] Description:
[21:0:00.436] data/talkactions/scripts/test.lua:9: attempt to concatenate a table value
[21:0:00.436] stack traceback:
[21:0:00.436] data/talkactions/scripts/test.lua:9: in function <data/talkactions/scripts/test.lua:8>

What's wrong?
 
Last edited:
'c' is nil.
Bad idea to do it like that btw, it'll keep spamming forever addEvent. ......

Yes, 'c' is nil, but it doesn't metter cause error applies to something else.
I'm trying to do something like this:
Lua:
local c = {
	p = 1234
}

function onSay(cid, words, param, channel)
	while (getPlayerStorageValue(cid, c.p) == 1) do
		local player = {cid = cid}
		addEvent(g, player)
	end
	return true
end

function g(player)
	doPlayerSendTextMessage(player.cid, 4, "".. getCreaturePosition(player.cid) .."")
	return true
end
But i receive the same error as before...
Can someone help me?

Btw. I want to spam forever my addEvent.
 
Well...

1º Why you use "c" if you simple can use:
p = 1234

2º In the main post's script, this is bad:
addEvent(g, cid)

cause addEvents needs to be managed like this:
addEvent(functionname, callbacktime, parameters spaced by ",")

so it should be like:
addEvent(g, 1000, cid)

3º Here the script:
Lua:
local storage = 1234

local function g(cid)
doPlayerSendTextMessage(cid, 4, "" .. getCreaturePosition(cid) .. "")
addEvent(g, 1000, cid)
return true
end

function onSay(cid, words, param, channel)
if getPlayerStorageValue(cid, storage) == 1 then
addEvent(g, 1000, 1)
end
return true
end

Hope it works....

I though you wanted this:
If player say something, and he has storage 1234 == 1, then spam forever his position xD
 
Okay, let me teach you..

getCreaturePosition(cid) will return a TABLE, and inside that table is x, y, z, stackpos.
you can't just call a table and expect it to output the information the way you want it.

Secondly, there is no need to use an addEvent, addEvents are to add delays on the function you are executing.

Thirdly, the storage number c.p can't be used. because c.p also states a TABLE and you have no set variables in the script.
(I am assuming you have no variables/tables set in libs/)

Anyway, change INSERT_STORAGE_HERE to a number that isn't being used on your server as a storage value, and it should work the way you want it.

Lua:
function onSay(cid, words, param, channel)
	if (getPlayerStorageValue(cid, INSERT_STORAGE_HERE) == 1) then
		doPlayerSendTextMessage(cid, 4, "{ x = " .. getCreaturePosition(cid).x .. ", y = " .. getCreaturePosition(cid).y .. ", z = " .. getCreaturePosition(cid).z .. " }")
	end
	return true
end

EDIT: @UP read what i said about getCreaturePosition()
 
@up: he is defining a value on the table, which is "p", and the table is local.... the script will not return the value like x=, y=, z=, but it will return it from another form....

And addEvent and other function is to spam it forever... ;)
 
Aff, I forgot about callbacktime...
Thanks for answers and your time.
All got repute.
Btw. I can use table c.p, It'll works.

Topic to close.
 
Ahh, I missed the local table c.p, because you editted your original post.

But you are wrong. the reason WHY it is returning the error is because getCreaturePosition() returns a table.

Yes, it will loop the addEvent function over and over again, but there is no reason for an addEvent function unless he wants the position of the player to be shown after x seconds.

You must concatenate to piece the string into the format which he requires.
 
Oh! I missed something...

With that spam forever, if you have it activated and you logout, you will get errors... So you have to define both addEvents like a global variable...

checkPos = addEvent(blabla)

checkPos = addEven(blabla)

And make an onLogout script that have this:

stopEvent(checkPos)

xD
 
Back
Top