the SERVER scripting thread

Moderator: EUO Moderators

Post Reply
Dennisd
How do I attack?
Posts: 4
Joined: Fri Jun 16, 2006 2:00 pm

Post by Dennisd »

Some nice stuff egg!

Here is another intro link I found. Very neat stuff

http://www.devmaster.net/articles/lua/lua1.php

EDIT:

I spent most of the day reading up on Lua, compiling it on Visual C++ Express 2005 and playing around with some sample code. Very brillant stuff here egg! Spent a good deal reading what you have posted here in this thread.
User avatar
ChickMagnet
LAUGHING OUT LOUD LIKE A MORON
Posts: 53
Joined: Wed Dec 21, 2005 9:35 am

Post by ChickMagnet »

egg is raising the average IQ of society
I'm Veris btw -_-
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Some examples for "advanced" m.code scripts:

The full m.code is 0x0000000
The syntax is 0xERGBMOB
E = Edge glow
R = Red
G = Green
B = Blue
MOB = monster code

Random dyed and glowing mob script: [changed codes to hex values to make more readable -egg]

Code: Select all

function dye(m)
     e = math.random(0,15) * 0x1000000 -- edge glow
     r = math.random(0,15) * 0x100000 -- red
     g = math.random(0,15) * 0x10000 -- green
     b = math.random(0,15) * 0x1000 -- blue
     m.code = m.code + e + r + g + b
end
(thanks to Hellslave for this one, though his initial idea did not wrong and it took me hours to get it right ;) )

Changing the sprites of a spawner using a table to randomly pick them.
[quote]
function table(m)
c = {0x258, 0x384} -- defines table and can be expanded
m.code = c[math.random(1,2)] -- randomly picks the first or second m.code from the table. The second number's value equals the numbers of m.codes in the table.
end
[/quote]
I'll address this in a separate post below -egg


/!\ Changing the m.code of a spawner spawned monster with a script will mess up its spawner. Meaning that around 6 mobs will be spawned instead of the number defined by the spawner unless the area of the spawner is set to -1.

This is because the spanwer literally counts the mobs around it with the spanwers code. If a rat spawner counts 2 rats and it wants 3, it will spawn 1 rat. If the rat is turned into a goblin immediately after is is spawned, then the spawner will always want one more rat. -egg
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

Re: the scripting thread

Post by eggmceye »

LordMortiferus wrote:

Code: Select all

function table(m)
     c = {0x258, 0x384} -- defines table and can be expanded
     m.code = c[math.random(1,2)] -- randomly picks the first or second m.code from the table. The second number's value equals the numbers of m.codes in the table.
end
my problems with this - some of it is really nitpipcky but don't forget I'nm a pro programmer with like 30yrs xp :p
i) func name is too generic - also table, tho not a reserved word in lua, might as well be. Unless I knew what you were doing I'd have no idea what this was about
ii) I already wrote a func for selecting a random element from an array - it's in funcs.lua XD

in funcs.lua

Code: Select all

