• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved General .lua help!

Leeroyjenkinz

New Member
Joined
Jun 24, 2013
Messages
28
Reaction score
2
Hey, I have a question.

I have a luafunction which is doPlayerSetExtraAttackSpeed(cid, speed) and I was wondering how can I use that function in a spell and make it last for 3 seconds, and when 3 seconds is over with it will doPlayerSetExtraAttackSpeed(cid, 0)?

Any help pls ;3

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10000)
setConditionParam(condition, CONDITION_PARAM_BUFF, true)
setCombatCondition(combat, condition)


function onCastSpell(cid, var)
return doCombat(cid, combat, var)
doPlayerSetExtraAttackSpeed(cid, 2000)

end
 
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10000)
setConditionParam(condition, CONDITION_PARAM_BUFF, true)
setCombatCondition(combat, condition)

local function removeAS(cid)
if not isPlayer(cid) then return true end
doPlayerSetExtraAttackSpeed(cid, 0)
end

function onCastSpell(cid, var)
doPlayerSetExtraAttackSpeed(cid, 2000)
addEvent(removeAS, 3 * 1000, cid)
return doCombat(cid, combat, var)
end
 
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10000)
setConditionParam(condition, CONDITION_PARAM_BUFF, true)
setCombatCondition(combat, condition)

local function removeAS(cid)
if not isPlayer(cid) then return true end
doPlayerSetExtraAttackSpeed(cid, 0)
end

function onCastSpell(cid, var)
doPlayerSetExtraAttackSpeed(cid, 2000)
addEvent(removeAS, 3 * 1000, cid)
return doCombat(cid, combat, var)
end
Thank you!!

Another question... how could I add an internal cooldown on this movement script?
Basically, I want it to work as is with storage values, but only make it able to be used once every 30 minutes (I have no idea how I would go about that)

pos1 = {x=21920, y=21944, z=7}
pos2 = {x=21922, y=29143, z=7}
pos3 = {x=29122, y=29145, z=7}

function onStepIn(cid, item, frompos, item2, topos)
if getPlayerStorageValue(cid,15321) == -1 then

doSummonCreature("creature name", pos1)
doSummonCreature("creature name", pos2)
doSummonCreature("creature name", pos3)
doPlayerSendTextMessage(cid, 0x13, "text here")
setPlayerStorageValue(cid,15321,1)
end
return 1
end
 
You can use exhaustion.check/get/set for each player.
LUA:
pos1 = {x=21920, y=21944, z=7}
pos2 = {x=21922, y=29143, z=7}
pos3 = {x=29122, y=29145, z=7}

function onStepIn(cid, item, frompos, item2, topos)
        local storage = 4095
	if exhaustion.check(cid, storage) then
		return doPlayerSendCancel(cid, "You have to wait "..math.floor(exhaustion.get(cid, storage)/60).." minutes.")
	end
	doSummonCreature("creature name", pos1)
	doSummonCreature("creature name", pos2)
	doSummonCreature("creature name", pos3)
	doPlayerSendTextMessage(cid, 0x13, "text here")
	exhaustion.set(cid, storage, 1800)
	return 1
end
Functions if you don't have them
LUA:
exhaustion =
{
	check = function (cid, storage)
		return getPlayerStorageValue(cid, storage) >= os.time(t)
	end,

	get = function (cid, storage)
		local exhaust = getPlayerStorageValue(cid, storage)
		if(exhaust > 0) then
			local left = exhaust - os.time(t)
			if(left >= 0) then
				return left
			end
		end

		return false
	end,

	set = function (cid, storage, time)
		setPlayerStorageValue(cid, storage, os.time(t) + time)
	end,

	make = function (cid, storage, time)
		local exhaust = exhaustion.get(cid, storage)
		if(not exhaust) then
			exhaustion.set(cid, storage, time)
			return true
		end

		return false
	end
}

Or for global you can do it like this.
LUA:
pos1 = {x=21920, y=21944, z=7}
pos2 = {x=21922, y=29143, z=7}
pos3 = {x=29122, y=29145, z=7}

function onStepIn(cid, item, frompos, item2, topos)
        local storage = 4095
	if globalexhaustion.check(storage) then
		return doPlayerSendCancel(cid, "You have to wait "..math.floor(globalexhaustion.get(storage)/60).." minutes.")
	end
	doSummonCreature("creature name", pos1)
	doSummonCreature("creature name", pos2)
	doSummonCreature("creature name", pos3)
	doPlayerSendTextMessage(cid, 0x13, "text here")
	globalexhaustion.set(storage, 1800)
	return 1
