• 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 function ChangePlayerSpeed(cid)

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
Can someone help me to create this funcion?

I will use to add/remove speed
LUA:
function ChangePlayerSpeed(cid)
           
end



Why? Because i'm trying to make a functional Boots of waterwalking
LUA:
local condition = createConditionObject(CONDITION_DROWN)
setConditionParam(condition, CONDITION_PARAM_PERIODICDAMAGE, -20)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_TICKINTERVAL, 5000)
 
local t = {5405, 5406, 5407, 5408, 5409, 5410, 5743, 5744, 5764, 9671, 9672, 9673}
local HOTD_DECAYING = 12541
 
function onStepIn(cid)
	if isPlayer(cid) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
			doAddCondition(cid, condition)
		end
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 5461 then
			local s = getCreatureStorage(cid, 25)
			if os.time() < s then
				doTransformItem(v.uid, 12541)
				doItemSetAttribute(v.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(v.uid)
			end
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			if os.time() < getCreatureStorage(cid, 2358) == 1 then
				doChangeSpeed(cid, 1200)
			end
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and (toPosition.x == 0 or not isInArray(t, getThingfromPos(toPosition).itemid)) then
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 12541 then
			doTransformItem(v.uid, 5461)
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			doChangeSpeed(cid, -1200)
		end
		doRemoveCondition(cid, CONDITION_DROWN)
	end
end
 
Last edited:
local speed = 100
local time = 1800
doChangeSpeed(cid, speed)
addEvent(doChangeSpeed, time*1000+40, cid, -speed)

No work?
 
I'm trying this:

+speed
LUA:
doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)+300))
-speed
LUA:
doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)-300))

Whats wrong?
 
Add this on login.lua

LUA:
local speed = 500
if isPlayer(cid) then
doChangeSpeed(cid, speed)
end
 
I got this, but not working
LUA:
local condition = createConditionObject(CONDITION_DROWN)
setConditionParam(condition, CONDITION_PARAM_PERIODICDAMAGE, -20)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_TICKINTERVAL, 5000)
 
local t = {5405, 5406, 5407, 5408, 5409, 5410, 5743, 5744, 5764, 9671, 9672, 9673}
local speed = 400
local HOTD_DECAYING = 12541
 
function onStepIn(cid)
	if isPlayer(cid) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
			doAddCondition(cid, condition)
		end
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 5461 then
			local s = getCreatureStorage(cid, 25)
			if os.time() < s then
				doTransformItem(v.uid, 12541)
				doItemSetAttribute(v.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(v.uid)
			end
		end
	end
 
	if isPlayer(cid) and isUnderWater(cid) then
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 and getCreatureStorage(cid, 2358) == -1 then
			setPlayerStorageValue(cid, 2358, 1)
			doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)+speed))
		else
			setPlayerStorageValue(cid, 2358, 1)
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and (toPosition.x == 0 or not isInArray(t, getThingfromPos(toPosition).itemid)) then
		doRemoveCondition(cid, CONDITION_DROWN)
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 12541 then
			doTransformItem(v.uid, 5461)
		end
	end
 
	if isPlayer(cid) and isUnderWater(cid) then
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 and getCreatureStorage(cid, 2358) == 1 then
			setPlayerStorageValue(cid, 2358, -1)
			doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)-speed))
		else
			setPlayerStorageValue(cid, 2358, -1)
		end
	end
end
 
function onEquip(cid, item, slot, boolean)
	if(isUnderWater(cid) and (item.itemid == HOTD_DECAYING or getItemAttribute(item.uid, "duration") ~= nil)) then
		callFunction(cid, item.uid, slot, boolean)
	end
 
	return true
end
 
Last edited:
Try

LUA:
local condition = createConditionObject(CONDITION_DROWN)
setConditionParam(condition, CONDITION_PARAM_PERIODICDAMAGE, -20)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_TICKINTERVAL, 5000)
 
local t = {5405, 5406, 5407, 5408, 5409, 5410, 5743, 5744, 5764, 9671, 9672, 9673}
local speed = 300
 
