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

oldPos

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
'data\spells\scripts\support'
magic shield

PHP:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)

local condition = createConditionObject(CONDITION_MANASHIELD)
setConditionParam(condition, CONDITION_PARAM_TICKS, 200000)
setCombatCondition(combat, condition)

function onCastSpell(cid, var)
	repeatEffect(getCreaturePos(cid), CONST_ME_MAGIC_BLUE, 1 * 60 * 50, 100)
	return doCombat(cid, combat, var)
end
--
'data'
functions

PHP:
function repeatEffect(pos, effect, delay, repeatTime)
	if repeatTime > 0 then
		doSendMagicEffect(pos, effect)
		repeatTime = repeatTime - 1
		addEvent(repeatEffect, delay, pos, effect, delay, repeatTime)
	end
end
--
The spell can repeat the effect, but don't repeat at new player position...
Look:
lookwn4.jpg

Help-me to send magicEffect in new player position...
 
Hehe, after your request I also thinked about this shield which I seen on some 7.6 server.

Code:
repeatEffect(getCreaturePos(cid), CONST_ME_MAGIC_BLUE, 1 * 60 * 50, 100)
To:
Code:
repeatEffect(cid, CONST_ME_MAGIC_BLUE, 1 * 60 * 50, 100)

And
Code:
doSendMagicEffect(pos, effect)
To:
Code:
doSendMagicEffect(getCreaturePos(cid), effect)
 
A :)
Code:
function repeatEffect(pos, effect, delay, repeatTime)
To:
Code:
function repeatEffect(cid, effect, delay, repeatTime)
 
erroroq8.jpg


Functions.LUA:
PHP:
function doPlayerGiveItem(cid, itemid, count, charges)
	local hasCharges = (isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE)
	if(hasCharges and charges == nil) then
		charges = 1
	end
	while count > 0 do
		local tempcount = 1
		if(hasCharges) then
			tempcount = charges
		end
		if(isItemStackable(itemid) == TRUE) then
			tempcount = math.min (100, count)
   		end
	   	local ret = doPlayerAddItem(cid, itemid, tempcount)
	   	if(ret == LUA_ERROR) then
			ret = doCreateItem(itemid, tempcount, getPlayerPosition(cid))
		end
		if(ret ~= LUA_ERROR) then
			if(hasCharges) then
				count = count - 1
			else
				count = count - tempcount
			end
		else
			return LUA_ERROR
		end
	end
	return LUA_NO_ERROR
end

function doPlayerTakeItem(cid, itemid, count)
	if(getPlayerItemCount(cid,itemid) >= count) then
		while count > 0 do
			local tempcount = 0
			if(isItemStackable(itemid) == TRUE) then
				tempcount = math.min (100, count)
			else
				tempcount = 1
			end
			local ret = doPlayerRemoveItem(cid, itemid, tempcount)
			if(ret ~= LUA_ERROR) then
				count = count-tempcount
			else
				return LUA_ERROR
			end
		end
		if(count == 0) then
			return LUA_NO_ERROR
		end
	else
		return LUA_ERROR
	end
end

function doPlayerAddMoney(cid, amount)
	local crystals = math.floor(amount/10000)
	amount = amount - crystals*10000
	local platinum = math.floor(amount/100)
	amount = amount - platinum*100
	local gold = amount
	local ret = 0
	if(crystals > 0) then
		ret = doPlayerGiveItem(cid, ITEM_CRYSTAL_COIN, crystals)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	if(platinum > 0) then
		ret = doPlayerGiveItem(cid, ITEM_PLATINUM_COIN, platinum)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	if(gold > 0) then
		ret = doPlayerGiveItem(cid, ITEM_GOLD_COIN, gold)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	return LUA_NO_ERROR
end

function doPlayerBuyItem(cid, itemid, count, cost, charges)
	if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		return doPlayerGiveItem(cid, itemid, count, charges)
	end
	return LUA_ERROR
end

function doPlayerSellItem(cid, itemid, count, cost)
	if(doPlayerTakeItem(cid, itemid, count) == LUA_NO_ERROR) then
		if(doPlayerAddMoney(cid, cost) ~= LUA_NO_ERROR) then
			error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
		end
		return LUA_NO_ERROR
	end
	return LUA_ERROR
end

function isInRange(pos, fromPos, toPos)
	if pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z then
		return TRUE
	end
	return FALSE
end

function isNumber(p)
	local m = ""
	for i = 1, string.len(p) do
		m = string.sub(p, i, i)
		if m == "0" or m == "1" or m == "2" or m == "3" or m == "4" or m == "5" or m == "6" or m == "7" or m == "8" or m == "9" then
			-- continue
		else
			return FALSE
		end
	end
	return TRUE
end

function isPremium(cid)
	if isPlayer(cid) == TRUE and getPlayerPremiumDays(cid) > 0 then
		return TRUE
	end
	return FALSE
end

function rows(connection, sql_statement)
	local cursor = assert(connection:execute(sql_statement))
	return function ()
		return cursor:fetch()
	end
end

function getMonthDayEnding(day)
	if day == "01" or day == "21" or day == "31" then
		return "st"
	elseif day == "02" or day == "22" then
		return "nd"
	elseif day == "03" or day == "23" then
		return "rd"
	else
		return "th"
	end
end

