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

Solved Please help me with npc LUA script to sell mounts.

Rote Faust

New Member
Joined
Dec 24, 2010
Messages
16
Reaction score
1
okay, I realize all I do on here is ask for help, but I really do try to figure things out on my own first. That being said, I need some help making a script to sell mounts.

I want to be able to say the mount name, and if i don't have enough money, the npc says "you don't have enough money!"
If I already have the mount, when I say the name I want the npc to say "you already have the (mount name here) mount!"
and finally if I don't have the mount already, and I have enough money, I want the npc to give me the mount, thake my money, and say "you now have the (mount name here) mount!"

Phew! I hope you understand. This is the first script I tried to make, and I admit my utter noobness :$
Below is the script I have so far. By the way, with the script how it is now, no matter what i say, the npc says "you don't have enough money!" (if i do have the money, he takes it and gives me the mount but still says the same thing)

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

 
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
function creatureSayCallback(cid, type, msg)
       	
	

	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) == 1 then
		  npcHandler:say('You already have the War Horse mount!', cid)

	end       		
	

	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198801, 1)
			doPlayerAddMountEx(cid,17)
			npcHandler:say('You now have the War Horse mount!', cid)
	         end

		else
			npcHandler:say('You don\'t have enough money!', cid)
		
		end
	  

	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) == 1 then
		   npcHandler:say('You already have the War Bear mount!', cid)

		end		


	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) <= 0 then    
		     if doPlayerRemoveMoney(cid,5000) == TRUE then
			doPlayerAddMountEx(cid,3)
			setPlayerStorageValue(cid, 198802, 1)
			npcHandler:say('You now have the War Bear mount!', cid)
		   end

		else
			npcHandler:say('You don\'t have enough money!', cid)
		
	    end
	

	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) == 1 then
		   npcHandler:say('You already have the Armored War Horse mount!', cid)

		end

	
      	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198803, 1)
			doPlayerAddMountEx(cid,22)
			npcHandler:say('You now have the Armored War Horse mount!', cid)
		   end
	
		else
			npcHandler:say('You don\'t have enough money!', cid)
		end		

end

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

P.S. If it matters, I use OTserv 9.1 r.6105

Thank you so much for your time, and I will +REP anyone who can help!
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
 
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
function creatureSayCallback(cid, type, msg)
 
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) == 1 then
		  npcHandler:say('You already have the War Horse mount!', cid)
 
	end       		
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) <= 0 and getPlayerItemCount(cid, 2160) >= 5000 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198801, 1)
			doPlayerAddMountEx(cid,17)
			npcHandler:say('You now have the War Horse mount!', cid)
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
 
		end
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) == 1 then
		   npcHandler:say('You already have the War Bear mount!', cid)
 
		end		
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) <= 0 then    
		     if doPlayerRemoveMoney(cid,5000) == TRUE then
			doPlayerAddMountEx(cid,3)
			setPlayerStorageValue(cid, 198802, 1)
			npcHandler:say('You now have the War Bear mount!', cid)
		   end
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
 
	    end
 
 
	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) == 1 then
		   npcHandler:say('You already have the Armored War Horse mount!', cid)
 
		end
 
 
      	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198803, 1)
			doPlayerAddMountEx(cid,22)
			npcHandler:say('You now have the Armored War Horse mount!', cid)
		   end
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
		end		
 
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

i am new with npcs sry if it didn't work
 
well, that didn't work.

It is still doing the same thing, only now I have to have 5000 crystal coins (equal to 50,000,000 gold) in my backpack

thanks for trying though.

also I forgot an "end" , I will edit first post to what I have now.

------UPDATE------

wow I feel dumb... I fixed it though. I had the some ends in the wrong place.

