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

MoveEvent Random teleport and check if player is on sqm

Thetobbe

New Member
Joined
Aug 12, 2008
Messages
5
Reaction score
0
Hello!
I'm trying to make so then a player steps on a sqm he gets teleported to random places. And after looking at some ppls code at the forum i got that to work. But if a player already standing on the sqm there the next is about to get teleported to i want it to randomize again so the player gets to a empty spot.
Hope you understand what i mean!

Here is my code so far:
Code:
function onStepIn(cid, item, pos)
if cid > 0 then
	if item.actionid == 30001 then
		if(item.itemid == 5024) then
			local location = {
				{x=480, y=463, z=8},
				{x=484, y=463, z=8},
				{x=488, y=463, z=8},
				{x=492, y=463, z=8},
				{x=496, y=463, z=8},
				{x=500, y=463, z=8}
			}
			lugar = math.random(1,6)
			doTeleportThing(cid,location[lugar])
			doPlayerSendTextMessage(cid,22,"Welcome to the training monks! To get out go in to the blue teleport.")
			doPlayerSendTextMessage(cid,21,"Do not macro train, you will get banned!")
		end
	end
end
end
 
After spending like 6h yesterday i got everything to work.
It works like this, First the player walks into a tp and comes to the training places. (there all the trainers are), then he walks into a tp that select a free training spot. If there is no empty training spot he gets teleported to the "exit" spot and get a error message about all the training spots are full.

The script: (Create a text file with the name training monks.lua in movements\scripts)
Code:
function onStepIn(cid, item, pos)
if cid > 0 then
	if item.actionid == 30001 then
		if(item.itemid == 5024) then
			local location = {
				{x=480, y=463, z=8, stackpos=253},
				{x=484, y=463, z=8, stackpos=253},
				{x=488, y=463, z=8, stackpos=253},
				{x=492, y=463, z=8, stackpos=253},
				{x=496, y=463, z=8, stackpos=253},
				{x=500, y=463, z=8, stackpos=253},
				{x=480, y=469, z=8, stackpos=253},
				{x=484, y=469, z=8, stackpos=253},
				{x=488, y=469, z=8, stackpos=253},
				{x=492, y=469, z=8, stackpos=253},
				{x=496, y=469, z=8, stackpos=253},
				{x=500, y=469, z=8, stackpos=253},
				{x=480, y=473, z=8, stackpos=253},
				{x=484, y=473, z=8, stackpos=253},
				{x=488, y=473, z=8, stackpos=253},
				{x=492, y=473, z=8, stackpos=253},
				{x=496, y=473, z=8, stackpos=253},
				{x=500, y=473, z=8, stackpos=253},
				{x=480, y=479, z=8, stackpos=253},
				{x=484, y=479, z=8, stackpos=253},
				{x=488, y=479, z=8, stackpos=253},
				{x=492, y=479, z=8, stackpos=253},
				{x=496, y=479, z=8, stackpos=253},
				{x=500, y=479, z=8, stackpos=253}
			}
			playerposition = {x=470, y=471, z=8, stackpos=253}
			i2 = 0
			local playerteleported = 1
			for i=0,23 do
				i2 = i2 +1
				getplayer = getThingfromPos(location[i2])
				if getplayer.itemid > 0 then
					playerteleported = 1
				else
					doTeleportThing(cid,location[i2])
					doPlayerSendTextMessage(cid,22,"Welcome to the training monks! To get out go in to the blue teleport. (Made by TheTobbe)")
					doPlayerSendTextMessage(cid,21,"Do not macro train, you will get banned!")
					playerteleported = 0
					break
				end
			end
			if playerteleported > 0 then
				doTeleportThing(cid,{x=469, y=471, z=8})
				doPlayerSendTextMessage(cid,22,"There was no empty training spot.")
			end
		end
	end
end
end
(There is 24 training spots!)

Put this in movements\movements.xml
Code:
<movevent event="StepIn" itemid="5024" script="training monks.lua" />
Here is some pictures of it :)


 
Last edited:
Haha thanks :)
If training spot 1 is empty the player will always be teleported to that one, if its used he will be teleported to training spot 2 and so on.

