ArcEmu: Lua Server Hooks Tutorial - 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

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Lua Server Hooks Tutorial For LuaHypArc

#21 User is offline   Meisterdieb 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 13-November 09

Posted 14 November 2009 - 01:28 PM

Yes that would work
0

#22 User is offline   Bob Herman 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 452
  • Joined: 11-October 08
  • Gender:Male

Posted 15 November 2009 - 09:07 AM

Sorry to spam you guys, but I have a little issue. I'm really not familiar with LUA errors, and this script gave me this one:

Quote

' failed. (could not load)
scripts\chat.lua:51: '<eof>' expected near 'end'


Here is the script:

--Locals--
local RELOAD = "#Reload"
local HOME = "#Home"
local BUFFS = "#Buffs"
local REMOVERESS = "#RemoveRess"
local GURUBASHI =  "#Arena"
local DALARAN = "#Dalaran"
local SHATTRATH = "#Shattrath" 
local race=player:GetPlayerRace()


function OnChat(event, pPlayer, message, type, language)
	if(message == RELOAD and pPlayer:IsGm()) then
			ReloadLuaEngine()
			pPlayer:SendChatMessageToPlayer(15, 0, "Reloading Engine")
	end
    if(message == HOME) then
            if(race==1 or race==3 or race==4 or race==7 or race==11) then
                    --Horde--
					pPlayer:Teleport(1, 1502.71, -4415.42, 22.5512)
            end
            elseif(race==2 or race==5 or race==6 or race==8 or race==1) then
                    --Alliance--
					pPlayer:Teleport(0, -8913.23, 554.633, 94.7944)
            end
    end
	if(message == BUFFS) then
		pPlayer:CastSpell(48102)
		pPlayer:CastSpell(58451)
		pPlayer:CastSpell(48104)
		pPlayer:CastSpell(58449)
		pPlayer:CastSpell(48100)
		pPlayer:CastSpell(20217)
		pPlayer:CastSpell(61024)
		pPlayer:CastSpell(48469)
		pPlayer:CastSpell(57294)
	end
	if(message == REMOVERESS) then
		pPlayer:LearnSpell(15007)
		pPlayer:UnlearnSpell(15007)
	end
	if(message == GURUBASHI) then
		pPlayer:Teleport(0, -13152.9, 342.729, 53.1328)
	end
	if(message == DALARAN) then
		pPlayer:Teleport(571, 5785.24, 724.91, 641.081)
	end
	if(message == SHATTRATH) then
		pPlayer:Teleport(530, -1722.58, 5382.7, 2.47504)
	end
end


RegisterServerHook(16, "OnChat")


Line 51 is the very last end, before the RegisterServerHook.

Thanks for all help :D

edit: I removed the end on line 51, to see if that was the error, and I got:

Quote

failed (could not run)
scripts\chat.lua:9: attempt to index global 'player' (a nil value)


Line 9 is:

local race=player:GetPlayerRace()

0

#23 User is offline   Shauren 

  • Helper
  • Group: Contributor
  • Posts: 808
  • Joined: 04-November 08
  • Gender:Male
  • Location:Poland
  • Interests:hmm, wow?

Posted 15 November 2009 - 03:15 PM

try that
--Locals--
local RELOAD = "#Reload"
local HOME = "#Home"
local BUFFS = "#Buffs"
local REMOVERESS = "#RemoveRess"
local GURUBASHI =  "#Arena"
local DALARAN = "#Dalaran"
local SHATTRATH = "#Shattrath" 

function OnChat(event, pPlayer, message, type, language)
    if(message == RELOAD and pPlayer:IsGm()) then
        ReloadLuaEngine()
        pPlayer:SendChatMessageToPlayer(15, 0, "Reloading Engine")
    end
    if(message == HOME) then
        local race = pPlayer:GetPlayerRace()
        if(race==1 or race==3 or race==4 or race==7 or race==11) then
            --Horde--
            pPlayer:Teleport(1, 1502.71, -4415.42, 22.5512)
        elseif(race==2 or race==5 or race==6 or race==8 or race==1) then
            --Alliance--
            pPlayer:Teleport(0, -8913.23, 554.633, 94.7944)
        end
    end
    if(message == BUFFS) then
        pPlayer:CastSpell(48102)
        pPlayer:CastSpell(58451)
        pPlayer:CastSpell(48104)
        pPlayer:CastSpell(58449)
        pPlayer:CastSpell(48100)
        pPlayer:CastSpell(20217)
        pPlayer:CastSpell(61024)
        pPlayer:CastSpell(48469)
        pPlayer:CastSpell(57294)
    end
    if(message == REMOVERESS) then
        pPlayer:LearnSpell(15007)
        pPlayer:UnlearnSpell(15007)
    end
    if(message == GURUBASHI) then
        pPlayer:Teleport(0, -13152.9, 342.729, 53.1328)
    end
    if(message == DALARAN) then
        pPlayer:Teleport(571, 5785.24, 724.91, 641.081)
    end
    if(message == SHATTRATH) then
        pPlayer:Teleport(530, -1722.58, 5382.7, 2.47504)
    end
