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

[Help] Forgotte Server Banker

Status
Not open for further replies.

Mokerhamer

Retired Global Mod
Senator
Joined
Aug 6, 2007
Messages
1,767
Reaction score
35
[Help] TFS Banker Transfer (Need to fix before release of banker!)

I got olmoost my npc working all things work expect for
Transfer money can anyone help me?

Bug Shown:
-None


What's wrong with it then:
If i'm done i'm going to make some minor fixes and released it only on this forum

Bugged Lines:
Code:
elseif getCreatureName(cid}[COLOR="Magenta"]<---- How do i get the name the player said he wants to transfers to?[/COLOR]
and isNumber(getCount(msg)) and talk_state == 4 then
talk_state = 0

if doTransferBankMoney(cid, toplayer, count) then
setPlayerStorageValue(cid,300, oldcount-count)
set[COLOR="magenta"]to[/COLOR]PlayerStorageValue(cid,300, oldcount+count)

I dont think "settoPlayerStorageValue" is going to work since it dosen't exist what can i use instead?

Transfer Part:
Code:
   ------------------------Begin!--transfer--Crap----
            elseif msgcontains(msg, 'transfer') then
			if getPlayerPremiumDays(cid) > 0 then
			selfSay('If you want to transver sai this,   Name   Amount')
					talk_state = 4
			else
				selfSay(bank_need_premium)
				talk_state = 0
			end
---transver--Confurm--Yes
elseif getCreatureName(cid) and isNumber(getCount(msg)) and talk_state == 4 then
talk_state = 0
if doTransferBankMoney(cid, toplayer, count) then
setPlayerStorageValue(cid,300, oldcount-count)
settoPlayerStorageValue(cid,300, oldcount+count)
selfSay('Transver success')
else
selfSay(no_money)
end
------------------------End!--transfer--Crap----
 
Last edited:
Would help if you could tell us what errors you get.
 
i get this error

Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bank.lua
data/npc/scripts/bank.lua:57: 'end' expected (to close 'function' at line 12) near 'elseif'
 
Try to remove the 'end' above:
--------------------------------------no----------------------
 
Try to remove the 'end' above:
--------------------------------------no----------------------

dit that now i get this error

Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bank.lua
data/npc/scripts/bank.lua:56: 'end' expected (to close 'if' at line 27) near 'elseif'
 
Change:
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
doPlayerRemoveMoney(cid,count)
setPlayerStorageValue(cid,storageid)
else
selfSay(no_money)
to:
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if doPlayerRemoveMoney(cid,count) == TRUE then
setPlayerStorageValue(cid,storageid)
else
selfSay(no_money)
end
 
Oh great!

it responds on everything i sai only not if i sai "deposit"

Code:
Lua Script Error: [Npc interface] 
data/npc/scripts/bank.lua:onCreatureSay

data/npc/scripts/bank.lua:35: attempt to call global 'isPremium' (a nil value)

i checked i don not have "isPremium" function in my global.lua
 
Change:
if isPremium(cid) then
to:
if getPlayerPremiumDays(cid) > 0 then
 
Change:
if isPremium(cid) then
to:
if getPlayerPremiumDays(cid) > 0 then

Testid it but it's a bit buggy every time when i sai deposit it sais nothing..

i think it's the getcount

Bug:
Code:
Lua Script Error: [Npc interface] 
data/npc/scripts/bank.lua:onCreatureSay

data/npc/scripts/bank.lua:36: attempt to call global 'selfsay' (a nil value)


Script till now:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
	if(npcHandler.focus ~= cid) then
		return false
	end
	
		bank_need_premium = 'Sorry, you need a premium account to the bank!'
		no_money = 'You dont have enough money!'
		lost_track = 'What are u talking about?'
		money_give = 'Here you are, Spend that money smart!'
		player_gold = getPlayerItemCount(cid,2148)
		player_plat = getPlayerItemCount(cid,2152)*100
		player_crys = getPlayerItemCount(cid,2160)*10000
		player_money = player_gold + player_plat + player_crys
		
		if msgcontains(msg, 'banker') then
			selfSay('Hello there! if you need any help just sai  information')
		elseif msgcontains(msg, 'information') then
			selfSay('Hello i am the city banker you can do many things here.')
					elseif msgcontains(msg, 'help') then
			selfSay('I cant help you, if you want some information just sai information')
