Greetings everyone!
I've become a little rusty when it comes to scripting, haven't done it in years. I tried the search function but didn't really find what I'm looking for. Tried a lot of things but I just can't get it to work the way I want.
The basic situation:
You all know the demon helmet quest. You go through a teleport and there's a switch on the right. If you pull this switch a teleport appears (to get out again) and a stone on the left disappears (so you can get the rewards).
What I have is:
I managed to create a script that lets a teleport appear and the stone disappear when you hit the lever. You can reverse this by flipping back the switch.
What I want though:
Is this whole thing to be timed. If you go down and hit the switch the teleport appears and the stone disappears. There the play should NOT be able to flip back the switch. Instead it should flip back itself (removing the teleport and placing the stone) after a certain ammount of time. After it automatically flipped back you can ofcourse use it again (starting the whole timer loop again).
The script I have so far is as thus:
And by the way, I'm using TFS 0.3 beta3 if this is of any importance.
It is probably easy as hell but like I mentioned I'm a bit rusty. Any help is appreciated.
[EDIT]
Thanks to the people posting their suggestions here (you're getting reps) I managed to get the code to fully work the way I wanted it to. This is what it looks like now:
I've become a little rusty when it comes to scripting, haven't done it in years. I tried the search function but didn't really find what I'm looking for. Tried a lot of things but I just can't get it to work the way I want.
The basic situation:
You all know the demon helmet quest. You go through a teleport and there's a switch on the right. If you pull this switch a teleport appears (to get out again) and a stone on the left disappears (so you can get the rewards).
What I have is:
I managed to create a script that lets a teleport appear and the stone disappear when you hit the lever. You can reverse this by flipping back the switch.
What I want though:
Is this whole thing to be timed. If you go down and hit the switch the teleport appears and the stone disappears. There the play should NOT be able to flip back the switch. Instead it should flip back itself (removing the teleport and placing the stone) after a certain ammount of time. After it automatically flipped back you can ofcourse use it again (starting the whole timer loop again).
The script I have so far is as thus:
Code:
function onUse(cid, item, frompos, item2, topos)
local pinkstonepos1 = {x=634, y=664, z=13, stackpos=1}
local timeToRemove = 5 --in seconds
local TeleportToPos = { x = 645, y = 660, z = 12, stackpos = 1 }
local TeleportInPos = { x = 636, y = 662, z = 13, stackpos = 1 }
local LeverPos = { x = 647, y = 663, z = 13, stackpos = 1 }
local pinkstone1 = getThingfromPos(pinkstonepos1)
local Teleport = getThingfromPos(TeleportInPos)
local Lever = getThingfromPos(LeverPos)
function doRemoveTeleport()
if Teleport.itemid == 1387 then
doRemoveItem(getThingfromPos(TeleportInPos).uid)
doSendMagicEffect(TeleportInPos, CONST_ME_POFF)
end
end
if item.itemid == 1945 then
doRemoveItem(pinkstone1.uid, 1)
doCreateTeleport(1387, TeleportToPos, TeleportInPos)
doSendMagicEffect(TeleportInPos, CONST_ME_TELEPORT)
doPlayerSendTextMessage(cid,22,"Click!")
elseif item.itemid == 1946 then
doCreateItem(1355, 1, pinkstonepos1)
doRemoveTeleport(1387, 1, Teleport)
doPlayerSendTextMessage(cid,22,"Click!")
end
end
And by the way, I'm using TFS 0.3 beta3 if this is of any importance.
It is probably easy as hell but like I mentioned I'm a bit rusty. Any help is appreciated.
[EDIT]
Thanks to the people posting their suggestions here (you're getting reps) I managed to get the code to fully work the way I wanted it to. This is what it looks like now:
PHP:
local pinkstonepos1 = {x=634, y=664, z=13}
local TeleportToPos = { x = 645, y = 660, z = 12}
local TeleportInPos = { x = 636, y = 662, z = 13}
local LeverPos = { x = 647, y = 663, z = 13}
local timeToRemove = 5 --in seconds
function onUse(cid, item, frompos, item2, topos)
local pinkstone1 = getTileItemById(pinkstonepos1, 1355)
local teleport = getTileItemById(TeleportInPos, 1387)
if item.itemid == 1945 then
doRemoveItem(pinkstone1.uid, 1)
doCreateTeleport(1387, TeleportToPos, TeleportInPos)
doSendMagicEffect(TeleportInPos, CONST_ME_TELEPORT)
doPlayerSendTextMessage(cid,22,"Click!")
addEvent(doRemoveTeleport, timeToRemove * 1000)
else if item.itemid == 1946 then
doPlayerSendCancel(cid,"Sorry, not possible.")
return 1
end
end
end
function doRemoveTeleport()
local pinkstone1 = getTileItemById(pinkstonepos1, 1355)
local teleport = getTileItemById(TeleportInPos, 1387)
local Lever = getTileItemById(LeverPos, 1946)
if teleport.uid > 0 then
doCreateItem(1355, 1, pinkstonepos1)
doRemoveItem(teleport.uid)
doSendMagicEffect(TeleportInPos, CONST_ME_POFF)
doTransformItem(Lever.uid, 1945)
end
end
Last edited: