ArcEmu: Help With Lua Scripting - 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

Help With Lua Scripting Scripting

#1 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 16 August 2012 - 08:07 PM

Hey, Guys, i need some help with lua scripting, what i want to do is to make an npc cast spell and change model and say stuff on spawn, but i dont know how to here's my script i'll post it now,

HERE IT IS:

-- Hand of The Deceiver
function Deceiver_OnEnterCombat(pUnit, Event)
   Unit:RegisterEvent("Deceiver_Bolt", 4000, 0)
   Unit:RegisterEvent("Deceiver_channel", 1000, 0)
end

function Deceiver_Bolt(pUnit, Event)
   Unit:FullCastSpellOnTarget(45770,Unit:GetClosestPlayer())
end

-- This is the where the "Hand of The Deceiver" Channels his spell.
function Deceiver_channel(pUnit, Event)
   if pUnit:GetHealthPct() == 01 then
 	pUnit:CastSpelll(30742)
end
end


function Deceiver_OnDeath(pUnit, Event)
   pUnit:SpawnCreature(25315, 1699.307251, 629.165710, 27.559992, 3.815375, 14, 0)
   pUnit:RegisterEvent("boss_spawn", 1000, 0)
end

-- END

function phase_1(pUnit, Event)
 if pUnit:GetHealthPct() < 95 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "Chaos!")
  pUnit:CastSpellOnTarget(47248)
  pUnit:PlaySoundToSet(12505)
  pUnit:RegisterEvent("phase_2",1000, 0)
 end
end

function phase_2(pUnit, Event)
 if pUnit:GetHealthPct() < 94 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "Destruction!")
  pUnit:CastSpell(39023)
  pUnit:PlaySoundToSet(12506)
  pUnit:RegisterEvent("phase_3",1000, 0)
 end
end
 
function phase_3(pUnit, Event)
 if pUnit:GetHealthPct() < 93 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "Oblivion!")
  pUnit:PlaySoundToSet(12507)
  pUnit:CastSpell(38627)
  pUnit:CastSpell(38533)
  pUnit:CastSpell(38533)
  pUnit:CastSpell(38533)
  pUnit:RegisterEvent("phase_4",1000, 0)
 end
end
 
function phase_4(pUnit, Event)
 if pUnit:GetHealthPct() < 50 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "I will not be denied! This world shall fall!")
  pUnit:PlaySoundToSet(12508)
  pUnit:CastSpell(45664)
  pUnit:RegisterEvent("phase_5",1000, 0)
 end
end
 
function phase_5(pUnit, Event)
 if pUnit:GetHealthPct() < 20 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "Do not harbor false hope. You cannot win!")
  pUnit:PlaySoundToSet(12509)
  pUnit:CastSpell(40343)
  pUnit:CastSpell(38441)
  pUnit:CastSpell(512)
  pUnit:CastSpell(25442)
  pUnit:CastSpell(17668)
  pUnit:CastSpell(40876)
  pUnit:RegisterEvent("phase_6",1000, 0)
 end
end


function phase_6(pUnit, Event)
 if pUnit:GetHealthPct() < 01 then
  pUnit:RemoveEvents();
  pUnit:SendChatMessage(14, 0, "Ragh! The powers of the Sunwell turn against me! What have you done? What have you done?!")
  pUnit:PlaySoundToSet(12510)
  pUnit:CastSpell(44998)
  pUnit:RegisterEvent("phase_7",1000, 0)
 end
end

function phase_7(pUnit, Event)
 if pUnit:GetHealthPct() < 100 then
  pUnit:RemoveEvents();        
  pUnit:CastSpell(46474)
 end
end

function boss_spawn(pUnit,Event)
	pUnit:Root()
	pUnit:SetFaction(14)
	pUnit:CastSpell(35177)
	pUnit:SetModel(23200)
	pUnit:SendChatMessage(14, 0, "The expendible have perished... So be it! Now I shall succeed where Sargeras could not! I will bleed this wretched world and secure my place as the true master of the Burning Legion. The end has come! Let the unraveling of this world commence!")
	pUnit:PlaySoundToSet(12500)
pUnit:RegisterEvent("boss_start",1000, 0)
end

function boss_start(pUnit, Event)
 pUnit:RegisterEvent("phase_1",1000, 0)
 end

