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

Teleport Rune MAKING ME CRAZY!

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
Hello otlanders! Please, i need a little help to finish my script. I already tried everything, and searched every post, but could not manage to make it work.

This is what i need:
I need a teleport rune (action script) to teleport the player to his original city. But after you use it, it runs an event to charge the rune and need 30 seconds to get ready to teleport the player. BUUUUUT this will only happen if player has condition infight == FALSE.

This is my problem, i need to check if, during the time to charge de rune, the player does not get battle condition. If he gets it, the event is aborted and a msg appears like: You got battle, the charging was aborted. I need this to prevent players to get out of a war.

I already have the script, but i need to add this loop of verification for battle!

Pls Help!!
 
Lua:
	i = 0
	while i < 30 do
		i = i + 1
		if getCreatureCondition(cid, CONDITION_INFIGHT) == FALSE then
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Teleportation has charged for "..i.." seconds.")
			if i == 30 then
				doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
			end
		else 
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Teleportation was cancelled, you entered battle.")
			i = 30
		end
	end

Only problem is you need a a delay in the loop, for every second instead of millisecond, so find the solution to that.

Focus on making the
Code:
i = i + 1
a delay of 1 second?
 
Ever heard of addEvent(function, delay, ...) :p?

Using an addEvent for each second in a 30 second event, would be a bad idea. Imagine, 100 people using the same teleport rune.

In my eyes, why make a addEvent script which will use more resources when you can use a loop.
 
I use a teleport rune on my server, except it has a 60 minute cooldown, although I'm sure you can change it to suit your needs.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
	local scrollid = 2264 -- Id of your rune.
	local temple = getPlayerMasterPos(cid) -- Dont touch


 
	if item.itemid == scrollid and getCreatureCondition(cid, CONDITION_INFIGHT) == false then
		local coolDown = getPlayerStorageValue(cid, 1338)
		local timeNow = os.time()
		if (timeNow - coolDown) >= 3600 then
			addEvent(telePlayer, 10000, {player = cid, dest = temple})
			addEvent(teleCount, 2000, {player = cid, times = 8})
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE,"You will be teleported in 10 seconds if you stay out of battle.")
		else
			local timeRem = 60 - math.floor((timeNow - coolDown) / 60)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your Rune of Teleport is on cooldown (' .. timeRem .. ' minutes remaining).')
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You can\'t use this rune with battle signs.')
	end
	return true
end

function teleCount(parameters)
	pos = getCreaturePosition(parameters.player)
	if getCreatureCondition(parameters.player, CONDITION_INFIGHT) == false then
		if parameters.times >= 1 then
			doSendMagicEffect(pos, 11)
			doCreatureSay(parameters.player,"Teleporting in " .. parameters.times .. " seconds.", TALKTYPE_ORANGE_1)
			times = parameters.times - 2
			addEvent(teleCount, 2000, {times = times, player = parameters.player})
		end
	else
		doPlayerSendTextMessage(parameters.player, MESSAGE_INFO_DESCR, 'You must stay out of battle to be teleported.')
	end


end



function telePlayer(parameters)

	if getCreatureCondition(parameters.player, CONDITION_INFIGHT) == false then
		doTeleportThing(parameters.player,parameters.dest)
		local coolDown = os.time()
		setPlayerStorageValue(parameters.player, 1338, coolDown)
		doSendMagicEffect(parameters.dest, 10)
		doCreatureSay(parameters.player,"Teleport!", TALKTYPE_ORANGE_1)
	else
		-- doCreatureSay(parameters.player,"You must stay out of battle to be teleported.", TALKTYPE_ORANGE_1)
	end
 
return true
 
end

The timer works using a player storage value with the time (os.time) they used the rune. It also includes a 10 second count down before the rune teleports the player (so you can't escape PvP in a flash) and also will not work with battle signs. My inspiration came from WoW. :)

Cheers.
 
Back
Top Bottom