Contest: Guides, Lore, and Help

Contests run by staff will be posted here.
Locked
Admin
Site Admin
Posts: 206
Joined: May 3rd, 2012, 5:47 am

Contest: Guides, Lore, and Help

Post by Admin »

As part of our ongoing efforts to continuously engage and interact with the community we will begin running monthly forum-based contests in addition to the usual in-game roleplay, events, and activities that typically take place.

This month's event will run from 27 January 2013 through 22 February 2013 with judging to take place the following week and be completed no later than 28 February 2013. All efforts will be made to ensure that the contest appeals to the largest amount of people; however, if this month's contest doesn't interest you, perhaps next month's will be more to your liking.

The criteria for the event is to help improve, expand, and clarify documentation for Cosrin: A New Dawn in three distinct areas. Before we go into the specifics, first some ground rules for participation:
  • All entries to the contest must be submitted as a reply to this topic; not in a separate forum nor in a separate thread. Exceptions may apply for very limited and specific cases.
  • Old ideas, topics, or anything else may be 'submitted' as an entry into the contest so long as they are your own original ideas and not that of another player, both past or present.
  • Some parts of the contest may be first-come, first-serve. In order to 'secure' a specific section, a reply to this post requesting it is necessary. The order of the postings will determine the order of assignment.
  • You may not sign up for more than one first-come, first-serve section per category.
  • You may submit entries for first-come, first-serve sections other than your own so long as your assigned entry is submitted.
  • If all first-come, first-serve sections are assigned you may submit for any of them without first needing to be assigned a section.
Scripting Guides

With the release of the next generation wizard and full support of a lua scripting engine, many players are going through and trying to learn how best to utilize it for Cosrin: A New Dawn. For others, it has been seen as an opportunity for sharing technical knowledge and implementations of their own - and for that, we thank you.

But it wouldn't be fair without some compensation for your efforts; however, we'd like to break it down into specific categories:
  • [Nobody] Lua Overview
  • [Nobody] Built-In Commands
  • [Nobody] Character Information
  • [Halren] Events and Event Handlers
  • [Nobody] Session Variables
  • [Nobody] Timed Macros
  • [Eloras] Lua Standard Library Examples
  • [Trisana] Hunting Package - Casters
  • [Nobody] Hunting Package - Ranged
  • [Nobody] Hunting Package - Melee
In all cases, the complete script should be included as an attachment and the guide/usage/overview should make up the content of the post. Entries may be submitted that do not fall into any of the above listed categories if you so desire.

The above categories should be considered first-come, first-serve.

All guides shall be judged by the following criteria:
  • Whether or not the provided script produces interpreter errors :)
  • Functionality
  • Novelty
  • Efficiency
  • Usefulness
  • Documentation
  • Ease of Use
  • Relevance to Cosrin: A New Dawn
Website Content

For those of you who are less logical, less technical, or simply do not care for scripting, you may take part in this contest by working to expand and improve the pages of the Cosrin: A New Dawn website. We have been updating and adding features and content to the website over time, but many hands make for light work.

In some cases below, the pages may already have partial or complete content. If you think you can improve on what is already there, sign up for it. If you think a section is missing that should be included, note it in your submission and include rationale for its inclusion.

Entries may be submitted for the following categories:
  • [Nobody] World - Overview
  • [Nobody] World - Classes
  • [Trisana] World - Races
  • [Nobody] World - Skills and Spells
  • [Not Limited] World - Tales & Events
  • [Nobody] World - Maps
  • [Nobody] Play - Getting Started
  • [Nobody] Play - Guides & Tips (No Scripting Guides)
  • [Nobody] Support - Help
  • [Nobody] Support - Frequently Asked Questions
In all cases, the full text of the article, including formatting, should be submitted either as the text of the post or as a Rich Text Formatted document. Entries may be submitted that do not fall into any of the above listed categories if you so desire.

The above categories should be considered first-come, first-serve.

All articles shall be judged by the following criteria:
  • Correctness
  • Readability
  • Style
  • Relevance to Cosrin: A New Dawn
  • Usefulness
Help Files

For everyone else, who is neither too technical nor too creative, we have an opportunity to do a sweep through the OGC Desktop Client help file and expand, improve, and clarify the sections in the document. There are a large amount of sections in this document and they will be broken down into single pages.

In all cases, these are already present in the help manual. If you feel you can improve upon what is there, sign up for a section below and submit your entry. If you feel a section should be added that is not in the list, please note this in your submission along with rationale for why it should be added.

Entries may be submitted for the following categories:
  • [Nobody] Contents
  • [Nobody] Basics - Overview
  • [Nobody] Basics - What is this?
  • [Nobody] Basics - Features
  • [Nobody] Basics - Game Interface
  • [Nobody] Basics - Colors
  • [Nobody] Basics - Keyboard Shortcuts
  • [Nobody] Basics - Highlights
  • [Nobody] Basics - Macros
  • [Nobody] Basics - Internal Macro Commands
  • [Nobody] Basics - Speeding the Wizard Up
  • [Nobody] Basics - Nicknames
  • [Nobody] Basics - Aliases
  • [Lothaine] Basics - Speed Walking
  • [Nobody] Menus - File
  • [Nobody] Menus - Config
  • [Nobody] Menus - Magic
  • [Trisana] Menus - Stance
  • [Nobody] Menus - Window
  • [Nobody] Menus - Internet
  • [Nobody] Menus - Scripts
  • [Nobody] Menus - Help
  • [Nobody] Configuration - Options - Options - Overview
  • [Nobody] Configuration - Options - Options - Buffering
  • [Nobody] Configuration - Options - Options - Echo
  • [Nobody] Configuration - Options - Options - Profiles
  • [Nobody] Configuration - Options - Options - User Int
  • [Nobody] Configuration - Options - Options - Cmd History
  • [Nobody] Configuration - Options - Options - Profile Backup
  • [Nobody] Configuration - Options - Options - Speed Walk
  • [Nobody] Configuration - Options - Formatting - Overview
  • [Nobody] Configuration - Options - Formatting - Colors
  • [Nobody] Configuration - Options - Formatting - Coloring
  • [Nobody] Configuration - Options - Formatting - Hyperlinks
  • [Nobody] Configuration - Options - Formatting - Shops
  • [Nobody] Configuration - Options - Formatting - Status Bar
  • [Nobody] Configuration - Options - Formatting - Additional Timers
  • [Nobody] Configuration - Options - Formatting - Sheet
  • [Nobody] Configuration - Options - Toolbar
  • [Nobody] Configuration - Options - AFK
  • [Nobody] Configuration - Options - Movement Panel
  • [Nobody] Configuration - Options - Log Files - Overview
  • [Nobody] Configuration - Options - Log Files - Don't Log
  • [Nobody] Configuration - Options - Network
  • [Nobody] Configuration - Options - Online List
  • [Nobody] Configuration - Options - Output Windows
  • [Nobody] Configuration - Options - Scripting
  • [Nobody] Configuration - Options - Sounds - Overview
  • [Nobody] Configuration - Options - Sounds - Volume
  • [Nobody] Configuration - Options - Startup
  • [Nobody] Configuration - Options - Timed Operations
  • [Nobody] Configuration - Options - Whitelist - Overview
  • [Nobody] Configuration - Macros - Overview
  • [Nobody] Configuration - Macros - Macro Keys
  • [Nobody] Configuration - Macros - Function Keys
  • [Nobody] Configuration - Macros - NumPad
  • [Nobody] Configuration - Macros - Timed Macros
  • [Nobody] Configuration - Highlight Strings
  • [Nobody] Configuration - Nicknames
  • [Nobody] Configuration - Aliases
  • [Nobody] Configuration - Online List
In all cases, the full text of the article, including formatting, should be submitted either as the text of the post or as a Rich Text Formatted document. Entries may be submitted that do not fall into any of the above listed categories if you so desire.

The above categories should be considered first-come, first-serve.

All articles shall be judged by the following criteria:
  • Correctness
  • Readability
  • Style
  • Relevance to Cosrin: A New Dawn
  • Usefulness
Staff Commentary

Activities above are on the staff team's radar for improving the overall friendliness of Cosrin: A New Dawn for players who are new to the game. Anything not updated as part of a submission in this contest will continue to be worked as and when times allows for such activities to be completed.

Contest Rewards

For your hard work, dedication, and entry in the competition you will have a chance to win some valuable rewards and accolades. There will be general rewards for accepted entries and a slightly larger reward for the best submission per category.

As each category has its own entries and its own judging criteria, each category shall have an overall best submissions. There will not be an "best overall" as the three separate areas are greatly distinct from each other. Finally, it should be noted that the determination for best submission per category is based strictly on quality rather than quantity.

If there is an apparent flooding of entries, your submission will be judged based on your perceived worst entry.

Scripting Guides - Accepted Entries
  • Guide featured on the website and/or help manual.
  • Example scripts included as part of the wizard installer going forward.
  • Bronze medal good for a staff resurrection or a set of max mortal colors.
  • Prefix of your choosing.
Scripting Guides - Best Entry
  • Gold medal instead of bronze good for 3 staff resurrections or a single max available color.
  • Suffix of your choosing.
  • A permanent neckwear item, available for upgrade for six months; unique for at least one year.
  • One month's subscription, free of charge.
Website Content - Accepted Entries
  • Article permanently featured on the website and/or in-game help system.
  • Bronze medal good for a staff resurrection or a set of max mortal colors.
  • Prefix of your choosing.
Website Content - Best Entry
  • Gold medal instead of bronze good for 3 staff resurrections or a single max available color.
  • Suffix of your choosing.
  • A permanent neckwear item, available for upgrade for six months; unique for at least one year.
  • One month's subscription, free of charge.
Help Files - Accepted Entries
  • Article permanently featured in the wizard help manual and/or in-game help system.
  • Bronze medal good for a staff resurrection or a set of max mortal colors.
  • Prefix of your choosing.
Help Files - Best Entry
  • Gold medal instead of bronze good for 3 staff resurrections or a single max available color.
  • Suffix of your choosing.
  • A permanent neckwear item, available for upgrade for six months; unique for at least one year.
  • One month's subscription, free of charge.
Closing Commentary

We look forward to seeing what you as a community can come up with and will help in every step of the way to the best of our abilities. If you have any questions, please speak to a staff member in game or send an email to admin@cosrintwo.com.

Cosrin Staff
Admin
Site Admin
Posts: 206
Joined: May 3rd, 2012, 5:47 am

Re: Contest: Guides, Lore, and Help

Post by Admin »

Beginning 08 February 2013, I will start handing out some of the available choices, starting with the Help Files, to members of the staff team to complete.

They are not necessarily bound to a single entry per section as they get no reward beyond less whippings; so if there is a category that you would very much like to pursue, sign up early.
Admin
Site Admin
Posts: 206
Joined: May 3rd, 2012, 5:47 am

Re: Contest: Guides, Lore, and Help

Post by Admin »

Admin wrote:If you think a section is missing that should be included, note it in your submission and include rationale for its inclusion.
Since there have been questions, concerns, and comments about the lack of lore/story/history options, I am quoting this block from the original contest write-up.

We absolutely approve of, and in fact encourage, any and all players who wish to provide such material as an entry to the contest to do so, and it will be judged as any other article for the website will be judged.

To help clarify this, I have added into the original a post a new category:

World - Tales & Events

This category is open-ended, is not first-come, first-serve and can be for just about anything you want - be it a story told in a tavern, a historian recounting a fabled battle, a tortuous training path set upon by a dedicated warrior, or anything else your mind can come up with.

The game is only as rich as the stories it holds and creates; so you too can be rewarded for helping expand that, if you've no desire for one of the more "technical" or "bland" categories available.

Note: Guild History entries will be rejected with prejudice.
eloras
Posts: 13
Joined: June 17th, 2012, 3:23 pm

Re: Contest: Guides, Lore, and Help

Post by eloras »

This is a guide trying to cover most of the standard libraries in LUA.
This guide is aimed for people who have a basic understanding of if-statements,
for loops, and know the basics of simple scripting.

For a more comprehensive guide please check http://www.lua.org/manual/5.1/manual.html

This guide will teach you about the standard function in LUA, as well as the
basics of the io library, math library, and string library. I have provided
a small script showing how each function works. Any script should work simply
by copy-pasting it directly into an empty file.

Do a script not work? Did i miswrite something in the guide? Do you think something
is very unclear? Or did I simply miss something important? The do not hesitate
to send me a message on the forums and I'll look into it.

dofile:

dofile is used to include other files to your script and is almost
always necessary in bigger script. Take a look at the following examples:

myScript.lua

Code: Select all

	-- Prints a line when the file is included.
	Echo("hello from myScript.lua")
	
	-- Sets a variable in the myScript.lua file.
	myString = "this is a string"
	
	-- Creates a function which will write out the
	-- line you specified two times.
	function EchoTheEcho(echo)
		Echo(echo.. '\n'..echo)
	end
test.lua

Code: Select all

	-- Here we include the file 'myScript.lua'
	dofile("myScript.lua")
	
	--Output:
	-- hello from myScript.lua
	
	-- Since we included the file 'myScript.lua' we can now
	-- use all variables that existed in that file.
	Echo(myString)
	
	-- Output:
	-- this is a string
	
	-- Here we call a function we created in the file 'myScript.lua'
	-- we can create any amount of functions we want in other files
	-- and use them as much as we wish as long as we simply include
	-- the file the function lies in.
	EchoTheEcho("Eloras is a sorcerer")
	
	-- Output:
	-- Eloras is a sorcerer
	-- Eloras is a sorcerer

pairs:

pairs is an iterator function that can be used to iterate a table.
To most of our needs, it will be combined with the for statement and it will look like this:

Code: Select all

	-- Here we create a table and set data to it, the syntax for this is index=value
	-- notice that if you want to use a string as value you need to use "" around the string.
	myTable = { name="eloras", guild="mages", class="sorcerer", age=32 }

	-- Here we create a for loop that will loop through each item in the table
	-- and sets the index of the current item in the variable index, and sets the
	-- value of the current item in the value variable.
	for index, value in pairs(myTable) do
		-- And here we can use the index and value to for example print them out.
	   Echo("Index: '"..index.."', Value: '"..value.."'")
	end

	--Output:
	--Index: 'age', Value: '32'
	--Index: 'class', Value: 'sorcerer'
	--Index: 'name', Value: 'eloras'
	--Index: 'guild', Value: 'mages'
Notice that when having a table with alphabetical indexes specified, it will not necessarily print
out the indexes in the right order. An other way to get a specific value from a table is by
calling its index directly and it will look something like this:

