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

Action [Tutorial] Mirror, mirror in my hand...v2.0

Zyntax

*WannaBe Scripter*
Joined
Jan 27, 2010
Messages
533
Reaction score
40
Location
Lua & XML Section
Hey guys!

Updates:

v2.0
Code:
Updated the whole tutorial to TFS0.3.5pl1
Advanced the script (Thanks to zakius!)
Added new screenshots
Minor bug fixing


I thought the community could use some inspiration about some
RPG stuff.
I would like to introduce the Magic Mirror to you.

I thought to give you some ideas on how to put a different feeling to your
server (except for the "ueSpam, r0xing x99999 exp, hanting" servers).

Well then, let's start!

What's up with this tutorial?
Easy explained: You're stuck in your path and you can only continue if you use the Magic Mirror to port into another time.
Activate something there and port back to see what happend!

A little picture story:

Oh Noes! I can't pass! But I got my Magic Mirror! Help me!
mirroree.jpg


Haha! GO Mirror GO!
usec.jpg


*Poff* Wooah! There's a switch! I'll use it!
teleg.jpg


No kidding! There's a bridge! I can continue!
endw.jpg


Well, that's the end of the story and the lucky player can continue
on his mission.


Setup & Scripts

As I said in the beginning, we will only need 2 scripts for this.
But first off all we should prepare our location:

setupr.jpg


The idea is very simple:
Draw a specific location in "light-style"
(for example, a good looking house, naturefilled mountains, ...)
Copy the area (or create a new one) which looks exact the same, just in "dark-style"
(for example, broken walls, rotten mountains, ...)

Now write down every position I marked in the picture above:
fromPos1 = {x= , y= }
fromPos2 = {x= , y= }
LeverID, Bridge and so on...

Sidenote: if you don't want to map a lever and move a bridge, then be original
and think of something else, you're free to do that :D


If you have all those positions, adjust them in the scripts below:

%data/actions/scripts/tools
create a new file called mirror.lua

