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

Lua npc script 7.6

Pro Warbringer

Retired with developing
Joined
Sep 23, 2008
Messages
3,582
Reaction score
24
Location
Austria
Well ive started to make my NPC wich changes Life Crystal into an Life Ring but its hard
:(
Can you help me out a bit since i need it badly..
Lua:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
 		selfSay('Hello ' .. creatureGetName(cid) .. '! I trade Life Crystals to Life Rings.')
 		focus = cid
 		talk_start = os.clock()

	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'Trade Life Crystal') then
 			if isTrade Life Crystal(cid) then
 				selfSay('Sorry, you dont have an Life Crystal.')
 				talk_state = 0
 			elseif getPlayerLevel(creatureGetName(cid)) < 8 then
				selfSay('Sorry, you need level 8 to trade Life Crystals.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to trade Life Crystals.')
				talk_state = 0
			end

		elseif msgcontains(msg, 'Trade Life Crystal') or msgcontains(msg, 'Trade Crystal') then
			selfSay('Do you want to trade a Life Crystal?')
			talk_state = 2

		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					selfSay('/i 2168 ' .. creatureGetName(cid))
					selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')
				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					selfSay('/i 2168 ' .. creatureGetName(cid))
					selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')
				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
			end
			talk_state = 0

  		elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
  			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
  			focus = 0
  			talk_start = 0
  		end
  	end
end



function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end

Yeah i want it cost 500 gold's..
Kind Regard's,
Pro Warbringer



p.s. IT SHOULD TRADE LIFE CRYSTAL FOR LIFE RING
ILL REP!
 
Change:
Code:
selfSay('/i 2168 ' .. creatureGetName(cid))
selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')

To:
Code:
doPlayerRemoveItem(cid, id of l. cristal, 1)
doPlayerAddItem(cid, id of l. ring, 1)
selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')
 
So the script looks like this
Lua:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
 		selfSay('Hello ' .. creatureGetName(cid) .. '! I trade Life Crystals to Life Rings.')
 		focus = cid
 		talk_start = os.clock()

	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'Trade Life Crystal') then
 			if isTrade Life Crystal(cid) then
 				selfSay('Sorry, you dont have an Life Crystal.')
 				talk_state = 0
 			elseif getPlayerLevel(creatureGetName(cid)) < 8 then
				selfSay('Sorry, you need level 8 to trade Life Crystals.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to trade Life Crystals.')
				talk_state = 0
			end

		elseif msgcontains(msg, 'Trade Life Crystal') or msgcontains(msg, 'Trade Crystal') then
			selfSay('Do you want to trade a Life Crystal?')
			talk_state = 2

		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					doPlayerRemoveItem(cid, id of l. cristal, 1)
                    doPlayerAddItem(cid, id of l. ring, 1)
                    selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')

				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					doPlayerRemoveItem(cid, id of l. cristal, 1)
                    doPlayerAddItem(cid, id of l. ring, 1)
                    selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')

				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
			end
			talk_state = 0

  		elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
  			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
  			focus = 0
  			talk_start = 0
  		end
  	end
end



function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end
 
NPC-
Code:
<?xml version="1.0"?>
<npc name="Chester Kahs" script="data/npc/scripts/lifecrystalchanger.lua" access="5">
	<look type="128" head="4" body="114" legs="132" feet="115"/>
</npc>





SCRIPT-
Lua:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
 		selfSay('Hello ' .. creatureGetName(cid) .. '! I trade Life Crystals to Life Rings.')
 		focus = cid
 		talk_start = os.clock()

	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'Trade Life Crystal') then
 			if isTrade Life Crystal(cid) then
 				selfSay('Sorry, you dont have an Life Crystal.')
 				talk_state = 0
 			elseif getPlayerLevel(creatureGetName(cid)) < 8 then
				selfSay('Sorry, you need level 8 to trade Life Crystals.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to trade Life Crystals.')
				talk_state = 0
			end

		elseif msgcontains(msg, 'Trade Life Crystal') or msgcontains(msg, 'Trade Crystal') then
			selfSay('Do you want to trade a Life Crystal?')
			talk_state = 2

		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					doPlayerRemoveItem(cid, id of l. 2177, 1)
                    doPlayerAddItem(cid, id of l. 2168, 1)
                    selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')

				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if pay(cid,500) then
					doPlayerRemoveItem(cid, id of l. 2177, 1)
                    doPlayerAddItem(cid, id of l. 2168, 1)
                    selfSay('You traded the Life Crystal to an Life Ring.. THANKS!')

				else
					selfSay('Sorry, you do not have enough money You need 500 gold coins.')
				end
			end
			talk_state = 0

  		elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
  			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
  			focus = 0
  			talk_start = 0
  		end
  	end
end



function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end

This is the new script please help me if its not right cant find error's so far but i dunno if the functions are right.. (doPlayerRemoveItem(cid, id of 1. crystal, 1))
 
Last edited:
Back
Top