Code: Select all

	-- Creates the table.
   myTable = { name="eloras", guild="mages", class="sorcerer" }
   
   -- Here we use myTable['name'] and myTable['class'] to fetch the values for those specific indexes.
   Echo("My name is "..myTable['name'].." and I am a "..myTable['class'])
   
   -- Output:
   -- My name is eloras and I am a sorcerer
   
   -- This way of calling an index is used quite frequently, I'm sure most of you
   -- have used it to check if you for example aren't hasted like this:
   
   if effects["hasted"] ~= true then
      -- Here you can do something to become hasted again.
      --Put("chant haste") PauseMS(1200) Put("t")
   end
   
   -- You can also set values to the table by specifying a index on your own.
   myTable["race"] = "elf"
   Echo("Did i forget to mention I'm an "..myTable["race"].."?")
   
   -- Output:
   -- Did i forget to mention I'm an elf?
ipairs:

ipairs is similar to pairs since it will also iterate a table, the main
difference is that it only iterate indexes with numbers, for example:

Code: Select all

	-- Creates a table with only indexes.
	myTable = {2, 4, 6, 8, 10}

	-- Like in the previous example, here we loop through each item in the table
	-- But since we this time use ipairs instead of pairs the order of the table
	-- will be preserved
	for index, value in ipairs(myTable) do
		-- Prints out the index and value of the current item.
		Echo("Index: '"..index.."', Value: '"..value.."'")
	end

   -- Output:Index: '1', Value: '2'
   -- Index: '2', Value: '4'
   -- Index: '3', Value: '6'
   -- Index: '4', Value: '8'
   -- Index: '5', Value: '10
And like in the previous example you can set a value at any index by simply specifying it:

Code: Select all

	-- Creates our table.
	myTable = {2, 4, 6}
	
	-- Resets index 2 to be 44 instead of 4.
	myTable[2] = 44
   
	Echo("index 2 has value: '".myTable[2].."'")
   
	-- Output: 
	-- index 2 has value: '44'
tonumber:

tonumber is used to convert an string or other objects to a number, it can
also be used to validate if something actually is a number. If the thing you validate
can be converted to a number, the number is returned, otherwise nil is returned.
Here are some examples:

Code: Select all

	-- Defining our variables.
	myString = "123"
	mySecondString = "sample string"

	--  In case tonumber does not return nil, its a number.
	if tonumber(myString) ~= nil then
		Echo("myString is a number")
	else
		Echo("myString is not a number")
	end

	--  In case tonumber does not return nil, its a number.
	if tonumber(mySecondString) ~= nil then
		Echo("mySecondString is a number")
	else
		Echo("mySecondString is not a number")
	end

	-- Output:
	-- myString is a number
	-- mySecondString is not a number
tonumber can also be good to use when you need to convert a string containing a number
to an actual number to use, here is a example of that:

Code: Select all

	-- Here we assign MyString the string 11
	MyString = "11"
	
	-- Here we assign MyNumber the number 5
	MyNumber = 5
	
	-- Here we use tonumber to convert the string containing 11 to the actual number 11.
	MyNewNumber = MyNumber + tonumber(MyString)
	
	Echo(MyNewNumber)
	-- Output:
	-- 16
type:

type is a function that will tell you what type of object you have, can be
very good to use if your function require a string or a table to work properly.
There are 7 distinct types in LUA they are: number, string, boolean, table,
function, thread and userdata.

Here are some examples using the function type():

Code: Select all

	-- Creates a function which sole purpose is to loop through a table
	function loopThisTable(myObject)
	
		-- Here we check if the object specified infact is a table.
		if type(myObject) == "table" do
		
			-- In case the object is a table, we loop through it with pairs().
			for index, value in pairs(myObject) do
				-- Prints out each item in the object.
				Echo("Index: '"..index.."', Value: '"..value.."'")
			end
			
		-- In case the object we got weren't a table we will get here.
		else
		
			-- So we let the user know that a table is required and we also tell them
			-- what kind of object the function really got.
			Echo("A table must be given, got '"..type(myObject).."'")
		end
	end

	loopThisTable("a string")
	-- Output: 
	-- A table must be given, got 'string'

	loopThisTable(3)
	-- Output:
	-- A table must be given, got 'number'

	myTestTable = {class="sorcerer", name="eloras")
	loopThisTable(myTestTable)
	-- Output: 
	-- Index: 'name', Value: 'eloras'
	-- Index: 'class', Value: 'sorcerer'

	loopThisTable({2,4,6})
	-- Output:
	-- Index: '1', Value: '2'
	-- Index: '2', Value: '4'
	-- Index: '3', Value: '6'
Other ways to use the function can be if you want to find out what kind of object
you have and then do something with it, let me show you an example of that:

Code: Select all

	-- Here we define the name of our function.
	function ICanPrintEverything(object)
	
		-- Here we check in case the object is a string.
		if type(object) == "string" then
			-- Since its a string we can print it out normally.
			Echo(object)
		
		-- Here we check in case the object is a number.
		elseif type(object) == "number" then
			-- Since its a number we can print it out normally.
			Echo(object)
			
		-- Here we check in case the object is a boolean (the value true or false).
		elseif type(object) == "boolean" then
			-- Technically a boolean is not a string, so its not to be mixed with the
			-- actuall strings "true" and "false" but if we Echo them out, it will
			-- show up as if they were a string containing that word.
			Echo(object)
		
		-- Here we check in case the object is a table.
		elseif type(object) == "table" then
		
			-- Since its a table, we need to loop through each item in the table
			-- in order to properly print out what it is containing. Now if you really
			-- want you can place a table inside a table inside a table ...etc
			-- but we shall not go into how lo loop through that here.
			for index, value in pairs(object) do
				-- Prints out each item in the object.
				Echo("Index: '"..index.."', Value: '"..value.."'")
			end
		else
			Echo("Unrecognized type: '"..type(object).."'")
		end
	end
	
	ICanPrintEverything("myString")
	
	-- Output:
	-- myString
	
	-- There is no need to put the number in a variable, purely there for demonstration purposes.
	myNumber = 153
	ICanPrintEverything(myNumber)
	
	-- Output:
	-- 153
	
	ICanPrintEverything(true)
	
	-- Output:
	-- true
	
	-- Just like with the number, you can pass the table dircectly into the function
	-- instead of putting it into a variable.
	myTable = {name="Eloras", class="Sorcerer", guild="Mages' guild", age="32"}
	ICanPrintEverything(myTable)
	
	-- Output
	-- Index: 'age', Value: '32'
	-- Index: 'class', Value: 'Sorcerer'
	-- Index: 'name', Value: 'Eloras'
	-- Index: 'guild', Value: 'Mages' guild'
string.gsub:

string.gsub is used to replace all occurrences of a string with another string,
could be very useful if you need to manipulate a string you have. Now when can this possibly
be used one might ask, one way to use it is if you store data to a file and need to update a specific
line, or change a value to an other value. More info about storing and reading data to files will come.

Here is a sample script to show you how string.gsub can be used.

Code: Select all

	-- Here we assign a value to our string.
	myString = "Eloras is a berserker"
	
	-- Print it out.
	Echo (myString)

	-- Here we use the string.gsub function to replace every occurrence of berserker with sorcerer.
	-- And sets the variable myString to the modified string.
	myString = string.gsub(myString, "berserker", "sorcerer")
	Echo (myString)
   
	-- Output:
	-- Eloras is a berserker
	-- Eloras is a sorcerer
string.len:

string.len is used to count the number of characters in a string, very useful
if you need to loop through each character of a string or if for example if you want to
check how many arguments is supplied to your script.

A simple usage of string.len can look like this:

