ArcEmu: Require Some Help... - 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

Require Some Help... Lua Script anti pvp

#1 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 10 September 2010 - 02:15 PM

well i dont have any crashes or anything like, the npc just does nothing >_< i dont really get it why... im kinda new with LUA, i like more C++ but i couldnt find the correct scripting like this in C++....

function Animantrix_Guard(pUnit, Event)
	pUnit:RegisterEvent("LookingForAttackers", 1000, 0)
end

function LookingforAttackers(pUnit, Event, Player)
	local friends = pUnit:GetInRangeFriends()
	for k,v in pairs(friends) do
		if v:IsInCombat() == true and v:IsPlayerAttacking() == true and v:GetDistance(pUnit) <= 1800 then
		pUnit:FullCastSpell(39249)
		pUnit:SendChatMessage(12, 0, "Do Not Duel or PvP In the Mall.")
		pUnit:RegisterEvent("ChargeAttacker", 2000, 0)
	end
end
end

function ChargeAttacker(pUnit, Event, Player)
	pUnit:FullCastSpellOnTarget(41272)
	pUnit:RegisterEvent("LookingforCasters", 3000, 0)
end

function LookingForCasters(pUnit, Event, Player)
	local friends = pUnit:GetInRangeFriends()
	for k,v in pairs(friends) do
		if v:IsInCombat() == true and v:IsCasting() == true and v:GetDistance(pUnit) <= 1800 then
		pUnit:FullCastSpell(39249)
		pUnit:SendChatMessage(12, 0, "Do Not Duel or PvP In the Mall.")
		pUnit:RegisterEvent("ChargeCaster", 3000, 0)
end
end
end

function ChargeCaster(pUnit, Event, Player)
	pUnit:FullCastSpellOnTarget(41272, Player)
end

RegisterUnitEvent(800002, 18, "Animantrix_Guard")


Any help what im doing wrong is good plx ? D:
0

#2 User is offline   Neglected 

  • Member
  • Pip
  • Group: Members
  • Posts: 25
  • Joined: 27-May 09
  • Gender:Male

Posted 10 September 2010 - 02:30 PM

Can you tell me if there are any errors in the console?
Lua Wiki Editor.
Ahn'Qiraj PvP EU - Hitswitch [Rogue]; Aeire [Priest]; Neglected [Warlock]
0

#3 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 10 September 2010 - 03:20 PM

View PostKeO, on 10 September 2010 - 02:15 PM, said:

im kinda new with LUA

http://www.lua.org/about.html

Quote

Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!


View PostKeO, on 10 September 2010 - 02:15 PM, said:

i like more C++ but i couldnt find the correct scripting like this in C++....

Did you try taking a look at the ArcScripts repo? it's full of examples :P
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#4 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 10 September 2010 - 09:14 PM

View PostSaintJamesApostle, on 10 September 2010 - 03:20 PM, said:

http://www.lua.org/about.html



Did you try taking a look at the ArcScripts repo? it's full of examples :)


Thanks for the links, ill check it up.... and i did took a look at the arcscripts repo, they also have one script for "NeutralGuards" which i tested in shattered sun since i see its the only one registered, but the guards only change their faction but they dont attack the player attacking :P thats why i didnt use it, i also tried to modify that one to my use but no luck....

@Marforious i did tried to use that one before, 2 things i didnt like = The player just get killed and usually no message appears ? O_o and 2.- IsPlayerAttacking only takes for those whos attacking with melee no spells... also i tried to change this one since i thought to see the guards in "action" :)

@Neglected i dont get any errores in the console, not even a crash or the npc changing faction (since i dont think i added that in the lua script) just the guard does nothing o.o

Edit: Okay got some progress.. i was missing the lil cap letters on the functions =.= but well i thought Lua would use also the same pointers like C++ ? im getting the spam on the consola about "IsCasting" not valid o.o is there any other one to recognize if the player is casting ?
0

#5 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 11 September 2010 - 03:03 AM

Looks like you gave up pretty soon on C++...

Quote

well i thought Lua would use also the same pointers like C++ ?

you shouldn't "think", you should just read the ArcEmu documentation about Lua functions :P
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#6 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 11 September 2010 - 04:31 AM

