• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Searching for a movement for training rooms, trainers depends on player's vocation.

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Reaction score
14
Location
Poland
Hello :)

I need a movement, which onStepIn summons 2 training monks in a room like this:
.___.
|M.M|
|. P .|
|-D-|


M - Training Monk
P - Player
D - Door
. - Stone


If player is paladin, it summons Paladin Monk, if knight, it summons Knight Monk and the same for sorcerer and druid.

And onStepOut deletes both monks (names depends on player's vocation).


Thanks,
Hermes
 
It's working! Rep+ added :>! But hm, look. onStepIn and onStepOut can be placed in one file. Player log off = stepOut.

How can I optimize this script to more short state?

And what about adding a line, if server can't remove trainer (for example it's killed) it's not printing lua script error in console?

Code:
function onStepIn(cid, item, toPosition, fromPosition)

local trainers = {
	["Sorcerer Trainer"] = 1,
	["Druid Trainer"] = 2,
	["Paladin Trainer"] = 3,
	["Knight Trainer"] = 4
}

local positions = {
	[4000] = { {x = toPosition.x-1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y-1, z = toPosition.z, stackpos = 253} }, -- North
	[4001] = { {x = toPosition.x-1, y = toPosition.y+1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }, -- South
	[4002] = { {x = toPosition.x+1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }, -- East
	[4003] = { {x = toPosition.x-1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x-1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }  -- West
}



	for trainer, vocation in pairs(trainers) do
				if getPlayerVocation(cid) == vocation then
					for action, position in pairs(positions) do
						if isPlayer(getThingfromPos(getCreaturePosition(cid)).uid) == TRUE then
							if item.actionid == action then
								doSummonCreature(trainer, position[1])
								doSummonCreature(trainer, position[2])
							break
							end
						end
					
					end
				end


	end
	return TRUE
end

function onStepOut(cid, item, toPosition, fromPosition)

local trainers = {
	["Sorcerer Trainer"] = 1,
	["Druid Trainer"] = 2,
	["Paladin Trainer"] = 3,
	["Knight Trainer"] = 4
}


local positions = {
	[4000] = { {x = toPosition.x-1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y-1, z = toPosition.z, stackpos = 253} }, -- North
	[4001] = { {x = toPosition.x-1, y = toPosition.y+1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }, -- South
	[4002] = { {x = toPosition.x+1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x+1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }, -- East
	[4003] = { {x = toPosition.x-1, y = toPosition.y-1, z = toPosition.z, stackpos = 253}, {x = toPosition.x-1, y = toPosition.y+1, z = toPosition.z, stackpos = 253} }  -- West
}


	for trainer, vocation in pairs(trainers) do
				if getPlayerVocation(cid) == vocation then
					for action, position in pairs(positions) do
						if isPlayer(getThingfromPos(getCreaturePosition(cid)).uid) == TRUE then
							if item.actionid == action then
							rem = getThingfromPos(position[1])
							rem2 = getThingfromPos(position[2])
							doRemoveCreature(rem.uid)
							doRemoveCreature(rem2.uid)
							break
							end
						end
					
					end
				end


	end
	return TRUE
end
 
Yea but those messages are messy a bit :P if I insert:

Code:
else
doPlayerSendCancel(cid,"Trainers couldn't be removed.")

Will it stop printing those errors in console?

BTW. these locals are written twice in each function. Both onStepIn and onStepOut. :P
 
Last edited:
Back
Top