end
Funtions
LUA:
globalexhaustion =
{
	check = function (storage)
		return getGlobalStorageValue(storage) >= os.time(t)
	end,

	get = function (storage)
		local exhaust = getGlobalStorageValue(storage)
		if(exhaust > 0) then
			local left = exhaust - os.time(t)
			if(left >= 0) then
				return left
			end
		end

		return false
	end,

	set = function (storage, time)
		setGlobalStorageValue(storage, os.time(t) + time)
	end,

	make = function (storage, time)
		local exhaust = globalexhaustion.get(storage)
		if(not exhaust) then
			globalexhaustion.set(storage, time)
			return true
		end

		return false
	end
}
 
Or for global you can do it like this.
LUA:
pos1 = {x=21920, y=21944, z=7}
pos2 = {x=21922, y=29143, z=7}
pos3 = {x=29122, y=29145, z=7}

function onStepIn(cid, item, frompos, item2, topos)
        local storage = 4095
	if globalexhaustion.check(storage) then
		return doPlayerSendCancel(cid, "You have to wait "..math.floor(globalexhaustion.get(storage)/60).." minutes.")
	end
	doSummonCreature("creature name", pos1)
	doSummonCreature("creature name", pos2)
	doSummonCreature("creature name", pos3)
	doPlayerSendTextMessage(cid, 0x13, "text here")
	globalexhaustion.set(storage, 1800)
	return 1
end
Funtions
How could i make something like
local globalexhausttime?
local storageID
:P?
 
The time is here 1800, the time is in seconds so it's now 30 min.
If you want to make a variable for that, you can just add globalexhausttime instead of 1800 and then local globalexhausttime = 1800 at the top.
And for the storage I already made a variable storage, you can change this to local storageID if you want and then change the word storage in the rest of the script to storageID.
 
I hate making new threads and cluttering the board so I'll just keep posting here if I need help ;33

When NPC's walk into my movement script (onStepIn) the script I use gets confused as it's not a player for obvious reasons :P
GPydZ2X.png

Code:
local SWITCHES = { {416, 417}, {426, 425}, {446, 447}, {3216, 3217} }

local function doTransformTile(item)
	for i, v in pairs(SWITCHES) do
		if(item.itemid == v[1]) then
			return doTransformItem(item.uid, v[2])
		elseif(item.itemid == v[2]) then
			return doTransformItem(item.uid, v[1])
		end
	end
end

function onStepIn(cid, item, topos, frompos)
	if(item.actionid > 0) then
		return TRUE
	end

	doTransformTile(item)
	local depot = {}
	for x = -1, 1 do
		for y = -1, 1 do
			topos.x = topos.x + x
			topos.y = topos.y + y
			depot = getTileItemByType(topos, ITEM_TYPE_DEPOT)
			if(depot.uid > 0) then
				local depotItems = getPlayerDepotItems(cid, getDepotId(depot.uid))
				local depotStr = "Your depot contains " .. depotItems .. " items."
				if(depotItems == 1) then
					depotStr = "Your depot contains 1 item."
				end
				doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, depotStr)
				return TRUE
			end
			-- The pos has changed, change it back
			topos.x = topos.x - x
			topos.y = topos.y - y
		end
	end
	return TRUE
end

function onStepOut(cid, item, topos, frompos)
	doTransformTile(item)
	return TRUE
end
 
Add this (under function onStepIn(cid, item, topos, frompos))
LUA:
if not isPlayer(cid) then
	return true
end
I tried adding it (here's my new script)
Code:
local SWITCHES = { {416, 417}, {426, 425}, {446, 447}, {3216, 3217} }

local function doTransformTile(item)
	for i, v in pairs(SWITCHES) do
		if(item.itemid == v[1]) then
			return doTransformItem(item.uid, v[2])
		elseif(item.itemid == v[2]) then
			return doTransformItem(item.uid, v[1])
		end
	end
end

function onStepIn(cid, item, topos, frompos)
if not isPlayer(cid) then
	return true
end
	if(item.actionid > 0) then
		return TRUE
	end

	doTransformTile(item)
	local depot = {}
	for x = -1, 1 do
		for y = -1, 1 do
			topos.x = topos.x + x
			topos.y = topos.y + y
			depot = getTileItemByType(topos, ITEM_TYPE_DEPOT)
			if(depot.uid > 0) then
				local depotItems = getPlayerDepotItems(cid, getDepotId(depot.uid))
				local depotStr = "Your depot contains " .. depotItems .. " items."
				if(depotItems == 1) then
					depotStr = "Your depot contains 1 item."
				end
				doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, depotStr)
				return TRUE
			end
			-- The pos has changed, change it back
			topos.x = topos.x - x
			topos.y = topos.y - y
		end
	end
	return TRUE
end

function onStepOut(cid, item, topos, frompos)
	doTransformTile(item)
	return TRUE
end

Should I just add that isNotPlayer in the functions that are giving me errors?
u4Qx1ho.png


- - - Updated - - -

Solved! Had a bad isPlayer function :P
 
Back
Top