----------------------------------------------------------------------deposit--------------------------------
		elseif msgcontains(msg, 'deposit') then
			if getPlayerPremiumDays(cid) > 0 then
			selfsay('How mutch would u like to deposit?')
			if isNumber (getCount(msg)) >= 1 then
			selfsay('Are u sure you want to deposit somting here?')
					talk_state = 1
				else
					selfSay(lost_track)
					talk_state = 0
					end
			else
				selfSay(bank_need_premium)
				talk_state = 0
			end
-------------------------------------------------yes-----------------------
             elseif msgcontains(msg, 'yes') and talk_state == 1 then
               talk_state = 0
             if doPlayerRemoveMoney(cid,count) == TRUE then
               setPlayerStorageValue(cid,storageid)
             else
               selfSay(no_money)
             end
--------------------------------------no----------------------
		elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 3) then
			selfSay('Why the fuck dit you start this conversation anywais?')
			talk_state = 0
			end
	    return true
           end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

P.s)
I cant see when an admin is offline/online on this forum.. so it's triky for me to see if you are looking in this threat or not
 
Last edited:
now its responding for "deposit" but when you tell him how much you want to deposit it shows error :banker.lua:eek:nCreatureSay
banker.lua:37: attempt to call global 'getCount' <a nil value>
 
now its responding for "deposit" but when you tell him how much you want to deposit it shows error :banker.lua:eek:nCreatureSay
banker.lua:37: attempt to call global 'getCount' <a nil value>


when i sai banker it dosen't respond to me at all and it dosen't even give an error i'm 100% sure it's the get getCOunt function

Script:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) 

end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	-- Place all your code in here. Remember that hi, bye and all that stuff is already 

handled by the npcsystem, so you do not have to take care of that yourself.
	if(npcHandler.focus ~= cid) then
		return false
	end
	
		bank_need_premium = 'Sorry, you need a premium account to the bank!'
		no_money = 'You dont have enough money!'
		lost_track = 'What are u talking about?'
		money_give = 'Here you are, Spend that money smart!'
		player_gold = getPlayerItemCount(cid,2148)
		player_plat = getPlayerItemCount(cid,2152)*100
		player_crys = getPlayerItemCount(cid,2160)*10000
		player_money = player_gold + player_plat + player_crys
		
		if msgcontains(msg, 'banker') then
			selfSay('Hello there! if you need any help just sai  information')
		elseif msgcontains(msg, 'information') then
			selfSay('Hello i am the city banker you can do many things here.')
					elseif msgcontains(msg, 'help') then
			selfSay('I cant help you, if you want some information just sai 

information')
----------------------------------------------------------------------deposit---------------

-----------------
		elseif msgcontains(msg, 'Deposit') then
			if getPlayerPremiumDays(cid) > 0 then
			[COLOR="Magenta"]selfSay('How mutch would u like to deposit?')
			if isNumber (getCount(msg)) >= 1 then
			selfSay('Are u sure you want to deposit somting here?')[/COLOR]					talk_state = 1
				else
					selfSay(lost_track)
					talk_state = 0
					end
			else
				selfSay(bank_need_premium)
				talk_state = 0
			end
-------------------------------------------------yes-----------------------
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if doPlayerRemoveMoney(cid,count) == TRUE then
setPlayerStorageValue(cid,storageid)
else
selfSay(no_money)
end
--------------------------------------no----------------------
		elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 3) then
			selfSay('Why the fuck dit you start this conversation anywais?')
			talk_state = 0
			end
	    return true
           end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
now its responding for "deposit" but when you tell him how much you want to deposit it shows error :banker.lua:eek:nCreatureSay
banker.lua:37: attempt to call global 'getCount' <a nil value>


