Action Teleport To Temple Scroll

GangsteR

RPG Maker
Joined
Jul 1, 2007
Messages
815
Best answers
0
Reaction score
2
Location
Turkiye
Hi all!
I created new script!
When you use this scroll you will teleport to temple (or anywhere:p).
P.S: I am newbie at scripting! ;)

Create TPScroll.lua at your actions/scripts folder and copy this;
Just edit temple coords :thumbup: (if you want you can edit level and itemid too :p)

PHP:
local scroll = 6119
local temple = {x=xxx, y=xxx, z=x}
local level = 25

function onUse(cid, item, frompos, item2, topos)
    if item.itemid == scroll and getPlayerLevel(cid) >= level then
        doTeleportThing(cid, temple, TRUE)
        doSendMagicEffect(temple,10)
        doSendAnimatedText(temple, "You are in temple!", 5)
        doRemoveItem(cid, item.uid, 1)
    else
        doPlayerSendCancel(cid, "Sorry, your level must higher than 25!")
    end
return 1
end
And finally add this to actions.xml

Code:
<action itemid="6119" script="TPScroll.lua"/>
Comments are welcome! :thumbup:
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
TFS 0.3
Code:
function onUse(cid, item)
	if hasCondition(cid, CONDITION_INFIGHT) == TRUE then
		doPlayerSendCancel(cid, "You may not use this scroll while in-fight!")
		return FALSE
	end
	
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	return TRUE
end
It will teleport you to your temple.
 
OP
GangsteR

GangsteR

RPG Maker
Joined
Jul 1, 2007
Messages
815
Best answers
0
Reaction score
2
Location
Turkiye
since 0.2 haven't got getTownTemplePosition i created this :)
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
Try with this, I dont have 0.2 :mad:

data/functions.lua:
Code:
function getTownTemplePosition(townId)
	local towns = {
		[1] = { x = 100, y = 100, z = 7 },
		[2] = { x = 120, y = 130, z = 6 }
	}
	
	for k, v in pairs(towns) do
		if townId == k then
			return { v[1], v[2], v[3] }
		else
			return debugPrint("[GetTownTemplePosition]: Town not found.")
		end
	end
end
 

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
Why you write keys, not needed o.o

+ it's ipairs you should use x)

and in ur loop k[1], k[2], k[3] is nil :) you meant k.x or k["x"] but preferably just v :)

Code:
function getTownTemplePosition(townId)
	local towns = {
		{ x = 100, y = 100, z = 7 },
		{ x = 120, y = 130, z = 6 }
	}
	
	for k, v in ipairs(towns) do
		if townId == k then
			return v
		else
			return debugPrint("[GetTownTemplePosition]: Town not found.")
		end
	end
end
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
Why you write keys, not needed o.o

+ it's ipairs you should use x)

and in ur loop k[1], k[2], k[3] is nil :) you meant k.x or k["x"] but preferably just v :)

Code:
function getTownTemplePosition(townId)
	local towns = {
		{ x = 100, y = 100, z = 7 },
		{ x = 120, y = 130, z = 6 }
	}
	
	for k, v in ipairs(towns) do
		if townId == k then
			return v
		else
			return debugPrint("[GetTownTemplePosition]: Town not found.")
		end
	end
end
Okej, tank is you mi master :):):)
 

slawkens

Developer
Premium User
Joined
Aug 27, 2007
Messages
2,873
Best answers
60
Reaction score
389
Location
Germany
Hi masters, is this loop reeeeealy needed here? ; DD

return towns[townId] ~= nil and towns[townId] or LUA_ERROR
 

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
Hi masters, is this loop reeeeealy needed here? ; DD

return towns[townId] ~= nil and towns[townId] or LUA_ERROR
I only correct noobishness x) But I missed quite some noobishness o.o

elseif in loop -.- smartass x)
 
Last edited:

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Best answers
0
Reaction score
51
Location
Włocławek
lol, simply something it:
PHP:
function getTownTemplePosition(townId)
	local towns = {
		[1] = { x = 100, y = 100, z = 7 },
		[2] = { x = 120, y = 130, z = 6 }
	}
	if towns[townId] then
		return towns[townid]
	end
end
 

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
lol, simply something it:
PHP:
function getTownTemplePosition(townId)
	local towns = {
		[1] = { x = 100, y = 100, z = 7 },
		[2] = { x = 120, y = 130, z = 6 }
	}
	if towns[townId] then
		return towns[townid]
	end
end
yeah but more efficient to place it outside of the functions and possibly inside of a do-block ;>

Like
PHP:
do
	local towns = {
		[1] = { x = 100, y = 100, z = 7 },
		[2] = { x = 120, y = 130, z = 6 }
	}

	function getTownTemplePosition(townId)
		if(type(townId) ~= 'number') then
			error("luaGetTownTemplePosition: Expecting number for 'townId' (got " .. type(townId) .. ")", 2)
		end

		return towns[townId] or LUA_ERROR
	end
end
 

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Best answers
0
Reaction score
9
Location
NYC
How can i change it to not remove this item? Please!
 

Kanakashy

Twifysoft Designer
Joined
Jan 14, 2009
Messages
1,546
Best answers
0
Reaction score
39
Location
Puerto Rico
could u make that when u use the tpscroll appears a box naming the towns that u want to travel. its seem like a bit dificult my question but its not allways imposible.
 

Kanakashy

Twifysoft Designer
Joined
Jan 14, 2009
Messages
1,546
Best answers
0
Reaction score
39
Location
Puerto Rico
could u make that when u use the tpscroll appears a box naming the towns that u want to travel. its seem like a bit dificult my question but its not allways imposible.


srry for doble post idk wtf happen?
 

sikkee

New Member
Joined
Feb 27, 2010
Messages
89
Best answers
0
Reaction score
2
"Lua Script Error: [Action Interface]
data/actions/scripts/tpscroll.lua:eek:nUse

attempt to index a number value"


What is wrong? :(
 
Top