Lua:
----------------------------------------------------
---------<<< Area Teleportation Script >>>----------
-----------------<<< made by >>>--------------------
-------------<<< zakius & Zyntax >>>----------------
--------------<<< @ OTLand.net  >>>-----------------
----------------------------------------------------
local config ={	
	       array={
		      [1]={
		           frompos={x=589, y=583},
			   topos={x=594, y=586},
			   z = 7,
			   targetarray=2
			  },
		      [2]={
			   frompos={x=615, y=584},
			   topos={x=620, y=587},
			   z = 7,
			   targetarray=1	
			  },
		--EXAMPLE AREA:
		    --[3]={
		    --	   frompos={x=XXX, y=XXX},
		    --	   topos={x=XXX, y=XXX},
		    --	   z=X,
		    --	   targetarray=X
		    --    },
		 },		
	
	actionID = 2020,  --Write your actionID of your Item
	teletime = 5 --Time in seconds when the player gets teleportet
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	
-- DO NOT EDIT THE LINES BELOW (unless you know what you're doing)--
	local failure = true
	local user = getPlayerName(cid)
	    if item.actionid == config.actionID then
		for i = 1, #config.array do
		local z = config.array[i].z
		local ax = 0
                  for x = config.array[i].frompos.x, config.array[i].topos.x do
		    local ay = 0
                      for y = config.array[i].frompos.y, config.array[i].topos.y do
			 if (isPlayer(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
			      if(user == getPlayerName(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
                                doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
				failure = false
                                addEvent(tele, config.teletime * 1000, cid, user, ax, ay, i)
                                break
                        end
                    end
                    ay = ay + 1
                end
                ax = ax + 1
            end
          end
	end
    if (failure) then
        doPlayerSendCancel(cid, 'You cannot use the mirror here.')
    end
	return true
end
function tele(cid, user, ax, ay, i)
	local target=config.array[i].targetarray
	local topos={x=config.array[target].frompos.x+ax , y=config.array[target].frompos.y+ay, z=config.array[target].z}
	doTeleportThing(cid, topos)
	doSendMagicEffect(topos, CONST_ME_ENERGYAREA)
	doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end

IMPORTANT:
The script checks all AREAS which you defined in the array in the script.
Make sure to write down the correct fromPos and toPos coordinates!
TARGETARRAY:
If your starting position = area1 and you want to teleport to your
second area (fromPos2,toPos2) then edit targetarray = 2!
If you want to port from area1 to area3 edit targetarray = 3!
If you want to teleport between different z coordinates just edit
the z = value.
Another feature:
If you port from area1 square 2,4 then you will be ported to
area2 square 2,4

You can also draw 10 areas and adjust the script to check all those
areas if the user = Player who stands in the specific area.

%data/actions/action.xml add this line:

Lua:
<action actionid="2020" event="script" value="tools/mirror.lua"/>

Sidenote: You have to put the same actionId to your Item which
you want to be used in order to teleport!
I took a mirror because it reminds me at Zelda - A Link to the past!


Creating & Removing the Bridge

That's an easy one aswell.
Write down the positions where the bridge should be created
and add them in the config:
[1] = first position
[2] = second position
and so on...

%data/actions/scripts/tools create a new file and name it bridge.lua

Lua:
local config = {
		 bridgeId = 3764, --ID of the bridge
		 reset = 30, --ResetTime in seconds
		 pos = { 
			 [1]= {x=591, y=588, z=7, stackpos=1},
			 [2]= {x=591, y=589, z=7, stackpos=1},
			 [3]= {x=591, y=590, z=7, stackpos=1},
			 [4]= {x=591, y=591, z=7, stackpos=1},
			 [5]= {x=591, y=592, z=7, stackpos=1}
		       }
		}


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

	if item.uid == 4011 then
	  for i = 1, #config.pos do
	    doSendMagicEffect(config.pos[i], CONST_ME_ENERGYAREA)
	    doCreateItem(config.bridgeId, config.pos[i])
	  end
	  doPlayerSendTextMessage(cid, 22, 'Something happend in the light world!\nCheck it out!')
	  doTransformItem(item.uid, item.itemid + 1)
	  addEvent(resetbridge, config.reset * 1000, item)	
	
	elseif item.itemid == 1946 then
	  doPlayerSendCancel(cid, 'Sorry not possible')
	end
 return 1
end

function resetbridge(item)
	for i = 1, #config.pos do
		doRemoveItem(getTileItemById(config.pos[i], config.bridgeId).uid)
		doSendMagicEffect(config.pos[i], CONST_ME_ENERGYAREA)
	end
	doTransformItem(item.uid, item.itemid)
end


And now for the last part,

%data/actions/action.xml add this line:

Lua:
<action uniqueid="4011" event="script" value="tools/bridge.lua"/>


You successfully implemented RPG feeling! :peace:


Sidenote:
If you find any bugs, mistakes, undeclared sections or any
other failures then post them right away!
I'm not perfect so mistakes are common :$

Credits:

Credits goes to -> Zakius (thanks for your great help with the script!)

So far, I hope that I inspired some scripters/mappers out there!

Regards,

Zyntax
 
Last edited:
fixed the "use on ground" bug, but player still can drop mirror after using it and will be teleported, trying to do something with it too
Code:
local config =
{	array =
	{
		[1] =
		{
			frompos = {x = 896, y = 1173},
			topos = {x = 903, y = 1177},
			z = 7,
			targetarray = 2
		},
		[2] =
		{
			frompos = {x = 920, y = 1172},
			topos = {x = 927, y = 1176},
			z = 7,
			targetarray = 1	
		},
    },		
	teletime = 5, --Time in seconds when the player gets teleportet
}
local function tele(cid, user, ax, ay, i, item)
	local target = config.array[i].targetarray
	local topos = {x = config.array[target].frompos.x + ax , y = config.array[target].frompos.y + ay, z = config.array[target].z}
	doTeleportThing(cid, topos)
	doSendMagicEffect(topos, CONST_ME_ENERGYAREA)
	doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local failure = true
	local user = getPlayerName(cid)
    if item.itemid == 2560 and item.actionid == 2020 then
	if getThingPosition(item.uid).stackpos==-1 then
		for i = 1, #config.array do
			local z = config.array[i].z
			local ax = 0
            for x = config.array[i].frompos.x, config.array[i].topos.x do
				local ay = 0
                for y = config.array[i].frompos.y, config.array[i].topos.y do
				    if (isPlayer(getThingFromPos({x = x, y = y, z = z, stackpos = 253}).uid)) then
					        if(user == getPlayerName(getThingFromPos({x = x, y = y, z = z, stackpos = 253}).uid)) then
                            doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
							failure = false
                            addEvent(tele, config.teletime * 1000, cid, user, ax, ay, i)
                            break
                        end
                    end
                    ay = ay + 1
                end
                ax = ax + 1
            end
		end
	end
	end
    if (failure) then
        doPlayerSendCancel(cid, 'You cannot use the mirror here.')
    end
	return true
end
 
Last edited:
another siked rpg script! keep em coming there looking nice =)!
lmaoo and yea the scripts arent crazy hard lol there actually basic its more the creativeness than the script itself with the story behind it nice job!
 
really usefull function could be sth like teleport player from area to area:
you select two areas of same shape and size, and if player is on 1,1 sqm of first area appears on 1,1 sqm of second one, if he is on 3,5 sqm of first area appears on 3,5 sqm of second one.
Oh, I have idea how to do it :D

I'll post it here soon
 
not tested(I can try making something with it tommorow)
about optimizing: I guess there is a isPlayerInArea or something like this already, but using loops you can get coords (I mean x and y from upper left corner) so for this usage loops are better(more realistic feeling)
Code:
local config =
{
	teletime = 5, --Time in seconds when the player gets teleportet
    fromPos1 = {x=588, y=583}, --See picture above
    toPos1 = {x=595, y=587},
    fromPos2 = {x=617, y=586},
    toPos2 = {x=619, y=587},
	z = 7
}
                               
function onUse(cid, item, fromPosition, itemEx, toPosition)

local failure = true
local user = getPlayerName(cid)
local z = config.z
local tox = 0
local toy = 0
		if item.itemid == 2560 and item.actionid == 2020 then
			for x = config.fromPos1.x, config.toPos1.x do
				for y = config.fromPos1.y, config.toPos1.y do
					if (isPlayer(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid) == 1) then
						if(user == getPlayerName(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
							doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
							failure = false
							addEvent(teleshadow1, config.teletime * 1000, cid, user)
							break
						end
					end
					local toy = toy + 1
				end
				local tox = tox + 1
			end
			local tox = 0
			local toy = 0
			for x = config.fromPos2.x, config.toPos2.x do
				for y = config.fromPos2.y, config.toPos2.y do
					if (isPlayer(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid) == 1) then
						if(user == getPlayerName(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
							doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
							failure = false
							addEvent(telelight1, config.teletime * 1000, cid, user)
							break
						end
					end
					local toy = toy + 1
				end
				local tox = tox + 1
            end        
        end
        if failure == true then
           doPlayerSendCancel(cid, 'You cannot use the mirror here.')
        end
        return 1
end

function teleshadow1(cid, user)
doTeleportThing(cid, {fromPos2.x+tox , fromPos2.y+toy, config.z})
doSendMagicEffect(config.teleshadow1, CONST_ME_ENERGYAREA)
doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end

function telelight1(cid, user)
doTeleportThing(cid, {fromPos1.x+tox , fromPos1.y+toy, config.z})
doSendMagicEffect(config.telelight1, CONST_ME_ENERGYAREA)
doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end

should work if I didn't missed soething
 
Yeah, right...
what doesnt work?
ah I found one thing ;d sec
Code:
local config =
{
	teletime = 5, --Time in seconds when the player gets teleportet
    fromPos1 = {x=588, y=583}, --See picture above
    toPos1 = {x=595, y=587},
    fromPos2 = {x=617, y=586},
    toPos2 = {x=619, y=587},
	z = 7
}

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

local failure = true
local user = getPlayerName(cid)
local z = config.z
local tox = 0
local toy = 0
	if item.itemid == 2560 and item.actionid == 2020 then
		for x = config.fromPos1.x, config.toPos1.x do
			for y = config.fromPos1.y, config.toPos1.y do
				if (isPlayer(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid) == 1) then
					if(user == getPlayerName(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
						doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
						failure = false
						addEvent(teleshadow1, config.teletime * 1000, cid, user)
						break
					end
				end
				local toy = toy + 1
			end
			local tox = tox + 1
		end
		if (failure) then
			local tox = 0
			local toy = 0
			for x = config.fromPos2.x, config.toPos2.x do
				for y = config.fromPos2.y, config.toPos2.y do
					if (isPlayer(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid) == 1) then
						if(user == getPlayerName(getThingFromPos({x=x, y=y, z=z, stackpos=253}).uid)) then
							doPlayerSay(cid, 'Mirror, mirror in my hand\nbring me to the other land!', 19)
							failure = false
							addEvent(telelight1, config.teletime * 1000, cid, user)
							break
						end
					end
					local toy = toy + 1
				end
				local tox = tox + 1
			end   
		end
    end
    if (failure) then
        doPlayerSendCancel(cid, 'You cannot use the mirror here.')
    end
return 1
end

function teleshadow1(cid, user)
doTeleportThing(cid, {fromPos2.x+tox , fromPos2.y+toy, config.z})
doSendMagicEffect(config.teleshadow1, CONST_ME_ENERGYAREA)
doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end

function telelight1(cid, user)
doTeleportThing(cid, {fromPos1.x+tox2 , fromPos1.y+toy2, config.z})
doSendMagicEffect(config.telelight1, CONST_ME_ENERGYAREA)
doPlayerSendTextMessage(cid, 21, 'Your wish is my order, Master '..user..'.')
end
now?
 
Last edited:
hmm, so change back if(failure) to if failure == true ;f
wanted to shorten a bit, but I guess 0 is false and anything other true in that type of condition

ahh, also you should put tox and toy as parameters

I got to go now, but you should figure out what to do if something left
 
Last edited:
looks good for me ;f
one thing is that you can use ax and ay again in second area ckeck, because its made only if failure==true, just reset them back to 0.

Maybe add me to msn, I dont like using forum as chat ;d
 
Ok, ok, I'm downloading MSN right now.

By the way, the telepositions in y direction are totally screwed ;)

This is going to be a looong night :peace:
 
It's creative, but could be improved a bit. For example, someone using the mirror on the ground will be trapped in the "dark" world. Also, you didn't consider people being trapped on disappearing tiles...

It's a good base for some rpg quests though, people should edit it for their own needs after all.
 
damn right :D
but I dont know how to chech if player have in slot/bp item.uid
ok, I know :D
will post here fixed one soon and pm zyntax with it

emm, actually I don't know if my idea will work :D
Also it have to check again in the teleporting finction(player can drop mirror after using it)
It will be long day(again):D
 
Last edited:
It's creative, but could be improved a bit. For example, someone using the mirror on the ground will be trapped in the "dark" world. Also, you didn't consider people being trapped on disappearing tiles...

It's a good base for some rpg quests though, people should edit it for their own needs after all.

Hmm, yeah you got your point there.

Well for the "use the mirror on the ground" I'll use a getPlayerItemCount(cid, itemID) to check if he has the mirror in his backpack.

But, he could throw the mirror away while he's waiting for the teleport :eek:

Hmpf, source edit -> Mirror = Undropable :p
 
Back
Top