You forgot to add this in your global.lua

Code:
	-- Function used to match a number value from a string.
	function ShopModule:getCount(message)
		local ret = 1
		local b, e = string.find(message, PATTERN_COUNT)
		if b ~= nil and e ~= nil then
			ret = tonumber(string.sub(message, b, e))
		end
		if(ret <= 0) then
			ret = 1
		elseif(ret > self.maxCount) then
			ret = self.maxCount
		end
		
		return ret
	end


I dit not test it yet since i'm babysitting -.-"but if some one could try
to change
Code:
if isNumber (getCount(msg)) >= 1 then
to
Code:
if isNumber getCount(message) >= 1 then
 
Last edited:
after i added it to global.lua now it says : :attempt to index global 'ShopModule' <a nil value>
Warning: [LuaScriptInterface::initState] Can not load data/global.lua.
 
after i added it to global.lua now it says : :attempt to index global 'ShopModule' <a nil value>
Warning: [LuaScriptInterface::initState] Can not load data/global.lua.



post your global.lua i'll check if you have added it right
 
Code:
FALSE = 0

LUA_ERROR = -1
LUA_NO_ERROR = 0

NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
SOUTHWEST = 4
SOUTHEAST = 5
NORTHWEST = 6
NORTHEAST = 7

COMBAT_FORMULA_UNDEFINED = 0
COMBAT_FORMULA_LEVELMAGIC = 1
COMBAT_FORMULA_SKILL = 2

CONDITION_PARAM_OWNER = 1
CONDITION_PARAM_TICKS = 2
CONDITION_PARAM_OUTFIT = 3
CONDITION_PARAM_HEALTHGAIN = 4
CONDITION_PARAM_HEALTHTICKS = 5
CONDITION_PARAM_MANAGAIN = 6
CONDITION_PARAM_MANATICKS = 7
CONDITION_PARAM_DELAYED = 8
CONDITION_PARAM_SPEED = 9
CONDITION_PARAM_LIGHT_LEVEL = 10
CONDITION_PARAM_LIGHT_COLOR = 11
CONDITION_PARAM_SOULGAIN = 12
CONDITION_PARAM_SOULTICKS = 13
CONDITION_PARAM_MINVALUE = 14
CONDITION_PARAM_MAXVALUE = 15
CONDITION_PARAM_STARTVALUE = 16
CONDITION_PARAM_TICKINTERVAL = 17
CONDITION_PARAM_FORCEUPDATE = 18
CONDITION_PARAM_SKILL_MELEE = 19
CONDITION_PARAM_SKILL_FIST = 20
CONDITION_PARAM_SKILL_CLUB = 21
CONDITION_PARAM_SKILL_SWORD = 22
CONDITION_PARAM_SKILL_AXE = 23
CONDITION_PARAM_SKILL_DISTANCE = 24
CONDITION_PARAM_SKILL_SHIELD = 25
CONDITION_PARAM_SKILL_FISHING = 26
CONDITION_PARAM_STAT_MAXHITPOINTS = 27
CONDITION_PARAM_STAT_MAXMANAPOINTS = 28
CONDITION_PARAM_STAT_SOULPOINTS = 29
CONDITION_PARAM_STAT_MAGICPOINTS = 30
CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT = 31
CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT = 32
CONDITION_PARAM_STAT_SOULPOINTSPERCENT = 33
CONDITION_PARAM_STAT_MAGICPOINTSPERCENT = 34

COMBAT_PARAM_TYPE = 1
COMBAT_PARAM_EFFECT = 2
COMBAT_PARAM_DISTANCEEFFECT = 3
COMBAT_PARAM_BLOCKSHIELD = 4
COMBAT_PARAM_BLOCKARMOR = 5
COMBAT_PARAM_TARGETCASTERORTOPMOST = 6
COMBAT_PARAM_CREATEITEM = 7
COMBAT_PARAM_AGGRESSIVE = 8
COMBAT_PARAM_DISPEL = 9