function onStepIn(cid)
	if isPlayer(cid) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
			doAddCondition(cid, condition)
		end
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 5461 then
			local s = getCreatureStorage(cid, 25)
			if os.time() < s then
				doTransformItem(v.uid, 12541)
				doItemSetAttribute(v.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(v.uid)
			end
		end
		local feet = getPlayerSlotItem(cid, CONST_SLOT_FEET)
		if feet.itemid == 2358 and getCreatureStorage(cid, 555777) == -1 then
			setPlayerStorageValue(cid, 555777, 1)
			doChangeSpeed(cid, speed)
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and (toPosition.x == 0 or not isInArray(t, getThingfromPos(toPosition).itemid)) then
		doRemoveCondition(cid, CONDITION_DROWN)
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 12541 then
			doTransformItem(v.uid, 5461)
		end
	end
	local feet = getPlayerSlotItem(cid, CONST_SLOT_FEET)
	if feet.itemid == 2358 and getCreatureStorage(cid, 555777) > 0 then
		setPlayerStorageValue(cid, 555777, -1)
		doChangeSpeed(cid, -speed)
	end
end
 
function onEquip(cid, item, slot, boolean)
	if slot == CONST_SLOT_HEAD then
		local s = getCreatureStorage(cid, 25)
		if os.time() < s then
			local p = getThingPos(cid)
			p.stackpos = 0
			if isInArray(t, getThingfromPos(p).itemid) then
				if item.itemid == 5461 then
					doTransformItem(item.uid, 12541)
				end
				doItemSetAttribute(item.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(item.uid)
			end
		elseif item.itemid == 12541 then
			doTransformItem(item.uid, 5461)
		end
	end
	return callFunction(cid, item.uid, slot, boolean)
end
 
doChangeSpeed(cid, delta)

The second parameter for that function is delta I think. So it is the difference.
doChangeSpeed(cid, 30) wont set the speed to 30 but will add 30 speed to the player.
doChangeSpeed(cid, -100) will remove 100 speed.
Maybe that is the problem
 
If player walk in 4sqm underwater and stepout then he still get speed

LUA:
local speed = 500

function onStepIn(cid)
	if isPlayer(cid) and isUnderWater(cid) then
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 and getCreatureStorage(cid, 2358) == -1 then
			setPlayerStorageValue(cid, 2358, 1)
			doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)+speed))
		else
			setPlayerStorageValue(cid, 2358, 1)
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and isUnderWater(cid) then
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 and getCreatureStorage(cid, 2358) == 1 then
			setPlayerStorageValue(cid, 2358, -1)
			doChangeSpeed(cid, (getCreatureSpeed(cid)+getCreatureBaseSpeed(cid)-speed))
		else
			setPlayerStorageValue(cid, 2358, -1)
		end
	end
end
 
doChangeSpeed(cid,(1000-getCreatureSpeed(cid)))
while 1000 is the new speed
LUA:
function ChangePlayerSpeed(cid,speed)
	doChangeSpeed(cid,(speed-getCreatureSpeed(cid)))
end
 
When player leave underwater he is VERY SLOW, how to fix?

LUA:
local condition = createConditionObject(CONDITION_DROWN)
setConditionParam(condition, CONDITION_PARAM_PERIODICDAMAGE, -20)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_TICKINTERVAL, 5000)
 
local t = {5405, 5406, 5407, 5408, 5409, 5410, 5743, 5744, 5764, 9671, 9672, 9673}
local HOTD_DECAYING = 12541
 
function onStepIn(cid)
	if isPlayer(cid) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
			doAddCondition(cid, condition)
		end
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 5461 then
			local s = getCreatureStorage(cid, 25)
			if os.time() < s then
				doTransformItem(v.uid, 12541)
				doItemSetAttribute(v.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(v.uid)
			end
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			if os.time() < getCreatureStorage(cid, 2358) == 1 then
				doChangeSpeed(cid,(2000-getCreatureSpeed(cid)))
			end
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and (toPosition.x == 0 or not isInArray(t, getThingfromPos(toPosition).itemid)) then
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 12541 then
			doTransformItem(v.uid, 5461)
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			doChangeSpeed(cid,(-2000-getCreatureSpeed(cid)))
		end
		doRemoveCondition(cid, CONDITION_DROWN)
	end
end
 
Last edited:
EDIT: Nvm I just saw the full thing. It's ok. Use getCreatureBaseSpeed(cid) as they said.
 
Last edited:
It's not adding speed onstepin, why?

LUA:
local condition = createConditionObject(CONDITION_DROWN)
setConditionParam(condition, CONDITION_PARAM_PERIODICDAMAGE, -20)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_TICKINTERVAL, 5000)
 
local t = {5405, 5406, 5407, 5408, 5409, 5410, 5743, 5744, 5764, 9671, 9672, 9673}
local HOTD_DECAYING = 12541
 
function onStepIn(cid)
	if isPlayer(cid) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
			doAddCondition(cid, condition)
		end
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 5461 then
			local s = getCreatureStorage(cid, 25)
			if os.time() < s then
				doTransformItem(v.uid, 12541)
				doItemSetAttribute(v.uid, 'duration', (s - os.time()) * 1000)
				doDecayItem(v.uid)
			end
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			if os.time() < getCreatureStorage(cid, 2358) == 1 then
				doChangeSpeed(cid,(2000-getCreatureSpeed(cid)))
			end
		end
	end
end
 
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition)
	if isPlayer(cid) and (toPosition.x == 0 or not isInArray(t, getThingfromPos(toPosition).itemid)) then
		local v = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
		if v.itemid == 12541 then
			doTransformItem(v.uid, 5461)
		end
		if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2358 then
			doChangeSpeed(cid,(getCreatureBaseSpeed(cid)-getCreatureSpeed(cid))) 
		end
		doRemoveCondition(cid, CONDITION_DROWN)
	end
end
 
Guess you will have to change this in items.otb
the tiles already change player's speed to 100 or something like that
 
What if onEquip check if is underwater then doItemSetAttribute(itemEx.uid, "speed", 200)

EDIT:
Do not work
LUA:
function onEquip(cid, item, slot) 
local item = doCreateItemEx(2358,1)
	if isPlayer(cid) then
		doItemSetAttribute(item, "speed", 2000) 
		setPlayerStorageValue(cid, 2358,1)
	end
return true
end

function onDeEquip(cid, item, slot)
local item = doCreateItemEx(2358,1)
	if getPlayerStorageValue(cid, 2358) == 1 then
		doItemSetAttribute(item, "speed", 0) 
	end
return true
end

- - - Updated - - -

bump :S
 
Last edited:
I checked the sources and it seems doItemSetAttribute doesn't works for movement speed, only attack speed.
 
Back
Top