end


RegisterServerHook(16, "OnChat")

0

#24 User is offline   Bob Herman 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 452
  • Joined: 11-October 08
  • Gender:Male

Posted 16 November 2009 - 06:05 PM

Thanks a bunch Shauren, that worked great. Now I have one last issue before I can release this script. SendChatMessageToPlayer doesn't work for me. I keep getting this error:

(unit expected, got no value)


I am using it currently in this format:

pPlayer:SendChatMessageToPlayer(15, 0, "Reloading Engine")


Once again, thanks for any help. Also, I have another question. I have players that are coming on to my server to advertise their own (feathermoon). Is there a way that I could make a filter for 'feathermoon' or 'Feathermoon'? I thought of using the same thing as my command structure, but the problem with that is that it looks for messages with EXACTLY what the specific word/command. Is there a way I could make it look through messages for anything containing the word, and replace it with something else?

So if someone said:

Quote

Go to feathermoon, it's the best!


it would change it to:

Quote

Go to Septimus, it's the best!

0

#25 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 16 November 2009 - 10:41 PM

SendChatMessageToPlayer takes a 4th argument, the player to send the message to. :P
pPlayer:SendChatMessageToPlayer(15, 0, "Reloading Engine", player)

And you can achieve your word-replacing idea with your regular OnChat server hooks and use the Lua string.gsub command combined with returning 0 and manually sending the message... give this a try
function OnChat(event, plr, message, type, language)
   if (string.find(message:lower(), "feathermoon") ~= nil)
      message = string.gsub(message:lower(), "feathermoon", "septimus")
      plr:PlayerSendChatMessage(type, language, message)
      return 0
   end
end


Of course there's a catch, the message would be sent as all lower case, but this is to increase the strength of the word detection. Also, they could just put a space in the word for example to bypass the system. But this is the general idea.
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#26 User is offline   pingue 

  • Member
  • Pip
  • Group: Members
  • Posts: 99
  • Joined: 18-July 09
  • Gender:Male
  • Location:EARTH LULZ!
  • Interests:web designing.. grilz n titz, wow :3

Posted 16 November 2009 - 11:09 PM

View Posthypersniper, on 16 November 2009 - 10:41 PM, said:

SendChatMessageToPlayer takes a 4th argument, the player to send the message to. :)
pPlayer:SendChatMessageToPlayer(15, 0, "Reloading Engine", player)

And you can achieve your word-replacing idea with your regular OnChat server hooks and use the Lua string.gsub command combined with returning 0 and manually sending the message... give this a try
function OnChat(event, plr, message, type, language)
   if (string.find(message:lower(), "feathermoon") ~= nil)
      message = string.gsub(message:lower(), "feathermoon", "septimus")
      plr:PlayerSendChatMessage(type, language, message)
      return 0
   end
end


Of course there's a catch, the message would be sent as all lower case, but this is to increase the strength of the word detection. Also, they could just put a space in the word for example to bypass the system. But this is the general idea.

Isn't working :P
Posted Image
0

#27 User is offline   Bob Herman 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 452
  • Joined: 11-October 08
  • Gender:Male

Posted 17 November 2009 - 08:38 AM

View Postpingue, on 16 November 2009 - 11:09 PM, said:

Isn't working :P


Bud, make sure you only add this part:

   if (string.find(message:lower(), "feathermoon") ~= nil)
      message = string.gsub(message:lower(), "feathermoon", "septimus")
      plr:PlayerSendChatMessage(type, language, message)
      return 0
   end