CALLBACK_PARAM_LEVELMAGICVALUE = 1
CALLBACK_PARAM_SKILLVALUE = 2
CALLBACK_PARAM_TARGETTILE = 3
CALLBACK_PARAM_TARGETCREATURE = 4

COMBAT_NONE = 0
COMBAT_PHYSICALDAMAGE = 1
COMBAT_ENERGYDAMAGE = 2
COMBAT_POISONDAMAGE = 4 
COMBAT_FIREDAMAGE = 8
COMBAT_UNDEFINEDDAMAGE = 16
COMBAT_LIFEDRAIN = 32
COMBAT_MANADRAIN = 64
COMBAT_HEALING = 128
COMBAT_DROWNDAMAGE = 256

CONDITION_NONE = 0
CONDITION_POISON = 1
CONDITION_FIRE = 2
CONDITION_ENERGY = 4
CONDITION_LIFEDRAIN = 8
CONDITION_HASTE = 16
CONDITION_PARALYZE = 32
CONDITION_OUTFIT = 64
CONDITION_INVISIBLE = 128
CONDITION_LIGHT = 256
CONDITION_MANASHIELD = 512
CONDITION_INFIGHT = 1024
CONDITION_DRUNK = 2048
CONDITION_EXHAUSTED = 4096
CONDITION_FOOD = 8192
CONDITION_REGENERATION = 8192
CONDITION_SOUL = 16384
CONDITION_DROWN = 32768
CONDITION_MUTED = 65536
CONDITION_TRADETICKS = 131072
CONDITION_YELLTICKS = 262144
CONDITION_ATTRIBUTES = 524288

CONST_SLOT_HEAD = 1
CONST_SLOT_NECKLACE = 2
CONST_SLOT_BACKPACK = 3
CONST_SLOT_ARMOR = 4
CONST_SLOT_RIGHT = 5
CONST_SLOT_LEFT = 6
CONST_SLOT_LEGS = 7
CONST_SLOT_FEET = 8
CONST_SLOT_RING = 9
CONST_SLOT_AMMO = 10

CONST_ME_DRAWBLOOD = 0
CONST_ME_LOSEENERGY = 1
CONST_ME_POFF = 2
CONST_ME_BLOCKHIT = 3
CONST_ME_EXPLOSIONAREA = 4
CONST_ME_EXPLOSIONHIT = 5
CONST_ME_FIREAREA = 6
CONST_ME_YELLOW_RINGS = 7
CONST_ME_GREEN_RINGS = 8
CONST_ME_HITAREA = 9
CONST_ME_ENERGYAREA = 10
CONST_ME_ENERGYHIT = 11
CONST_ME_MAGIC_BLUE = 12
CONST_ME_MAGIC_RED = 13
CONST_ME_MAGIC_GREEN = 14
CONST_ME_HITBYFIRE = 15
CONST_ME_HITBYPOISON = 16
CONST_ME_MORTAREA = 17
CONST_ME_SOUND_BLUE = 18
CONST_ME_SOUND_RED = 19
CONST_ME_POISONAREA = 20
CONST_ME_SOUND_YELLOW = 21
CONST_ME_SOUND_PURPLE = 22
CONST_ME_SOUND_BLUE = 23
CONST_ME_SOUND_WHITE = 24
CONST_ME_BUBBLES = 25
CONST_ME_CRAPS = 26
CONST_ME_GIFT_WRAPS = 27
CONST_ME_FIREWORK_YELLOW = 28
CONST_ME_FIREWORK_RED = 29
CONST_ME_FIREWORK_BLUE = 30
CONST_ME_STUN = 31
CONST_ME_SLEEP = 32
CONST_ME_WATERCREATURE = 33
CONST_ME_GROUNDSHAKER = 34
CONST_ME_NONE = 255