View PostSaintJamesApostle, on 11 September 2010 - 03:03 AM, said:

Looks like you gave up pretty soon on C++...

you shouldn't "think", you should just read the ArcEmu documentation about Lua functions :P


I'm really sorry, yea i gave up on C++ fast =.= i was tired and kinda stressed, and im not being lazy or anything like... but could you tell me where to find that documentation ? i thought i would see it here on the forums and i've only seen tutorials and other releases.... and sorry if its asking too much =.=
0

#7 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 11 September 2010 - 04:54 AM

http://arcemu.info/t...NE_COMMANDS.txt
http://www.arcemu.in...itle=CatRDirect
the wiki link was on the main page of the wiki under "script engine documentation :P
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#8 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 11 September 2010 - 05:03 AM

View PostSaintJamesApostle, on 11 September 2010 - 04:54 AM, said:

http://arcemu.info/t...NE_COMMANDS.txt
http://www.arcemu.in...itle=CatRDirect
the wiki link was on the main page of the wiki under "script engine documentation :P


Thanks lots, i see its a lot to read so imma just bookmark it xD and finish reading tomorrow :) but thanks again....
1

#9 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 11 September 2010 - 05:20 AM

You are welcome, it's always nice to see someone who wants to read our documentation :P enjoy the reading
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#10 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 11 September 2010 - 05:47 AM

View PostSaintJamesApostle, on 11 September 2010 - 05:20 AM, said:

You are welcome, it's always nice to see someone who wants to read our documentation :) enjoy the reading


Lol yea i can bet nobody wants to read, but atleast for me its really interesting learning more stuff.... and okay reading and learning this documentation helped me lots, LOTS = i have fixed my script :P but now i noticed something.... when the npc attacks, he doesnt goes back to the original spot where i spawned him or i placed him at the beginning, and i've been checking the functions and i dont really see one that says "moveto" or "gobackto" etc.... the only way i could see this is to get the original spawn point from GetSpawnLocation from the unit itself and then like another to get it back... thats the function i cant find to move the npc to the SpawnLocation o.o is there one or i kinda want to do too much ? xD lol or it will be easier to do .despawn and then respawn again ?

Edit: A thought... can i use this?
local startspawn = pUnit:GetSpawnLocation()
then after the casts and ends the functions i would use -
pUnit:MoveTo(startspawn)
? is it possible or i need to put the coordinates exactly ? because i couldnt use it then if im spawning more than 1 guard.... or i would have to create 1 script per guard spawned then ? >_<
0

#11 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 11 September 2010 - 06:04 AM

Looks like a question for our Lua experts Parox and Hypersniper ^^ I don't know anything about Lua so can't help you much, other then try it, see if it works, change it, try again, and so on^^
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#12 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 11 September 2010 - 06:15 AM

Ah alright will test it after i sleep xD 6:15 am here >_< atleast i can sleep peacefully now :P thanks a lot for the help :)
0

#13 User is offline   Neglected 

  • Member
  • Pip
  • Group: Members
  • Posts: 25
  • Joined: 27-May 09
  • Gender:Male

Posted 11 September 2010 - 07:37 AM

This, I can help with. :)
:GetSpawnLocation() returns 4 values: X, Y, Z, and O.
Now, in order to get the values we want we can just do this:
local x, y, z, o = pUnit:GetSpawnLocation()


This will correctly assign the values we want to the correct variables. X becomes the Unit's Spawn X, and so on.
For this example you could just do any of the following.
local x, y, z, o = pUnit:GetSpawnLocation()
pUnit:MoveTo(x, y, z, o)

or
pUnit:MoveTo(pUnit:GetSpawnLocation())
-- We can do this since the brackets are evaluated first.


However, what if we wanted just the spawn Y and Z position for example?
We could do this.
local _, y, z = pUnit:GetSpawnLocation()


The _ is considered a "trash" variable and can be used in place of variable names to get values in case of multiple returning functions. Lua functions will always return their amount of values (unless you put a () around the statement, then it only returns the first one), so we need to "reach" the arguments using a) trash variables or :P select() (Which I won't go into, you can learn about that yourself).

The issue with him not returning might be an issue such as you don't have :RemoveEvents() in his LeaveCombat function (which you also don't have). The thing is, is that you're registering a function (ChargeCaster) every 3 seconds indefinitely. You need to remove that event or it'll continue trying to find the player it charged. :)