But there is one small problem, then how can i stop people from throwing stuff at the teleporter becouse atm the things they throw will be "over" the teleporter.
 
Last edited:
Haha thanks :)
If training spot 1 is empty the player will always be teleported to that one, if its used he will be teleported to training spot 2 and so on.

But there is one small problem, then how can i stop people from throwing stuff at the teleporter becouse atm the things they throw will be "over" the teleporter.
Make it into a tile instead of a teleporter?
 
i cant se the pic -.-
(There is 24 training spots!)

Put this in movements\movements.xml

Code:
<movevent event="StepIn" itemid="5024" script="training monks.lua" />
Here is some pictures of it
 
After spending like 6h yesterday i got everything to work.
It works like this, First the player walks into a tp and comes to the training places. (there all the trainers are), then he walks into a tp that select a free training spot. If there is no empty training spot he gets teleported to the "exit" spot and get a error message about all the training spots are full.

The script: (Create a text file with the name training monks.lua in movements\scripts)
Code:
function onStepIn(cid, item, pos)
if cid > 0 then
	if item.actionid == 30001 then
		if(item.itemid == 5024) then
			local location = {
				{x=480, y=463, z=8, stackpos=253},
				{x=484, y=463, z=8, stackpos=253},
				{x=488, y=463, z=8, stackpos=253},
				{x=492, y=463, z=8, stackpos=253},
				{x=496, y=463, z=8, stackpos=253},
				{x=500, y=463, z=8, stackpos=253},
				{x=480, y=469, z=8, stackpos=253},
				{x=484, y=469, z=8, stackpos=253},
				{x=488, y=469, z=8, stackpos=253},
				{x=492, y=469, z=8, stackpos=253},
				{x=496, y=469, z=8, stackpos=253},
				{x=500, y=469, z=8, stackpos=253},
				{x=480, y=473, z=8, stackpos=253},
				{x=484, y=473, z=8, stackpos=253},
				{x=488, y=473, z=8, stackpos=253},
				{x=492, y=473, z=8, stackpos=253},
				{x=496, y=473, z=8, stackpos=253},
				{x=500, y=473, z=8, stackpos=253},
				{x=480, y=479, z=8, stackpos=253},
				{x=484, y=479, z=8, stackpos=253},
				{x=488, y=479, z=8, stackpos=253},
				{x=492, y=479, z=8, stackpos=253},
				{x=496, y=479, z=8, stackpos=253},
				{x=500, y=479, z=8, stackpos=253}
			}
			playerposition = {x=470, y=471, z=8, stackpos=253}
			i2 = 0
			local playerteleported = 1
			for i=0,23 do
				i2 = i2 +1
				getplayer = getThingfromPos(location[i2])
				if getplayer.itemid > 0 then
					playerteleported = 1
				else
					doTeleportThing(cid,location[i2])
					doPlayerSendTextMessage(cid,22,"Welcome to the training monks! To get out go in to the blue teleport. (Made by TheTobbe)")
					doPlayerSendTextMessage(cid,21,"Do not macro train, you will get banned!")
					playerteleported = 0
					break
				end
			end
			if playerteleported > 0 then
				doTeleportThing(cid,{x=469, y=471, z=8})
				doPlayerSendTextMessage(cid,22,"There was no empty training spot.")
			end
		end
	end
end
end
(There is 24 training spots!)

Put this in movements\movements.xml
Code:
<movevent event="StepIn" itemid="5024" script="training monks.lua" />
Hello. Im using this script on TFS 0.3.4pl2 and I did a little modification to it. I just wanted to help you make your code a little better. First things first:
Code:
<movevent type="StepIn" actionid="30001" event="script" value="training monks.lua" />
By changing it from itemid="5024" to actionid="30001" you make the script call only when players step in a portal with action 30001 instead of anytime they step in item 5024. Because of that, we can also eliminate
Code:
 	if item.actionid == 30001 then
		if(item.itemid == 5024) then