CONST_ANI_SPEAR = 0
CONST_ANI_BOLT = 1
CONST_ANI_ARROW = 2
CONST_ANI_FIRE = 3
CONST_ANI_ENERGY = 4
CONST_ANI_POISONARROW = 5
CONST_ANI_BURSTARROW = 6
CONST_ANI_THROWINGSTAR = 7
CONST_ANI_THROWINGKNIFE = 8
CONST_ANI_SMALLSTONE = 9
CONST_ANI_SUDDENDEATH = 10
CONST_ANI_LARGEROCK = 11
CONST_ANI_SNOWBALL = 12
CONST_ANI_POWERBOLT = 13
CONST_ANI_POISON = 14
CONST_ANI_INFERNALBOLT = 15
CONST_ANI_HUNTINGSPEAR = 16
CONST_ANI_ENCHANTEDSPEAR = 17
CONST_ANI_REDASSASSINSTAR = 18
CONST_ANI_GREENASSASSINSTAR = 19
CONST_ANI_ROYALSPEAR = 20
CONST_ANI_SNIPERARROW = 21
CONST_ANI_ONYXARROW = 22
CONST_ANI_PIERCINGBOLT = 23
CONST_ANI_WHIRLWINDSWORD = 24
CONST_ANI_WHIRLWINDAXE = 25
CONST_ANI_WHIRLWINDMACE = 26
CONST_ANI_ETHEREALSPEAR = 27
CONST_ANI_WEAPONTYPE = 254
CONST_ANI_NONE = 255

TALKTYPE_SAY  = 1
TALKTYPE_WHISPER = 2
TALKTYPE_YELL = 3
TALKTYPE_PRIVATE = 4
TALKTYPE_CHANNEL_Y = 5
TALKTYPE_BROADCAST = 9
TALKTYPE_CHANNEL_R1 = 10
TALKTYPE_PRIVATE_RED = 11
TALKTYPE_CHANNEL_O = 12
TALKTYPE_CHANNEL_R2 = 14
TALKTYPE_ORANGE_1 = 16
TALKTYPE_ORANGE_2 = 17

MESSAGE_STATUS_WARNING = 18
MESSAGE_EVENT_ADVANCE = 19
MESSAGE_EVENT_DEFAULT = 20
MESSAGE_STATUS_DEFAULT = 21
MESSAGE_INFO_DESCR = 22
MESSAGE_STATUS_SMALL = 23
MESSAGE_STATUS_CONSOLE_BLUE = 24
MESSAGE_STATUS_CONSOLE_RED  = 25

TEXTCOLOR_BLUE = 5
TEXTCOLOR_LIGHTBLUE = 35
TEXTCOLOR_LIGHTGREEN = 30
TEXTCOLOR_CRYSTAL = 65
TEXTCOLOR_PLATINUM = 89
TEXTCOLOR_LIGHTGREY = 172
TEXTCOLOR_RED = 180
TEXTCOLOR_ORANGE = 198
TEXTCOLOR_GOLD = 210
TEXTCOLOR_WHITE_EXP = 215
TEXTCOLOR_NONE = 255

SKILL_FIST = 0
SKILL_CLUB = 1
SKILL_SWORD = 2
SKILL_AXE = 3
SKILL_DISTANCE = 4
SKILL_SHIELD = 5
SKILL_FISHING = 6

CONTAINER_POSITION = 65535

STACKPOS_GROUND = 0
STACKPOS_FIRST_ITEM_ABOVE_GROUNDTILE = 1
STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE = 2
STACKPOS_THIRD_ITEM_ABOVE_GROUNDTILE = 3
STACKPOS_FOURTH_ITEM_ABOVE_GROUNDTILE = 4
STACKPOS_FIFTH_ITEM_ABOVE_GROUNDTILE = 5
STACKPOS_TOP_CREATURE = 253
STACKPOS_TOP_FIELD = 254
STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE = 255

