Hello,
If the timer start the code then cs2d close without error's
1
timer (5000, "PLAYERS[id].tmp.atk = PLAYERS[id].tmp.atk - 5")
Admin/mod comment
Fixed the title slightly. /Engi Do you really think that we can do anything by only looking at one line of a script that has more than a thousand lines in it? It's the Tibia Script by Weiwen -.-
and when i delete the 2 " then come this error:
1
LUA ERROR: sys/lua/cs2dtibia/items.lua:90: ')' expected near '='
I don't what are you trying to say... but I think that you can fix the error by removing the space between the function name and the brackets. 1
timer (5000,"lua", "PLAYERS[".. id.."].tmp.atk = PLAYERS[".. id.."].tmp.atk - 5")
Have fun^_^ edited 1×, last 14.04.14 07:34:44 pm
timer (5000, "decreaseattack", id)
function decreaseattack (id)
	PLAYERS[id].tmp.atk = PLAYERS[id].tmp.atk - 5
end
or
timer (5000, "parse", "lua \"PLAYERS[" .. id .. "].tmp.atk = PLAYERS[" .. id .. "].tmp.atk - 5\"")
From the forum title above, i thought cs2d was close or cs2d tibia was close. Change title... XoOt Super User Offline
@ RisingXD:
I just knew the problem of that topic by just reading the title, so whats the matter aboit it.
Ontopic - this is what happens when you try to make another bad tibia edit. cozen's script only works if 'id' is a string. It won't work when id is a number, in which case you will have to make it a string. @ Torque: It's completely not true. DC's function read both number and string which case you can call something without changing the number's type to string. Just test this.
test = {}
test[1] = 0
test[2] = 1
timer (0, "parse", "lua \"test[" .. (1) .. "] = test[" .. (2) .. "]\"")
for key, value in ipairs (test) do
	print ("test[" .. key .. "] = " .. value)
end
Just a little note, it would be a lot easier if you didn't use any spaces in a timer so you don't have to use \"<stuff>\" all the time.. EDIT: This info was false sorry for almost misinforming you.
Cozen in your example you are still passing a string parameter to the function parse. If you don't pass a string parameter "p" it will get recognised as the count value c. As described in the info.
info.txt has written
[Timer]
- timer(time,"func",["p"],[c]) Create a timer which will call the Lua function "func" after a
certain time in milliseconds (time).
Moreover it can pass a string parameter (p) to this function.
The timer calls the function once by default. However you can call
it several times by entering a count value (c). Using 0 or lower
count values will make the timer call the function infinite times.
I was trying to possibly save you guys some time because just a few days ago I did this wrong myself. edited 1×, last 16.04.14 01:29:09 pm
Admin/mod comment
Removed more-tag. /DC Dousea has written
@
Torque: It's completely not true.
DC's function read both number and string...
I think you misunderstood Torque's point - your first script would have to have a tonumber() conversion in the decreaseattack() function, since PLAYERS[id] requires id to be a number. The second script should work as-is. @ Torque: Maybe i don't understand you correctly but LUA insert the arguments in order.
1
2
3
4
5
6
function someexample(id)
	id=tonumber(id)	-- Number-To-String conversion caused by timer
	msg2(id,"Hi!")
end
timer(5000,"someexample",id)
Code above would call function someexample with parameter(first argument) is id(some player ID). But in function someexample, id is string. So just simple, Dousea code would work fine with(out) error (because the number-to-string conversion).
And one more note: it would never jump to count parameter.
You can try it if you still doesn't believe. @ Torque, @ EngiN33R: Just try this, this function works perfectly without any "string-to-number" conversion.
1
2
3
4
5
6
7
8
9
addhook ("join", "joinhook")
function joinhook (id)
	timer (5000, "sayhello", id)
	
	function sayhello (id)
		msg2 (id, "Hello, " .. player (id, "name"))
	end
end
Ah you guys are right and I was wrong. What caused my confusion was that 'p' gets passed as a string. If you are under the assumption that you are going to receive a number (like I was) that can cause problems.
I think... I'm not sure about anything now anymore Dousea has written
@
Torque, @
EngiN33R: Just try this, this function works perfectly without any "string-to-number" conversion.
Well yes, this one does because msg2 is a built-in CS2D function, and they treat strings and numbers for IDs equally. I suggest you try this:
1
2
3
4
5
6
7
8
9
10
11
12
tbltest = {1,2,3}
print("Table value "..tbltest[1].." at index 1") -- Output: Table value 1 at index 1
function testfunc(a)
	tbltest[a] = 0
end
timer(1000, "testfunc", 1)
print("Table value "..tbltest[1].." at index 1") -- Output: Table value 1 at index 1
print("Table value "..tbltest["1"].." at index '1'") -- Output: Table value 0 at index '1'
@ EngiN33R: Seems yours have an error there. Can't call tbltest["1"] and causing this:
attempt to concatenate field '1' (a nil value)
But you're right, the value of tbltest[1] still 1. I tested my own by checking the type of "index".
function checktype (index)
	print (type (index)) -- Print: "string"
end
timer (1000, "checktype", 1)