function boss_OnKill(pUnit, Event)
  pUnit:SendChatMessage(14, 0, "Another step towards destruction!")
  pUnit:PlaySoundToSet(12501)
  pUnit:CastSpell(31972)
 end

RegisterUnitEvent(25588, 1, "Deceiver_OnEnterCombat")
RegisterUnitEvent(25588, 2, "Deceiver_channel")
RegisterUnitEvent(25588, 3, "Deceiver_Bolt")
RegisterUnitEvent(25588, 4, "Deceiver_OnDeath")
RegisterUnitEvent(25315, 5, "boss_spawn")
RegisterUnitEvent(25315, 6, "boss_start")
RegisterUnitEvent(25315, 7, "boss_OnKill")



Any help would be appreciated greatly.

Thank you.
0

#2 User is offline   dracbane 

  • Member
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 19-May 10
  • Gender:Male

Posted 16 August 2012 - 08:54 PM

View Post5p3ctr3, on 16 August 2012 - 08:07 PM, said:

i want to do is to make an npc cast spell and change model and say stuff on spawn



I was trying to figure this out last night. I can get everything to work on entering combat, but there doesn't seem to be a ON_SPAWN hook or anything similar for NPCs (at least that is implemented and working). I tried a few hooks but none of them seemed to do the trick. Now, I know you can make the NPC channel a spell on another NPC or an object through the database, but I am having problems with this myself as the channeling doesn't stop upon entering combat or even death of one of the mobs with this method lol.


EDIT!


Finally found the hook I wanted!!! To get the npc to do something on spawn use the UNIT_EVENT_ON_LOAD hook. So when you register your event you will use

RegisterUnitEvent(NPCID, 18, functionname), then the function will look like