because we nolonger need to check the action or the itemid since movements.xml is doing that for us. Remember to remove the 2 "Ends" at the end of the file too!

Next thing we can get rid of is
Code:
if cid > 0 then
and also its "End" at the end of the file. The movement checks for a CID onStepIn so we don't have to check it here, either :)

Under your locations, the line
Code:
playerposition = {x=470, y=471, z=8, stackpos=253}
isn't used or called anywhere, this line can be completely removed.

Next we have some optimizations in your "for" statement. You can remove
Code:
i2 = 0
from the script as well. Your for statement has a dedicated number (23). We can set it to automatically get the number of locations by itself by changing
Code:
for i=0,23 do
to
Code:
 for i=1,#location
Next we can remove
Code:
i2 = i2 +1
because we're getting rid of i2 completely. On the next line we can change
Code:
getplayer = getThingfromPos(location[i2])
to
Code:
getplayer = getThingfromPos(location[i])
The next line we wanna change is the i2 in line
Code:
doTeleportThing(cid,location[i2])
to
Code:
doTeleportThing(cid,location[i])
since we're removing i2 from the script.

This post is gonna be really hard to read and I apologize. I will post a complete script in the next post.
 
movements.xml
Code:
<movevent type="StepIn" actionid="30001" event="script" value="trainingmonks.lua" />

trainingmonks.lua
Code:
function onStepIn(cid, item, pos)
	local location = {
		{x=480, y=463, z=8, stackpos=253}, -- Location 1
		{x=484, y=463, z=8, stackpos=253}, -- Location 2
		{x=488, y=463, z=8, stackpos=253}, -- Location 3
		{x=492, y=463, z=8, stackpos=253}, -- Location 4
		{x=496, y=463, z=8, stackpos=253},
		{x=500, y=463, z=8, stackpos=253},
		{x=480, y=469, z=8, stackpos=253},
		{x=484, y=469, z=8, stackpos=253},
		{x=488, y=469, z=8, stackpos=253},
		{x=492, y=469, z=8, stackpos=253},
		{x=496, y=469, z=8, stackpos=253},
		{x=500, y=469, z=8, stackpos=253},
		{x=480, y=473, z=8, stackpos=253},
		{x=484, y=473, z=8, stackpos=253},
		{x=488, y=473, z=8, stackpos=253},
		{x=492, y=473, z=8, stackpos=253},
		{x=496, y=473, z=8, stackpos=253},
		{x=500, y=473, z=8, stackpos=253},
		{x=480, y=479, z=8, stackpos=253},
		{x=484, y=479, z=8, stackpos=253},
		{x=488, y=479, z=8, stackpos=253},
		{x=492, y=479, z=8, stackpos=253},
		{x=496, y=479, z=8, stackpos=253},
		{x=500, y=479, z=8, stackpos=253} -- Last Location. Add more locations above if needed or remove. Keep this line as last one.
	}

	
	for i=1,#location do
		getplayer = getThingfromPos(location[i])
		if getplayer.itemid > 0 then
			playerteleported = 1
		else
			doTeleportThing(cid,location[i])
			doPlayerSendTextMessage(cid,22,"Welcome to the training monks! Step in the portal to leave. (Made by TheTobbe)")
			doPlayerSendTextMessage(cid,21,"Do not macro train, you will get banned!")
			playerteleported = 0
			break
		end
	end
	
	if playerteleported > 0 then
		doTeleportThing(cid,{x=469, y=471, z=8})
		doPlayerSendTextMessage(cid,22,"There was no empty training spot.")
	end
end
 
