• 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 Scripting Problem

ramsaii

New Member
Joined
Mar 1, 2008
Messages
5
Reaction score
0
I'm having a problem in a script I have written. It allows you to cut down trees, and then transforms the tree into a brough. I want the tree to respawn after a set amount of time, however I'm having a problem with my addEvent function. I am pretty sure I am using it correctly:
Code:
function onUse(cid, item, frompos, item2, topos)
  	if item2.itemid == 2707 or item2.itemid == 2708 or item2.itemid == 2701 or item2.itemid == 2702 or item2.itemid == 2703 or item2.itemid == 2706 then
		axeskill = getPlayerSkill(cid,3)
		formula = axeskill /200+0.85* math.random()
playerPos = getCreaturePosition(cid)

		
		
		if formula > 0.70 then
			doSendMagicEffect(topos,3)	
			doPlayerAddItem(cid,5901,1)
			doPlayerAddSkillTry(cid,3,2)
			doPlayerSendTextMessage(cid,22,"You have successfully chopped down the tree!")
		
		elseif formula < 0.30 then
			addEvent(onTime,1000,a)
			doTransformItem(item2.uid,2770)
		      doDecayItem(item2.uid)
			doSendMagicEffect(topos,2)
			doPlayerSendTextMessage(cid,22,"You destroyed the tree!")
			doPlayerAddSkillTry(cid,3,1)
			

		
		else
			doSendMagicEffect(topos,2)
			doPlayerAddSkillTry(cid,3,1)
			doPlayerSendTextMessage(cid,22,"You failed at chopping down the tree.")

		end
	end
		
	
	treeDecay = math.random()
	if treeDecay < 0.90 then
		doDecayItem(item2.uid)
	end

end

function onTime(a)
doPlayerSendTextMessage(cid,22,"Got here.")

end

Ok, for some reason it doesn't call the onTime function at all, so "Got here." never gets displayed over my characters head. I know some code is unnecessary, I just haven't cleaned it up yet. What am I doing wrong? Thanks in advance for all input.
 
Last edited by a moderator:
In this case, it's waste to use addEvent, just go to items.xml and change the decay time for the tree, and use doDecayItem(item2.uid)
 
Colandus, that worked exactly how I needed it to.. I didn't know there was a decayTo tag for item.xml =\ I guess the answer is simple sometimes =).

Thanks for all the help
 
Quick question, though, why does it not call the addEvent function sometimes. I've had another script that uses it mysteriously stop working. No changes to it whatsoever. The function is just sometimes ignored.

In other words, why doesn't this work...

if condition then
doCreateItem(409,1,teleportPosition)
addEvent(onTime,10000,cid)
end

function onTime(cid)
code
end

It never does the onTime function, why not?
 
Last edited:
Well, actually it was kind of strange. Usually I place the event function directly before the main function. I've tried it on the top and bottom of the main function (not like it should matter), but I've made sure that the previous function is closed before I start the new one. I changed the name of the function from onTime to timer, and that worked... =\ Do all of the event functions have to be different? I don't see why they would, since they run locally, but maybe that was it?
 
Back
Top