function getMonthString(month)
	if month == 1 then
		return "January"
	elseif month == 2 then
		return "February"
	elseif month == 3 then
		return "March"
	elseif month == 4 then
		return "April"
	elseif month == 5 then
		return "May"
	elseif month == 6 then
		return "June"
	elseif month == 7 then
		return "July"
	elseif month == 8 then
		return "August"
	elseif month == 9 then
		return "September"
	elseif month == 10 then
		return "October"
	elseif month == 11 then
		return "November"
	elseif month == 12 then
		return "December"
	end
end

function getArticle(str)
	if string.find(str, "[A,a,E,e,I,i,O,o,U,u,Y,y]") == TRUE then
		return "an"
	end
	return "a"
end

function getDistanceBetween(firstPosition, secondPosition)
	local xDif = math.abs(firstPosition.x - secondPosition.x)
	local yDif = math.abs(firstPosition.y - secondPosition.y)

	local posDif = math.max(xDif, yDif)
	if(firstPosition.z ~= secondPosition.z) then
		posDif = posDif + 9 + 6
	end
	return posDif
end

function doPlayerAddAddons(cid, addon)
	for i = 0, table.maxn(maleOutfits) do
		doPlayerAddOutfit(cid, maleOutfits[i], addon)
	end

	for i = 0, table.maxn(femaleOutfits) do
		doPlayerAddOutfit(cid, femaleOutfits[i], addon)
	end
end

function numRows(cursor)
	local row = cursor:fetch()
	local rows = 0
	while row do
		rows = rows + 1
		row = cursor:fetch()
	end
	cursor:close()
	return rows
end

local saveDelay = 1 * 60 * 1000
local storageValue = 2342

if (getGlobalStorageValue(storageValue) == -1) then
function save(saveDelay)
saveData()
print("**!**Server Saved**!**")
addEvent(save, saveDelay, saveDelay)
end
addEvent(save, saveDelay, saveDelay)
setGlobalStorageValue(storageValue, 1)
end

function getConfigInfo(info)
	if (type(info) ~= 'string') then return nil end

	dofile('config.lua')
	return _G[info]
end

function hasCondition(cid, condition)
	return getCreatureCondition(cid, condition)
end

function exhaust(cid, storevalue, exhausttime)   
-- Exhaustion function by Alreth, v1.1 2006-06-24 01:31   
-- Returns 1 if not exhausted and 0 if exhausted   
    newExhaust = os.time()   
    oldExhaust = getPlayerStorageValue(cid, storevalue)   
    if (oldExhaust == nil or oldExhaust < 0) then   
        oldExhaust = 0   
    end   
    if (exhausttime == nil or exhausttime < 0) then   
        exhausttime = 1   
    end   
    diffTime = os.difftime(newExhaust, oldExhaust)   
    if (diffTime >= exhausttime or diffTime < 0) then   
        setPlayerStorageValue(cid, storevalue, newExhaust)    
        return 1   
    else   
        return 0   
    end   
end

function repeatEffect(cid, effect, delay, repeatTime)
	if repeatTime > 0 then
		doSendMagicEffect(getCreaturePos(cid), effect)
		repeatTime = repeatTime - 1
		addEvent(repeatEffect, delay, pos, effect, delay, repeatTime)
	end
end
 
You are using tags?

Use it:
Code:
function repeatEffect(cid, effect, delay, repeatTime)
    if repeatTime > 0 then
        doSendMagicEffect(getCreaturePosition(cid), effect)
        repeatTime = repeatTime - 1
        addEvent(repeatEffect, delay, cid, effect, delay, repeatTime)
    end
end
 
Hyhy, sorry, but its impossible that after this modifications you have this error :P

You changed in functions.lua to what i posted @up?
 
Now are working:
PHP:
local combat = createCombatObject() 
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE) 
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0) 

local condition = createConditionObject(CONDITION_MANASHIELD) 
setConditionParam(condition, CONDITION_PARAM_TICKS, 90000) 
setCombatCondition(combat, condition) 

function onCastSpell(cid, var)
    repeatEffect(cid, CONST_ME_TELEPORT, 1 * 60 * 20, 90)
    return doCombat(cid, combat, var) 
end

PHP:
function repeatEffect(cid, effect, delay, repeatTime)
    if repeatTime > 0 then
        doSendMagicEffect(getCreaturePosition(cid), effect)
        repeatTime = repeatTime - 1
        addEvent(repeatEffect, delay, cid, effect, delay, repeatTime)
    end
end

The spell end, but the magicEffect no.
How I ajust the time of effect?
I'm not good in math!
I need:
Utamo vita: duration 2min
magicEffect: 2min
 
delay - delayBetween repeats
repeatTime - how much it will be repeated

Ex.
repeatEffect(cid, CONST_ME_TELEPORT, 1000, 120)

It will work like this:
sendEffect
1000ms wait
sendEffect
1000ms wait
sendEffect
1000ms wait
[..]

/\This example will work for 2 minutes with 1s delay between effects.

More examples:
repeatEffect(cid, CONST_ME_TELEPORT, 2000, 60)
2000 * 60 = 120000 = 120 seconds = 2 min

repeatEffect(cid, CONST_ME_TELEPORT, 500, 240)
500 * 240 = 120000 = 120 seconds = 2 min

repeatEffect(cid, CONST_ME_TELEPORT, 5000, 24)
5000 * 24 = 120000 = 120 seconds = 2 min

repeatEffect(cid, CONST_ME_TELEPORT, 3000, 40)
3000 * 40 = 120000 = 120 seconds = 2 min

Very fast:
repeatEffect(cid, CONST_ME_TELEPORT, 250, 480)
3000 * 40 = 120000 = 120 seconds = 2 min
 
Last edited:
Back
Top