this is the fixed script:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
 
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
function creatureSayCallback(cid, type, msg)
 
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) == 1 then
		  npcHandler:say('You already have the War Horse mount!', cid)
 
	end       		
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198801, 1)
			doPlayerAddMountEx(cid,17)
			npcHandler:say('You now have the War Horse mount!', cid)
 
		
		else
			npcHandler:say('You don\'t have enough money!', cid)
 
		end
	      end
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) == 1 then
		   npcHandler:say('You already have the War Bear mount!', cid)
 
		end		
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) <= 0 then    
		     if doPlayerRemoveMoney(cid,5000) == TRUE then
			doPlayerAddMountEx(cid,3)
			setPlayerStorageValue(cid, 198802, 1)
			npcHandler:say('You now have the War Bear mount!', cid)
		   
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
 		end
	    end
 
 
	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) == 1 then
		   npcHandler:say('You already have the Armored War Horse mount!', cid)
 
		end
 
 
      	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198803, 1)
			doPlayerAddMountEx(cid,22)
			npcHandler:say('You now have the Armored War Horse mount!', cid)
		   
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
		  end
		end		
 
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
thanks for your help.
 
Last edited:
nah sry i had a little mistake fixing it

- - - Updated - - -

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
 
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
function creatureSayCallback(cid, type, msg)
 
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) == 1 then
		  npcHandler:say('You already have the War Horse mount!', cid)
 
	end       		
 
 
	if msgcontains(msg, 'war horse') and getPlayerStorageValue(cid, 198801) <= 0 and getPlayerItemCount(cid, 2152) >= 5000 then
		   doPlayerRemoveMoney(cid,5000)
		        setPlayerStorageValue(cid, 198801, 1)
			doPlayerAddMountEx(cid,17)
			npcHandler:say('You now have the War Horse mount!', cid)
 
		elseif getPlayerItemCount(cid, 2160) < 5000 then
			npcHandler:say('You don\'t have enough money!', cid)
 
		end
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) == 1 and getPlayerItemCount(cid, 2152) >= 5000 then
		   npcHandler:say('You already have the War Bear mount!', cid)
 
		end		
 
 
	if msgcontains(msg, 'war bear') and getPlayerStorageValue(cid, 198802) <= 0 then    
		     doPlayerRemoveMoney(cid,5000)
			doPlayerAddMountEx(cid,3)
			setPlayerStorageValue(cid, 198802, 1)
			npcHandler:say('You now have the War Bear mount!', cid)
		   end
 
		elseif getPlayerItemCount(cid, 2152) < 5000 then
			npcHandler:say('You don\'t have enough money!', cid)
 
 
 
	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) == 1 then
		   npcHandler:say('You already have the Armored War Horse mount!', cid)
 
		end
 
 
      	if msgcontains(msg, 'armored horse') and getPlayerStorageValue(cid, 198803) <= 0 then
		  if doPlayerRemoveMoney(cid,5000) == TRUE then
		        setPlayerStorageValue(cid, 198803, 1)
			doPlayerAddMountEx(cid,22)
			npcHandler:say('You now have the Armored War Horse mount!', cid)
		   end
 
		else
			npcHandler:say('You don\'t have enough money!', cid)
		end		
 
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
thanks tetra20, after some lunch and a fresh look, I fixed it myself.

btw, I don't know about your server, but item id"2152" in my server is the platinum coin, so the function where you say "getPlayerItemCount(cid, 2152) >= 5000" that means i will need 5000 or more of the item "platinum coin" for it to go on with the script.

I think the function you are thinking of is "getPlayerMoney(cid) >= 5000" which would make it so if i had 5000 gold in any coin format it would go on with the script, but it isn't needed since i have the "if" in there for doPlayerRemoveMoney, that makes it so if it can't remove 5000 gold (because i don't have it on me) it will go to the "else" and say "you don't have enough money"
 
thats what i did look at my second post i deleted the if at doPlayerRemoveMoney(cid, 5000) btw the getPlayerItemCount(cid, 2152) >=5000 mean that if the player have the itemid 2152== 5000 or more than 5000 then it will remove if you don't have 5000 coin it won't continue and send you a cancel
 
Back
Top