RETURNVALUE_NOERROR = 1
RETURNVALUE_NOTPOSSIBLE = 2
RETURNVALUE_NOTENOUGHROOM = 3
RETURNVALUE_PLAYERISPZLOCKED = 4
RETURNVALUE_PLAYERISNOTINVITED = 5
RETURNVALUE_CANNOTTHROW = 6
RETURNVALUE_THEREISNOWAY = 7
RETURNVALUE_DESTINATIONOUTOFREACH = 8
RETURNVALUE_CREATUREBLOCK = 9
RETURNVALUE_NOTMOVEABLE = 10
RETURNVALUE_DROPTWOHANDEDITEM = 11
RETURNVALUE_BOTHHANDSNEEDTOBEFREE = 12
RETURNVALUE_CANONLYUSEONEWEAPON = 13
RETURNVALUE_NEEDEXCHANGE = 14
RETURNVALUE_CANNOTBEDRESSED = 15
RETURNVALUE_PUTTHISOBJECTINYOURHAND = 16
RETURNVALUE_PUTTHISOBJECTINBOTHHANDS = 17
RETURNVALUE_TOOFARAWAY = 18
RETURNVALUE_FIRSTGODOWNSTAIRS = 19
RETURNVALUE_FIRSTGOUPSTAIRS = 20
RETURNVALUE_CONTAINERNOTENOUGHROOM = 21
RETURNVALUE_NOTENOUGHCAPACITY = 22
RETURNVALUE_CANNOTPICKUP = 23
RETURNVALUE_THISISIMPOSSIBLE = 24
RETURNVALUE_DEPOTISFULL = 25
RETURNVALUE_CREATUREDOESNOTEXIST = 26
RETURNVALUE_CANNOTUSETHISOBJECT = 27
RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE = 28
RETURNVALUE_NOTREQUIREDLEVELTOUSERUNE = 29
RETURNVALUE_YOUAREALREADYTRADING = 30
RETURNVALUE_THISPLAYERISALREADYTRADING = 31
RETURNVALUE_YOUMAYNOTLOGOUTDURINGAFIGHT = 32
RETURNVALUE_DIRECTPLAYERSHOOT = 33
RETURNVALUE_NOTENOUGHLEVEL = 34
RETURNVALUE_NOTENOUGHMAGICLEVEL = 35
RETURNVALUE_NOTENOUGHMANA = 36
RETURNVALUE_NOTENOUGHSOUL = 37
RETURNVALUE_YOUAREEXHAUSTED = 38
RETURNVALUE_PLAYERISNOTREACHABLE = 39
RETURNVALUE_CANONLYUSETHISRUNEONCREATURES = 40
RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE = 41
RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER = 42
RETURNVALUE_YOUMAYNOTATTACKAPERSONINPROTECTIONZONE = 43
RETURNVALUE_YOUMAYNOTATTACKAPERSONWHILEINPROTECTIONZONE = 44
RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE = 45
RETURNVALUE_YOUMAYNOTLOGOUTHERE = 46
RETURNVALUE_YOUCANONLYUSEITONCREATURES = 47
RETURNVALUE_CREATUREISNOTREACHABLE = 48
RETURNVALUE_SECUREMODEON = 49

