ArcEmu: How Do I Use My Own Function In A Function - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1

How Do I Use My Own Function In A Function

#1 User is offline   Altogoten 

  • Member
  • Pip
  • Group: Members
  • Posts: 37
  • Joined: 11-May 09
  • Gender:Male
  • Server OS:Linux

Posted 24 March 2014 - 10:45 AM

hello i have a question about lua again
i have made a function for getting GM rights

now i want to use that in my function that is registerd in the sever so that i can get the rank and give it a name

function STAFFENTER.GetGM(player)
	if (player:GetGmRank() == "az" ) then
		return "HeadAdmin"
	end
end


so i want to use that in my other function
function STAFFENTER.StaffOnEnterWorldFirstTimeWelcome(event, player)
	
	for i = 1, #class_colour do
		if(class_colour[i][1] == player:GetPlayerClass())then
			colour = class_colour[i][2]
		end
	end

	if (player:GetGmRank() ~= "0") then
		SendWorldMessage("|cFF35bab8<"..STAFFENTER.ServerName.." - Announce>|r - |CFFbbbbbbWelcome to your new [HeadAdmin]:|r "..colour..""..player:GetName().."|r|CFFbbbbbb!|r", 2)
	end
		
end

and i will like to do the same for the get class color script

my whole script i have now is looking like thiss
STAFFENTER = {}
local class_colour = {
{"Warrior","|cFF993300"},
{"Paladin","|cFFFF00FF"},
{"Hunter","|cFF00FF00"},
{"Rogue","|cFFFFFF00"},
{"Priest","|cFFFFFFFF"},
{"Death Knight","|cFF800000"},
{"Shaman","|cFF000080"},
{"Mage","|cFFCCCCFF"},
{"Warlock","|cFF800080"},
{"Druid","|cFFFF6600"}
}

local colour = "|cFFC79C6E" -- Default colour



--[~~~~~~~~]--
--[ Config ]--
--[~~~~~~~~]--

STAFFENTER.ServerName = "Emerald Dream" --Change "ServerName" with your Server Name.

--[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]--
--[ You can edit all SendWorldMessage : ''Welcome our [ServerNameStaff][HeadAdmin] and the colors. ]--
--[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]--

function STAFFENTER.GetGM(player)
	if (player:GetGmRank() == "az" ) then
		return "HeadAdmin"
	end
end


function STAFFENTER.StaffOnEnterWorldFirstTimeWelcome(event, player)
	
	for i = 1, #class_colour do
		if(class_colour[i][1] == player:GetPlayerClass())then
			colour = class_colour[i][2]
		end
	end

	if (player:GetGmRank() ~= "0") then
		SendWorldMessage("|cFF35bab8<"..STAFFENTER.ServerName.." - Announce>|r - |CFFbbbbbbWelcome to your new [HeadAdmin]:|r "..colour..""..player:GetName().."|r|CFFbbbbbb!|r", 2)
	end
		
end

function STAFFENTER.StaffOnSTAFFENTERWorldWelcome(event, player)
	
	for i = 1, #class_colour do
		if(class_colour[i][1] == player:GetPlayerClass())then
			colour = class_colour[i][2]
		end
	end
	
	if (player:GetGmRank() == "az" ) then
		STAFFENTER.Rank = "HeadAdmin"
	end
	if (player:GetGmRank() ~= "0") then
		SendWorldMessage("|cFF35bab8<"..STAFFENTER.ServerName.." - Announce>|r - |CFFbbbbbbWelcome Back [HeadAdmin]:|r "..colour..""..player:GetName().."|r|CFFbbbbbb!|r", 2)
	end
	
end

RegisterServerHook(3, "STAFFENTER.StaffOnEnterWorldFirstTimeWelcome")
RegisterServerHook(19, "STAFFENTER.StaffOnSTAFFENTERWorldWelcome")



Hope someone can help me i want only 1 fucntion for the getGM and only 1 function for the class colors
and use it in the both server hook functions
0

#2 User is offline   Satanail 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 150
  • Joined: 11-March 12
  • Gender:Male
  • Location:Absurdistan
  • Server OS:Windows

Posted 24 March 2014 - 01:34 PM

You don't even need a function for that. You can simply create a table like the colour table, but this one will contain the strings, returned by GetGmRank() and the names for each gm rang. This is what I did:
STAFFENTER = {}
local class_colour = {
{"Warrior","|cFF993300"},
{"Paladin","|cFFFF00FF"},
{"Hunter","|cFF00FF00"},
{"Rogue","|cFFFFFF00"},
{"Priest","|cFFFFFFFF"},
{"Death Knight","|cFF800000"},
{"Shaman","|cFF000080"},
{"Mage","|cFFCCCCFF"},
{"Warlock","|cFF800080"},
{"Druid","|cFFFF6600"}
}

 -- Column 1 - strings, returned by GetGmRank() lua
 -- Column 2 - Strings, that will be displayed in msg.