Here's a script that'll do what you want (theoretically).

function Animantrix_Guard(pUnit) -- We don't need the Event variable.
	pUnit:RegisterEvent("LookingForAttackers", 1000, 0)
end

function LookingforAttackers(pUnit) -- We don't need the Event variable and the Player one is non-existant.
	for _, v in ipairs(pUnit:GetInRangeFriends()) do -- ipairs is more efficient than pairs for most cases.
		if v:IsInCombat() == true and v:GetDistanceYards(pUnit) <= 42 then
			if v:IsInCasting() or v:IsPlayerAttacking() then -- Eliminates the need for a second function.
				pUnit:FullCastSpell(39249)
				pUnit:SendChatMessage(12, 0, "Do Not Duel or PvP In the Mall.")
				-- Register Event can take direct functions. :)
				ChargeAttacker = function(pUnit, target)
					if target then
						pUnit:FullCastSpellOnTarget(41272, target)
					end
				end
				pUnit:RegisterEvent(ChargeAttacker(pUnit, v), 2000, 1)
			end
		end
	end
end


RegisterUnitEvent(800002, 18, "Animantrix_Guard")

Lua Wiki Editor.
Ahn'Qiraj PvP EU - Hitswitch [Rogue]; Aeire [Priest]; Neglected [Warlock]
0

#14 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 12 September 2010 - 10:43 PM

View PostNeglected, on 11 September 2010 - 07:37 AM, said:

This, I can help with. :)
:GetSpawnLocation() returns 4 values: X, Y, Z, and O.
Now, in order to get the values we want we can just do this:
local x, y, z, o = pUnit:GetSpawnLocation()


This will correctly assign the values we want to the correct variables. X becomes the Unit's Spawn X, and so on.
For this example you could just do any of the following.
local x, y, z, o = pUnit:GetSpawnLocation()
pUnit:MoveTo(x, y, z, o)

or
pUnit:MoveTo(pUnit:GetSpawnLocation())
-- We can do this since the brackets are evaluated first.


However, what if we wanted just the spawn Y and Z position for example?
We could do this.
local _, y, z = pUnit:GetSpawnLocation()


The _ is considered a "trash" variable and can be used in place of variable names to get values in case of multiple returning functions. Lua functions will always return their amount of values (unless you put a () around the statement, then it only returns the first one), so we need to "reach" the arguments using a) trash variables or B) select() (Which I won't go into, you can learn about that yourself).

The issue with him not returning might be an issue such as you don't have :RemoveEvents() in his LeaveCombat function (which you also don't have). The thing is, is that you're registering a function (ChargeCaster) every 3 seconds indefinitely. You need to remove that event or it'll continue trying to find the player it charged. :)

Here's a script that'll do what you want (theoretically).

function Animantrix_Guard(pUnit) -- We don't need the Event variable.
	pUnit:RegisterEvent("LookingForAttackers", 1000, 0)
end

function LookingforAttackers(pUnit) -- We don't need the Event variable and the Player one is non-existant.
	for _, v in ipairs(pUnit:GetInRangeFriends()) do -- ipairs is more efficient than pairs for most cases.
		if v:IsInCombat() == true and v:GetDistanceYards(pUnit) <= 42 then
			if v:IsInCasting() or v:IsPlayerAttacking() then -- Eliminates the need for a second function.
				pUnit:FullCastSpell(39249)
				pUnit:SendChatMessage(12, 0, "Do Not Duel or PvP In the Mall.")
				-- Register Event can take direct functions. :D
				ChargeAttacker = function(pUnit, target)
					if target then
						pUnit:FullCastSpellOnTarget(41272, target)
					end
				end
				pUnit:RegisterEvent(ChargeAttacker(pUnit, v), 2000, 1)
			end
		end
	end
end


RegisterUnitEvent(800002, 18, "Animantrix_Guard")



Thanks a lot Neglected, actually i did got it working, but i like yours also its kinda more hmm organized :P and also yours have for casting options o.o its just what i was going to do today xD thanks a lot for the help and for the script, ill use yours if you dont mind Neglected, and then change it a bit :)