closedDoors =		{1209, 1210, 1212, 1213, 1219, 1221, 1231, 1232, 1234, 1235, 1237, 1239, 1249, 1250, 1252, 1253, 1539, 1541, 3535, 3536, 3538, 3544, 3545, 3547, 4913, 4914, 4916, 4917, 5082, 5084, 5098, 5099, 5101, 5107, 5108, 5110, 5116, 5117, 5119, 5125, 5126, 5128, 5134, 5135, 5137, 5138, 5140, 5141, 5143, 5144, 5278, 5279, 5281, 5282, 5284, 5286, 5515, 5517, 5732, 5733, 5735, 5736, 6192, 6193, 6195, 6196, 6198, 6200, 6249, 6250, 6252, 6253, 6255, 6257, 6795, 6797, 6799, 6801, 6891, 6892, 6894, 6900, 6901, 6903, 7033, 7034, 7036, 7042, 7043, 7045, 7054, 7056}
openDoors =		{1211, 1211, 1214, 1214, 1220, 1222, 1233, 1233, 1236, 1236, 1238, 1240, 1251, 1251, 1254, 1254, 1540, 1542, 3537, 3537, 3539, 3546, 3546, 3548, 4915, 4915, 4918, 4918, 5083, 5085, 5100, 5100, 5102, 5109, 5109, 5111, 5118, 5118, 5120, 5127, 5127, 5129, 5136, 5136, 5139, 5139, 5142, 5142, 5145, 5145, 5280, 5280, 5283, 5283, 5285, 5287, 5516, 5518, 5734, 5734, 5737, 5737, 6194, 6194, 6197, 6197, 6199, 6201, 6251, 6251, 6254, 6254, 6256, 6258, 6796, 6798, 6800, 6802, 6893, 6893, 6895, 6902, 6902, 6904, 7035, 7035, 7037, 7044, 7044, 7046, 7055, 7057}
verticalOpenDoors =	{1211, 1220, 1224, 1228, 1233, 1238, 1242, 1246, 1256, 1260, 1540, 3546, 3548, 3550, 3552, 4915, 5083, 5109, 5111, 5113, 5115, 5127, 5129, 5131, 5133, 5142, 5145, 5283, 5285, 5289, 5293, 5516, 5737, 5749, 6194, 6199, 6203, 6207, 6251, 6256, 6260, 6264, 6798, 6802, 6902, 6904, 6906, 6908, 7044, 7046, 7048, 7050, 7055}
horizontalOpenDoors =	{1214, 1222, 1226, 1230, 1236, 1240, 1244, 1248, 1258, 1262, 1542, 3537, 3539, 3541, 3543, 4918, 5085, 5100, 5102, 5104, 5106, 5118, 5120, 5122, 5124, 5136, 5139, 5280, 5287, 5291, 5295, 5518, 5734, 5746, 6197, 6201, 6205, 6209, 6254, 6258, 6262, 6266, 6796, 6800, 6893, 6895, 6897, 6899, 7035, 7037, 7039, 7041, 7057}
questDoors =		{1223, 1225, 1241, 1243, 1255, 1257, 3542, 3551, 5105, 5114, 5123, 5132, 5288, 5290, 5745, 5748, 6202, 6204, 6259, 6261, 6898, 6907, 7040, 7049}
levelDoors =		{1227, 1229, 1245, 1247, 1259, 1261, 3540, 3549, 5103, 5112, 5121, 5130, 5292, 5294, 6206, 6208, 6263, 6265, 6896, 6905, 7038, 7047}
keys =			{2086, 2087, 2088, 2089, 2090, 2091, 2092}

ITEM_GOLD_COIN = 2148
ITEM_PLATINUM_COIN = 2152
ITEM_CRYSTAL_COIN = 2160
ITEM_FISH = 2667
ITEM_WORM = 3976

function doPlayerGiveItem(cid, itemid, count, charges)
	local hasCharges = (isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE)
	if(hasCharges and charges == nil) then
		charges = 1
	end
	
	while count > 0 do
		local tempcount = 1
		
		if(hasCharges) then
			tempcount = charges
		end
		if(isItemStackable(itemid) == TRUE) then
			tempcount = math.min (100, count)
   		end
   		
	   	local ret = doPlayerAddItem(cid, itemid, tempcount)
	   	if(ret == LUA_ERROR) then
			ret = doCreateItem(itemid, tempcount, getPlayerPosition(cid))
		end
		
		if(ret ~= LUA_ERROR) then
			if(hasCharges) then
				count = count - 1
			else
				count = count - tempcount
			end
		else
			return LUA_ERROR
		end
	end
	return LUA_NO_ERROR
end

function doPlayerTakeItem(cid, itemid, count)
	if(getPlayerItemCount(cid,itemid) >= count) then
		while count > 0 do
			local tempcount = 0
			if(isItemStackable(itemid) == TRUE) then
				tempcount = math.min (100, count)
			else
				tempcount = 1
			end
			local ret = doPlayerRemoveItem(cid, itemid, tempcount)
			
			if(ret ~= LUA_ERROR) then
				count = count-tempcount
			else
				return LUA_ERROR
			end
		end
		if(count == 0) then
			return LUA_NO_ERROR
		end
	else
		return LUA_ERROR
	end