Last edited:
Code:
local location = {
	{x=480, y=463, z=8},
	{x=484, y=463, z=8},
	{x=488, y=463, z=8}, 
	{x=492, y=463, z=8},
	{x=496, y=463, z=8},
	{x=500, y=463, z=8},
	{x=480, y=469, z=8},
	{x=484, y=469, z=8},
	{x=488, y=469, z=8},
	{x=492, y=469, z=8},
	{x=496, y=469, z=8},
	{x=500, y=469, z=8},
	{x=480, y=473, z=8},
	{x=484, y=473, z=8},
	{x=488, y=473, z=8},
	{x=492, y=473, z=8},
	{x=496, y=473, z=8},
	{x=500, y=473, z=8},
	{x=480, y=479, z=8},
	{x=484, y=479, z=8},
	{x=488, y=479, z=8},
	{x=492, y=479, z=8},
	{x=496, y=479, z=8},
	{x=500, y=479, z=8}
}
function onStepIn(cid, item, pos)
	for i = 1, #location do
		if getTopCreature(location[i]).uid > 0 then
			playerteleported = 1
		else
			doTeleportThing(cid,location[i])
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the training monks! Step in the portal to leave. (Made by TheTobbe)")
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "Do not macro train, you will get banned!")
			playerteleported = 0
			break
		end
	end
	if playerteleported > 0 then
		doTeleportThing(cid, {x=469, y=471, z=8})
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There was no empty training spot.")
	end
	return TRUE
end
:D
 
Is it possible that a spell (not a talkaction) teleports you to these training monks and also check if there's a player standing there?
 
You can just do it the same way but then with function onCastSpell instead of function onStepIn.
 
Well, I don't get any errrors but the spell doesn't work... here's the script
Code:
function onCastSpell(cid, item, pos)
if cid > 0 then
    if item.actionid == 30001 then
        if(item.itemid == 5024) then
            local location = {
                {x=1000, y=1000, z=7, stackpos=253},
                {x=484, y=463, z=8, stackpos=253},
                {x=488, y=463, z=8, stackpos=253},
                {x=492, y=463, z=8, stackpos=253},
                {x=496, y=463, z=8, stackpos=253},
                {x=500, y=463, z=8, stackpos=253},
                {x=480, y=469, z=8, stackpos=253},
                {x=484, y=469, z=8, stackpos=253},
                {x=488, y=469, z=8, stackpos=253},
                {x=492, y=469, z=8, stackpos=253},
                {x=496, y=469, z=8, stackpos=253},
                {x=500, y=469, z=8, stackpos=253},
                {x=480, y=473, z=8, stackpos=253},
                {x=484, y=473, z=8, stackpos=253},
                {x=488, y=473, z=8, stackpos=253},
                {x=492, y=473, z=8, stackpos=253},
                {x=496, y=473, z=8, stackpos=253},
                {x=500, y=473, z=8, stackpos=253},
                {x=480, y=479, z=8, stackpos=253},
                {x=484, y=479, z=8, stackpos=253},
                {x=488, y=479, z=8, stackpos=253},
                {x=492, y=479, z=8, stackpos=253},
                {x=496, y=479, z=8, stackpos=253},
                {x=500, y=479, z=8, stackpos=253}
            }
            playerposition = {x=470, y=471, z=8, stackpos=253}
            i2 = 0
            local playerteleported = 1
            for i=0,23 do
                i2 = i2 +1
                getplayer = getThingfromPos(location[i2])
                if getplayer.itemid > 0 then
                    playerteleported = 1
                else
                    doTeleportThing(cid,location[i2])
                    doPlayerSendTextMessage(cid,22,"Welcome to the training monks! To get out go in to the blue teleport. (Made by TheTobbe)")
                    doPlayerSendTextMessage(cid,21,"Do not macro train, you will get banned!")
                    playerteleported = 0
                    break
                end
            end
            if playerteleported > 0 then
                doTeleportThing(cid,{x=469, y=471, z=8})
                doPlayerSendTextMessage(cid,22,"There was no empty training spot.")
            end
        end
    end
end
end

Already changed locations.
Appreciate your help :)
 
Ok, I tried to fix it so i removed " if item.actionid == 30001 then- if(item.itemid == 5024) then" and it teleported me to the 1st location ... but if there's a player on it, it tells me the message which is "Do not macro train, you will get banned!" and it doesn't teleport me to the 2nd location... anyone can help?
what do I have to change?
 
trainingmonks.lua:37: in function <data/movements/scripts/trainingmonks.lua:1>
 
Back
Top