function functionname(pUnit)
pUnit:SetScale(#) - changes scale
pUnit:SetModel(ModelID) - will change model on spawn, use same line to change during a phase change ect.
pUnit:CastSpell(SpellID) - will cast spell on spawn
end
0

#3 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 16 August 2012 - 11:02 PM

Thanks, very much i got that working on spawn, but one problem aswell, When i spawn the mob he doesnt cast the spell, any ideas? here is the code im using for the spell:

pUnit:CastSpell(35177)

its not working for some rason i dont know why.

Ok that function Unit_on_Load does everything except for casting spells :( /cry

Please if anyone knows how to fix it please tell me how to, i've spent alot of time trying diffrent things and nothing seems to work if you have any ideas please tell me how to fix.
0

#4 User is offline   Magnifikator 

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

Posted 17 August 2012 - 02:23 AM

I didn't read the whole post but this can't work:

function Deceiver_OnEnterCombat(pUnit, Event)
   Unit:RegisterEvent("Deceiver_Bolt", 4000, 0)
   Unit:RegisterEvent("Deceiver_channel", 1000, 0)
end


You use Unit instead of pUnit.
Try out the LoE ArcEmu World database. Please visit dev.LandOfElves.net.

Posted Image


0

#5 User is offline   dracbane 

  • Member
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 19-May 10
  • Gender:Male

Posted 17 August 2012 - 05:46 PM

View Post5p3ctr3, on 16 August 2012 - 11:02 PM, said:

Thanks, very much i got that working on spawn, but one problem aswell, When i spawn the mob he doesnt cast the spell, any ideas? here is the code im using for the spell:

pUnit:CastSpell(35177)

its not working for some rason i dont know why.

Ok that function Unit_on_Load does everything except for casting spells :( /cry

Please if anyone knows how to fix it please tell me how to, i've spent alot of time trying diffrent things and nothing seems to work if you have any ideas please tell me how to fix.


It works fine for me O.o I was scripting away without any problems last night. make sure you are using the same unit name in the line(Unit, pUnit, ect) Also, I found one issue with LOAD, it doesn't affect mobs when they are respawned. It only works on the initial loading of the creature. So, if you are doing any kind of .npc respawn stuff it won't cast the spell the second time. Still working on getting around this issue, will let you know if I get it working better. Also put your new scripts up on pastebin and give me a link and I will see why the cast spell isn't working.

Edit: Also, I have only tested the OnLOAD cast spell with buffs, I have not put any channeled spells to the test. I have a feeling this will require more than just using CastSpell in OnLoad to accomplish correctly.
0

#6 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 17 August 2012 - 06:49 PM

Took a quick look, nothing fancy. (did not test)
Spoiler

0

#7 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 17 August 2012 - 06:50 PM

View Postdracbane, on 17 August 2012 - 05:46 PM, said:

It works fine for me O.o I was scripting away without any problems last night. make sure you are using the same unit name in the line(Unit, pUnit, ect) Also, I found one issue with LOAD, it doesn't affect mobs when they are respawned. It only works on the initial loading of the creature. So, if you are doing any kind of .npc respawn stuff it won't cast the spell the second time. Still working on getting around this issue, will let you know if I get it working better. Also put your new scripts up on pastebin and give me a link and I will see why the cast spell isn't working.

Edit: Also, I have only tested the OnLOAD cast spell with buffs, I have not put any channeled spells to the test. I have a feeling this will require more than just using CastSpell in OnLoad to accomplish correctly.

Ok great Thank you here's my script so far

http://pastebin.com/VdmU54iY
0

#8 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 17 August 2012 - 06:54 PM

This isnt always going to work
if pUnit:GetHealthPct() == 01 then

CastSpelll has a typo

etc ..

Check my post. I fixed all such things I could find, changed the on spawn thing to something that works if the onLoad hook wont do and fixed the registers.
0

#9 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 20 August 2012 - 02:02 AM

View PostRoller, on 17 August 2012 - 06:54 PM, said:

This isnt always going to work
if pUnit:GetHealthPct() == 01 then

CastSpelll has a typo

etc ..

Check my post. I fixed all such things I could find, changed the on spawn thing to something that works if the onLoad hook wont do and fixed the registers.

hhmmmm, your one works as fine as my new one does now but, still doesnt cast spell on spawn :S
0

#10 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 20 August 2012 - 08:28 AM

Ok, I tested it ingame a bit and I fixed the start.

Deciever now casts the summoning visual on spawn
He stops it on combat
He casts the spell he casts on combat correctly now
On death he spawns kiljaeden

Now, only ingame I realized the emerge / birth spell does not work .. It only works if the NPC is already spawned and on screen with the right model.
So .. I made a little work around here with timed events since I did not find any good solution (not that familiar with NPC/spell/etc mechanics)
On spawn Kiljaeden is now made unattackable so the animation can play, the animation is started with the spell after 200 ms (lowler wont work good or at all)
Then after the animation finishes, the NPC will be set attackable again and he will start saying stuff and the first phase starts.

Only fixed the start, did not check up on any phases etc.
Also, aren't there more Deceivers than one?
If so, then killing each will spawn the boss, which means like 3 kiljaedens spawned ..
Should script it to require more NPCs to be killed if necessary.

Spoiler

0

#11 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 21 August 2012 - 09:10 PM

View PostRoller, on 20 August 2012 - 08:28 AM, said:

Ok, I tested it ingame a bit and I fixed the start.

Deciever now casts the summoning visual on spawn
He stops it on combat
He casts the spell he casts on combat correctly now
On death he spawns kiljaeden

Now, only ingame I realized the emerge / birth spell does not work .. It only works if the NPC is already spawned and on screen with the right model.
So .. I made a little work around here with timed events since I did not find any good solution (not that familiar with NPC/spell/etc mechanics)
On spawn Kiljaeden is now made unattackable so the animation can play, the animation is started with the spell after 200 ms (lowler wont work good or at all)
Then after the animation finishes, the NPC will be set attackable again and he will start saying stuff and the first phase starts.

Only fixed the start, did not check up on any phases etc.
Also, aren't there more Deceivers than one?
If so, then killing each will spawn the boss, which means like 3 kiljaedens spawned ..
Should script it to require more NPCs to be killed if necessary.

Spoiler


This is GREAT! thanks so much, but yea i too want to get it to work when all 3 decievers are dead, but i dont know how to i tried but cant seem to get it to work, if u come up with a solution, then please post it here it would me alot. thank you
0

#12 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 22 August 2012 - 06:53 AM

View Post5p3ctr3, on 21 August 2012 - 09:10 PM, said:

This is GREAT! thanks so much, but yea i too want to get it to work when all 3 decievers are dead, but i dont know how to i tried but cant seem to get it to work, if u come up with a solution, then please post it here it would me alot. thank you

It shouldnt be that hard really, just use tables.
I think something like this should do:

local T = {} -- variable T is a table now

function Deceiver_OnDeath(pUnit, Event)
	pUnit:RemoveEvents()
	local inst = pUnit:GetInstanceID() -- each instance needs to be identified and have its own counter for the kills
	if(not T[inst]) then -- check if our instance is NOT found in the table
		T[inst] = 1
	elseif(T[inst] < 3) then -- 3 is the amount of Deceivers needed to spawn the boss
		T[inst] = T[inst] + 1
	else -- 3 Deceivers were killed, spawn the boss
		pUnit:SpawnCreature(25315, 1699.307251, 629.165710, 27.559992, 3.815375, 14, 0)
	end
end

0

#13 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 23 August 2012 - 07:50 PM

View PostRoller, on 22 August 2012 - 06:53 AM, said:

It shouldnt be that hard really, just use tables.
I think something like this should do:

local T = {} -- variable T is a table now

function Deceiver_OnDeath(pUnit, Event)
	pUnit:RemoveEvents()
	local inst = pUnit:GetInstanceID() -- each instance needs to be identified and have its own counter for the kills
	if(not T[inst]) then -- check if our instance is NOT found in the table
		T[inst] = 1
	elseif(T[inst] < 3) -- 3 is the amount of Deceivers needed to spawn the boss
		T[inst] = T[inst] + 1
	else -- 3 Deceivers were killed, spawn the boss
		pUnit:SpawnCreature(25315, 1699.307251, 629.165710, 27.559992, 3.815375, 14, 0)
	end
end


hmmm it wont load script unless i put a then at elseif(T[inst] < 3)

but then it wont spawn kil'jaeden :S needs something else there
0

#14 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 24 August 2012 - 04:49 AM

Ah, made a logic fail. < 3 should be < 2 to trigger spawn on 3 kills.
And yeah, there needs to be a 'then' in elseif.

Spoiler

0

#15 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 29 August 2012 - 06:32 PM

View PostRoller, on 24 August 2012 - 04:49 AM, said:

Ah, made a logic fail. < 3 should be < 2 to trigger spawn on 3 kills.
And yeah, there needs to be a 'then' in elseif.

Spoiler


This is very nice ty vm, but um i have anither question to ask, i need help with making a gameboject cast a spell on the player that uses it, right now what im working on aswell is the kalecgos fight, and im trying to make it when he spawns the portals the portals will cast the teleport spell on the player that uses it and teleport to the demon realm to fight sathrovarr the demon guy, but gameobject wont cast the spell on me when i use it, here's my script ill post it for you
Spoiler

0

#16 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 30 August 2012 - 05:30 AM

Gameobjects probably cant cast spells.
Make the player cast the spell on himself etc.
0

#17 User is offline   5p3ctr3 

  • Member
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 17-August 11
  • Gender:Male
  • Server OS:Windows

Posted 30 August 2012 - 05:31 PM

View PostRoller, on 30 August 2012 - 05:30 AM, said:

Gameobjects probably cant cast spells.
Make the player cast the spell on himself etc.

yea i tried that aswell but it wont work either here is the scrip again but for a player instead :


function Teleporting_onUse (pGameObject, Event, pPlayer)
pPlayer:CastSpell(46019)
end
RegisterGameObjectEvent(187055, 4, "Teleporting_onUse")
0

#18 User is offline   Roller 

  • Member
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 29-July 09

Posted 31 August 2012 - 04:29 AM

Try using CastSpellOnTarget() and pPlayer as the target.
The spell is not cast on self, it has a range and needs a target possibly.

Casting methods vary by spells.
0

#19 User is offline   dracbane 

  • Member
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 19-May 10
  • Gender:Male

Posted 31 August 2012 - 04:19 PM

View PostRoller, on 31 August 2012 - 04:29 AM, said:

Try using CastSpellOnTarget() and pPlayer as the target.
The spell is not cast on self, it has a range and needs a target possibly.

Casting methods vary by spells.


Yep, was what I was going to say after reading his post lol
0

Share this topic:


Page 1 of 1


Fast Reply

  

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