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

Tutorial learn lua?

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
I don't know if this is the correct section or not, but I would like some tutorials to learn Lua.. Anyone have anything? :)
 
Tutorials doesn't teach you, they're just a shortcut to make whatever the tutorial shows you.
If a tutorial show you how to make Blessing NPC, you wont know a SHIT how to make a Boat Npc.

if you want to learn, you do it by check the lua section, look how scripts looks, and then try to make your own, and test them, over and over until you make them work.
By doing this, you will catch up what and what doesn't work, and your skill will become 100x higher, than if you were learning from tutorials.

You need to face problems without help, else you'll never learn, not in the good way, you must learn yourself, how to solve issues you have never seen before. Once you've learned this... you can do unlimited things as you don't need a guy that's better than you to back you up.
 
J.Dre is my teacher xD

Idk.. I'm not very good, but I did find that being your on teacher is the best way to learn anything..
Just go around in the forum, look for some scripts, and change them up, and then eventually, it'll be easier.
Then go from there to try and create your own scripts, and from there, more complex ones, and so-on.
 
With basic scripting knowledge you can get pretty far. I am not particularly good with NPCs. So I make all interactions connect to lua script :P

Here is a rather unique NPC 100% by me. Feel free to study it, it is really simple. And you can do just about anything. This here is coded with only basic knowledge.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Oliver" floorchange="0" walkinterval="0">
	<health now="150" max="150"/>
	<look type="128" head="77" body="65" legs="59" feet="116" addons="1"/>

  <interaction range="3" idletime="30">

    <interact keywords="hi" focus="1">
      <!--These are the keywords will trigger this interaction-->
      <keywords>hello</keywords>
      <keywords>greet</keywords>
	  <keywords>hei</keywords>

      <response>
        <action name="script">
			selfSay('Hello there, I {sell} and {buy} wheat and flour in packs. (1 pack = 5 units).', cid)
        </action>
      </response>
  </interact>
   
   <!-- Manual buying shop system -->
	<interact keywords="buy">
	<keywords>shop</keywords>
      <response>
			<action name="script">
			local wheat = getStorage(50020)
			local flour = getStorage(50021)
			local wheat1 = (wheat / 5)
			local flour1 = (flour / 5)
			
			if wheat == -1 then
				doSetStorage(50020, 25)
			end
			if flour == -1 then
				doSetStorage(50021, 25)
			end
			
				selfSay("I have "..math.floor(wheat1).." {wheat} packs available (40gp each pack) and "..math.floor(flour1).." {flour} packs available (75gp each pack).", cid)
			</action>
		<action name="topic" value="2"/>
		</response>
    </interact>
	
	<interact keywords="wheat" topic="2">
	<keywords>crop</keywords>
      <response>
			<action name="script">
			local wheat = getStorage(50020)
			
			if wheat > 4 then
				if doPlayerRemoveMoney(cid, 40) == true then
					doPlayerAddItem(cid, 2694,5)
					doSetStorage(50020, getStorage(50020)-5)
					selfSay('Thank you! Here is your wheat!', cid)
				else
					selfSay('Sorry, this pack costs 40gp. ', cid)
				end	
			else
				selfSay('Sorry, I am out of wheat. I need to refill my supplies.', cid)
			end
			</action>
		</response>
    </interact>
	
	<interact keywords="flour" topic="2">
	<keywords>mel</keywords>
      <response>
			<action name="script">
			local flour = getStorage(50021)
			
			if flour > 4 then
				if doPlayerRemoveMoney(cid, 75) == true then
					doPlayerAddItem(cid, 2692,5)
					doSetStorage(50021, getStorage(50021)-5)
					selfSay('Thank you! Here is your flour!', cid)
				else
					selfSay('Sorry, this pack costs 75gp. ', cid)
				end	
			else
				selfSay('Sorry, I am out of flour. I need to refill my supplies.', cid)
			end
			</action>
		</response>
    </interact>
	<!-- End normal trade system -->
	
	<!-- Manual selling shop system -->
	<interact keywords="sell">
      <response>
			<action name="script">
			local wheat = getStorage(50020)
			local flour = getStorage(50021)
			
			if flour > 20 and wheat > 20 then
				selfSay("All my stocks are full. Perhaps later.", cid)
			else
				if flour > 20 then
					selfSay("I would like to buy some {wheat} (30gp). I might be interested in buying flour later.", cid)
				else
					if wheat > 20 then
						selfSay("I would like to buy some {flour} (45gp). I might be interested in buying wheat later.", cid)
					else
						selfSay("I would like to buy {flour} (45gp) and {wheat} (30gp)!", cid)
					end
				end
			end
			</action>
		<action name="topic" value="3"/>
		</response>
    </interact>
	
	<interact keywords="wheat" topic="3">
	<keywords>crop</keywords>
      <response>
			<action name="script">
			local wheat = getStorage(50020)
			
			if wheat > 20 then
				selfSay("My wheat stock is full, perhaps I will buy some later.", cid)
			else
				if doPlayerRemoveItem(cid, 2694,5) == true then						
					doPlayerAddMoney(cid, 30)
					doSetStorage(50020, getStorage(50020)+5)
					selfSay('Thanks you, here is your 30gp. Please come back again.', cid)
				else
					selfSay('Looks like you dont have enough wheat on you. I trade things in a pack of 5x units.', cid)
				end		
			end
			</action>
		</response>
    </interact>
	
	<interact keywords="flour" topic="3">
	<keywords>mel</keywords>
      <response>
			<action name="script">
			local flour = getStorage(50021)
			
			if flour > 20 then
				selfSay("My flour stock is full, perhaps I will buy some later.", cid)
			else
				if doPlayerRemoveItem(cid, 2692,5) == true then						
					doPlayerAddMoney(cid, 45)
					doSetStorage(50021, getStorage(50021)+5)
					selfSay('Thanks you, here is your 45gp. Please come back again.', cid)
				else
					selfSay('Looks like you dont have enough flour on you. I trade things in a pack of 5x units.', cid)
				end		
			end
			</action>
		</response>
    </interact>
	<!-- End normal selling trade system -->
	
	<interact keywords="bye" focus="0">
      <keywords>farewell</keywords>
		<response>
			<action name="script">
				selfSay('Farewell! Good luck to you!', cid)
			</action>
		</response>
    </interact>
  
</interaction>
</npc>

Heres a task for you:

What is special about this NPC? ;)
(in details).
Other people: Dont spoil the fun. D:
 
Last edited:
Back
Top