You don't need to re-add the function OnChat. Just put it in right after the command part like this:

   if(message  == CMD)
         ....
   end
   if (string.find(message:lower(), "feathermoon") ~= nil)
      message = string.gsub(message:lower(), "feathermoon", "septimus")
      plr:PlayerSendChatMessage(type, language, message)
      return 0
   end


Also sniper, does your LUA engine also work with the commands of LuaAppArc? Because Pingue found this which could be awesome to use to learn LUA, if LuaAppArc is compatible with your engine. Thanks a bunch! :)
0

#28 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 17 November 2009 - 10:49 PM

Yeah all the commands in that list work with HypArc :)
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#29 User is offline   Shauren 

  • Helper
  • Group: Contributor
  • Posts: 808
  • Joined: 04-November 08
  • Gender:Male
  • Location:Poland
  • Interests:hmm, wow?

Posted 18 November 2009 - 08:36 AM

dont we have table in world database for word filtering?
0

#30 User is offline   Muffler 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 366
  • Joined: 17-June 08
  • Gender:Male
  • Location:CCCP

Posted 05 December 2009 - 04:44 AM

what this ?
some time i see in console

Quote

PANIC: unprotected error in call to Lua API (scripts\RegisterServerHook_quest_ac
cept.lua:-1: attempt to index a nil value)


function QuestAccept (event, pPlayer, pQuestGiver, questId)
print ("Char:"..pPlayer:GetName().."\t take quest # "..questId)
 end
RegisterServerHook(14, "QuestAccept")


and cpu used 100% after ths

0

#31 User is offline   streetkiller 

  • Member
  • Pip
  • Group: Members
  • Posts: 25
  • Joined: 09-November 09
  • Gender:Male
  • Location:Netherlands

Posted 18 December 2009 - 03:19 PM

View PostBob Herman, on 14 November 2009 - 11:57 AM, said:

Does that exist?

Would I do:

	if(message == HOME) then
		if(plr:GetFaction()) == 1) then
			--Alliance--
		end
		elseif(plr:GetFaction() == 2) then
			--Horde--
		end
	end


edit

I looked at a teleport script... and would this work? (I don't have access to my server atm)

local race=player:GetPlayerRace()

	if(message == HOME) then
		if(race==1 or race==3 or race==4 or race==7 or race==11) then
			--Horde--
		end
		elseif(race==2 or race==5 or race==6 or race==8 or race==1) then
			--Alliance--
		end
	end


You made a type mistake in the seconds one you used the race==1 2 times will cause an error i quess you ment race==10
@Hypersniper Very nice tutorial ;)
0

#32 User is offline   aPan 

  • Newbie
  • Group: Members
  • Posts: 4
  • Joined: 15-May 09

Posted 11 February 2010 - 06:03 AM

I wanted to test the "welcome" msg.
But cant get it to work.

I put this in a file:

function Welcome(event, pPlayer)
pPlayer:SendAreaTriggerMessage("Welcome to the game!")
end

RegisterServerHook(19, "Welcome")


called Welcome.lua, in the scripts folder.

It says the LuaHypArc Engine loaded the script.
but when I log in to the server I dont see any msg.


What am I doing wrong?
There is no need to compile this, right?
1

#33 User is offline   Shadoxfix 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 312
  • Joined: 30-December 09
  • Gender:Male
  • Location:Netherlands

Posted 11 February 2010 - 02:01 PM

View PostaPan, on 11 February 2010 - 06:03 AM, said:

I wanted to test the "welcome" msg.
But cant get it to work.

I put this in a file:

function Welcome(event, pPlayer)
pPlayer:SendAreaTriggerMessage("Welcome to the game!")
end

RegisterServerHook(19, "Welcome")


called Welcome.lua, in the scripts folder.

It says the LuaHypArc Engine loaded the script.
but when I log in to the server I dont see any msg.


What am I doing wrong?
There is no need to compile this, right?

I tried it also a while ago yet no message
0

#34 User is offline   aPan 

  • Newbie
  • Group: Members
  • Posts: 4
  • Joined: 15-May 09

Posted 14 February 2010 - 04:30 PM

I guess nobody knows..
0

#35 User is offline   kamakaze 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 195
  • Joined: 13-October 08
  • Gender:Male

Posted 22 February 2010 - 03:24 PM

EDIT: NVM :P Ignore post.
Posted Image
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

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