ArcEmu: [lua] Another Crash :-) - 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

Labels

Make sure when posting a help or release topic you put [c++] or [lua] BEFORE your topic title!
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[lua] Another Crash :-)

#1 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 26 April 2012 - 05:32 AM

Well, looking to some of me previous posts I tried to change my script into the following one. (At the end I have to say this script is useless because it doesn't make what I wanted, but still it is a script :P )

-- Message send to all players (global function)
function SendWorldMsg(Text)
	SendWorldMessage("|cFFFFCC00[Server "..os.date("%H:%M").."] "..Text.."|r",2)
end

-- starts if NPC is loaded
function GurubashiArena_NPC_OnLoad(pUnit, Event)
	SendWorldMsg("Short John Mithril / Störtebrecher is in the Gurubashi Arena")
	RegisterTimedEvent("GurubashiArenaChest1", 27000, 1, pUnit)
end

function GurubashiArenaChest1(pUnit)
	SendWorldMsg("Gurubashi Arena starts in xxx minutes. Are you prepared ?")
	RegisterTimedEvent("GurubashiArenaChest2", 9000, 1, pUnit)
end

function GurubashiArenaChest2(pUnit)
	SendWorldMsg("Here's the chest!")
	
	PerformIngameSpawn(2, 179697, 0, -13203, 277, 21.86, 4.18, 100, 0)	-- despawn doesnt work

	pUnit:SendChatMessage(14, 0, "Arrr, Me Hearties! I be havin some extra Treasure that i be givin away at the Gurubashi Arena! All ye need to do is collect it is open the chest I leave on the arena floor!")
	SendWorldMsg("In 30 sec. (test) the chest is gone. Hurry!")

	RegisterTimedEvent("GurubashiArenaChest3", 30000, 1, pUnit)	
 end

function GurubashiArenaChest3(pUnit)
	SendWorldMsg("No more treasure.")

		local pChest = pUnit:GetGameObjectNearestCoords(-13203, 277, 22, 179697)
		if(pChest ~= nil) then
			pChest:RemoveFromWorld() 
		end

	-- loop to GurubashiArenaChest1
	RegisterTimedEvent("GurubashiArenaChest1", 27000, 1, pUnit)
end


--NPC Goblin Short John Mithril (en) / Störtebrecher (de)
RegisterUnitEvent(14508, 18, "GurubashiArena_NPC_OnLoad")	-- CREATURE_EVENT_ON_LOAD


That script works as long as there is a player in the Gurubashi Arena. If there are no (or no more) player in the arena the server crashes after about 5 minutes.

What happens ? I can imagine that after a while the core detects that there are no more players in this map cell. Than it stops the NPC 14508. But all the timed events runs further. So I get an invalid pUnit in the function GurubashiArenaChest3 after a while. That's the point where the server is crashing and restarts. I'm sure I can catch this error in Lua. I have tried it with the following code snippet. But doesn't work.

But still SERVER CRASHS ARE NOT AN OPTION even if the Lua programmer is too stupid :( I recommend to catch this error in the core and send an error to the console.

function GurubashiArenaChest3(pUnit)
	SendWorldMsg("No more treasure.")

	if(pUnit ~= nil) then
		local pChest = pUnit:GetGameObjectNearestCoords(-13203, 277, 22, 179697)
		if(pChest ~= nil) then
			pChest:RemoveFromWorld() 
		end
	else
		print("NPC seems to be unloaded")
	end
	
	-- loop to GurubashiArenaChest1
	RegisterTimedEvent("GurubashiArenaChest1", 27000, 1, pUnit)
end


The if (pUnit ~= nil) doesn't helped me to prevent the crash. Well, the unit is not nil, it's still here but not active. How to test that ? [Edit: maybe GetAIState() ?]
But may I'm completely wrong with the whole theory :D
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#2 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 27 April 2012 - 10:46 AM

Your theory is more than likely correct, your possible solution is not.
The Unit is indeed not NIL, actually it points to a previously valid memory location, BUT if the cells are unloaded the Unit is deleted so it's no longer valid.
I think Jackpoz started to work on some possible solution to these kinds of crashes when StoneHarry/Salamanda had similar issues, but I am unsure if he ever finished the work ( I assume not since he hasnt commited it ).
"The demand for free goods is infinite."
0

#3 User is offline   Loken 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 19-July 11
  • Gender:Male
  • Location:Lordaeron
  • Interests:Arcemu, WOW.
  • Server OS:Windows

Posted 27 April 2012 - 10:54 AM

I remember jackpoz said something of one virtual machine per map to fix this issue, sounds like luabridge :P
Posted Image
Posted Image
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 27 April 2012 - 11:02 AM

View PostLoken, on 27 April 2012 - 10:54 AM, said:

I remember jackpoz said something of one virtual machine per map to fix this issue, sounds like luabridge :P

Well I can't recall it that much.
"The demand for free goods is infinite."
0

#5 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 29 April 2012 - 08:16 AM

Is there a way to find out if a pUnit is valid (active, loaded, whatever)?

Something like
bool=IsValidUnit(pUnit) :P
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#6 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 29 April 2012 - 09:35 AM

View PostMagnifikator, on 29 April 2012 - 08:16 AM, said:

Is there a way to find out if a pUnit is valid (active, loaded, whatever)?

Something like
bool=IsValidUnit(pUnit) :P

Unfortunately there's no way to do that, and even if there were it would be quite wrong to do checks like that.
"The demand for free goods is infinite."
0

#7 User is offline   salamanda 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 161
  • Joined: 10-July 08

Posted 30 April 2012 - 12:25 PM

Not using timed events seems to solve everything.

Use:

pUnit:RegisterEvent("name", time, count)

instead.

Then if you check for the object and whether it is nil, it won't crash.

Personally I found it rather amusing you are using timed events instead of unit events when you call a unit event. :P The first parameter (unit) is always carried into the new function by default, so you don't need to parse it into the hook but you do need to add it to the parameters of the function you are calling.
0

#8 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 30 April 2012 - 02:39 PM

Well that's exactly the reason why I told in my first post: this script is useless because it doesn't make what I wanted :D So this learning process I have done already.

As long as you can't check if a NPC is valid you can't work with RegisterTimedEvent.
But you have to keep in mind that this strange script helped us to find 4 faults in the core that crashed the server :P. Dfighter was kind enough to fix them so fast. Thank you dfighter.
So this script was always a kind of workaround besides the non working lua commands :P

But to be honest, till today I didn't find a way to end my task with Gurubash Arena as I wanted.

The task is:
- Every 3h the server says: Gurubashi Arena starts in 15 minutes
- Players have enough time to go there
- A Goblin NPC is there and after 15 minutes he start yelling something and spawns a chest
- If there are not enough player the server says: Sorry not enough players, arena finished

The problem is: I can't detect if there are players in the arena. If there are no players there than the NPC is invalid.

I wanted to solve it like that:
1. Timer event 165 minutes -> function -> Server says: Gurubashi Arena starts in 15 minutes
2. Next timer event 15 minutes -> function -> NPC yell 'Welcome players'
Result: Doesn't work if there are no players :(

Other approach:
Use RegisterUnitEvent of the NPC.
Result: the arena never start if there are no player in the arena

Last approach:
1. The NPC ist now a gossip NPC
2. Timer event 165 minutes -> function -> Server says: Gurubashi Arena starts in 15 minutes
3a. If there are Players in the arena the first player can activate the arena quest with the gossip, everything seems to be ok
3b. If there are no Players in the arena nothing happen.

Result: Seems to be ok but it isn't. What happen if players come to late ? The arena start every 3h. But you have to be there in a defined time window.
I thought to switch of the gossip flag of the NPC after a while. And switch it on after 3h for the new arena.
Result: Doesn't work because I can't switch off flags of a NPC that is may not valid :D

I stuck deep into something :D


Edit:
pUnit:RegisterEvent("name", time, count)
For this I need first to have a valid pUnit. What I don't have.
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#9 User is offline   salamanda 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 161
  • Joined: 10-July 08

Posted 30 April 2012 - 03:35 PM

local canstart = false

function CheckIfArenaCanStart()
	local found = false
	for place, plrs in pairs(GetPlayersInWorld()) do
		if plrs then
			if plrs:GetAreaId() == 1 then -- gurubashi's area ID
				found = true
				break
			end
		end
	end
	if found then
		-- Player is there
		canstart = true
	end
end

RegisterTimedEvent("CheckIfArenaCanStart", 60000*3, 0)

function GoblinSpawn(pUnit, Event)
	pUnit:RegisterEvent("GoblinCanStart", 5000, 0)
end

function GoblinCanStart(pUnit)
	if canstart then
		pUnit:SendChatMessage(14,0,"Time to spawn a chest and stuff!")
		canstart = false
	end
end

RegisterUnitEvent(goblinID, 18, "GoblinSpawn")


Something like this?

As long as you are manipulating no dynamic objects through a timed event you should be fine.
0

#10 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 30 April 2012 - 04:15 PM

Yes, I think it could work with CheckIfArenaCanStart().

So I can test if there are players there. I think it will help. Will test it tomorrow.

Thanks.
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#11 User is offline   Satanail 

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

Posted 01 May 2012 - 03:47 AM

There is another way to do this script. In stead of adding timed events, that take more memory why don't you use just one AI update event and a variable, that serves as a timer. On every tick of the AI update event, there is a check if pUnit is nil and if it is, removes the event. This is what i could do so far about this script:
timer = 66

function SendWorldMsg(Text)
        SendWorldMessage("|cFFFFCC00[Server "..os.date("%H:%M").."] "..Text.."|r",2)
end

function GurubashiArena_NPC_OnLoad(pUnit, Event)
        SendWorldMsg("Short John Mithril / Stortebrecher is in the Gurubashi Arena")
        pUnit:RegisterAIUpdateEvent(1000)
end

function AIUpdate(pUnit)
if (pUnit ~= nil)then
	if(timer == 39)then
		SendWorldMsg("Gurubashi Arena starts in xxx minutes. Are you prepared ?")
	elseif(timer == 30)then
		SendWorldMsg("Here's the chest!")
		PerformIngameSpawn(2, 179697, 0, -13203, 277, 21.86, 4.18, 100, 0)      -- despawn doesnt work
		pUnit:SendChatMessage(14, 0, "Arrr, Me Hearties! I be havin some extra Treasure that i be givin away at the Gurubashi Arena! All ye need to do is collect it is open the chest I leave on the arena floor!")
		SendWorldMsg("In 30 sec. (test) the chest is gone. Hurry!")
	elseif(timer == 0)then
		timer = 66
		SendWorldMsg("No more treasure.")
		local pChest = pUnit:GetGameObjectNearestCoords(-13203, 277, 22, 179697)
		if(pChest ~= nil) then
			pChest:RemoveFromWorld() 
		end
	end
timer = timer -1
elseif(pUnit == nil)then
	pUnit:RemoveAIUpdateEvent()
end
end


RegisterUnitEvent(14508,21, "AIUpdate")
RegisterUnitEvent(14508, 18, "GurubashiArena_NPC_OnLoad") 


This is your script, but it's structured in another way:
So, i am leaving and re-entering the gurubashi arena area for about 30 min with an interval of 10 min and the server is stable. The script does stop working within about 5 min after i leave the area. just to make sure that the cell unloads i teleport myself to another map - GM island on map 1, that is quite far away from gurubasi arena. The server seems stable and i did not crash as of yet.
0

#12 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 01 May 2012 - 04:53 AM

While I was reading earlier the wiki I have seen several time these commands RegisterAIUpdateEvent() and RemoveAIUpdateEvent(). But because there is no description I didn't had any ideas what I can do with that commands :P

AI stands here for Artificial Intelligence ? And what does it mean in the context of ArcEmu ?
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#13 User is offline   Satanail 

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

Posted 01 May 2012 - 06:02 AM

View PostMagnifikator, on 01 May 2012 - 04:53 AM, said:

While I was reading earlier the wiki I have seen several time these commands RegisterAIUpdateEvent() and RemoveAIUpdateEvent(). But because there is no description I didn't had any ideas what I can do with that commands :P

AI stands here for Artificial Intelligence ? And what does it mean in the context of ArcEmu ?

Well, as much as i know, this is an event that is executed in a specified period. Don't know what is AI standing for but it is used to control events (like this script where the AIUpdate starts on event spawn npc (or load in cell)), combat behaviour of a boss or other npc (when AIupdate event is started on event enter combat). With the help of AIupdate and some locals you can make your script smaller and a lot better. There are some examples you can find in arcemu scripts, that come with the core files. - \arcemu\src\scripts\lua\Lua\AUCHINDOUN. There are some boss scripts that don't have multiple functions registered, but only one AIUpdate event and a counter/s or timer/s like the variable "timer" in my example and also tables to control the bosses. AIUpdate is also used in C++ scripts.
0

#14 User is offline   Magnifikator 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 398
  • Joined: 05-October 11
  • Gender:Male
  • Location:Switzerland
  • Server OS:Windows

Posted 06 May 2012 - 02:56 PM

Just to give some feedback. Both of the scripts by Satanail and salamanda makes some problems. Satanails script f.ex. nerver start if there is no player in the arena. But in combination of the idea of salamanda with the player checking loop and the use of AIUpdate recommened by Satanail it works perfect. :( So, thank for the inspiration :P

I have changed the functionality a little bit so that I know now also how much players are in the arena and the total of their levels. Depending on this information I could make the area a little bit more interesting by spawning some bad wolfs :P

Here's my script idea:
local ItsShowtime = false

-- Checks how much players are in the zone
function PlayersInArena()
	local count = 0
	local level = 0
	for place, plrs in pairs(GetPlayersInWorld()) do
		if (plrs) then
			if (plrs:GetAreaId() == 2177) then 	-- Gurubashi area ID
				level = level + plrs:GetPlayerLevel()
				count = count + 1
			end
		end
	end
	return count, level
end

local Arena_period		=  60000			-- Arena repeats ever 1 min.
local Arena_invitation	=  15000			-- Time Players are invited before area starts
--local Arena_period		= 3*3600000			-- Arena repeats ever 3 hours.
--local Arena_invitation	=  900000			-- Time Players are invited before area starts

-----------------------------------------
-- The timer section
-----------------------------------------
function GurubashiArenaEvent(pUnit, Event)
	RegisterTimedEvent("GurubashiArena1", Arena_period-Arena_invitation, 1)
end

function GurubashiArena1(pUnit, Event)
	SendWorldMsg("Gurubashi Arena starts in 15 minutes. Are you prepared ?")
	RegisterTimedEvent("GurubashiArena2", Arena_invitation, 1)
end

function GurubashiArena2(pUnit)
	ArenaPlayers, PlayerLevel = PlayersInArena()
	if (ArenaPlayers>1) then
		-- (St�rtebrecher) 
		SendWorldMsg("Short John Mithrilis in the Gurubashi Arena and "..ArenaPlayers.." heroes ("..PlayerLevel.."). Arena can start.")
		ItsShowtime = true
	else
		SendWorldMsg("Gurubashi Arena will not start. Not enough players.")
	end
	RegisterTimedEvent("GurubashiArenaEvent", 1, 1)
end

RegisterTimedEvent("GurubashiArenaEvent", 5000, 1)


-----------------------------------------
-- The NPC section
-----------------------------------------
function GurubashiArena_NPC_OnLoad(pUnit, event)
	pUnit:RegisterAIUpdateEvent(5000)
end

function GurubashiArena_AIUpdate(pUnit)

	if(ItsShowtime) then
		ItsShowtime = false	
		
		pUnit:SpawnGameObject(179697, -13209, 277, 21.9, 4.1, 900000, 100) --chest
		
		-- TODO: spawn some nice bad wolfs :-)

		pUnit:SendChatMessage(14, 0, "Arrr, Me Hearties! I be havin' some extra Treasure that i be givin' away at the Gurubashi Arena! All ye need to do is collect it is open the chest I leave on the arena floor!")

--		pUnit:SendChatMessage(14, 0, "In 15 min. the chest is gone. Hurry!")

	end
	
end



-- NPC Goblin Short John Mithril (en) / St�rtebrecher (de)
RegisterUnitEvent(14508, UNIT_EVENT_ON_LOAD, "GurubashiArena_NPC_OnLoad") 
RegisterUnitEvent(14508, UNIT_EVENT_ON_AIUPDATE, "GurubashiArena_AIUpdate")

Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

Share this topic:


Page 1 of 1
  • 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