Another Lua question [message #449318] |
Fri, 01 July 2011 13:32 ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
hego64
Messages: 19 Registered: April 2011 Location: Hegoville
Karma: 0
|
Recruit |
|
|
Ok, I figured I may be able to use this for my kill hook.
function myscript:Killed(ID, obj, killer)
print("Killed", ID, obj, killer)
end
Thing is, I don't know how to use it. Anyone have any ideas or know how to use this? I could really use the help with this please.
If not, could someone give me an alternate way like e-mail or a different site that I may be able to reach jnz? I pm'd him but he hasn't been active since April, so I'm not really expecting a response.
Thanks,
-Hego64
|
|
|
Re: Another Lua question [message #449319 is a reply to message #449318] |
Fri, 01 July 2011 13:57 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
iRANian
Messages: 4307 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
something like:
function OnObjectCreate(o) --whenever an object is created
if Is_A_Star(o) then --check if they're a real player
Attach_Script_Once(o, "myscript", "")
--attach myscript to them if they are
myscript = {}
function myscript:Killed(ID, obj, killer)--this function gets called whenever something this script is attached to is killed
print("Killed", ID, obj, killer)
end
Register_Script("myscript", "", myscript)--register our script with the engine
I don't really know how LUA works and how the LUA plugin works though. I think the print() call in myscript::Killed() is incorrect (what do you want to make it do?), take a look at http://icculus.org/~theoddone33/lua/ for a tutorial on it.
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
[Updated on: Fri, 01 July 2011 13:59] Report message to a moderator
|
|
|
Re: Another Lua question [message #449324 is a reply to message #449319] |
Fri, 01 July 2011 14:41 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
![](http://renegadeforums.com/images/custom_avatars/25625.png) |
sla.ro(master)
Messages: 610 Registered: September 2010 Location: Romania
Karma: 0
|
Colonel |
|
|
here is the fixed code, i saw some missing 'end'
function OnObjectCreate(o) --whenever an object is created
if Is_A_Star(o) then --check if they're a real player
Attach_Script_Once(o, "myscript", "")
-- attach myscript to them if they are players
end
end
myscript = {}
function myscript:Killed(ID, obj, killer)
-- called if someone get killed by someone else, not called if killed by null objects, like dying from falling.
print("Killed", ID, obj, killer)
end
Register_Script("myscript", "", myscript) --register script
this should work
Creator of Mutant Co-Op
Developer of LuaTT
|
|
|
|
|
Re: Another Lua question [message #449336 is a reply to message #449326] |
Fri, 01 July 2011 19:50 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
hego64
Messages: 19 Registered: April 2011 Location: Hegoville
Karma: 0
|
Recruit |
|
|
Ok, I'm going to sound dumb for this, but...How can I edit this for like my previous post about the spectate stuff?
function myscript:Killed(ID, obj, killer)
print("Killed", ID, obj, killer)
end
I mean, I can do normal stuff in lua like weps and vehs and stuff, but I'm no hand at functions that I don't know.
Thanks for all your help y'all
-Hego64
Edit: I tried the whole thing that you guys had given me unedited in the server, and I got an error in the FDS on line 176.
(prolly a dumb idea to try it without anything added, but I had just wanted to fiddle with it for a bit)
Line 176: Register_Script("myscript", "", myscript) --register script
The error said that it couldn't have more than one script named the same thing.
[Updated on: Fri, 01 July 2011 19:55] Report message to a moderator
|
|
|
Re: Another Lua question [message #449340 is a reply to message #449318] |
Sat, 02 July 2011 05:30 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) |
![](http://renegadeforums.com/images/avatars/Mutant1_Halo38.jpg) |
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
If it says you can't have 2 scripts named the same, it means you probably have another script named 'myscript'.
Try renaming your script. Using something that describes the scripts action in 1 (or a few ) word(s) would be a good idea.
[Updated on: Sat, 02 July 2011 05:30] Report message to a moderator
|
|
|