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

TalkAction Buy promotion!

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,667
Solutions
125
Reaction score
1,114
Location
Germany
GitHub
slawkens
This simple command allow player to buy promotion :rolleyes:

Works only on TFS 0.3.

data/talkactions/scripts/promotion.lua
Code:
local config = {
	promotion = 1,	-- promotion level, default = 1 . Ignore if you don't have new vocations.
	minLevel = 20,	-- Level needed to buy promotion
	cost = 20000, 	-- Promotion cost in gp
	premium = "yes"  -- is premium needed to buy promotion?
}

local disabledVocations = {0}

config.premium = getBooleanFromString(config.premium)

function onSay(cid, words, param)
	if(isInArray(disabledVocations, getPlayerVocation(cid)) == TRUE) then
		doPlayerSendCancel(cid, "Your vocation cannot buy promotion.")
	elseif(config.premium == TRUE and isPremium(cid) == FALSE) then
		doPlayerSendCancel(cid, "You need a premium account.")
	elseif(getPlayerPromotionLevel(cid) >= config.promotion) then
		doPlayerSendCancel(cid, "You are already promoted.")
	elseif(getPlayerLevel(cid) < config.minLevel) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need " .. config.minLevel .. " to get promotion.")
	elseif(doPlayerRemoveMoney(cid, config.cost) ~= TRUE) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You do not have enought money! (Promotion cost " .. config.cost .. " gp.")
	else
		setPlayerPromotionLevel(cid, config.promotion)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have been succesful promoted to " .. getVocationInfo(getPlayerVocation(cid)).name .. ".")
	end
	return TRUE
end

talkactions.xml
Code:
<talkaction words="!buypromotion" script="promotion.lua"/>
 
Last edited:
Code:
[16/12/2008 14:08:47] luagetDistanceTo(). Thing not found
[16/12/2008 14:10:10] Warning: [Event::loadScript] Can not load script. data/talkactions/scripts/promotion.lua
[16/12/2008 14:10:10] data/talkactions/scripts/promotion.lua:1: unexpected symbol near '{'

o_O
what is this
 
Currently with this script you don't need a premium. I'll add it configurable.
 
Im getting error. But thats maybe because im using new vocations. Can you help me out?
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<vocations>
	<vocation id="0" name="None" description="none" gaincap="5" gainhp="5" gainmana="5" gainhpticks="6" gainhpamount="1" gainmanaticks="6" gainmanaamount="1" manamultiplier="4.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="0">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/> 
		<skill id="0" multiplier="1.5"/>
		<skill id="1" multiplier="2.0"/>
		<skill id="2" multiplier="2.0"/>
		<skill id="3" multiplier="2.0"/>
		<skill id="4" multiplier="2.0"/>
		<skill id="5" multiplier="1.5"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="1" name="Master Sorcerer" description="a master sorcerer" gaincap="10" gainhp="5" gainmana="30" gainhpticks="6" gainhpamount="15" gainmanaticks="3" gainmanaamount="25" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="1">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/> 
		<skill id="0" multiplier="1.5"/>
		<skill id="1" multiplier="2.0"/>
		<skill id="2" multiplier="2.0"/>
		<skill id="3" multiplier="2.0"/>
		<skill id="4" multiplier="2.0"/>
		<skill id="5" multiplier="1.5"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="2" name="Elder Druid" description="a elder druid" gaincap="10" gainhp="5" gainmana="30" gainhpticks="6" gainhpamount="15" gainmanaticks="3" gainmanaamount="25" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="2">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.5"/>
		<skill id="1" multiplier="1.8"/>
		<skill id="2" multiplier="1.8"/>
		<skill id="3" multiplier="1.8"/>
		<skill id="4" multiplier="1.8"/>
		<skill id="5" multiplier="1.5"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="3" name="Royal Paladin" description="a royal paladin" gaincap="20" gainhp="10" gainmana="15" gainhpticks="4" gainhpamount="15" gainmanaticks="4" gainmanaamount="25" manamultiplier="1.4" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="3">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.2"/>
		<skill id="1" multiplier="1.2"/>
		<skill id="2" multiplier="1.2"/>
		<skill id="3" multiplier="1.2"/>
		<skill id="4" multiplier="1.1"/>
		<skill id="5" multiplier="1.1"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="4" name="Elite Knight" description="a elite knight" gaincap="25" gainhp="15" gainmana="5" gainhpticks="3" gainhpamount="15" gainmanaticks="6" gainmanaamount="25" manamultiplier="3.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="4">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.1"/>
		<skill id="1" multiplier="1.1"/>
		<skill id="2" multiplier="1.1"/>
		<skill id="3" multiplier="1.1"/>
		<skill id="4" multiplier="1.4"/>
		<skill id="5" multiplier="1.1"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="5" name="Ultimate Sorcerer" description="a ultimate sorcerer" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="35" gainmanaticks="2" gainmanaamount="100" manamultiplier="1.1" attackspeed="1000" soulmax="200" gainsoulticks="15" fromvoc="1">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.5"/>
		<skill id="1" multiplier="2.0"/>
		<skill id="2" multiplier="2.0"/>
		<skill id="3" multiplier="2.0"/>
		<skill id="4" multiplier="2.0"/>
		<skill id="5" multiplier="1.5"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="6" name="Ultimate Druid" description="an ultimate druid" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="35" gainmanaticks="2" gainmanaamount="100" manamultiplier="1.1" attackspeed="1000" soulmax="200" gainsoulticks="15" fromvoc="2">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.5"/>
		<skill id="1" multiplier="1.8"/>
		<skill id="2" multiplier="1.8"/>
		<skill id="3" multiplier="1.8"/>
		<skill id="4" multiplier="1.8"/>
		<skill id="5" multiplier="1.5"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="7" name="Ultimate Paladin" description="a ultimate paladin" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="55" gainmanaticks="3" gainmanaamount="50" manamultiplier="1.4" attackspeed="750" soulmax="200" gainsoulticks="15" fromvoc="3">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.2"/>
		<skill id="1" multiplier="1.2"/>
		<skill id="2" multiplier="1.2"/>
		<skill id="3" multiplier="1.2"/>
		<skill id="4" multiplier="1.1"/>
		<skill id="5" multiplier="1.1"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
	<vocation id="8" name="Ultimate Knight" description="an ultimate knight" gaincap="25" gainhp="15" gainmana="5" gainhpticks="2" gainhpamount="85" gainmanaticks="4" gainmanaamount="35" manamultiplier="3.0" attackspeed="750" soulmax="200" gainsoulticks="15" fromvoc="4">
		<formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
		<skill id="0" multiplier="1.1"/>
		<skill id="1" multiplier="1.1"/>
		<skill id="2" multiplier="1.1"/>
		<skill id="3" multiplier="1.1"/>
		<skill id="4" multiplier="1.4"/>
		<skill id="5" multiplier="1.1"/>
		<skill id="6" multiplier="1.1"/>
	</vocation>
</vocations>
 
Version with premium config and small issue patch (now you cannot buy a promotion with vocation = 0):
PHP:
local config = {
	promotion = 1,	-- promotion level, default = 1 . Ignore if you don't have new vocations.
	minLevel = 20,	-- Level needed to buy promotion
	cost = 20000,	-- Promotion cost in gp
	premium = "yes"	--is premium needed to buy promotion
}

function onSay(cid, words, param)
	if getPlayerVocation(cid) == 0 then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need to have a vocation to buy a promotion.")
		return TRUE
	end
	if (config.premium == "yes" and isPremium(cid)) or (config.premium ~= "yes") then	
		if(getPlayerPromotionLevel(cid) >= config.promotion) then
			doPlayerSendCancel(cid, "You are already promoted.")
		elseif(getPlayerLevel(cid) < config.minLevel) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need to be " .. config.minLevel .. " to get promotion.")
		elseif(doPlayerRemoveMoney(cid, config.cost) ~= TRUE) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You do not have enought money! (Promotion cost " .. config.cost .. " gp.")
		else
			setPlayerPromotionLevel(cid, config.promotion)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have been succesful promoted to " .. getVocationInfo(getPlayerVocation(cid)).name .. ".")
		end
	else
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a premium account to buy a promotion.")
	end
	return TRUE
end
 
Thanks man, i'll try it!

ooops look down instead

I'm using tfs 0.2 getting this error:
PHP:
[22/12/2008  03:04:23] Lua Script Error: [TalkAction Interface] 
[22/12/2008  03:04:23] data/talkactions/scripts/promotion.lua:onSay

[22/12/2008  03:04:23] data/talkactions/scripts/promotion.lua:14: attempt to call global 'getPlayerPromotionLevel' (a nil value)
[22/12/2008  03:04:23] stack traceback:
[22/12/2008  03:04:23]     data/talkactions/scripts/promotion.lua:14: in function <data/talkactions/scripts/promotion.lua:8>
 
Last edited by a moderator:
[17/10/2015 00:09:43] data/talkactions/scripts/promotion.lua:14: attempt to call global 'getPlayerPromotionLevel' (a nil value)
[17/10/2015 00:09:43] stack traceback:
[17/10/2015 00:09:43] data/talkactions/scripts/promotion.lua:14: in function <data/talkactions/scripts/promotion.lua:8>
 
Back
Top