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

Will this work?

mpa

Member
Joined
Oct 8, 2008
Messages
319
Reaction score
13
Location
Sweden
I have just started with lua and I have no idea if this will work (it is my first):
PHP:
dofile(getDataDir() .. "lib/exhaustion.lua")
    local item = 2263
    local time = 10
    local town = getPlayerMasterPos(cid)
    local exhausttime = 60 * 60 * 1000
    local storevalue = 4850
    
function onUse(cid, item, frompos, item2, topos)
        if item.itemid == item and isPlayerPzLocked(cid) == FALSE and (exhaust(cid, storevalue, exhausttime) == 1) then
            doPlayerSendTextMessage(cid,"You will be teleported to your home town in 10 seconds!",19)
        
function teleportTimer(cid)
            doTeleportThing(cid, town, 1) 
            addEvent(teleportTimer, (time * 1000)    
        else
            doPlayerSendTextMessage(cid,"You are pz locked",19)
    end
    return TRUE
end
end
Will it work?
If not, what did I do wrong?

I don't really know about that exhaust. Is there a better way to do it? (cooldown 60 min)
 
Last edited:
I have just started with lua and I have no idea if this will work (it is my first):
Code:
    local item = xxxx
    local time = 10
    local town = getPlayerTown(cid)
    
function onUse(cid, item, frompos, item2, topos)
    if item.itemid == item and isPlayerPzLocked(cid) == FALSE then
        doPlayerSendTextMessage(cid,"You will be teleported to your home town in 10 seconds!",19)
        addEvent(doTeleportThing(cid, town, 1), time * 1000)
    else
        doPlayerSendTextMessage(cid,"You are pz locked",19)
    end
    return TRUE
end
Will it work?
If not, what did I do wrong?

Thanks,
mpa

no it won't

town returns a number not a position so when you try to teleport the player it will debug you pretty much you'd need an array with the temple positions for the towns and then like doteleportthing(cid,templePos[town],1), unless 0.3 has something for temple position i don't know about
 
no it won't

town returns a number not a position so when you try to teleport the player it will debug you pretty much you'd need an array with the temple positions for the towns and then like doteleportthing(cid,templePos[town],1), unless 0.3 has something for temple position i don't know about
Oh, Didn't think about that. So this is the only error? I thought it would be more :O
I will see if i can figure this out. :thumbup:

Edit: I edited the script in my first post.
Will it work now? :wub:
I would also like to know how you can put a cooldown on this (like in wow).
 
Last edited:
should work if not
PHP:
 addEvent(teleportTimer, time * 1000,cid)
and add function

PHP:
function teleportTimer(cid)
     doTeleportThing(cid, town, 1)
end

never hurts to try to see if it works too :) i use 0.2 so i don't have getmasterpos to try it out
 
So it should be something like this?
PHP:
function teleportTimer(cid)
    doTeleportThing(cid, town, 1) 
    addEvent(teleportTimer, (time * 1000)
I'm sure this is totally wrong, lol :)

Edit:
I have changed the script a bit, here it is now:
PHP:
    local item = 2263
    local time = 10
    local town = getPlayerTown(cid)
    local exhausttime = 60 * 60 * 1000
    local storevalue = 4850
    
function onUse(cid, item, frompos, item2, topos)
        if item.itemid == item and isPlayerPzLocked(cid) == FALSE and if (exhaust(cid, storevalue, exhausttime) == 1) then
            doPlayerSendTextMessage(cid,"You will be teleported to your home town in 10 seconds!",19)
        
function teleportTimer(cid)
            doTeleportThing(cid, town, 1) 
            addEvent(teleportTimer, (time * 1000)    
        else
            doPlayerSendTextMessage(cid,"You are pz locked",19)
    end
    return TRUE
end
end

I don't really know about that exhaust. Is there a better way to do it? (cooldown 60 min)
 
Last edited:
I also made this script, what do you think?
PHP:
local pos = getCreaturePosition(cid)
local effect = 29

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) >= 50 then
            setPlayerExtraExpRate(cid, 5)
            doSendAnimatedText(getThingPos(cid), "Power!", TEXTCOLOR_RED)
            doSendMagicEffect(pos, effect)
            doRemoveItem(item.uid, 1)
else
    doPlayerSendCancel(cid, "Sorry, your level is not high enough.")
    end
    return TRUE
end
 
Last edited:
It should be something like that:
PHP:
	local item = 2263
	local time = 10
	local town = getPlayerMasterPos(cid)
	local exhausttime = 60 * 60 * 1000
	local storevalue = 4850

	local function teleportTimer(cid)
		doTeleportThing(cid, town, 1)    
    	end

function onUse(cid, item, frompos, item2, topos)
	if item.itemid == item and isPlayerPzLocked(cid) == FALSE and (exhaust(cid, storevalue, exhausttime) == 1) then
		doPlayerSendTextMessage(cid,"You will be teleported to your home town in 10 seconds!",19)
		addEvent(teleportTimer, (time * 1000)
	else
		doPlayerSendTextMessage(cid,"You are pz locked",19)
        end
	return TRUE
end
Don't put if after and like:
Code:
if item.itemid == item and isPlayerPzLocked(cid) == FALSE and if (exhaustion.make(cid, storevalue, exhausttime) == 1) then
It should be just and :)
Also you need to add
Code:
dofile(getDataDir() .. "lib/exhaustion.lua")
in data/lib/data.lua for exhaust functions.
 
Well... it should works ;D I've added levelNeeded variable only.
PHP:
local pos = getCreaturePosition(cid)
local effect = 29
local levelNeeded = 50

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerLevel(cid) >= levelNeeded then
		setPlayerExtraExpRate(cid, 5)
		doSendAnimatedText(getThingPos(cid), "Power!", TEXTCOLOR_RED)
		doSendMagicEffect(pos, effect)
		doRemoveItem(item.uid, 1)
	else
		doPlayerSendCancel(cid, "Sorry, you need to be at least "..levelNeeded..".")
	end
return TRUE
end
 
Back
Top