function get_random_element(a)

 return a[math.random(1,#a)]
 
end
in your code

Code: Select all

 ca = {0x258, 0x384, 0x211, 0x200} -- array of potential mobs, var name ca for code array
 c=get_random_element(ca) -- pulls one of the array at random
Aerie
Here for the lesbians.
Posts: 498
Joined: Sun Jan 02, 2011 7:32 am

Re: the scripting thread

Post by Aerie »

/me wishes /me could understand this. (better, anyway..) :mad:
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

LUA, server API, etc

Post by eggmceye »

EUO LUA is the worst documented API in the world, however here is something to chew on

The actual C++ to LUA interface/API
http://swut.net/files/eao.pkg.cpp

This file has all the server functions that LUA can use. It's undocumented. The only tute for euo+lua is Rusty's guide below. The good news is that it's all pretty easy. The bad news is that there are tons of things that you 'need to know' or learn to make things work. Like doing 'fov updates' or syncs after certain things. Best way to learn is copy & mod existing things. If in doubt, ask me, and if you don't know how to do something, ask, and if you need some server feature function even I can add it in if isn't too hard.

Rusty's LUA scripting guide
http://euotopia.com/manual/index.php/Ru ... g_with_LUA

My original, ancient API doc
viewtopic.php?f=12&t=2657

I might review and update this - it's basically correct still, but may be missing a few things.
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: the scripting thread

Post by mud »

Can I do anything with statues?

For a boss I wanna do a couple things:
  • Have statues of dragons that come to life to start the boss fight. I know how to do all of this except, how do I get the item code for a statue? Ideally I'd like both one facing left and one facing right. This isn't possible in maped too, is it?
  • Make a statue of players temporarily during a fight. Is this possible to do somehow? I don't really need to know how to do the surrounding stuff, just how to get the item code of a statue that matches a player's avatar.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

The code for a statue is a 7 digit hexcode: 0xCBBBAAA
AAA = 545 --- defines this item to be a statue
BBB = mob code
C = number of the frame to be used (normally the sprites of a mob has four frames for animation)
e.g. 0x3350545 would be a statue of a blood golem using the last of its 4 frames - so it would be a golem with raised arms.

I am not sure about flipping an item sprite - afaik it is not part of the item code.
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: the scripting thread

Post by mud »

LordMortiferus wrote:The code for a statue is a 7 digit hexcode: 0xCBBBAAA
AAA = 545 --- defines this item to be a statue
BBB = mob code
C = number of the frame to be used (normally the sprites of a mob has four frames for animation)
e.g. 0x3350545 would be a statue of a blood golem using the last of its 4 frames - so it would be a golem with raised arms.

I am not sure about flipping an item sprite - afaik it is not part of the item code.
Cool, thanks! Very good info.

I'm thinking if I take the low-order 12 bits of a player's 'code' member-variable, to get rid of tinting, and use that as the mob code, that will probably work for making a statue of a player. Hopefully.

Or maybe I'm supposed to call get_draw_code() on the player? Hmmmm.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: LUA, server API, etc

Post by LordMortiferus »

Thanks for the blood and moss overlays.
Please consider to change the type of 5d0 and 5d1 from furniture "f" to something else so they can be used over secret doors and on floor tiles as well.
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

Re: LUA, server API, etc

Post by eggmceye »

yeh I realised that once I copied the file in - changed to type I (which is a nonblocking furniture)
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

Is there any info somewhere about the details of setting up instances?

I took a look at the BM instance and also the mino's heroic portal thing, but one thing I'm not seeing is: how do I do some setup on the "new" map? Like ideally I'd want it to call load_map_256(300) (or whatever the auto-assigned instance map level is instead of 300) when the instance is created, or my own named function or anything like that.

Is that possible? If not I can probably work around it by putting a stp feature right after where the people start on the level or something and hook that up to a function, but that seems kinda ugly.

Or alternatively, is there some function in the LUA API that will let me do manually what those magic instance portals/stairs are doing? Namely: load up a temp map that's a copy of another, but only if one doesn't already exist for the player (and if they're in a party they all share one). I mean I see load_temp_map(...), but that wouldn't do all of that cool logic itself, would it somehow?
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

Re: LUA, server API, etc

Post by eggmceye »

ok so what you want is the instance map to call some startup function? that the noninstance version doesn't call?

I haven't tested it but theoretically, if you make an instance of say map 50 then the parent map 50's loadup func should get called too. Then inside that func you can put code that checks to see if the map is an instance, eg

Code: Select all

function load_map_050(lvl, load_on_the_fly)

  map=get_map_ptr(lvl)

  if map.instance then

   -- extra loading here
  end
  
end
only problem is that .instance, tho exists, is not visible to lua (I can easily add that) then it all needs testing but theoretically easy mod

is this what you wanted?
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

eggmceye wrote:ok so what you want is the instance map to call some startup function? that the noninstance version doesn't call?

I haven't tested it but theoretically, if you make an instance of say map 50 then the parent map 50's loadup func should get called too. Then inside that func you can put code that checks to see if the map is an instance, eg

Code: Select all

function load_map_050(lvl, load_on_the_fly)

  map=get_map_ptr(lvl)

  if map.instance then

   -- extra loading here
  end
  
end
only problem is that .instance, tho exists, is not visible to lua (I can easily add that) then it all needs testing but theoretically easy mod

is this what you wanted?
I think the problem is that it doesn't seem to be calling the load_map_xxx function at all for an instance. So if it's supposed to be doing that either it's bugged or I did something wrong.

What I have is just a portal on map 258 set to val=-256, and the "item" of the portal is set to ffffffff (I just copied the style from the minos heroic portal, not sure if the ffffffff thing actually means anything). I get a line in the server log that's:

Code: Select all

28-10-2012 22:51:49: loading instance old=256 new=300 script=[] owner=[test]
But my load_map_256 function is never called, unless I /tele to the original level 256, and then it's only called with the first parameter set to 256.

Let me know if it'd be helpful if I threw a quick test of that into my dropbox folder or something. I noticed that I could not actually find an instance that currently uses the load_map_xxx functionality at the same time, so it's possible it's just never come up?
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

Re: LUA, server API, etc

Post by eggmceye »

I've added (not live but will paste into dropbox soon) a moasv.exe that has a hook that is called when instance loaded

so instead of load_map_054(lvl, on_the_fly) a func

Code: Select all

function load_instance_054(lvl) 
  ...
end
will be called instead.
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

That sounds perfect. Thanks Max!
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

Hmm, it looks like it's calling load_instance_256(256) instead of load_instance_256(300) like I expected. User error?
User avatar
eggmceye
hello
Posts: 10577
Joined: Mon Mar 11, 2002 3:55 pm
Location: Sydney, Australia
Contact:

Re: LUA, server API, etc

Post by eggmceye »

more like programmer (me) error because you need

Code: Select all

function load_instance_054(actual_level, parent_level)
  ...
end
right?

actually you probably don't really need parent but I'll leave it there - above will the be the api in about 5 mins
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

Yeah, anything like that would be perfect. Thanks Max.
mud
I once posted in TFIOOC!
Posts: 134
Joined: Wed Nov 09, 2005 12:29 pm

Re: LUA, server API, etc

Post by mud »

Sorry to be a pain in the ass, but the version you put in Dropbox after we chatted in game still seems to be calling load_instance_300(300, 256) instead of load_instance_256(300, 256).
Post Reply