Code: Select all

	-- Assigns a value to our string.
	myString = "hello"
	
	-- Here we use string.len() to find out the length of the string and echo it out.
	Echo("string length: '"..string.len(myString).."'")
   
	-- Output:
	-- string length: '5'
   
	--A simpler way to do this, is simply adding a #-sign in front of your string looking like this:
	Echo("string length: '"..#myString.."'")
   
	-- Output:
	-- string length: '5'
Now, as you people might have noticed, in the wizard you can execute a script from the command line
by writing '.scriptname'. So say you have a script called 'color.lua' and you want it to color each person
you specify as a argument, now if you should accidentally hit enter without passing an argument it would
not run as you might expect, so we should actually count the arguments passed to the script. So assuming you run
a script with the line '.color eloras denithur' it could look something like this:

Code: Select all

	-- Here we check if the length (counting the number of arguments in args) is bigger than 0.
	if #args > 0 then
	
		-- Here we tell the loop to set the variable i to 1, and loop as many times as there
		-- are items in the variable args. We can then fetch each argument by using args[i]
		-- since i will automatically increase by one for each time it loops.
		for i = 1, #args do
		
			-- Casts the spell with id 42 (ogre strength)
			Put("chant 42")
			
			-- Waits for your cooldown to disappear.
			PauseMS(1200)
			
			-- Target the player that was passed down as an argument.
			Put("t "..args[i])
			
			-- Casts the spell with id 45 (light shards)
			Put("chant 45")
			
			-- Waits for your cooldown to disappear.
			PauseMS(1200)
			
			-- Target the player that was passed down as an argument.
			Put("t "..args[i])
			
			-- Casts the spell with id 48 (eagle eye)
			Put("chant 48")
			
			-- Waits for your cooldown to disappear.
			PauseMS(1200)
			
			-- Target the player that was passed down as an argument.
			Put("t "..args[i])
		end
	end
string.lower and string.upper:

string.lower is used to turn a string into all lower characters. string.upper is the complete
opposite of string.lower. Here is a very basic example of how to use it:

Code: Select all

	-- Assigns a value to our string.
	myString = "HeLlO YoU"

	-- Here we use string.lower() to turn the entire string
	-- into lower case characters and echo it out.
	Echo(string.lower(myString))

	-- Output
	-- hello you


	-- Here we use string.upper() to turn the entire string
	-- into upper case characters and echo it out.
	Echo(string.upper(myString))
	-- Output
	-- HELLO YOU
string.reverse

string.reverse is a fairly standard function with one clear goal, to reverse a string,
for usage of this function, check the example below.

Code: Select all

	-- Defines our string
	myString = "Eloras is a sorcerer"
	
	-- Reverses the string and sets it into a variable.
	reversedString = string.reverse(myString)
	
	-- Echo the string out.
	Echo(reversedString)
	
	-- Output:
	-- rerecros a si sarolE
	
	
	-- There are of course ways to do this with less code, say you already
	-- had a variable which you want to reverse then you can simply use
	-- Echo and string.reverse directly on it, without saving data into
	-- variables first.
	
	Echo(string.reverse(myString))
	
	-- Output:
	--
string.find and string.sub:

string.find is used to find out what index the specified pattern is in a string.
string.sub is used to cut out a piece of the supplied string. Here are some examples:

Code: Select all

	-- Assigns a value to our string.
	myString = "Eloras is a sorcerer and he owns a star dragon."

	-- Say we want to cut that string after the 6th char, we need to do as follows:
	
	-- This tells the function that we want our new string to start at index one and end at index 6.
	-- NOTE: This will not change the value of the variable myString at all.
	newString = string.sub(myString, 1, 6)
	
	-- Echos out the new string we made.
	Echo(newString)

	-- Output:
	-- Eloras
Now what if we instead what to cut the string at the first space to get the first word?
That's where we use string.sub to find the index of the first space and use it in string.sub

Code: Select all

	-- Assigns a value to myString
	myString = "Eloras is a sorcerer and he owns a star dragon."

	-- This will find the location (index in the string) of the first space, and store it
	-- in the variable space_index
	space_index = string.find(myString, " ")

	-- Notice here that we use space_index-1 that is because we dont actually
	-- want the space to be apart of the new string, so we have to reduce the
	-- value of the variable with one.
	newString = string.sub(myString, 1, space_index-1)

	-- Echos out our new string.
	Echo(newString)

	-- Output:
	-- Eloras
Now, say we want to find every word in that sentence, we can build a loop that will find
each occurrence of a space, and print out that word. It will look something like this:

Code: Select all

	-- We set the offset at 0, it will serve the purpose of remembering where in
	-- in the string we are, so we don't fetch the same word twice or something.
	local offset = 1

	-- String we will use to fetch each word from.
	local myString = "Eloras is a sorcerer and he owns a star dragon"

	-- This variable will hold the space index so we know where to cut the string of.
	local space_index 

	-- This variable will temporarily hold each word of the sentence.
	local myWord

	-- Here if you don't remember what #string do, it checks the length of the string myString
	-- so this while lop will continue until offset is greater on the same value as the length of
	-- the variable myString.
	while offset <= #myString do
	
		-- This time we specified an offset to string.find that means, it will begin to search for the first
		-- occurrence of a space from the offset specified.
		space_index = string.find(myString, " ", offset)
      
		-- When we get to the end of the sentence there is no space there
		-- so we need to add a check to see in case space_index in nil
		-- that means we take the rest of the string as the last word.
		if space_index == nil then
		
			-- When we do not specify where it should end, it will take the
			-- remaining part of the string from the index 'offset'.
			myWord = string.sub(myString, offset)

			-- Sets the space_index to the end of the string.
			space_index = #myString
      
		-- In case space_index is not nil, that means a space was found and
		-- we can cut the string in the way we planned.
		else
		
			-- As I mentioned before, since we do not want the space to be apart of the word
			-- we need to add -1 to the space_index to get rid of it.
			myWord = string.sub(myString, offset, space_index-1)
		end
      
		-- Here we set the offset of the string to the location AFTER the space
		-- that is why we added the +1.
		offset = space_index+1

		-- Prints out each word.
		Echo(myWord)
	end

	-- Output: 
	-- Eloras
	-- is
	-- a
	-- sorcerer
	-- and
	-- he
	-- owns
	-- a
	-- star
	-- dragon
The math. library:

LUA has quite strong math library, it can be used in many different ways, I wont create a specific section for each
of them, but I'll write an example script that will cover a few of the basic ones, should you need further details
on the math library, please check http://www.lua.org/manual/5.1/manual.html#5.6

Code: Select all

	-- math.ceil() will return the lowest whole number
	-- that is greater or equal than the specified number.
	Echo(math.ceil(3.1415))

	-- Output:
	-- 4

	-- math.floor() will return the highest whole number
	-- that is lower or equal than the specified number.
	Echo(math.floor(3.1415))

	-- Output:
	-- 3

	-- math.min() will return the lowest value given as an argument to the function.
	Echo(math.min(5, 4, 8, 2, 9, 1.214, 1.382))

	-- Output:
	-- 1.214

	-- math.max() will return the highest value given as an argument to the function.
	Echo(math.max(5, 8, 21, 48, 9*9))

	-- Output:
	-- 81

	-- math.random(), gives a random number between two specified values.
	-- what is important to know with any "random" function is that nothing when it comes
	-- to computers is random, everything is simply a sequence of numbers.
	-- So in order to emulate a random pattern, we need to reseed the random function with
	-- an integer, ideally you would want to use a clock with milliseconds or something to 
	-- be able to reseed it after every use, sadly the best we can do in LUA is to use
	-- os.time() that however only goes down to seconds, so to get a better random result I
	-- suggest not using the random function more often than once every second.
	math.randomseed(os.time())
	Echo(math.random(1, 10))

	-- Output: (this will not be the same output for everyone) 
	-- 8
The io. library:

The IO library (Input and Output) can be used to read / save data to files, it may
be good if you need to stare data between game sessions, you can then read and save data to the file.
The functions I'll go through is: io.open(), io.write, io.close() and io.lines(). Do note in the
examples below i do NOT use io.lines() directly, instead you can use the 'handle' of the opened file.

Look at this quick example.

Code: Select all

	-- Here we open the file myfile.txt in write mode (thats the "w" part). That function will then
	-- return a filehandle that we save in our function aFileHandle.
	aFileHandle = io.open("myfile.txt", "w")
	
	-- Instead of writing io.read or io.write here we use aFileHandle:read or aFileHandle:write.
	-- This is because what if you have 2 files open at the same time, we need to be able to track
	-- which file we actually should write to, or read from, or close. That's what the handles are for.
	
	-- Here we say that we should write a line to the filehandle 'aFileHandle'
	aFileHandle:write("Just a test", "\n")
More information about the IO library can be found here: http://www.lua.org/manual/5.1/manual.html#5.7
Here is a short script going through the most basics of the io. library.

Code: Select all

	-- This will open a file for writing data to it, the different modes that can be supplied
	-- instead of "w" (write mode), are "r" (read mode) "a" (append mode), i wont go in to the
	-- other modes that exist, for future information please see the official manual.

	-- Please do note that using "w" it will overwrite all existing data the file curretly has.
	myFile = io.open("myfile.txt", "w")

	-- This will write a line to the file you opened.
	myFile:write("Hello my new file", "\n")

	-- This closes the file and it's recommended to be done as soon as you are
	-- done writing data to the file.
	myFile:close()

	-- Now to read data from the file we can write as follows

	-- this will loop through each line of the file and set
	-- the variable '_line' to the actual line of the file.
	for _line in io.lines("myfile.txt") do
		Echo(_line)
	end
   
   -- Output:
   -- Hello my new file
   

	-- Now if you want to append something to the file write like this:

	-- This opens the file 'myfile.txt' in "append" mode.
	myFile = io.open("myfile.txt", "a")

	-- Writes a line to the file.
	myfile:write("this is the second line", "\n")

	-- Closes the file.
	myfile:close()

	-- Now lets read through the file once again to see if the content changed.
	for _line in io.lines("myfile.txt") do
	  Echo(_line)
	end

	-- Output:
	-- Hello my new file
	-- this is the second line
the os. library:

The OS library (Operating System) can be used to run commands to you operating system or to
collect data about your system, such as current date, current time, remove files or folders
rename files and folders. I wont go through any of them here, for use of that library
go ahead and check: http://www.lua.org/manual/5.1/manual.html#5.8


Afterwords:

And last but not least, what you can do with all this is quite limitless, it is only your
imagination that sets the limits. Since relevance to cosrin is a criteria is this content
I decided to use my speedwalk for that, now why some might ask, am I too lazy to write a
new script? Could I not think of anything else?

The answer to that is the speedwalk function is very essential to cosrin, most of us use
speeedwalk in the normal client, and that is feature we all want in our scripts, the
speedwalk function uses several function such as string.len (#), string.find, tonumber,
string.sub as well as some of the built in commands that the wizard has. Therefore
I find it to be a valid entry, unless you have not checked out the topic i created
in 'wizard scripting' i'll add the current version of the speedwalk function as a
attached file.

With that I thank you all for taking your time and reading my guide of LUA Standard Library.
-- Eloras
Attachments
speedwalk.zip
(1.54 KiB) Downloaded 400 times
Halren
Posts: 86
Joined: May 29th, 2012, 1:38 am

Re: Contest: Guides, Lore, and Help

Post by Halren »

Note: This is a guide in a category I made up, if it does not seem suitable feel free to discard this entry. Note that I use screenshots instead of actual tables because this forum does not allow for BBCode tables. As actual website content these would of course be HTML tables instead of pictures. I would add the original document but .RTF and .DOCX are not allowed to be added as attachments.

Website Content: Play - Recommended Hunting Areas

This page contains recommendations for optimal hunting areas, where optimal is defined by maximizing experience gained per hour. The optimal hunting areas differ for several classes, hence the breakdown into multiple tables.

Image

Image

Image
Last edited by Halren on February 20th, 2013, 1:56 pm, edited 1 time in total.
Halren
Posts: 86
Joined: May 29th, 2012, 1:38 am

Re: Contest: Guides, Lore, and Help

Post by Halren »

Note: This is a guide in a category I made up, if it does not seem suitable feel free to discard this entry. I do however feel Rogues are worth their own hunting package because of the unique hunting style of assassination. Also I know I officially had to post my claimed guide first, but that subject seems to have a wizard bug at the moment so I cannot post that guide just yet.

Guide: Hunting package - Rogues
This is a short guide on how to use the Hunting Package - Rogues. This package contains scripts for two different hunting scenarios: basic hunting without assassination, and hunting with assassination.

Basic Hunting, no assassination
The "basicHuntRogue.lua" script is meant for basic hunting and currently configured for low level rogues. This script is to be ran as a Timed Macro, if you are unfamiliar with how to configure timed macros you can read about them here: http://www.cosrintwo.com/forums/viewtop ... f=29&t=212

The basicHuntRogue script does the following:

If you are below 100 HP it eats a paste of healing, and then equips your shield again.
If your weapon is not poisoned, it kills all remaining monsters in the room and then poisons your weapon.
If you are unhasted it eats a paste of adrenaline, and then equips your shield again.
If you have no red it eats a paste of potent strength, and then equips your shield again.
If you have no green it eats a paste of potent versions, and then equips your shield again.
Executes normal hunting macro.

Code: Select all

function waitForUnbalance()
	while character.unbalanced == true do
		PauseMS(100)
	end	
end

weapon = "nasty black dagger"
shield = "shield"

if character.hp < 100 then -- Change threshhold to whatever HP you start to feel unsafe at, make sure its not more than your max HP
	waitForUnbalance() -- Replace this with your preferred way of getting healed, or remove if you dont need it
	Put("get gold;;pack left;;wield paste of healing;;eat paste")
	PauseMS(2000)
	Put("pack left;;wield "..shield)
return end
		
-- Check weapon to apply enchant if needed
if character.righthand == weapon then
	Put("aim;;poison") end
		
-- Ensure colours are on
if effects["Strong"] == false then 
	waitForUnbalance()-- Replace this with your preferred way of getting Red, or remove if you dont need it
	Put("pack left;;wield paste of potent strength;;eat paste") 
	PauseMS(2000)
	Put("pack left;;wield "..shield)
return	end

if effects["Accurate"] == false then
	waitForUnbalance()-- Replace this with your preferred way of getting Green, or remove if you dont need it
	Put("pack left;;wield paste of potent visions;;eat paste") 
	PauseMS(2000)
	Put("pack left;;wield "..shield)
return	end

if effects["Hasted"] == false then
	waitForUnbalance()-- Replace this with your preferred way of getting Haste, or remove if you dont need it
	Put("pack left;;wield paste of adrenaline;;eat paste") 
	PauseMS(2000)
	Put("pack left;;wield "..shield)
return end
		
-- Now I can hunt.
Put("aim;;ch;;w;;aim;;ch;;e")
By default this uses monk pastes for colours, haste and healing. This can all be removed or changed to any alternate way of getting colours. At the top there are two variables, Weapon and Shield, the values set to these variables must match the name of your weapon (without enchants) and shield.

If you have the script set up as a timed macro as described in the guide linked above:
Image
you can start basic hunting with the following Macro Command: {SCRIPT toggle basicHunt}
Image

Hunting with Assassination
Hunting with assassination is slightly more complex. In this example code the script is configured to assassination hunt in charons, however the lines to turn this into cats3 are also included in the script (but commented out).

The main script to be executed for this is "assassHuntRogue.lua", this script again should be ran as a timedMacro. For guidance on how timedMacros work and how to configure them, see http://www.cosrintwo.com/forums/viewtop ... f=29&t=212. This script will do around the same as the basicHuntRogue script, however if an assassination target is found it will instead start using the rogues' face paint in order to assassinate the important targets.

Code: Select all

function waitForUnbalance()
	while character.unbalanced == true do
		PauseMS(100)
	end	
end

weapon = "draconian dagger"
shield = "void"

AssassOn = GetVariable("AssassOn")
AssassHuntString = GetVariable("AssassHuntString")
NormalHuntString = GetVariable("NormalHuntString")

	if character.hp < 600 then
		waitForUnbalance() -- Replace this with your preferred way of getting healed, or remove if you dont need it
			Put("get gold;;pack left;;wield paste of potent healing;;eat paste")
			PauseMS(2000)
			Put("pack left;;wield "..shield)
	return end
	
	if effects["Strong"] == false then
			waitForUnbalance() -- Replace this with your preferred way of getting Red, or remove if you dont need it
			Put("pack left;;wield paste of potent strength;;eat paste") 
			PauseMS(2000)
			Put("pack left;;wield "..shield)
	return end
	
	if effects["Accurate"] == false then
			waitForUnbalance() -- Replace this with your preferred way of getting Green, or remove if you dont need it
			Put("pack left;;wield paste of potent vision;;eat paste") 
			PauseMS(2000)
			Put("pack left;;wield "..shield)
	return end
	
			
	if effects["Hasted"] == false then
			waitForUnbalance() -- Replace this with your preferred way of getting Haste, or remove if you dont need it
			Put("pack left;;wield paste of adrenaline;;eat paste") 
			PauseMS(2000)
			Put("pack left;;wield "..shield)
	return end
	
	Echo("Assassination status: "..AssassOn)
	if string.find(AssassOn, "assass") then
	 if effects["Hidden"] == false then
	 	waitForUnbalance()
	 	if effects["Hidden"] == false then
	 	Put("activate face blacking paint")
	 	PauseMS(2200)
	 	end
	 end
	 	Put(AssassHuntString)
	else
	 if character.righthand == weapon then
	 	Put("poison")
	 else
	 	Put(NormalHuntString)
	 end
	end
However in order for assassHuntRogue.lua to work the "assassHuntRogue_registerEvents.lua" script has to be active.

The assassHuntRogue_registerEvents scripts will parse all incoming lines to see if there are mobs spotted that you wish to assassinate, in the sample code this means it looks for Hydras and Star Sorcerers. If these mobs are found (and its not in relation to them dying) a global variable is set to indicate assassination is required.

The assassHuntRogue_registerEvents script also has two global variables that define the normal hunting macro and the assassination hunting macro, this is how you define which monsters you want to target whenever you have flagged that assassination should be used. Also if you want to change hunting area only the assassHuntRogue_registerEvents variables need to be altered while the main script can stay the same.

Code: Select all

function event_line(data)
 -- if string.find(string.lower(data), "undead knight") or string.find(string.lower(data), "fire imp") or string.find(string.lower(data), "skeletal wizard") or string.find(string.lower(data), "greater skeleton") or string.find(string.lower(data), "gnoll champion") then -- If statement for Cats3
 if string.find(string.lower(data), "star sorc") or string.find(string.lower(data), "hydra") then -- If statement for Charons
	if  string.find(string.lower(data), "had") or string.find(string.lower(data), "slain") or string.find(string.lower(data), "there is no") or string.find(string.lower(data), "hydra scale") or string.find(string.lower(data), "hydra bone") or string.find(string.lower(data), "hydra spawn") then
		SetVariable("AssassOn", "clear")
		Echo("Assass target killed")
	else
		SetVariable("AssassOn", "assassOn")
		Echo("Assass target parsed")
	end
 end
 
 if string.find(string.lower(data), "has gained a level") then
  Put("guildtithe 75")
 end

end 

RegisterEvent("line", event_line)
SetVariable("AssassOn", "clear")
SetVariable("AssassHuntString", "t;;aim mouther;;aim hydra spawn;;aim hydra;;aim star sorcerer;;aim") -- AssassString for Charons
--SetVariable("AssassHuntString", "t;;aim fire imp;;aim undead knight;;aim skeletal wizard;;aim greater skeleton;;aim gnoll champion;;aim") -- AssassString forCats
SetVariable("NormalHuntString", "aim;;ch;;e;;aim;;ch;;w") -- 0
To run this script, add the following as a macro command: {SCRIPT on assassHuntRogue_registerEvents.lua}
Image

Keep in mind hitting escape will cancel this script just as all others, so ensure this script is running while you want to use the assassHuntRogue.lua script. If you are running the assassHuntRogue_registerEvents script all you need to do is start assassHuntRogue as a timed macro and you will be assassinating whatever is in your way.

If you have the script set up as a timed macro as described in the guide linked above:
Image
you can start assassination hunting with the following Macro Command: {SCRIPT toggle assassHunt}
Image
Image
Attachments
rogue.rar
(1.83 KiB) Downloaded 353 times
Trisana
Posts: 21
Joined: June 2nd, 2012, 6:22 pm

Re: Contest: Guides, Lore, and Help

Post by Trisana »

Hunting Package: Mages
As a mage, hunting can be tricky. Spell points are not infinite, and often run out in the middle of battle. Mages are not as tough as fighters or monks, and tend to get hit hard. A good hunting script should work as seamlessly as possible to regenerate SP and HP as efficiently as possible while still allowing the mage to attack mobs. This Mages’ hunting package contains a functions.lua file where all of my custom functions are stored, as well as a hunting script for mages. This tutorial assumes you have basic knowledge of LUA and have read the wizard manual and/or tutorials in the wizard scripting section of the forum.
Let’s start with the functions.lua file, as it will be the heart of all of your hunting scripts.

Code: Select all

 --
-- A neat and simple script to handle speedwalk.
-- Usage: SmartSpeedwalk("3w7n2[ne][buy 14][unpack sword][drink potion]2~")
-- If you want to edit the default delaytime of 285ms, add it as a second
-- parameter to the function.
--
function SmartSpeedwalk(speedwalk, delaytime)
   --
   -- Splits the speedwalk up into single movement commands.
   --
   local offset = 1
   local char
   
   while offset <= #speedwalk do
      local waitFor = delaytime or 225
      local command = ""
      local repeats = 0

      -- Creates a loop which will check incase multiple numbers are
      -- specified in a row for a high repeat count.
      for i= 1, 4 do
         -- Fetches the next char in the speedwalk.
         char = string.sub(speedwalk, offset, offset)
      
         -- Incase its a number, its an action we need to repeat.
         -- We also set the offset to +1 so we can check the next character.
         if tonumber(char) ~= nil then
            offset = offset+1
            repeats = repeats*10+char
         else
            -- Sets the repeat value to 1 only if it has not already been set
            if repeats == 0 then repeats = 1 end
            do break end
         end
      end
      
      -- If we find a [, we fetch all content untill first occurance of a ]
      -- So if you write [drink potion] it would fetch 'drink potion'
      if char == "[" then
         local tmp_pos = string.find(speedwalk, "]", offset)
         command = string.sub(speedwalk, offset+1, tmp_pos-1)
         offset = offset+#command+1

      -- One second pause
      elseif char == "~" then
         waitFor = 1000
      else
         command = char
      end
      
      
      -- Repeat for the specified amount of times.
      for i=1, repeats do
         -- If a comand was given, then execute it.
         if command ~= "" then
            Put(command)
         end
         
         -- Pauses the speedwalk.
         PauseMS(waitFor)
      end

      -- Next character in string
      offset = offset+1
   end
end

function ActivateGuildring()
	-- Rings out.
	Put("get gold;;activate guildring")
	PauseMS(2200)

	local success = false
	local lines = GetGameText()
	local speedwalkDelay = 360
	
	-- Buys guildring.
	for i = 100, #lines do
		if string.find(lines[i], GetVariable("CharacterName").." Activates her Mages' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "mages")
			--Echo(CharacterGuild)
			SmartSpeedwalk("n[pack right][buy 1][don guildring]s", speedwalkDelay)
			break
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Fighters' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "fighters")
			SmartSpeedwalk("ne[pack right][buy 1][don guildring][w][s]", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Rogues' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "rogues")
			SmartSpeedwalk("e[press button]s[pack right][buy 1][don guildring]nw", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Monks' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "monks")
			SmartSpeedwalk("[pack right][buy 13][don guildring]", speedwalkDelay)
			break
		
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Mages' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "mages")
			--Echo(CharacterGuild)
			SmartSpeedwalk("n[pack right][buy 1][don guildring]s", speedwalkDelay)
			break
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Fighters' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "fighters")
			SmartSpeedwalk("ne[pack right][buy 1][don guildring][w][s]", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Rogues' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "rogues")
			SmartSpeedwalk("e[press button]s[pack right][buy 1][don guildring]nw", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Monks' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "monks")
			SmartSpeedwalk("[pack right][buy 13][don guildring]", speedwalkDelay)
			break
		end
	end
	return success
end

-- Activates ring of recall and buys a new one, then takes character to shrine.
function BuyRingofRecall()
	--Ring
	Put("g gold;;Activate ring of recall")
	--Wait two secs for UT
	Pause(2)
	--Buy a new one, then put me in the shrine to rest.
	SmartSpeedwalk("9ww2n2e2~[buy 3]2w2s[se][rest]")
end
 

--**********Various Speedwalks************

function GoToCats3()
	--Checks the character for unbalance. If they are balanced, check for a compass, go to buy a compass or go to cats3
		if character.unbalanced == false then
			Put("activate compass")
			text = WaitFor("Activates her ^Ymagical compass^N", "You are not holding or wearing a ^Gcompass^N")
			Pause(3)
			if text == "You are not holding or wearing a ^Gcompass^N" then
				BuyCompass()
			end
			Pause(5)
			--Assumes Your remember by Cats2 is in Remember slot #9
			Put("t 9")
			SmartSpeedwalk("[se]edes[se]2[sw][se]s[sw]w~4[sw][se]s2[sw]w3[sw]4[se]s[se]2ed~d[nw]w[nw]")
		end
end

function GoToTymore()
	if character.unbalanced == false then
		Put("activate compass")
		text = WaitFor("Activates her ^Ymagical compass^N", "You are not holding or wearing a ^Gcompass^N")
		Pause(3)
		if text == "You are not holding or wearing a ^Gcompass^N" then
			BuyCompass()
		else
			--Assumes your remember outside of tymore is in Remember slot #4
			Put("t 4")
			SmartSpeedwalk("~2n[ne]")
		return end
	end
end

function GoToSewers2()
	--Sewers2 speedwalk.
		--Outside the herb shop
	if character.roomtitle == "^YOn Copper Walk in Moorgate by Apothecary shop^N" then
		SmartSpeedwalk("4w10n~")
	--Inside the herb shop
	elseif character.roomtitle == "^YInside an Apothecary's shop^N" then
		SmartSpeedwalk("n4w10n~")
	--Outside the potion shop
	elseif character.roomtitle == "^YOn Autumn Walk next to an alchemists shop^N" then
		SmartSpeedwalk("w5s~7w5n~")
	end
	Put("pack right;;unpack crowbar")
	Put("use crowbar")
	SmartSpeedwalk("de~2[se]3[sw]2[se][sw]~")
	Put("open door")
	SmartSpeedwalk("[ne][nw]n3[ne]")
end

--Purchase various items for different classes

function BuyPotion()
	ActivateGuildring()
	if GetVariable("CharacterGuild") == "mages" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2~n[withdraw 10000]s")
		end
		--Take me from Guild Recall to the potion shop
		SmartSpeedwalk("3e2se[ne]~")
	elseif GetVariable("CharacterGuild") == "fighters" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2~2w[withdraw 10000]2e")
		end
		--Take me from Guild Recall to the potion shop.
		SmartSpeedwalk("2~2[sw]w7ne[ne]~")
	elseif GetVariable("CharacterGuild") == "monks" then
		if(character.gold < 10000) then
			SmartSpeedwalk("[withdraw 10000]")
		end
		SmartSpeedwalk("2~2n7w[ne]~")
	elseif GetVariable("CharacterGuild") == "rogues" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2n3w4nw[withdraw 10000]~e4s3e2s")
		end
		SmartSpeedwalk("2n9w10ne[ne]~")
	end
	Put("buy 14")
	Put("sw")
end

function BuyMarlarane()
	ActivateGuildring()
	if GetVariable("CharacterGuild") == "mages" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2~n[withdraw 5000]s")
		end
		--Take me from Guild Recall to the potion shop
		SmartSpeedwalk("3e12s2w[sw]~")
	elseif GetVariable("CharacterGuild") == "fighters" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2~2w[withdraw 5000]2e")
		end
		--Take me from Guild Recall to the herb shop.
		SmartSpeedwalk("2[sw]w3s2w[sw]~")
	elseif GetVariable("CharacterGuild") == "monks" then
		if(character.gold < 5000) then
			SmartSpeedwalk("[withdraw 5000]")
		end
		SmartSpeedwalk("2ne[ne]~")
	elseif GetVariable("CharacterGuild") == "rogues" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2n3w4nw[withdraw 5000]~e4s3e2s")
		end
		SmartSpeedwalk("2n11w[sw]~")
	end
	Put("buy 6")
	Put("ne")
end


--*************Trigger Functions**************

function healself()
local text = tostring(TRIGGER)
	if text == "There is no ^Rcreature^N in the room" then
		if character.hp < 1084 then
			Put("g gold;;t;;cast heal")
            PauseMS(700)
		end
	end
end



function BuyCompass()
	-- Shrine
	if character.roomtitle == "^YThe Tranquil Healing Shrine^N" then
		SmartSpeedwalk("[nw]2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Moorgate centre
	elseif character.roomtitle == "^YAt the centre of Moorgate's market^N" then
		SmartSpeedwalk("10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Mages' Guild recall
	elseif character.roomtitle == "^YIn the entrance hall of the Mages' Guild^N" then
		SmartSpeedwalk("3e7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the mages' guild
	elseif character.roomtitle == "^YOn Brent Street in Moorgate by the Mages' guild^N" then
		SmartSpeedwalk("7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YOutside the gates to the Mages' Guild^N" then
		SmartSpeedwalk("e7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Fighters' guild recall
	elseif character.roomtitle == "^YThe grand meeting hall in the Fighters' Guild^N" then
		SmartSpeedwalk("2[sw]w2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the fighters' guild
	elseif character.roomtitle == "^YOn Brent Street in Moorgate by the Fighters' Guild^N" then
		SmartSpeedwalk("2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YBefore the portcullis of the Fighters' Guild^N" then
		SmartSpeedwalk("w2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the adventurer's guild
	elseif character.roomtitle == "^Y^YOn Broadside Walk by the ^CADVENTURERS' GUILD^Y!^N" then
		SmartSpeedwalk("2n2e[buy 7]2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Monks' guild recall
	elseif character.roomtitle == "^YInner Courtyard of the Monks' Guild^N" then
		SmartSpeedwalk("n[nw]w5s10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the monks' guild
	elseif character.roomtitle == "^YStanding before the entrance to the Monks' Guild^N" then
		SmartSpeedwalk("[nw]w5s10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Rogues' guild recall
	elseif character.roomtitle == "^YIn the meeting hall of the Rogues' Guild^N" then
		SmartSpeedwalk("n[nw]2w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the rogues' guild
	elseif character.roomtitle == "^YOutside the locked gates to the Rogues' Guild^N" then
		SmartSpeedwalk("[nw]2w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YOn Copper Walk by the Rogues' Guild^N" then
		SmartSpeedwalk("3w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the herb shop
	elseif character.roomtitle == "^YOn Copper Walk in Moorgate by Apothecary shop^N" then
		SmartSpeedwalk("3e5n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Inside the herb shop
	elseif character.roomtitle == "^YInside an Apothecary's shop^N" then
		SmartSpeedwalk("n3e5n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the potion shop
	elseif character.roomtitle == "^YOn Autumn Walk next to an alchemists shop^N" then
		SmartSpeedwalk("w5s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the rune shop
	elseif character.roomtitle == "^YOn Copper Walk in Moorgate by the Embalmers^N" then
		SmartSpeedwalk("7w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Inside the rune shop
	elseif character.roomtitle == "^YBefore 'Swiftly and with Style' Undertakers and Embalmers Salon^N" then
		SmartSpeedwalk("n7w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	end
end 
This may look like a lot and be intimidating, but let’s break it down.
The first function in this file is SmartSpeedwalk. This is a function that was created by Eloras to read speedwalks appropriately, as they do not translate well using the PUT() command. In version 503 or higher there is a built in SpeedWalk() function available for use, but in V503 this function does not support pauses, so this tutorial will be using the custom function instead. Speedwalks can be incredibly important in having a seamless hunting script, so this function is important.

Code: Select all

 --
-- A neat and simple script to handle speedwalk.
-- Usage: SmartSpeedwalk("3w7n2[ne][buy 14][unpack sword][drink potion]2~")
-- If you want to edit the default delaytime of 285ms, add it as a second
-- parameter to the function.
--
function SmartSpeedwalk(speedwalk, delaytime)
   --
   -- Splits the speedwalk up into single movement commands.
   --
   local offset = 1
   local char
   
   while offset <= #speedwalk do
      local waitFor = delaytime or 225
      local command = ""
      local repeats = 0

      -- Creates a loop which will check incase multiple numbers are
      -- specified in a row for a high repeat count.
      for i= 1, 4 do
         -- Fetches the next char in the speedwalk.
         char = string.sub(speedwalk, offset, offset)
      
         -- Incase its a number, its an action we need to repeat.
         -- We also set the offset to +1 so we can check the next character.
         if tonumber(char) ~= nil then
            offset = offset+1
            repeats = repeats*10+char
         else
            -- Sets the repeat value to 1 only if it has not already been set
            if repeats == 0 then repeats = 1 end
            do break end
         end
      end
      
      -- If we find a [, we fetch all content untill first occurance of a ]
      -- So if you write [drink potion] it would fetch 'drink potion'
      if char == "[" then
         local tmp_pos = string.find(speedwalk, "]", offset)
         command = string.sub(speedwalk, offset+1, tmp_pos-1)
         offset = offset+#command+1

      -- One second pause
      elseif char == "~" then
         waitFor = 1000
      else
         command = char
      end
      
      
      -- Repeat for the specified amount of times.
      for i=1, repeats do
         -- If a comand was given, then execute it.
         if command ~= "" then
            Put(command)
         end
         
         -- Pauses the speedwalk.
         PauseMS(waitFor)
      end

      -- Next character in string
      offset = offset+1
   end
end 
The second function in this file is ActivateGuildring. This is a function that will activate your guildring. Based on what kind of guildring you have, and thus, what guild you are in, it will speedwalk you to buy a new guildring and sit you back in your guild’s recall afterwards.

Code: Select all

 function ActivateGuildring()
	-- Rings out.
	Put("get gold;;activate guildring")
	PauseMS(2200)

	local success = false
	local lines = GetGameText()
	local speedwalkDelay = 360
	
	-- Buys guildring.
	for i = 100, #lines do
		if string.find(lines[i], GetVariable("CharacterName").." Activates her Mages' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "mages")
			--Echo(CharacterGuild)
			SmartSpeedwalk("n[pack right][buy 1][don guildring]s", speedwalkDelay)
			break
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Fighters' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "fighters")
			SmartSpeedwalk("ne[pack right][buy 1][don guildring][w][s]", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Rogues' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "rogues")
			SmartSpeedwalk("e[press button]s[pack right][buy 1][don guildring]nw", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates her Monks' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "monks")
			SmartSpeedwalk("[pack right][buy 13][don guildring]", speedwalkDelay)
			break
		
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Mages' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "mages")
			--Echo(CharacterGuild)
			SmartSpeedwalk("n[pack right][buy 1][don guildring]s", speedwalkDelay)
			break
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Fighters' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "fighters")
			SmartSpeedwalk("ne[pack right][buy 1][don guildring][w][s]", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Rogues' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "rogues")
			SmartSpeedwalk("e[press button]s[pack right][buy 1][don guildring]nw", speedwalkDelay)
			break
			
		elseif string.find(lines[i], GetVariable("CharacterName").." Activates his Monks' Guild ring") then
			success = true
			SetVariable("CharacterGuild", "monks")
			SmartSpeedwalk("[pack right][buy 13][don guildring]", speedwalkDelay)
			break
		end
	end
	return success
end 
The next few functions are speedwalks. They will take you to various different common hunting grounds. Some of these assume you have a remember to a specific place in a specific number. These numbers may need to be altered based on your personal remembers.

Code: Select all

 function GoToCats3()
	--Checks the character for unbalance. If they are balanced, check for a compass, go to buy a compass or go to cats3
		if character.unbalanced == false then
			Put("activate compass")
			text = WaitFor("Activates her ^Ymagical compass^N", "You are not holding or wearing a ^Gcompass^N")
			Pause(3)
			if text == "You are not holding or wearing a ^Gcompass^N" then
				BuyCompass()
			end
			Pause(5)
			--Assumes Your remember by Cats2 is in Remember slot #9
			Put("t 9")
			SmartSpeedwalk("[se]edes[se]2[sw][se]s[sw]w~4[sw][se]s2[sw]w3[sw]4[se]s[se]2ed~d[nw]w[nw]")
		end
end 

Code: Select all

 function GoToTymore()
	if character.unbalanced == false then
		Put("activate compass")
		text = WaitFor("Activates her ^Ymagical compass^N", "You are not holding or wearing a ^Gcompass^N")
		Pause(3)
		if text == "You are not holding or wearing a ^Gcompass^N" then
			BuyCompass()
		else
			--Assumes your remember outside of tymore is in Remember slot #4
			Put("t 4")
			SmartSpeedwalk("~2n[ne]")
		return end
	end
end

Code: Select all

 function GoToSewers2()
	--Sewers2 speedwalk.
		--Outside the herb shop
	if character.roomtitle == "^YOn Copper Walk in Moorgate by Apothecary shop^N" then
		SmartSpeedwalk("4w10n~")
	--Inside the herb shop
	elseif character.roomtitle == "^YInside an Apothecary's shop^N" then
		SmartSpeedwalk("n4w10n~")
	--Outside the potion shop
	elseif character.roomtitle == "^YOn Autumn Walk next to an alchemists shop^N" then
		SmartSpeedwalk("w5s~7w5n~")
	end
	Put("pack right;;unpack crowbar")
	Put("use crowbar")
	SmartSpeedwalk("de~2[se]3[sw]2[se][sw]~")
	Put("open door")
	SmartSpeedwalk("[ne][nw]n3[ne]")
End
Next are two functions that will buy items for you. The first is a potion speedwalk. It calls ActivateGuildring(), which means that you will activate your guildring, buy a new one, then go to guild recall. If you have less than 10,000 gold (the price of a potion before barter), you will withdraw 10,000 gold. Either way, from there, you will walk to the potions shop just outside the mages’ guild and purchase a potion.

Code: Select all

 function BuyPotion()
	ActivateGuildring()
	if GetVariable("CharacterGuild") == "mages" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2~n[withdraw 10000]s")
		end
		--Take me from Guild Recall to the potion shop
		SmartSpeedwalk("3e2se[ne]~")
	elseif GetVariable("CharacterGuild") == "fighters" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2~2w[withdraw 10000]2e")
		end
		--Take me from Guild Recall to the potion shop.
		SmartSpeedwalk("2~2[sw]w7ne[ne]~")
	elseif GetVariable("CharacterGuild") == "monks" then
		if(character.gold < 10000) then
			SmartSpeedwalk("[withdraw 10000]")
		end
		SmartSpeedwalk("2~2n7w[ne]~")
	elseif GetVariable("CharacterGuild") == "rogues" then
		if(character.gold < 10000) then
			SmartSpeedwalk("2n3w4nw[withdraw 10000]~e4s3e2s")
		end
		SmartSpeedwalk("2n9w10ne[ne]~")
	end
	Put("buy 14")
	Put("sw")
end 
The second function buys a mar’larane based on what guild you are in. It calls ActivateGuildring(), which as before ensures that you will activate your guildring, buy a new one, then go to guild recall. If you have less than 5,000 gold (roughly the price of a mar’larane before barter), you will withdraw 5,000 gold. Either way, from there, you will walk to the mar’larane shop by the fighters’ guild and buy a mar’larane.

Code: Select all

 function BuyMarlarane()
	ActivateGuildring()
	if GetVariable("CharacterGuild") == "mages" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2~n[withdraw 5000]s")
		end
		--Take me from Guild Recall to the potion shop
		SmartSpeedwalk("3e12s2w[sw]~")
	elseif GetVariable("CharacterGuild") == "fighters" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2~2w[withdraw 5000]2e")
		end
		--Take me from Guild Recall to the herb shop.
		SmartSpeedwalk("2[sw]w3s2w[sw]~")
	elseif GetVariable("CharacterGuild") == "monks" then
		if(character.gold < 5000) then
			SmartSpeedwalk("[withdraw 5000]")
		end
		SmartSpeedwalk("2ne[ne]~")
	elseif GetVariable("CharacterGuild") == "rogues" then
		if(character.gold < 5000) then
			SmartSpeedwalk("2n3w4nw[withdraw 5000]~e4s3e2s")
		end
		SmartSpeedwalk("2n11w[sw]~")
	end
	Put("buy 6")
	Put("ne")
End
Separated from the rest of the functions are my trigger functions. I currently have two set up. The first is a simple healing trigger. I have set this up so that when there are no creatures in the room and I am below full health, I will heal myself. This keeps me fully healed in between battles. In order to utilize this function, you must set up a highlight string. Click on config > Highlight strings. In the highlight text field, enter “There is no ^Rcreature^N in the room”. In the script field, select functions.lua. In the function name field, enter “healself”. Don’t forget to click “add” to add the highlight before clicking “ok”! Now whenever the text “There is no creature in the room” appears, if your HP is less than the number entered, you will attempt to heal yourself.
Image

Code: Select all

 function healself()
local text = tostring(TRIGGER)
	if text == "There is no ^Rcreature^N in the room" then
		if character.hp < 1084 then
			Put("g gold;;t;;cast heal")
            PauseMS(700)
		end
	end
end 
Lastly is a trigger for buying compasses. I use this not only as a trigger, but also as a function within most of my speedwalk functions in case I do not have a compass. This function checks the room title of the room the character is currently in. If it is a room title that is recognized within the function, it will speedwalk you to the compass shop, then the shrine. In order to use this as a trigger, click on config > highlight strings. In the highlight text field, enter “You are not holding or wearing a ^Gcompass”. In the script field, select functions.lua. In the function name field, enter “BuyCompass”. Don’t forget to click “add” to add the highlight before clicking “ok”! Now whenever the text “You are not holding or wearing a compass” appears, if you are in a room recognized by the BuyCompass function, you will buy a new compass.

Image

Code: Select all

 function BuyCompass()
	-- Shrine
	if character.roomtitle == "^YThe Tranquil Healing Shrine^N" then
		SmartSpeedwalk("[nw]2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Moorgate centre
	elseif character.roomtitle == "^YAt the centre of Moorgate's market^N" then
		SmartSpeedwalk("10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Mages' Guild recall
	elseif character.roomtitle == "^YIn the entrance hall of the Mages' Guild^N" then
		SmartSpeedwalk("3e7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the mages' guild
	elseif character.roomtitle == "^YOn Brent Street in Moorgate by the Mages' guild^N" then
		SmartSpeedwalk("7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YOutside the gates to the Mages' Guild^N" then
		SmartSpeedwalk("e7s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Fighters' guild recall
	elseif character.roomtitle == "^YThe grand meeting hall in the Fighters' Guild^N" then
		SmartSpeedwalk("2[sw]w2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the fighters' guild
	elseif character.roomtitle == "^YOn Brent Street in Moorgate by the Fighters' Guild^N" then
		SmartSpeedwalk("2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YBefore the portcullis of the Fighters' Guild^N" then
		SmartSpeedwalk("w2n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the adventurer's guild
	elseif character.roomtitle == "^Y^YOn Broadside Walk by the ^CADVENTURERS' GUILD^Y!^N" then
		SmartSpeedwalk("2n2e[buy 7]2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Monks' guild recall
	elseif character.roomtitle == "^YInner Courtyard of the Monks' Guild^N" then
		SmartSpeedwalk("n[nw]w5s10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the monks' guild
	elseif character.roomtitle == "^YStanding before the entrance to the Monks' Guild^N" then
		SmartSpeedwalk("[nw]w5s10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Rogues' guild recall
	elseif character.roomtitle == "^YIn the meeting hall of the Rogues' Guild^N" then
		SmartSpeedwalk("n[nw]2w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the rogues' guild
	elseif character.roomtitle == "^YOutside the locked gates to the Rogues' Guild^N" then
		SmartSpeedwalk("[nw]2w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	elseif character.roomtitle == "^YOn Copper Walk by the Rogues' Guild^N" then
		SmartSpeedwalk("3w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the herb shop
	elseif character.roomtitle == "^YOn Copper Walk in Moorgate by Apothecary shop^N" then
		SmartSpeedwalk("3e5n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Inside the herb shop
	elseif character.roomtitle == "^YInside an Apothecary's shop^N" then
		SmartSpeedwalk("n3e5n4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the potion shop
	elseif character.roomtitle == "^YOn Autumn Walk next to an alchemists shop^N" then
		SmartSpeedwalk("w5s4w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Outside the rune shop
	elseif character.roomtitle == "^YOn Copper Walk in Moorgate by the Embalmers^N" then
		SmartSpeedwalk("7w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	--Inside the rune shop
	elseif character.roomtitle == "^YBefore 'Swiftly and with Style' Undertakers and Embalmers Salon^N" then
		SmartSpeedwalk("n7w5n10w2n2e[buy 7]~2w2s[se][rest]")
		Put("Activate compass")
		Pause(2)
	end
end 
Now that we’ve tackled functions.lua, let’s look at how all of this comes into play in an actual hunting script.

Code: Select all

 require "functions"
--If my HP is below 100, ring me out!!	
	if character.hp<200 then
		if character.unbalanced == false then
			if effects["Confused"] == false then
				ActivateGuildring()
				Exit()
			return end
		return end
	 return end
-- If my Spell Points are below 21, drink a potion. If I don't have a potion, ring me out, buy a potion, then take me back to my hunting grounds	
	if character.sp<21 then
		if character.unbalanced == false then
		--[[For pastes
		Put("pack right;;unpack paste of potent energies")
		text = WaitFor("UNPACKs a ^Gpaste of potent energies^N", "You do not have a ^Gpaste of potent energies^N in your backpack")
		if text == "You do not have a ^Gpaste of potent energies^N in your backpack" then]]
		--For Potions
		Put("pack right;;unpack potion")
		text = WaitFor("You do not have a ^Gpotion^N in your backpack", "UNPACKs a ^Gdraught of the gods^N")
			if text == "You do not have a ^Gpotion^N in your backpack" then
				if character.unbalanced == false then
					if effects["Confused"] == false then
						BuyPotion()
						GoToTymore()
					return end
				return end
				else
					Put("drink potion")
					--Put("eat paste")
					Pause(2)
			return end
		return end
	end
-- If I have less than 700 hp, heal me
	if character.hp<800 then
		Put("cast 33;;t")
		PauseMS(400)return end
	
-- Protection spell
	if effects["Protected"] == false then
		Put("cast 47;;t")
		PauseMS(400) return end
--Hasted paste
	if effects["Hasted"] == false then
		Put("pack right;;unpack paste of adrenaline;;eat paste")
		Pause(2) return end
--Entangle resistance
	if effects["Entangle Resistant"] == false then
		Put("cast 58;;t")
		PauseMS(400)return end
	
	if effects["Poison Resistant"] == false then
		Put("cast bloodshrine;;t")
		PauseMS(400) return end
--[[Longford Hunting macro
	Put("g gold;;t cinder wisp;;t;;cast ice ball;;e;;w")]]
--[[Charons hunting macro
	Put("g gold;;t hydra spawn;;t giant spider;;t mouther;;t;;cast ice ball;;n;;s")]]
--[[Sewers hunting macro
	Put("g gold;;t pteropida;;t crocodile;;t black orc;;t;;cast ice ball;;n;;s")]]
--Tymore hunting macro
	Put("g gold;;t blood speckled croc;;t;;cast 8;;n;;s")
--[[Prison hunting macro
	Put("g gold;;t lizard man guard;;t;;cast 8")]]
--[[Bracken hunting macro
	Put("g gold;;re;;t white mosquito;;t red mosquito;;t wailing sacrifice;;t;;cast inferno")]]
--[[Ants Lair hunting macro
	Put("g gold;;re;;t sentinel ant;;t custodial ant;;t;;cast 8")]] 
Let’s break this down. The first thing this script does is open functions.lua so that you can reference the functions created there. It then checks your hit points. If they are below 200, you are balanced, and you are not confused, if will ring you out and buy a new guildring.

Code: Select all

 require "functions"
--If my HP is below 100, ring me out!!	
	if character.hp<200 then
		if character.unbalanced == false then
			if effects["Confused"] == false then
				ActivateGuildring()
				Exit()
			return end
		return end
	 return end
Next is a check for spell points. If your spell points are below 21 and you are balanced, you will unpack either a paste or potion, depending on which section is commented out. The script is currently set up to use draughts of the gods. If I do not have a draught of the gods, the script will ring me out, buy a new guildring, buy a new potion, and then take me back to my hunting Spot in Tymore. If I have a potion, it will simply drink it.

Code: Select all

 -- If my Spell Points are below 16, drink a potion. If I don't have a potion, ring me out, buy a potion, then take me back to my hunting grounds	
	if character.sp<21 then
		if character.unbalanced == false then
		--[[For pastes
		Put("pack right;;unpack paste of potent energies")
		text = WaitFor("UNPACKs a ^Gpaste of potent energies^N", "You do not have a ^Gpaste of potent energies^N in your backpack")
		if text == "You do not have a ^Gpaste of potent energies^N in your backpack" then]]
		--For Potions
		Put("pack right;;unpack potion")
		text = WaitFor("You do not have a ^Gpotion^N in your backpack", "UNPACKs a ^Gdraught of the gods^N")
			if text == "You do not have a ^Gpotion^N in your backpack" then
				if character.unbalanced == false then
					if effects["Confused"] == false then
						BuyPotion()
						GoToTymore()
					return end
				return end
				else
					Put("drink potion")
					--Put("eat paste")
					Pause(2)
			return end
		return end
	end
Next, if I have more than 200 HP and more than 21 SP, it will check to see if I have less than 800 hitpoints. If I do, I will heal myself. You may need to change what spell is cast, because I use Body Restore.

Code: Select all

 -- If I have less than 800 hp, heal me
	if character.hp<800 then
		Put("cast 33;;t")
		PauseMS(400)return end
Next, if I am high on hit points and have more than 21 SP, the script will check to see if I am protected. If I am not, I will provide dragon shards for myself.

Code: Select all

 -- Protection spell
	if effects["Protected"] == false then
		Put("cast 47;;t")
		PauseMS(400) return end
If I am fine on HP and SP and am protected, but am not Hasted, I will unpack a paste of adrenaline and eat it.

Code: Select all

--Hasted paste
	if effects["Hasted"] == false then
		Put("pack right;;unpack paste of adrenaline;;eat paste")
		Pause(2) return end
If I am fine on HP and SP, have dragon shards and haste, but do not have entangle resistance, I will cast that on myself.

Code: Select all

 --Entangle resistance
	if effects["Entangle Resistant"] == false then
		Put("cast 58;;t")
		PauseMS(400)return end
If my HP and SP are fine, I have dragon shards, haste, and entangle resistance, but do not have Poison resistance, I will cast that on myself.

Code: Select all

 	if effects["Poison Resistant"] == false then
		Put("cast bloodshrine;;t")
		PauseMS(400) return end
Next are my hunting macros. I have set this up so that the hunting macro being used is for Tymore. To switch, simply comment out the tymore macro and uncomment out a different macro, or create your own!

Code: Select all

--[[Longford Hunting macro
	Put("g gold;;t cinder wisp;;t;;cast ice ball;;e;;w")]]
--[[Charons hunting macro
	Put("g gold;;t hydra spawn;;t giant spider;;t mouther;;t;;cast ice ball;;n;;s")]]
--[[Sewers hunting macro
	Put("g gold;;t pteropida;;t crocodile;;t black orc;;t;;cast ice ball;;n;;s")]]
--Tymore hunting macro
	Put("g gold;;t blood speckled croc;;t;;cast 8;;n;;s")
--[[Prison hunting macro
	Put("g gold;;t lizard man guard;;t;;cast 8")]]
--[[Bracken hunting macro
	Put("g gold;;re;;t white mosquito;;t red mosquito;;t wailing sacrifice;;t;;cast inferno")]]
--[[Ants Lair hunting macro
	Put("g gold;;re;;t sentinel ant;;t custodial ant;;t;;cast 8")]]
Now that we’ve gone through what the hunting script does, what do we do to start it? We use something called a timed macro. Go to config > Macros, and click on the “Timed Macros” tab. Click “Add”. Name your macro something you can easily remember; I have named mine “THunt” for Trisana Hunting script. For the interval, put 360. Under macro Filename, select the hunting script you created. Click “Apply”.
Image

Next click on the “function keys” tab. Pick a Key to toggle your hunting script. I have put mine in F3. In the Macro Command field for that key, put {SCRIPT toggle THunt} where THunt is the name of your timed macro. Click “OK”.
Image


Now in order to start hunting, all you need to do is hit the appropriate F-key! To stop the hunting script, just hit the key again.
Attachments
MageHuntingPackage.rar
(4.06 KiB) Downloaded 379 times
User avatar
Lothaine
Posts: 49
Joined: May 27th, 2012, 10:47 pm

Re: Contest: Guides, Lore, and Help

Post by Lothaine »

Help Files > Basics > Speed Walking

Speed Walking

Also see Configuration, Speedwalk.

Speed walking allows you to send a stream of directions or commands in one entry.

Executing a Speedwalk:
Begin a command with the speed walk character (default comma), followed by your movement/directions.
Note: Doesn't matter if commands are in upper or lower case.

Example: ,nnsseee
Sends 7 directions to the game; 2 North, 2 South, 3 East.

However, there's a better way accomplish the above. Numbers can be used to replicate a direction. The number comes first.

Example: ,2n2s3e
Sends the exact same 7 directions to the game; 2 North, 2 South, 3 East.


Movement Commands:
Since a command like "NE" will execute as North then East, you're probably wondering how to move NorthEast. There are effectively three ways to move diagonally:

1. By default, each direction is 1 character:

N - North
S - South
E - East
W - West
U - Up
D - Down
H - NorthWest
J - NorthEast
K - SouthWest
L - SouthEast

If remembering directions such as H, J, K, and L isn't appealing, you'll likely prefer one of the following two methods:

2. Diagonal directions (NW, SW, NE, SE) are recognized if you put a space in front of them.

Example (excluding the quotation marks): " ,2n2s3e2 se"
Sends the previous 7 directions to the game along with the diagonal; 2 North, 2 South, 3 East, 2 SouthEast. The number goes before the space: "2 se".
Note: In the configuration, the default can be changed so that a space is significant. This effectively reverses the space's role. In this mode NW will be treated as NorthWest first (as opposed to North then West). N <space> W would be required to send 2 directions.

3. Brackets can be used to frame commands, including movement.

Example: ,2ne[se]4[ne]wn3[nw]ws
Sends 15 directions to the game; 2 North, East, SouthEast, 4 NorthEast, West, North, 3 NorthWest, West, South.


Grouped Movement:
Parenthesis can be used to group movement. The purpose of this is to issue the grouped set multiple times.
Note: Parenthesis and Brackets can be used together.

Example: ,3([nw]se)
Sends 9 directions to the game; NorthWest, South, East, NorthWest, South, East, NorthWest, South, East.
Lothaine of the Mages' Guild
CosrinLothaine@gmail.com
Kaede
Posts: 9
Joined: May 25th, 2012, 1:58 pm

Re: Contest: Guides, Lore, and Help

Post by Kaede »

WORLD > CLASSES > BATTLEMAGE

Attached. Enjoy!

P.S. Since these forums don't allow the uploading of anything even remotely normal when it comes to document formats, I have put the .doc into a .rar
Attachments
BMdo.rar
The .doc is in here!
(13.08 KiB) Downloaded 355 times
Korlic
Posts: 3
Joined: August 24th, 2012, 11:51 am

Re: Contest: Guides, Lore, and Help

Post by Korlic »

The following file is a help file to help explain the basic concept of macros.
Attachments
Basics Macros.rar
(12.33 KiB) Downloaded 349 times
Trisana
Posts: 21
Joined: June 2nd, 2012, 6:22 pm

Re: Contest: Guides, Lore, and Help

Post by Trisana »

Website Content: Races

Human

You should know about this race!

Unique Features:
  • Unarmed Combat (1 level)
    Barter (1 level)
Image

Dwarf

Sturdy but slow.

Unique Features:
  • Dwarven Language (1 level)
    Drinking (1 level)
    Two Handed Weapons (1 level)
    Resilience (1 level)
Image

Elf

Smart, quick, but somewhat weak

Unique Features:
  • Elvish Language (1 level)
    Spiritual Karma (1 level)
    Magic Spell Use (1 level)
    Missile Weapons (1 level)
    Spell Resistance (1 level)
    Awareness (1 level)
Image

HalfElf

A cross between a human and an Elf.

Unique Features:
  • Elven language (1 level)
    Awareness (1 level)
    One Handed Weapons (1 level)
    Swimming (1 level)
    Barter (1 level)
Image

Half Ogre

Big, strong, and stupid!

Unique Features:
  • Ogre language (1 level)
    Physical Training (2 levels)
    Two Handed Weapons (1 level)
    Resilience (1 level)
    Toughness (1 level)
    Drinking (1 level)
Image

Gnome

Speedy, hard to hit, somewhat weak.

Unique Features:
  • Gnomish Language (1 level)
    Assassination (1 level)
    Dodging (1 level)
Image

Halfling

Dexterous, hard to hit, somewhat weak

Unique Features:
  • Halfling language (1 level)
    Called Shot (1 level)
    Drinking (1 level)
    Missile Weapons (1 level)
    Dodging (1 level)
Image

Half Orc

Ugly, strong, but dumb

Unique Features:
  • Orcish Language (1 level)
    Drinking (1 level)
    Physical Training (1 level)
Image

Half Giant

Huge, strong, but clumsy.

Unique Features:
  • Giant Language (1 level)
    Physical Training (1 level)
    Toughness (2 levels)
Image

Lizard Man

Scaley, water breathing, weak

Unique Features:
  • Underwater breathing
    Saurian language (1 level)
    Swimming (6 levels)
    Toughness (1 level)
Image

Sprite

Small, winged, frail, they fly

Unique Features:
  • Always flying
    Sylvan Language (1 level)
    Spiritual Karma (1 level)
Image

Minotaur

Half Bull, Half Man

Unique Features:
  • Cannot wear helms
    Drinking (1 level)
    Two Handed Weapons (1 level)
    Toughness (1 level)
    Resilience (1 level)
    Physical Training (2 levels)
Image

Centaur

Half Horse, Half Man

Unique Features:
  • Unable to have mounts but has the “charge” command.
    Cannot wear leg armor.
    Drinking (1 level)
    Two Handed Weapons (1 level)
    Toughness (1 level)
    Resilience (1 level)
    Physical Training (2 levels)
In addition to these features, centaurs receive unique text surrounding when they enter and exit a room. This text changes based on what stance they are currently in.

Normal
<character> canters from out of nowhere, coming to a halt and planting all four hooves on the ground.
<character> canters to the north as only a centaur can.

Parry
<character> trots to the north, scanning for danger or enemies as centaur often do.
<character> enters from the north, watching out for any ambush or danger.

Berserk
<character> gallops to the north, a centaur is a dangerous creature when angry.
<character> enters from the north, eyes burning brightly, ready for battle.

Image

Dark Elf

Elves gone bad!

Unique Features:
  • Spiritual Karma (1 level)
    Magic Spell Use (1 level)
    Missile weapons (1 level)
    Spell Resistance (1 level)
    Awareness (1 level)
Image

Dragon Kin

Half Man, Half Dragon, they fly!

Unique Features:
  • Can only wear rings, no armour.
    Cannot use mounts, but can use the “charge” command
    Can trigger fly using the fly/land commands
    Barter (1 level)
    Unarmed Combat (1 level)
In addition to these features, dragon kin receive unique text surrounding when they enter and exit a room. This text changes based on what stance they are currently in and also whether or not the dragon is currently flying.

Dragon Kin Enter and Exit text while flying

Normal
<character> glides in from the northwest and circles around in the air, gently flapping huge wings.
<character> glides to the north, flapping those powerful wings and breathing out bursts of fire.

Parry
<character> enters from the north, whirls around and scans for trouble with glowing dragon eyes.
<character> flies to the north, looking for signs of trouble, flexing sharp claws.

Berserk
<character> enters from the north, eyes glaring and breathing torrents of fire all around.
<character> roars to the north, leaving a trail of fire and smoke behind them.

Dragon Kin Enter and Exit text while in “landed” mode

Normal
<character> enters from the northeast, tail swishing and wings folded behind a broad back.
<character> strides to the north, rearing up onto strong hind legs.

Parry
<character> enters from the north, eyes scanning for trouble, smoke trailing from flaring nostrils.
<character> stomps to the north, looking around and folding massive wings tightly behind.

Berserk
<character> enters from the north, flames pouring from a fiery mouth, sharp teeth glistening.
<character> thunders to the north with clawed fists clenched and eyes shining bright.

Image

Catline

Half Panther, Half Man

Unique Features:
  • Missile Weapons (1 level)
    Dodging (1 level)
    Called Shot (1 level)
Image
Attachments
cosrin2 races content.rar
(22.28 KiB) Downloaded 339 times
Trisana
Posts: 21
Joined: June 2nd, 2012, 6:22 pm

Re: Contest: Guides, Lore, and Help

Post by Trisana »

Help Files > Menus > Stance

Cosrin: A New Dawn allows you to set three battle modes, also known as stances. Select any of the three stances from the STANCE Menu to switch to that battle mode. To tell what your current battle stance is, you can consult STATS.

Berserk

This combat mode causes your character to attack with more power, but also sacrifices a large amount of defense in the process. Characters in berserk get hit more often for more damage, and berserk largely negates the effects of protection spells.

Normal

This is the standard combat mode that your character is set to as a default when they log in. While in standard mode, a character can block some attacks and defensive and offensive abilities are similar.

Parry

This combat mode allows you to block or dodge a large majority of physical attacks. While parrying, your defensive ability is greatly increased, however, a character cannot attack creatures or cast spells while in this mode.
Halren
Posts: 86
Joined: May 29th, 2012, 1:38 am

Re: Contest: Guides, Lore, and Help

Post by Halren »

Events and Event handlers.
Registering events
The wizard allows you to subscribe on the event of the client receiving data, including the data that was sent. Essentially what this means is that it allows you to parse all the game data yourself within scripts. Running the following Lua script subscribes to this event and shows all data on screen.

Code: Select all

function event_line(data)

  Echo("Game  data: "..data)

end 

RegisterEvent("line", event_line)
Image

Data from the following channels will trigger this event, if the data comes from a channel other than game, it will be prefixed with a tag announcing from which channel it originates.

Code: Select all

Channel          Prefix
------------------------------
Game
Tells            [t]
Shouts           [s]
gshout           [G]
wail             [W]
tshout           [T]
event            [E]
logon            [L]
chat             [C]
hhshout          [H]
quest            [Q]
RegisterEvent("line", event_line) subscribes to the event of the client receiving a line of data. Whenever this happens it triggers the function given, in this case I created the function event_line. event_line will echo all received data to the game window. In order for this to take effect, the script containing this RegisterEvent must be ran first. It does not automatically work like triggers, and the event registration is only active while the script is running and thus can be canceled just like all scripts with Escape.

Image

All the above mentioned channels can also be seperately subscribed to. The following code will not trigger on all line data, it will only trigger on chats. The same could be done for shouts, tells, etcetera.

Code: Select all

function tell_event(data)
	Echo("chat event triggered : "..data)
end

RegisterEvent("chat", tell_event)
Example: Handling events
Getting all game data within a script is fun, but echoing everything double is not the most useful application for it. In this example I will register an event and parse it so in the case of a balance request, Halren will automatically give that person a weapon balance.

Code: Select all

function event_line(data)

	if string.find(string.lower(data), "balanceweaponplease") then
		-- Accepted ways of asking for a balance: Tells and Says. 
		name = returnPersonSendingTell(data)
		if name == "empty" then
			name = returnPersonSendingSay(data)
		end
		if name ~= "empty" then -- If name is still Empty means it wasnt a tell or a say, whoever requested the balance did it wrong!
			Put("balanceweapon "..name)	
		end
 	end

end 

RegisterEvent("line", event_line)

function returnPersonSendingTell(data)
	if string.find(data, "[t]") == 2 then
 		 line = string.sub(data, 6)
		 name = string.sub(line, 1, string.find(line, "Tells you:")-4)
		 return name
	 end 
	 
	 return "empty"
end

function returnPersonSendingSay(data)
	if string.find(data, "says") then
 		 line = string.sub(data, 3)
		 name = string.sub(line, 1, string.find(line, "says")-2)
		 return name
	 end
	 
	 return "empty"
end
After registering this event all incoming lines are parsed to see if "balanceweaponplease" is said anywhere. If so the script will try to parse the name from a say and tell in custom functions, if "balanceweaponplease" was said outside of a tell or say the script will ignore it. Else if name parsing was successful the character is given the command to weaponbalance the requesting party.

Image

Image

Using Timer events
Another type of event supported by the Cosrin client is the timer event. It allows you to start a timer that can either be repeated or dies off after the first time it fires. This can be used to for example create a rest timer. To create a rest timer first we have to calibrate the rest timer by detecting the pulse, we can do this by checking the line data with our line event for the text "You continue resting".

When said timer fires, we will try to call the new function "rest_timer" which commands the wizard to rest. If that rest is successful it will once more trigger a new rest event to be started due to the line event parsing "you continue resting" and calling a new RegisterTimer.

Code: Select all

function rest_timer(timername)
	Echo("rest_timer event fired, forcing new rest")
	Put("rest")
end

function event_line(data)
	-- Echo("Game  data: "..data)
	if string.find(string.lower(data), "you continue resting") then
		RegisterTimer("Rest", 59000, false, rest_timer) -- Register a timer that will fire the function "rest_timer" after 59 seconds. Note that this is a non repeating timer.
		Echo("Registered rest timer")
	end
end

RegisterEvent("line", event_line)
This results in the following output, with my wizard triggering a new "Rest" right before a new pulse for as long as I keep successfully resting on every pulse.

Image

Note that "RegisterTimer" has four parameters:
timername - name used to recognise and cancel the timer
interval - time period in milliseconds that the timer will fire
repeatable - If true, the timer will keep firing until cancelled. If false it will automatically cancel after it fires the first time.
handling function - the function to call when the timer fires

Using GlobalVariable Events
You can also subscribe on when a global variable changes, allowing the implementation of an observer pattern. The following code starts a loop that iterates 100 times. Every iteration it will change the global variable "FizzBuzz" to a different value. Through the RegisterGlobalVarEvent function provided by the wizard we can trigger an event every time this variable is altered, no matter where or in which script this happens. The first code block is the script that registers an event on the global variable FizzBuzz, the second runs the iteration in which we alter this variable.

Code: Select all

function global_changed(varname)
	Echo("a global value changed")
	-- Echo(varname.." value is now : "..GetVariable(varname))
end

SetVariable("FizzBuzz", "1")

RegisterGlobalVarEvent("FizzBuzz", global_changed)

Code: Select all

SetVariable("FizzBuzz", "1")

for i = 1, 100, 1 do
	FizzBuzz = ""
	if(i % 3) == 0 then FizzBuzz = "Fizz" end
	if(i % 5) == 0 then FizzBuzz = FizzBuzz.."Buzz" end
	if FizzBuzz == "" then FizzBuzz = i end
	
	SetVariable("FizzBuzz", FizzBuzz)
	
	Echo("Loop Iteration : "..i..", Global FizzBuzz value : "..GetVariable("FizzBuzz")..", Local FizzBuzz value : "..FizzBuzz)
end
As can be seen in the output, the "FizzBuzz value changed" echo from the GlobalVarEvent is triggered for every iteration, aka every single time the FizzBuzz global variable has been altered.

Code: Select all

a global value changed
Loop Iteration : 1, Global FizzBuzz value : 1, Local FizzBuzz value : 1
a global value changed
Loop Iteration : 2, Global FizzBuzz value : 2, Local FizzBuzz value : 2
a global value changed
Loop Iteration : 3, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 4, Global FizzBuzz value : 4, Local FizzBuzz value : 4
a global value changed
Loop Iteration : 5, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 6, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 7, Global FizzBuzz value : 7, Local FizzBuzz value : 7
a global value changed
Loop Iteration : 8, Global FizzBuzz value : 8, Local FizzBuzz value : 8
a global value changed
Loop Iteration : 9, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 10, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 11, Global FizzBuzz value : 11, Local FizzBuzz value : 11
a global value changed
Loop Iteration : 12, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 13, Global FizzBuzz value : 13, Local FizzBuzz value : 13
a global value changed
Loop Iteration : 14, Global FizzBuzz value : 14, Local FizzBuzz value : 14
a global value changed
Loop Iteration : 15, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 16, Global FizzBuzz value : 16, Local FizzBuzz value : 16
a global value changed
Loop Iteration : 17, Global FizzBuzz value : 17, Local FizzBuzz value : 17
a global value changed
Loop Iteration : 18, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 19, Global FizzBuzz value : 19, Local FizzBuzz value : 19
a global value changed
Loop Iteration : 20, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 21, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 22, Global FizzBuzz value : 22, Local FizzBuzz value : 22
a global value changed
Loop Iteration : 23, Global FizzBuzz value : 23, Local FizzBuzz value : 23
a global value changed
Loop Iteration : 24, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 25, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 26, Global FizzBuzz value : 26, Local FizzBuzz value : 26
a global value changed
Loop Iteration : 27, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 28, Global FizzBuzz value : 28, Local FizzBuzz value : 28
a global value changed
Loop Iteration : 29, Global FizzBuzz value : 29, Local FizzBuzz value : 29
a global value changed
Loop Iteration : 30, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 31, Global FizzBuzz value : 31, Local FizzBuzz value : 31
a global value changed
Loop Iteration : 32, Global FizzBuzz value : 32, Local FizzBuzz value : 32
a global value changed
Loop Iteration : 33, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 34, Global FizzBuzz value : 34, Local FizzBuzz value : 34
a global value changed
Loop Iteration : 35, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 36, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 37, Global FizzBuzz value : 37, Local FizzBuzz value : 37
a global value changed
Loop Iteration : 38, Global FizzBuzz value : 38, Local FizzBuzz value : 38
a global value changed
Loop Iteration : 39, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 40, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 41, Global FizzBuzz value : 41, Local FizzBuzz value : 41
a global value changed
Loop Iteration : 42, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 43, Global FizzBuzz value : 43, Local FizzBuzz value : 43
a global value changed
Loop Iteration : 44, Global FizzBuzz value : 44, Local FizzBuzz value : 44
a global value changed
Loop Iteration : 45, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 46, Global FizzBuzz value : 46, Local FizzBuzz value : 46
a global value changed
Loop Iteration : 47, Global FizzBuzz value : 47, Local FizzBuzz value : 47
a global value changed
Loop Iteration : 48, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 49, Global FizzBuzz value : 49, Local FizzBuzz value : 49
a global value changed
Loop Iteration : 50, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 51, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 52, Global FizzBuzz value : 52, Local FizzBuzz value : 52
a global value changed
Loop Iteration : 53, Global FizzBuzz value : 53, Local FizzBuzz value : 53
a global value changed
Loop Iteration : 54, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 55, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 56, Global FizzBuzz value : 56, Local FizzBuzz value : 56
a global value changed
Loop Iteration : 57, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 58, Global FizzBuzz value : 58, Local FizzBuzz value : 58
a global value changed
Loop Iteration : 59, Global FizzBuzz value : 59, Local FizzBuzz value : 59
a global value changed
Loop Iteration : 60, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 61, Global FizzBuzz value : 61, Local FizzBuzz value : 61
a global value changed
Loop Iteration : 62, Global FizzBuzz value : 62, Local FizzBuzz value : 62
a global value changed
Loop Iteration : 63, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 64, Global FizzBuzz value : 64, Local FizzBuzz value : 64
a global value changed
Loop Iteration : 65, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 66, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 67, Global FizzBuzz value : 67, Local FizzBuzz value : 67
a global value changed
Loop Iteration : 68, Global FizzBuzz value : 68, Local FizzBuzz value : 68
a global value changed
Loop Iteration : 69, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 70, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 71, Global FizzBuzz value : 71, Local FizzBuzz value : 71
a global value changed
Loop Iteration : 72, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 73, Global FizzBuzz value : 73, Local FizzBuzz value : 73
a global value changed
Loop Iteration : 74, Global FizzBuzz value : 74, Local FizzBuzz value : 74
a global value changed
Loop Iteration : 75, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 76, Global FizzBuzz value : 76, Local FizzBuzz value : 76
a global value changed
Loop Iteration : 77, Global FizzBuzz value : 77, Local FizzBuzz value : 77
a global value changed
Loop Iteration : 78, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 79, Global FizzBuzz value : 79, Local FizzBuzz value : 79
a global value changed
Loop Iteration : 80, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 81, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 82, Global FizzBuzz value : 82, Local FizzBuzz value : 82
a global value changed
Loop Iteration : 83, Global FizzBuzz value : 83, Local FizzBuzz value : 83
a global value changed
Loop Iteration : 84, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 85, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 86, Global FizzBuzz value : 86, Local FizzBuzz value : 86
a global value changed
Loop Iteration : 87, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 88, Global FizzBuzz value : 88, Local FizzBuzz value : 88
a global value changed
Loop Iteration : 89, Global FizzBuzz value : 89, Local FizzBuzz value : 89
a global value changed
Loop Iteration : 90, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 91, Global FizzBuzz value : 91, Local FizzBuzz value : 91
a global value changed
Loop Iteration : 92, Global FizzBuzz value : 92, Local FizzBuzz value : 92
a global value changed
Loop Iteration : 93, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 94, Global FizzBuzz value : 94, Local FizzBuzz value : 94
a global value changed
Loop Iteration : 95, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 96, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 97, Global FizzBuzz value : 97, Local FizzBuzz value : 97
a global value changed
Loop Iteration : 98, Global FizzBuzz value : 98, Local FizzBuzz value : 98
a global value changed
Loop Iteration : 99, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 100, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Note that implementing an observer pattern in your scripts is generally only useful in very advanced situations and is not necessary in basic scripts.

How to apply this knowledge to Cosrin
As stated above, this is definitely not the recommended way to implement simple things in Cosrin, but I will show an example of how you could use it. As a fighter I like to use potent healing pastes when I am low on health, I am however terrible at remembering how many I have, and subsequently I tend to run out of them without noticing. To combat this I can use the following script that does the following:

1) keep track of how many pastes I have left.
2) Whenever I have less than 3 pastes, automatically send a tell to a monk asking if he can kindly make me some more
3) if I run out completely I will ring back to my guild.

This code initializes the global variable where I track my pastes, and looks in my pouch to count them. It is recommended to purge your game window of content before doing this, else any previous references to pastes of potent healing will be counted as well. After initially tracking the amount of pastes of potent healing in your pouch the script will keep track of when a paste has been fully eaten and reduce the amount of pastes in the global variable.

Whenever the variable changes our event triggers to see how many are left, if there is one paste left we ask Khaji to please sell us 5 pastes of potent healing, if there are no pastes left we use guildring.

Code: Select all

function global_changed(varname)
	if varname == "PotentPasteCount" then
		Echo("New PotentPasteCount = "..GetVariable("PotentPasteCount"))
		if GetVariable("PotentPasteCount") == 0 or GetVariable("PotentPasteCount") == "0" then
			PauseMs(2700)
			Pause(character.ut)
			Put("activate guildring")
		elseif GetVariable("PotentPasteCount") == 1 or GetVariable("PotentPasteCount") == "1" then
			Put("Khaji Could I please buy 5 Paste of Potent healing from you")
		end		
	end
end

function event_line(data)
	if string.find(string.lower(data), "there is nothing left of the paste of potent healing...") then
		SetVariable("PotentPasteCount",  GetVariable("PotentPasteCount") - 1)
	end
end


SetVariable("PotentPasteCount", 0)


Put("inv")
Put("pouch")
WaitFor("You have the following items in your herb/potion pouch:")

-- Parse the amount of paste of potent healing in inventory
content = GetGameText()
for i =1,#content do
	for paste in string.gmatch(content[i], "paste of potent healing") do
		SetVariable("PotentPasteCount",  GetVariable("PotentPasteCount") + 1)
	end
end


RegisterGlobalVarEvent("PotentPasteCount", global_changed)
RegisterEvent("line", event_line)
Image

This is just an example of how you could use GlobalVarEvents in your scripts, it is not recommended to copy paste and use this script. If you were to actually use this in game it would be recommended to also keep tracking of picking up and dropping pastes to increase/reduce the paste count, as is you would have to restart the function every time you buy a new set of pastes.

Using GetEvent to request the next event
As stated previously, events will sit in a queue and the client will find the best moment to trigger the function assigned to this event. If an event is registered in the same script as where you want to use it, it will choose to hold the event in the queue until the script has ended. To demonstrate, the following code is the same FizzBuzz code as before, but the registering of the event is done in the same script as the iteration execution.

Code: Select all

function global_changed(varname)
	Echo("a global value changed")
	-- Echo(varname.." value is now : "..GetVariable(varname))
end

SetVariable("FizzBuzz", "1")

RegisterGlobalVarEvent("FizzBuzz", global_changed)

Pause(1)

for i = 1, 100, 1 do
	FizzBuzz = ""
	if(i % 3) == 0 then FizzBuzz = "Fizz" end
	if(i % 5) == 0 then FizzBuzz = FizzBuzz.."Buzz" end
	if FizzBuzz == "" then FizzBuzz = i end
	
	SetVariable("FizzBuzz", FizzBuzz)
	
	Echo("Loop Iteration : "..i..", Global FizzBuzz value : "..GetVariable("FizzBuzz")..", Local FizzBuzz value : "..FizzBuzz)
	
	--GetEvent()

end
The same code, just together in one file. This results in the widly different following output:

Code: Select all

Loop Iteration : 1, Global FizzBuzz value : 1, Local FizzBuzz value : 1
Loop Iteration : 2, Global FizzBuzz value : 2, Local FizzBuzz value : 2
Loop Iteration : 3, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 4, Global FizzBuzz value : 4, Local FizzBuzz value : 4
Loop Iteration : 5, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 6, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 7, Global FizzBuzz value : 7, Local FizzBuzz value : 7
Loop Iteration : 8, Global FizzBuzz value : 8, Local FizzBuzz value : 8
Loop Iteration : 9, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 10, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 11, Global FizzBuzz value : 11, Local FizzBuzz value : 11
Loop Iteration : 12, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 13, Global FizzBuzz value : 13, Local FizzBuzz value : 13
Loop Iteration : 14, Global FizzBuzz value : 14, Local FizzBuzz value : 14
Loop Iteration : 15, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 16, Global FizzBuzz value : 16, Local FizzBuzz value : 16
Loop Iteration : 17, Global FizzBuzz value : 17, Local FizzBuzz value : 17
Loop Iteration : 18, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 19, Global FizzBuzz value : 19, Local FizzBuzz value : 19
Loop Iteration : 20, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 21, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 22, Global FizzBuzz value : 22, Local FizzBuzz value : 22
Loop Iteration : 23, Global FizzBuzz value : 23, Local FizzBuzz value : 23
Loop Iteration : 24, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 25, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 26, Global FizzBuzz value : 26, Local FizzBuzz value : 26
Loop Iteration : 27, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 28, Global FizzBuzz value : 28, Local FizzBuzz value : 28
Loop Iteration : 29, Global FizzBuzz value : 29, Local FizzBuzz value : 29
Loop Iteration : 30, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 31, Global FizzBuzz value : 31, Local FizzBuzz value : 31
Loop Iteration : 32, Global FizzBuzz value : 32, Local FizzBuzz value : 32
Loop Iteration : 33, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 34, Global FizzBuzz value : 34, Local FizzBuzz value : 34
Loop Iteration : 35, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 36, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 37, Global FizzBuzz value : 37, Local FizzBuzz value : 37
Loop Iteration : 38, Global FizzBuzz value : 38, Local FizzBuzz value : 38
Loop Iteration : 39, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 40, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 41, Global FizzBuzz value : 41, Local FizzBuzz value : 41
Loop Iteration : 42, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 43, Global FizzBuzz value : 43, Local FizzBuzz value : 43
Loop Iteration : 44, Global FizzBuzz value : 44, Local FizzBuzz value : 44
Loop Iteration : 45, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 46, Global FizzBuzz value : 46, Local FizzBuzz value : 46
Loop Iteration : 47, Global FizzBuzz value : 47, Local FizzBuzz value : 47
Loop Iteration : 48, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 49, Global FizzBuzz value : 49, Local FizzBuzz value : 49
Loop Iteration : 50, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 51, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 52, Global FizzBuzz value : 52, Local FizzBuzz value : 52
Loop Iteration : 53, Global FizzBuzz value : 53, Local FizzBuzz value : 53
Loop Iteration : 54, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 55, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 56, Global FizzBuzz value : 56, Local FizzBuzz value : 56
Loop Iteration : 57, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 58, Global FizzBuzz value : 58, Local FizzBuzz value : 58
Loop Iteration : 59, Global FizzBuzz value : 59, Local FizzBuzz value : 59
Loop Iteration : 60, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 61, Global FizzBuzz value : 61, Local FizzBuzz value : 61
Loop Iteration : 62, Global FizzBuzz value : 62, Local FizzBuzz value : 62
Loop Iteration : 63, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 64, Global FizzBuzz value : 64, Local FizzBuzz value : 64
Loop Iteration : 65, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 66, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 67, Global FizzBuzz value : 67, Local FizzBuzz value : 67
Loop Iteration : 68, Global FizzBuzz value : 68, Local FizzBuzz value : 68
Loop Iteration : 69, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 70, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 71, Global FizzBuzz value : 71, Local FizzBuzz value : 71
Loop Iteration : 72, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 73, Global FizzBuzz value : 73, Local FizzBuzz value : 73
Loop Iteration : 74, Global FizzBuzz value : 74, Local FizzBuzz value : 74
Loop Iteration : 75, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 76, Global FizzBuzz value : 76, Local FizzBuzz value : 76
Loop Iteration : 77, Global FizzBuzz value : 77, Local FizzBuzz value : 77
Loop Iteration : 78, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 79, Global FizzBuzz value : 79, Local FizzBuzz value : 79
Loop Iteration : 80, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 81, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 82, Global FizzBuzz value : 82, Local FizzBuzz value : 82
Loop Iteration : 83, Global FizzBuzz value : 83, Local FizzBuzz value : 83
Loop Iteration : 84, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 85, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 86, Global FizzBuzz value : 86, Local FizzBuzz value : 86
Loop Iteration : 87, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 88, Global FizzBuzz value : 88, Local FizzBuzz value : 88
Loop Iteration : 89, Global FizzBuzz value : 89, Local FizzBuzz value : 89
Loop Iteration : 90, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
Loop Iteration : 91, Global FizzBuzz value : 91, Local FizzBuzz value : 91
Loop Iteration : 92, Global FizzBuzz value : 92, Local FizzBuzz value : 92
Loop Iteration : 93, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 94, Global FizzBuzz value : 94, Local FizzBuzz value : 94
Loop Iteration : 95, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
Loop Iteration : 96, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 97, Global FizzBuzz value : 97, Local FizzBuzz value : 97
Loop Iteration : 98, Global FizzBuzz value : 98, Local FizzBuzz value : 98
Loop Iteration : 99, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
Loop Iteration : 100, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
a global value changed
As you can see, the events are all queued up and released AFTER the script we register it in has finished. GetEvent() allows us to see the next Event in the queue (if there is one) without waiting.

GetEvent() returns two variables -
eventtype - The kind of event in the queue, line/globalvar/etc
eventdata - The name of the registered event

Using this we can manually tell an event function to trigger if the event is registered in the same script:

Code: Select all

function global_changed(varname)
	Echo("a global value changed")
	-- Echo(varname.." value is now : "..GetVariable(varname))
end

SetVariable("FizzBuzz", "1")

RegisterGlobalVarEvent("FizzBuzz", global_changed)

Pause(1)

for i = 1, 100, 1 do
	FizzBuzz = ""
	if(i % 3) == 0 then FizzBuzz = "Fizz" end
	if(i % 5) == 0 then FizzBuzz = FizzBuzz.."Buzz" end
	if FizzBuzz == "" then FizzBuzz = i end
	
	SetVariable("FizzBuzz", FizzBuzz)
	
	Echo("Loop Iteration : "..i..", Global FizzBuzz value : "..GetVariable("FizzBuzz")..", Local FizzBuzz value : "..FizzBuzz)
	
	local eventtype, eventdata = GetEvent()
	if eventtype then
		if eventtype == "globalvar" then
         	global_changed(eventdata)                             
		end
	 end   


end
We now get the following output:

Code: Select all

Loop Iteration : 1, Global FizzBuzz value : 1, Local FizzBuzz value : 1
a global value changed
Loop Iteration : 2, Global FizzBuzz value : 2, Local FizzBuzz value : 2
a global value changed
Loop Iteration : 3, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 4, Global FizzBuzz value : 4, Local FizzBuzz value : 4
a global value changed
Loop Iteration : 5, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 6, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 7, Global FizzBuzz value : 7, Local FizzBuzz value : 7
a global value changed
Loop Iteration : 8, Global FizzBuzz value : 8, Local FizzBuzz value : 8
a global value changed
Loop Iteration : 9, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 10, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 11, Global FizzBuzz value : 11, Local FizzBuzz value : 11
a global value changed
Loop Iteration : 12, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 13, Global FizzBuzz value : 13, Local FizzBuzz value : 13
a global value changed
Loop Iteration : 14, Global FizzBuzz value : 14, Local FizzBuzz value : 14
a global value changed
Loop Iteration : 15, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 16, Global FizzBuzz value : 16, Local FizzBuzz value : 16
a global value changed
Loop Iteration : 17, Global FizzBuzz value : 17, Local FizzBuzz value : 17
a global value changed
Loop Iteration : 18, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 19, Global FizzBuzz value : 19, Local FizzBuzz value : 19
a global value changed
Loop Iteration : 20, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 21, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 22, Global FizzBuzz value : 22, Local FizzBuzz value : 22
a global value changed
Loop Iteration : 23, Global FizzBuzz value : 23, Local FizzBuzz value : 23
a global value changed
Loop Iteration : 24, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 25, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 26, Global FizzBuzz value : 26, Local FizzBuzz value : 26
a global value changed
Loop Iteration : 27, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 28, Global FizzBuzz value : 28, Local FizzBuzz value : 28
a global value changed
Loop Iteration : 29, Global FizzBuzz value : 29, Local FizzBuzz value : 29
a global value changed
Loop Iteration : 30, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 31, Global FizzBuzz value : 31, Local FizzBuzz value : 31
a global value changed
Loop Iteration : 32, Global FizzBuzz value : 32, Local FizzBuzz value : 32
a global value changed
Loop Iteration : 33, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 34, Global FizzBuzz value : 34, Local FizzBuzz value : 34
a global value changed
Loop Iteration : 35, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 36, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 37, Global FizzBuzz value : 37, Local FizzBuzz value : 37
a global value changed
Loop Iteration : 38, Global FizzBuzz value : 38, Local FizzBuzz value : 38
a global value changed
Loop Iteration : 39, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 40, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 41, Global FizzBuzz value : 41, Local FizzBuzz value : 41
a global value changed
Loop Iteration : 42, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 43, Global FizzBuzz value : 43, Local FizzBuzz value : 43
a global value changed
Loop Iteration : 44, Global FizzBuzz value : 44, Local FizzBuzz value : 44
a global value changed
Loop Iteration : 45, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 46, Global FizzBuzz value : 46, Local FizzBuzz value : 46
a global value changed
Loop Iteration : 47, Global FizzBuzz value : 47, Local FizzBuzz value : 47
a global value changed
Loop Iteration : 48, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 49, Global FizzBuzz value : 49, Local FizzBuzz value : 49
a global value changed
Loop Iteration : 50, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 51, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 52, Global FizzBuzz value : 52, Local FizzBuzz value : 52
a global value changed
Loop Iteration : 53, Global FizzBuzz value : 53, Local FizzBuzz value : 53
a global value changed
Loop Iteration : 54, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 55, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 56, Global FizzBuzz value : 56, Local FizzBuzz value : 56
a global value changed
Loop Iteration : 57, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 58, Global FizzBuzz value : 58, Local FizzBuzz value : 58
a global value changed
Loop Iteration : 59, Global FizzBuzz value : 59, Local FizzBuzz value : 59
a global value changed
Loop Iteration : 60, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 61, Global FizzBuzz value : 61, Local FizzBuzz value : 61
a global value changed
Loop Iteration : 62, Global FizzBuzz value : 62, Local FizzBuzz value : 62
a global value changed
Loop Iteration : 63, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 64, Global FizzBuzz value : 64, Local FizzBuzz value : 64
a global value changed
Loop Iteration : 65, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 66, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 67, Global FizzBuzz value : 67, Local FizzBuzz value : 67
a global value changed
Loop Iteration : 68, Global FizzBuzz value : 68, Local FizzBuzz value : 68
a global value changed
Loop Iteration : 69, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 70, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 71, Global FizzBuzz value : 71, Local FizzBuzz value : 71
a global value changed
Loop Iteration : 72, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 73, Global FizzBuzz value : 73, Local FizzBuzz value : 73
a global value changed
Loop Iteration : 74, Global FizzBuzz value : 74, Local FizzBuzz value : 74
a global value changed
Loop Iteration : 75, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 76, Global FizzBuzz value : 76, Local FizzBuzz value : 76
a global value changed
Loop Iteration : 77, Global FizzBuzz value : 77, Local FizzBuzz value : 77
a global value changed
Loop Iteration : 78, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 79, Global FizzBuzz value : 79, Local FizzBuzz value : 79
a global value changed
Loop Iteration : 80, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 81, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 82, Global FizzBuzz value : 82, Local FizzBuzz value : 82
a global value changed
Loop Iteration : 83, Global FizzBuzz value : 83, Local FizzBuzz value : 83
a global value changed
Loop Iteration : 84, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 85, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 86, Global FizzBuzz value : 86, Local FizzBuzz value : 86
a global value changed
Loop Iteration : 87, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 88, Global FizzBuzz value : 88, Local FizzBuzz value : 88
a global value changed
Loop Iteration : 89, Global FizzBuzz value : 89, Local FizzBuzz value : 89
a global value changed
Loop Iteration : 90, Global FizzBuzz value : FizzBuzz, Local FizzBuzz value : FizzBuzz
a global value changed
Loop Iteration : 91, Global FizzBuzz value : 91, Local FizzBuzz value : 91
a global value changed
Loop Iteration : 92, Global FizzBuzz value : 92, Local FizzBuzz value : 92
a global value changed
Loop Iteration : 93, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 94, Global FizzBuzz value : 94, Local FizzBuzz value : 94
a global value changed
Loop Iteration : 95, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Loop Iteration : 96, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 97, Global FizzBuzz value : 97, Local FizzBuzz value : 97
a global value changed
Loop Iteration : 98, Global FizzBuzz value : 98, Local FizzBuzz value : 98
a global value changed
Loop Iteration : 99, Global FizzBuzz value : Fizz, Local FizzBuzz value : Fizz
a global value changed
Loop Iteration : 100, Global FizzBuzz value : Buzz, Local FizzBuzz value : Buzz
a global value changed
Caution when using this, reading an event from the queue removes it from the queue and will not automatically call the function belonging to that event. If you read an event you must handle it manually, if there would be any other event than a "globalvar" event caught by the above code it would discard it and it would never be executed. Only use this if you know exactly which events you might get with GetEvent, and handle them all.

Attachments
This guide has the following attachments:
- "startup_registerEvents.lua" contains the code that will react upon balanceweapon requests and start a rest timer whenever you are resting at a pulse.

- "runFizzBuzz_registerEvents.lua", followed by "runFizzBuzz.lua" will run the FizzBuzz sample algorithm displaying the observable pattern you can use when registering events on Global Variable changes.

- "trackPastes_registerEvents.lua" will start the script that monitors your paste usage and acts accordingly.

- "runFizzBuzzSingleScript.lua" demonstrates the GetEvent() function, if you want to know more about its behaviour try running it with and without line 21-26 commented out.
Attachments
EventsExampleScripts.rar
(2.21 KiB) Downloaded 302 times
Admin
Site Admin
Posts: 206
Joined: May 3rd, 2012, 5:47 am

Re: Contest: Guides, Lore, and Help

Post by Admin »

I just wanted to stop in and say thank you for all of the entries.

I am locking this thread while we take an in-depth look at all of the entries.
Admin
Site Admin
Posts: 206
Joined: May 3rd, 2012, 5:47 am

Re: Contest: Guides, Lore, and Help

Post by Admin »

Due to limited entries for the Help Files section, no Best Entry was selected.

Additionally, while it may not have been made explicitly clear, each player is entitled to the in-game rewards for his or her best entry. Multiple categories will not result in multiple "payouts".

That said, we have looked through the entries made to the contest, discussed them at depth, and determined the breakdown as follows:

Scripting Guides - Best Entry
  • Halren
Scripting Guides - Accepted Entries
  • Eloras
  • Trisana
Website Content - Best Entry
  • Kaede
Website Content - Accepted Entries
  • Trisana
Help Files - Accepted Entries
  • Korlic
  • Lothaine
  • Trisana
Contact me in game to receive or discuss your reward.

Cosrin Staff
Locked