• 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 Need help with 2 scripts

Ezeq

New Member
Joined
Nov 23, 2010
Messages
45
Reaction score
1
Hey guys,
I am beginner at Lua, and I have problem while compiling these 2 scripts. Would you help me rewrite them to working form?

1. This one works only on tiles of lava on which players can walk. The more tiles player walked, the more damage he will take. This effect should disappear after 3 minutes. I mean if player takes 600 dmg on this tile, after 3 min he will take basis damage (100). And I also want this timer to reset every time player walks on a tile with same ID.
Lua:
function onStepIn(cid, item, position)
local ppos = getCreaturePosition(cid)
local dmg = 100 * (getPlayerStorageValue(cid,3600))
if isPlayer(cid) then
doSendMagicEffect(ppos,15)
doAddCondition(cid,3)
    if getPlayerStorageValue(cid,3600) <= 0 then
        setPlayerStorageValue(cid,3600,1)
        addEvent(setPlayerStorageValue,3*60*1000,cid,3600,0)
    elseif getPlayerStorageValue(cid,3600) >= 1 then
        setPlayerStorageValue(cid,3600,(getPlayerStorageValue(cid,3600)+1))
        stopEvent(setPlayerStorageValue)
        addEvent(setPlayerStorageValue,3*60*1000,cid,3600,0)
    end
doSendAnimatedText(ppos,HERE_SHOULD_BE_THIS_DAMAGE, 192)
doCreatureAddHealth(cid, -(dmg))
end
return TRUE
end
2. In second one there are 3 different tiles. The problem is arithmetic method. I don't know how to write it correctly.
Lua:
local hp = getCreatureHealth(cid)
local mp = getCreatureMana(cid)
local php = 0.99 * hp
local pmp = 0.99 * mp
local pstorage = getPlayerStorageValue(cid,20203)
function onStep (cid, item, postion)
local ppos = getCreaturePosition(cid)
    if item.aid == 20200 then
        if getPlayerStorageValue(cid,20200) == -1 then
        setPlayerStorageValue(cid, 20200,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-php)
        doCreatureAddMana(cid,-pmp)
        doSendMagicEffect(ppos, 63)
        end
    elseif item.aid == 20201 then
        if getPlayerStorageValue(cid,20201) == -1 then
        setPlayerStorageValue(cid, 20201,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-php)
        doCreatureAddMana(cid,-pmp)
        doSendMagicEffect(ppos, 63)
        end
    elseif item.aid == 20202 then
        if getPlayerStorageValue(cid,20202) == -1 then
        setPlayerStorageValue(cid, 20202,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-php)
        doCreatureAddMana(cid,-pmp)
        doSendMagicEffect(ppos, 63)
        end
    end
end
 
What's the problem with second script?
EDIT: Found out, try this Idk if it will work, but its not giving me errors with my debug program tool.
Lua:
local hp = getCreatureHealth(cid)
local mp = getPlayerMana(cid)
local pstorage = getPlayerStorageValue(cid,20203)
function onStep (cid, item, postion)
local ppos = getCreaturePosition(cid)
    if item.aid == 20200 then
        if getPlayerStorageValue(cid,20200) == -1 then
        setPlayerStorageValue(cid, 20200,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-getCreatureHealth(cid)*0.99)
        doPlayerAddMana(cid,-getPlayerMana(cid)*0.99)
        doSendMagicEffect(ppos, 63)
        end
    elseif item.aid == 20201 then
        if getPlayerStorageValue(cid,20201) == -1 then
        setPlayerStorageValue(cid, 20201,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-getCreatureHealth(cid)*0.99)
        doPlayerAddMana(cid,-getPlayerMana(cid)*0.99)
        doSendMagicEffect(ppos, 63)
        end
    elseif item.aid == 20202 then
        if getPlayerStorageValue(cid,20202) == -1 then
        setPlayerStorageValue(cid, 20202,1)
        setPlayerStorageValue(cid, 20203,pstorage+1)
        doCreatureAddHealth(cid,-getCreatureHealth(cid)*0.99)
        doPlayerAddMana(cid,-getPlayerMana(cid)*0.99)
        doSendMagicEffect(ppos, 63)
        end
    end
end
 
Lua:
local damage = {255, 344, 555, 750}
local time = 10
hp = getCreatureMaxHealth(cid) - getCreatureHealth(cid)
function onStepIn(cid, item, position)
	if isPlayer(cid) and getPlayerStorageValue(cid, 3600) then
		setPlayerStorageValue(cid,3600)+1)
		addEvent(addDamageCondition(CONDITION_FIRE, 4, time, damage)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have lost: " .. hp .. "health due to fire damage.")
		setPlayerStorageValue(cid,3600)
	end
end
 
Lua:
local event = {}

local function reset(gid)
	local p = getPlayerByGUID(gid)
	if p then
		setPlayerStorageValue(p, 3600)
	else
		db.executeQuery('DELETE FROM `player_storage` WHERE `player_id` = ' .. gid .. ' AND `key` = 3600 LIMIT 1;')
	end
	event[gid] = nil
end

function onStepIn(cid, item, pos, fromPos)
	if isPlayer(cid) then
		local dmg, gid = 100 * math.max(1, getPlayerStorageValue(cid,3600)), getPlayerGUID(cid)
		if event[gid] then
			stopEvent(event[gid])
		end
		setPlayerStorageValue(cid, 3600, dmg / 100 + 1)
		event[gid] = addEvent(reset, 3*60*1000, gid)
		doSendMagicEffect(pos, 15)
		doCreatureAddHealth(cid, -dmg)
		doSendAnimatedText(pos, dmg, 192)
	end
end
 
Back
Top