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

Need help with quest

Humpasaur

New Member
Joined
Dec 7, 2009
Messages
18
Reaction score
0
Hey, I'm trying to make a quest to where when you pull the lever, if your standing on a certain tile, you will be teleported to "place". The problem is I don't know how to use the "IF playerposition = this coordinate then do this"... Heres my code so far, its not working obviously... lol

Code:
local playpos = {x=1073, y=974, z=7}
local place = {x=1022, y=993, z=7}
function onUse(cid, item, fromPosition, itemEx, toPosition)
  if getPlayerPosition(cid) == playpos then
doTeleportThing(cid, place)
end
end

I always have a follow up question, is there an example or tip you can give me to help me figure out how to do this:

Code:
When I pull switch
Summon demon to coordinate(xxx)
When player kills demon
Say Message "Good job, demon is dead"

Thanks again guys.
 
Lua:
local config = {
	monster = "Demon", -- Monster to be summoned
	tile = getClosestFreeTile(cid, getCreaturePosition(cid)) -- Position
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 then -- if its a non-used lever
		local monstah = doCreateMonster(config.monster, config.tile) -- Summon the demon, make him a table
		addEvent(lolcheck, 300, cid, monstah) -- Check if creature is dead with events
		doTransformItem(item.uid, item.itemid+1) -- Convert into used lever
	end
end

function lolcheck(cid, monstah)
	if not isCreature(monstah) then -- check if the table monstah (the demon) is a alive, by checking if its a creature
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good job demon is ded.") -- good job demon is ded
	else -- Loop if creature isn't dead
		addEvent(lolcheck, 300, cid, monstah)
	end
end

It could also be done with creatureevents, instead of addEvent, but meh.

Also; fixed.
Lua:
local playpos = {x=1073, y=974, z=7, stackpos = 253}
local place = {x=1022, y=993, z=7}

function onUse(cid, item, fromPosition, itemEx, toPosition)

	if getPlayerPosition(cid) == playpos then
		doTeleportThing(cid, place)
	end
	return FALSE
end

That should work. Also, moar organized.
 
Last edited:
Thanks, I appreciate it, I got it working now. Another question if you care to answer it though.

As a quest reward, I'm going to make it a fire sword. Only thing is I want it to have +2x attack speed... Is there a way to be able to do that without messing with the client? Maybe through a unique id or action id or something? Thanks again.
 
Lua:
..script..

local firesword = doPlayerAddItem(cid, fireswordID)
setItemAttackSpeed(firesword, (getItemAttackSpeed(firesword)*2))

..script..

That should work.
 
Last edited:
Lua:
..script..

local firesword = doPlayerAddItem(cid, fireswordID)
setItemAttackSpeed(firesword.uid, (getItemAttackSpeed(firesword.uid)*2))

..script..

That should work.
You don't need to use firesword.uid because doPlayerAddItem always returns uid of the item.
 
Change

Lua:
function lolcheck(cid, monstah)
        if not isCreature(monstah) then -- check if the table monstah (the demon) is a alive, by checking if its a creature
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good job demon is ded.") -- good job demon is ded
        else -- Loop if creature isn't dead
                addEvent(lolcheck, 300, cid, monstah)
        end
end

To

Lua:
function lolcheck(cid, monstah)
        if not isCreature(monstah) then -- check if the table monstah (the demon) is a alive, by checking if its a creature
                local firesword = doPlayerAddItem(cid, fireswordID)
                setItemAttackSpeed(firesword, (getItemAttackSpeed(firesword)*2))
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good job demon is ded.") -- good job demon is ded
        else -- Loop if creature isn't dead
                addEvent(lolcheck, 300, cid, monstah)
        end
end

Uhm, yes. Like that.
 
Alright, thanks. Just learned A LOT. Is there a place I can find out what stuff like (AddEvent) does? I'm wondering what the "300" params are used for. Time maybe?
 
Haha, glad I helped. I think that learning from the scripts is much better than just asking for them and adding them to your OT, because you will be able to make them later on.

addEvent(lolcheck, 300, cid, monstah)

~Function~
~Time, expresed in miliseconds~
~Params~

You can also use it to execute already defined functions, like doPlayerAddItem, doPlayerSetVocation, doChallengeCreature, etc...

You would use it like this:

addEvent(doPlayerAddItem, 300, cid, 2231)

If you've got another inquiry, feel free to PM me, ask on my profile, or post here again (if that is allowed, though).
 
Last edited:
Alright, I got everything working good except for the fire sword part. It just gives me a fire sword with regular attack speed then gives me the error message

Code:
[13/12/2009 20:26:40] [Error - Action Interface] 
[13/12/2009 20:26:40] In a timer event called from: 
[13/12/2009 20:26:40] data/actions/scripts/demon1.lua:onUse
[13/12/2009 20:26:40] Description: 
[13/12/2009 20:26:40] data/actions/scripts/demon1.lua:10: attempt to call global 'getItemAttackSpeed' (a nil value)
[13/12/2009 20:26:40] stack traceback:
[13/12/2009 20:26:40] 	data/actions/scripts/demon1.lua:10: in function <data/actions/scripts/demon1.lua:7>


and here is my script
Code:
function onUse(cid, item, frompos, item2, topos)
monster = "Rat"
demonpos = {x=1031, y=1027, z=7}
monstah = doCreateMonster(monster, demonpos)
addEvent(lolcheck, 300, cid, monstah)
end
function lolcheck(cid, monstah)
        if not isCreature(monstah) then 
   local firesword = doPlayerAddItem(cid, 2392)
                setItemAttackSpeed(firesword, (getItemAttackSpeed(firesword)*2))
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good job demon is ded.") 
        else
                addEvent(lolcheck, 300, cid, monstah)
        end
end

Thanks
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local monster = "Rat"
        doCreateMonster(monster, {x=1031, y=1027, z=7})
        addEvent(check, 300, cid)
end
local function check(cid)
        if (not isCreature(monster)) then
		local firesword = doCreateItem(cid, 2392)
		setItemAttackSpeed(firesword, (getItemAttackSpeed(firesword) * 2))
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good Job! The monster has been killed.") 
	else
		addEvent(check, 300, cid)
	end
end

:huh:
 
Last edited:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local monster = "Rat"
        doCreateMonster(monster, {x=1031, y=1027, z=7})
        addEvent(check, 300, cid)
end
local function check(cid)
        if (not isCreature(monster)) then
		local firesword = doCreateItem(cid, 2392)
		setItemAttackSpeed(firesword, (getItemAttackSpeed(firesword) * 2))
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good Job! The monster has been killed.") 
	else
		return addEvent(check, 300, cid)
	end
end

:huh:

[14/12/2009 09:11:15] [Error - Action Interface]
[14/12/2009 09:11:15] data/actions/scripts/demon1.lua:eek:nUse
[14/12/2009 09:11:15] Description:
[14/12/2009 09:11:15] (luaAddEvent) Callback parameter should be a function.
 
Lua:
local config = {
	monster = "Rat",
	where = {x=1031, y=1027, z=7}
}

function onUse(cid, item, frompos, item2, topos)
	 local monstah = doCreateMonster(config.monster, config.where)
	 addEvent(lolcheck, 300, cid, monstah)
end

function lolcheck(cid, monstah)
	 if not isCreature(monstah) then 
		 local firesword = doPlayerAddItem(cid, 2392)
		 setItemAttackSpeed(firesword, 1500)
		 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Good job demon is ded.") 
	 else
		 addEvent(lolcheck, 300, cid, monstah)
	 end
end
That should work. I tested it in Crying Damson, 0.3.5, and it worked.
Also, new one, more organized and it changes the swords attacking speed to the correct speed. It takes 3 seconds between attacks, and 3/2=1,5.
 
Back
Top