end


function doPlayerAddMoney(cid, amount)
	local crystals = math.floor(amount/10000)
	amount = amount - crystals*10000
	local platinum = math.floor(amount/100)
	amount = amount - platinum*100
	local gold = amount
	local ret = 0
	if(crystals > 0) then
		ret = doPlayerGiveItem(cid, ITEM_CRYSTAL_COIN, crystals)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	if(platinum > 0) then
		ret = doPlayerGiveItem(cid, ITEM_PLATINUM_COIN, platinum)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	if(gold > 0) then
		ret = doPlayerGiveItem(cid, ITEM_GOLD_COIN, gold)
		if(ret ~= LUA_NO_ERROR) then
			return LUA_ERROR
		end
	end
	return LUA_NO_ERROR
end

function doPlayerBuyItem(cid, itemid, count, cost, charges)
	if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		return doPlayerGiveItem(cid, itemid, count, charges)
	else
		return LUA_ERROR
	end
end

function doPlayerSellItem(cid, itemid, count, cost)
	if(doPlayerTakeItem(cid, itemid, count) == LUA_NO_ERROR) then
		if(doPlayerAddMoney(cid, cost) ~= LUA_NO_ERROR) then
			error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
		end
		return LUA_NO_ERROR
	else
		return LUA_ERROR
	end
end

function isInPosition(pos, fromPos, toPos)
	if pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z then
		return true
	end
	return false
end

function isNumber(p)
	local m = ""
	for i = 1, string.len(p) do
		m = string.sub(p, i, i)
		if m == "0" or m == "1" or m == "2" or m == "3" or m == "4" or m == "5" or m == "6" or m == "7" or m == "8" or m == "9" then
			-- continue
		else
			return false
		end
	end
	return true
end

-- Function used to match a number value from a string.
	function ShopModule:getCount(message)
		local ret = 1
		local b, e = string.find(message, PATTERN_COUNT)
		if b ~= nil and e ~= nil then
			ret = tonumber(string.sub(message, b, e))
		end
		if(ret <= 0) then
			ret = 1
		elseif(ret > self.maxCount) then
			ret = self.maxCount
		end
		
		return ret
	end

Here you go :p
 
Last edited by a moderator:
Hmm i tested the npc but i couldent get it to work i tryt to use:

Code:
if isNumber (getCount(message)) >= 1 then

Bug i get:
Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bank.lua
data/npc/scripts/bank.lua:37: 'then' expected near 'getCount'

================================================================

and i tryt this:
Code:
if isNumber then (getCount(message)) then

i get this bug:
Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bank.lua
data/npc/scripts/bank.lua:37: syntax error near 'then'

=================================================================
ANd i tryt this:
Code:
if isNumber getCount(msg) == True then


Bug
Code:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/bank.lua
data/npc/scripts/bank.lua:37: 'then' expected near 'getCount'
 
Last edited:
and what about mine global.lua :p? is it placed in right place or wrong ?

It's good but i think i screwed upp with getCount i think it should be a shop module.. so testing it


i added this in modules.lua:
Code:
	-- Function used to match a number value from a string. the getCount Module
	function ShopModule:getCount(message)
		local ret = 1
		local b, e = string.find(message, PATTERN_COUNT)
		if b ~= nil and e ~= nil then
			ret = tonumber(string.sub(message, b, e))
		end
		if(ret <= 0) then
			ret = 1
		elseif(ret > self.maxCount) then
			ret = self.maxCount
		end
		
		return ret
	end

and i added this in the top of the script:
Code:
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)



and in the script i changed the getCount function to:
Code:
if shopModule:getCount(msg) == TRUE then



But it still dosen't work it dosent respond when i sai deposit and it dosen't give any bug reports



Check first post!
 
Last edited:
Status
Not open for further replies.
Back
Top