• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Trainer Egg

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,670
Solutions
125
Reaction score
1,117
Location
Germany
GitHub
slawkens
Requested from here: http://otland.net/f132/request-trainer-egg-30702/

How it works: You're placing item on floor (It won't work in backpack!), and you use it. Monster is summoned, money removed.

WARNING: Only TFS 0.3+

data/actions/scripts/trainer_eqq.lua
Code:
local config = {
	summonName = "Training Monk",
	cost = 10000		-- in gp, put 0 to disable
	remove = "yes"		-- should egg by removed after use?
}

config.remove = getBooleanFromString(config.remove)
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local pos = getCreaturePosition(cid)
	if(pos.x == CONTAINER_POSITION) then
		doPlayerSendCancel(cid, "Put item on the floor first.")
		return TRUE
	end

	if(config.cost > 0 and getPlayerMoney(cid) < config.cost) then
		doPlayerSendCancel(cid, "Not enought money, trainer cost " .. config.cost .. " gp's.")
		return TRUE
	end

	local ret, effect = doSummonMonster(cid, config.summonName), CONST_ME_MAGIC_RED
	if(ret ~= RETURNVALUE_NOERROR) then
		effect = CONST_ME_POFF
		doPlayerSendDefaultCancel(cid, ret)
	else
		if(config.cost > 0) then
			doPlayerRemoveMoney(cid, config.cost)
		end
		if(config.remove == TRUE) then
			doRemoveItem(item.uid)
		end
	end

	doSendMagicEffect(pos, effect)
	return TRUE
end

Remember to add new line in actions.xml!
 
Last edited:
when i try to use
[28/04/2009 08:56:56] data/actions/scripts/traineregg.lua:18: attempt to call global 'doSummonMonster' (a nil value)
[28/04/2009 08:56:56] stack traceback:
[28/04/2009 08:56:56] data/actions/scripts/traineregg.lua:18: in function <data/actions/scripts/traineregg.lua:6>
 
I don't see why it shouldn't work on 0.2, too:
PHP:
local config = {
	summonName = "Training Monk",
	cost = 10000 --in gp, put 0 to disable
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local pos = getCreaturePosition(cid)
	if(pos.x == CONTAINER_POSITION) then
		doPlayerSendCancel(cid, "Put item on the floor first.")
		return TRUE
	end

	if(config.cost > 0 and getPlayerMoney(cid) < config.cost) then
		doPlayerSendCancel(cid, "Not enought money, trainer cost " .. config.cost .. " gp's.")
		return TRUE
	end

	local ret, effect = doSummonCreature(config.summonName, toPosition), CONST_ME_MAGIC_RED
	if(ret ~= RETURNVALUE_NOERROR) then
		effect = CONST_ME_POFF
		doPlayerSendDefaultCancel(cid, ret)
	else
		if(config.cost > 0) then
			doPlayerRemoveMoney(cid, config.cost)
		end
		doRemoveItem(item.uid)
	end

	doSendMagicEffect(pos, effect)
	return TRUE
end

PHP:
	local ret, effect = doSummonMonster(cid, config.summonName), CONST_ME_MAGIC_RED
to
PHP:
	local ret, effect = doSummonCreature(config.summonName, toPosition), CONST_ME_MAGIC_RED
 
12/08/2009 10:51:17] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/hydra_eqq.lua)
[12/08/2009 10:51:17] data/actions/scripts/hydra_eqq.lua:4: '}' expected (to close '{' at line 1) near 'remove'

local config = {
summonName = "hydra",
cost = 100 -- in gp, put 0 to disable
remove = "yes" -- should egg by removed after use?
}

config.remove = getBooleanFromString(config.remove)
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = getCreaturePosition(cid)
if(pos.x == CONTAINER_POSITION) then
doPlayerSendCancel(cid, "Put item on the floor first.")
return TRUE
end

if(config.cost > 0 and getPlayerMoney(cid) < config.cost) then
doPlayerSendCancel(cid, "Not enought money, trainer cost " .. config.cost .. " gp's.")
return TRUE
end

local ret, effect = doSummonCreature(config.summonName, toPosition), CONST_ME_MAGIC_RED
if(ret ~= RETURNVALUE_NOERROR) then
effect = CONST_ME_POFF
doPlayerSendDefaultCancel(cid, ret)
else
if(config.cost > 0) then
doPlayerRemoveMoney(cid, config.cost)
end
if(config.remove == TRUE) then
doRemoveItem(item.uid)
end
end

doSendMagicEffect(pos, effect)
return TRUE
end
 
Last edited:
Back
Top