One lil problem or well 2 problems, i used the IsInCasting from neglected and the console returns an error - attempt to call method ´IsInCasting´ <a nil value> and i tried also with IsCasting and not working ? >_< is there another way to detect if hes casting or not ?
0

#15 User is offline   iEzri 

  • < Ace of spades >
  • Group: Contributor
  • Posts: 1,692
  • Joined: 22-December 08
  • Gender:Female
  • Interests:I'm likely to cause mischief
  • Server OS:Linux

Posted 13 September 2010 - 12:21 AM

i think this could be what you are looking for:

http://www.arcemu.in...tCurrentSpellId
Posted Image I do not join. I lead.
0

#16 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 13 September 2010 - 01:00 AM

View PostiEzri, on 13 September 2010 - 12:21 AM, said:

i think this could be what you are looking for:

http://www.arcemu.in...tCurrentSpellId


I tried also with that one Ezri D: and not working i get the error nil valur... i also tried GetCaster, IsPlayer(IsCasting()) and nothing works D: or my script is wrong, or the IsCasting is not taking players ? altho i saw in the engine commands IsCasting it should be also working for players and creatures >_<
0

#17 User is offline   iEzri 

  • < Ace of spades >
  • Group: Contributor
  • Posts: 1,692
  • Joined: 22-December 08
  • Gender:Female
  • Interests:I'm likely to cause mischief
  • Server OS:Linux

Posted 13 September 2010 - 05:09 AM

View PostKeO, on 13 September 2010 - 01:00 AM, said:

I tried also with that one Ezri D: and not working i get the error nil valur... i also tried GetCaster, IsPlayer(IsCasting()) and nothing works D: or my script is wrong, or the IsCasting is not taking players ? altho i saw in the engine commands IsCasting it should be also working for players and creatures >_<


Nil

Nil is a type with a single value, nil!

It's main property is being different from any other value. So it's a little like Tommy Emmanuel when making an album and calling it "Dare to Be Different"... However, as people might be able to spot the following is true:

- a global variable has a nil value by default, before a first assignment
- you can assign nil to a global variable to delete it.

So it can be generally said that lua uses nil as a kind of non-value, to represent the absence of a useful value.

Please show us some exact code you are using there, and we might be able to point you on where you have been doing something wrong?
Posted Image I do not join. I lead.
0

#18 User is offline   KeO 

  • Member
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 12-March 10
  • Gender:Male

Posted 13 September 2010 - 11:35 AM

View PostiEzri, on 13 September 2010 - 05:09 AM, said:

Nil

Nil is a type with a single value, nil!

It's main property is being different from any other value. So it's a little like Tommy Emmanuel when making an album and calling it "Dare to Be Different"... However, as people might be able to spot the following is true:

- a global variable has a nil value by default, before a first assignment
- you can assign nil to a global variable to delete it.

So it can be generally said that lua uses nil as a kind of non-value, to represent the absence of a useful value.

Please show us some exact code you are using there, and we might be able to point you on where you have been doing something wrong?

I'm using the same code as neglected posted or recommended, just deleting the IsInCasting, i tried with IsCasting and didnt work, i tried with v:GetCurrentSpellId() == true and didnt work either, also without the == true, i tried also with v:IsPlayer(IsCasting()) and didnt work also.... i dont know what other function i should use o.o

Edit: My apologies..... i used GetCurrentSpellId now and it works as intended... i used before typing ID thats why it wasnt working.... sorry =.= and thanks a lot for the help
0

#19 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 13 September 2010 - 03:02 PM

Don't we have PvP guard support in Arcemu? I am pretty sure I remember some method like AggroPvPGuards that's called in dealdamage.
"The demand for free goods is infinite."
0

#20 User is offline   Foereaper 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 184
  • Joined: 21-May 09

Posted 25 September 2010 - 03:42 PM

View Postdfighter, on 13 September 2010 - 03:02 PM, said:

Don't we have PvP guard support in Arcemu? I am pretty sure I remember some method like AggroPvPGuards that's called in dealdamage.


It is, but it also triggers on fall damage, or any other damage for that matter..
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