local gm_table = {
{"a","GM A"},
{"z","GM Z"},
{"az","HeadAdmin"},
}

--[~~~~~~~~]--
--[ Config ]--
--[~~~~~~~~]--

STAFFENTER.ServerName = "Emerald Dream" --Change "ServerName" with your Server Name.

--[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]--
--[ You can edit all SendWorldMessage : ''Welcome our [ServerNameStaff][HeadAdmin] and the colors. ]--
--[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]--

function STAFFENTER.StaffOnEnterWorldFirstTimeWelcome(event, player)
local colour = "|cFFC79C6E" -- Default colour
local GMrank = "0" -- Default GM rank
	for i = 1, #class_colour do
		if(class_colour[i][1] == player:GetPlayerClass())then
			colour = class_colour[i][2]
		end
	end
	for m = 1, #gm_table do
		if(gm_table[m][1] == player:GetGmRank())then
			GMrank = gm_table[m][2]
		end
	end
	if (player:GetGmRank() ~= "") then
		SendWorldMessage("|cFF35bab8<"..STAFFENTER.ServerName.." - Announce>|r - |CFFbbbbbbWelcome to your new ["..GMrank.."]:|r "..colour..""..player:GetName().."|r|CFFbbbbbb!|r", 2)
	end
end

function STAFFENTER.StaffOnSTAFFENTERWorldWelcome(event, player)
local colour = "|cFFC79C6E" -- Default colour
local GMrank = "0" -- Default GM rank
	for i = 1, #class_colour do
		if(class_colour[i][1] == player:GetPlayerClass())then
			colour = class_colour[i][2]
		end
	end
	for m = 1, #gm_table do
		if(gm_table[m][1] == player:GetGmRank())then
			GMrank = gm_table[m][2]
		end
	end
	if (player:GetGmRank() ~= "") then
		SendWorldMessage("|cFF35bab8<"..STAFFENTER.ServerName.." - Announce>|r - |CFFbbbbbbWelcome Back ["..GMrank.."]:|r "..colour..""..player:GetName().."|r|CFFbbbbbb!|r", 2)
	end
end

RegisterServerHook(3, "STAFFENTER.StaffOnEnterWorldFirstTimeWelcome")
RegisterServerHook(19, "STAFFENTER.StaffOnSTAFFENTERWorldWelcome")


Tables have a huge potential in lua scripting.
Oh btw, in this case it's better to keep the locals "colour" and "GMrank" within the server hook function rather than on top of the script. They are not fixed values, I just put any random value there just in case. And also if you move them at the top of the file you might get errors if more than one person logs in at the same time. There they are valid serverwide once set. This might be done with the "getfenv" rather than with locals, but I don't think there will be any problem. After all, lua supports scripts with up to 200 locals.
0

#3 User is offline   Altogoten 

  • Member
  • Pip
  • Group: Members
  • Posts: 37
  • Joined: 11-May 09
  • Gender:Male
  • Server OS:Linux

Posted 24 March 2014 - 06:49 PM

ty again for your help if we can chat on steam or somthing i'm still learning LUA
so some support will be nice
have a lot of things i wanne try out xD
0

#4 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 25 March 2014 - 09:59 AM

There are great Lua books for learning the basics of Lua.
Try to read one, after that all this will be much much much easier to understand :)
"The demand for free goods is infinite."
1

#5 User is offline   Satanail 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 150
  • Joined: 11-March 12
  • Gender:Male
  • Location:Absurdistan
  • Server OS:Windows

Posted 25 March 2014 - 12:59 PM

Also you might want to use something like notepad++ instead of the regular text editors. It's really helpful for tracking things like functions and other things on your script and the chance of missing end to a function or some bracket is almost 0. Probably one of the most annoying things that beginners have to deal with especially if you try to write the script in regular notepad.
0

#6 User is offline   Altogoten 

  • Member
  • Pip
  • Group: Members
  • Posts: 37
  • Joined: 11-May 09
  • Gender:Male
  • Server OS:Linux

Posted 25 March 2014 - 01:25 PM

i already use notepad++ xD
and i dont wanne buy books
dont have the money for it :P
0

#7 User is offline   Satanail 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 150
  • Joined: 11-March 12
  • Gender:Male
  • Location:Absurdistan
  • Server OS:Windows

Posted 25 March 2014 - 02:49 PM

There is plenty of material you can google about lua scripting. I didn't have to buy any books, it's a relatively easy and interesting language to learn. You also can just read already written scripts. And of course the Arcemu Wiki is very useful.
But if you stumble upon arcemu lua script somewhere other than on the official arcemu website, be careful. Some if not most of them are horrible. If you have any trouble with something post a topic here. :)
2

Share this topic:


Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users