the SERVER scripting thread

Moderator: EUO Moderators

Post Reply
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Updated the copy&paste script for Maped. You can now copy&paste tiles, items, spawner and other features. Chedich helped me out with features and items.
Note: if you copy features you likely have to change the value as well as the x,y destinations manually after pasting them. Furthermore, the script is still not user-friendly - so feel free to contact me via pm if you need help.
Celerion
LAUGHING OUT LOUD LIKE A MORON
Posts: 64
Joined: Sat Dec 15, 2012 6:29 am

Re: LUA, server API, etc

Post by Celerion »

mud wrote:Is there a way to import LUA modules into the environment used by auxbox? I was going to do some networking type stuff if possible. I tried just installing Lua in windows and "require" the modules I wanted in an auxbox script, but it didn't seem to work no matter what I did. I also tried dofile and such.
It's only a work-around, but it should be possible to just paste all the code of the Lua modules, you would require, into the main-script (you don't need the "require ..."-line then, of course).
If the module itself depends on other modules, you'll have to paste their code too though.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Updated the copy&paste script for maped. Items are now set as furniture.
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 »

gunna be using this script for apocalyptic map instances ... mino halls will be the first ... haven't considered spawners yet though
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

I last posted in this thread in 2006 which is a fairly fucking epic self-necro :P (I'm sure it wasn't 2006. More like 2010!!)


However: Couldn't find / see / am lazy / Call out to hotshots (since there's obviously people in here who can code well).

REQUEST:

Example of trigger that calls a spawner using msg. e.g. Step on tile, msg is displayed, spawner launches monsters - however, must have timer attached. i.e. Step on msg, spawn, then <time=X> before it can be triggered again.

In game action: player steps on tile; monsters exploding in radius X surrounding them! (boo!)

REQUEST:

I know this exists, since I once had a copy of MapEd with scripts attached, but the simple <a> switch = effect script. However, must be able to call a created item. i.e. one of those hybrids created using gold piece + hex edit. Must also be able to spawn <feature> linked tile.

In game action: player <a> on switch, wall turns into statue. Or statue turns into monster. Or (note: this would be great) a lxy teleport is activated (!!!)



These might not be possible, but more coding based brilliance than mine, halp :)
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Here is a simple step-script that spawns a goblin near the stp-fea. Additionally a dragon egg is spawned at 0'0" with a heartbeat func as timer. When the time is up the egg dies and the stp can be triggered again.

Code: Select all

function cat_stp_spawn(id,x,y,z)
	-- spawn mob(s) around stp-fea
	for i = 1,4 do
		m = spawn_at(0x200, x, y, z, false)
		simple_send_event(m.id,EVENT_MAGIC,0x25,m.x,m.y)
	end
	local_msg(m, "It is a goblin!")
	
	
	-- spawn timer (should be placed at unreachable position of the map)
	m = spawn_at(0x364, 0, 0, z, false)
	
	
	-- save x,y coords to timer
	m:set_dmg_dice(x)
	m:set_dmg_sides(y) 
	
	-- set timer
	m.timer = 10
	m.heartbeat_func="cat_timer"	
	
	-- deactivate stp-fea
	map=get_map_ptr(z)
	map:set_feat_val(x, y, 0)
end

function cat_timer(m)
	-- timer
	m.timer = m.timer - 1
	if m.timer <= 0 then
		
		-- retrieve x,y coords for stp-fea 
		local x = m:get_dmg_dice()
		local y = m:get_dmg_sides()
		
		-- reactivate timer
		map=get_map_ptr(m.map_level)
		map:set_feat_val(x, y, 1)
		
		-- kill off timer
		hurt(m.id,m.hp+1,"time is up")
	end
end
Last edited by LordMortiferus on Sat Aug 09, 2014 6:18 pm, edited 2 times in total.
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

LordMortiferus wrote: function cat_stp_spawn(id,x,y,z) Do these variables need values?
m = spawn_at(0x200, x, y, z, false) X,Y is obvious, is the Z a level code? e.g. 34,75, >269<? What is the true/false variable?
simple_send_event(m.id,EVENT_MAGIC,0x17,m.x,m.y) Do the X, Y co-ords here have to match up? Also, is there a list of EVENT_ types? Can we color them etc? e.g. is it possible to have say, a lightning bolt spring from a maptile to another maptile?

m = spawn_at(0x364, 0, 0, z, false) Same question about z variable here


m:set_dmg_dice(x) Do these variables matter? The mob is not designed to interact with anything. i.e. 1, 1?
m:set_dmg_sides(y)


m.timer = 10 Is this seconds or minutes?


map=get_map_ptr(z) Z = map #?
map:set_feat_val(x, y, 0) More X,Y co-ords! since they're not using m.call, I take it these have to be manually changed?
end

map=get_map_ptr(m.map_level) This is calling the initial spawn - so that should have a map # in it
map:set_feat_val(x, y, 1)

That's fantastic, thank you! Using 3rd party non-accessible stuff for triggers has a long history (AO had invisible leets, I've used it elsewhere), didn't think that you could use LUA for it.

This will allow for Indiana style count-downs on events. i.e. Step on plate, trigger a count-down until X happens. In the above case, the spawner is triggered immediately. If you want to use a delay + reset, I presume there's a timer delay that can effect the initial trigger? i.e. The first (event) trigger can have a delay? And the count-down reset would be separate.

One last question - does the engine care if you spawn multiple dragon eggs on top of each other? Or should they each have a unique tile placement? (in case of multiple triggers if there's say a party of people spread out over a map)
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Here is a code snippet that kills off all enemies around you in a fearsome explosion when stepping on a stp-fea:

Code: Select all

function cat_stp_desintegrator(id,x,y,z)
	p = get_sent_ptr(id)
	local sx=x-4
	local ex=x+4
	local sy=y-4
	local ey=y+4
	for yy=sy,ey do
		for xx=sx,ex do
          	ptr=map:get_mon_ptr(xx,yy)
			if ptr~=nil and ptr:get_align()~=p:get_align() then
				send_event(m.map_level,-1,ptr.x,ptr.y,26,0) 
				hurt(ptr.id,ptr.hp+1,"Boooom")
			end
		end
	end
end
1) Paintbrush is for mtiles only atm afaik - guess egg could make a second paintbrush for items only.
2) The misbehaving undertiles are due to recent changes how undertiles work with certain mtiles like paths. The downloadable version of Maped needs to be updated - best bug egg about it ;)

# function cat_stp_spawn(id,x,y,z)
when you step on a stp-fea that has a function attached to it your id and the coords of the stp-fea are assigned to id, x, y, z respectively. This means x,y,z in this function are the coords of the stp-fea.

# m = spawn_at(0x200, x, y, z, false)
0x200 is a goblin
x,y,z are the coords with z being the level number
false just means that a field of vision update is not triggered when the mob is spawned (I guess)

# simple_send_event(m.id,EVENT_MAGIC,0x17,m.x,m.y)
I added this line to have a visiual indication when a mob is spawn (spell 0x17 KVX summon dragon - just the red box lights up around the mob but no dragon is summond)
m.x, m.y are the coords of the spawned monster but could be anything
dunno what you mean by color them
sending lightning from point a to point b is possible using:

Code: Select all

void  send_event(int lev, int id, int x, int y, int typ, int subtype, int tx=-1, int ty=-1);
# m:set_dmg_dice(x) m:set_dmg_sides(y)
I had to somehow pass the x,y coords of the stp-fea over to monster function. This is needed so the monster knows where the stp-fea is and can manipulate it.

# m.timer
this is just a number. Within the heartbeat script of the mob (function cat_timer(m)) this number is counted down every second by the value of 1 (m.timer = m.timer - 1)

# map=get_map_ptr(m.map_level)
to change features you need to have the pointer (map) of the respective level, in this case it is the level the mob is (m.map_level). In the initial stp-fea function I used z instead of m.map_level. (note again z was assigned a value by and within the function cat_stp_spawn(id,x,y,z))

I hope I was able to explain stuff without writing down too much bs.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Catherine wrote: This will allow for Indiana style count-downs on events. i.e. Step on plate, trigger a count-down until X happens. In the above case, the spawner is triggered immediately. If you want to use a delay + reset, I presume there's a timer delay that can effect the initial trigger? i.e. The first (event) trigger can have a delay? And the count-down reset would be separate.

One last question - does the engine care if you spawn multiple dragon eggs on top of each other? Or should they each have a unique tile placement? (in case of multiple triggers if there's say a party of people spread out over a map)
1# If I understand you correctly your plan is that stepping on a stp-fea does not immediately spawn a mob but with a delay. This is possible by using the dragon egg timer which is immediately spawned. Instead of the mob being spawned by the stp-function it can be spawned by this timer after a given time.

2# The dragon egg will be spawned on a free tile near the given coords if those are occupied, but it would be best if you give any timer unique coordinates.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

the yellow tile calls cat_stp_spawn and the red calls cat_desintegrator
Image
excuse the lousy gif quality
also have edited the cat_stp_spawn function in the previous post - now it spawns 4 goblins with an ijo spell effect instead of the kqx or whatever it was.
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

# m = spawn_at(0x200, x, y, z, false)

Egg's example used:

Code: Select all

spawn_at(0x21d,3,3,z)
      spawn_at(0x21d,11,3,z)
      spawn_at(0x21d,3,11,z)
      spawn_at(0x21d,11,11,z)
This spawns a single goblin or single mobs at specific areas. Not what I was after - how do you set it as a spawner with a radius / multiple #s? Ideally, the # would be randomized as well. e.g. 4-10 spawn radius 4 centered on the stp trigger. Or is

Code: Select all

for i = 1,4 do
a radius?

Also, why I asked for an EVENT_ list is that instead of the summoning bling, I'd like an earthquake. EVENT_"ivpy"? Just giving me the example "void" doesn't really help if I don't have the list of variables. :/


Also, is it possible to have two scripts attached to mobs? e.g. Stp spawner that can be modified by global heroic / epic versions? What about mobs that already have coded behaviours? (e.g. slimes, corpsers, gazers etc). Specifically - are mobs spawned by trigger events modded by global scripts? A bit useless if the heroic / epic versions spit out bog standard versions ;)


p.s.

Current map is 25% done, the paintbrush tool is just epically easy (with manual fine tuning for visual goodness).

Code: Select all

function corpserambush_spawn(id,x,y,z)
   for i = 1,4 do
      m = spawn_at(0x265, x, y, z, false)
      simple_send_event(m.id,EVENT_IVPY,0x25,m.x,m.y)
	  void make_paralyzed(int id, int 10)
   end
   local_msg(m, "You hear a rumble and corpsers burst from the ground, throwing you to your knees!")
  
   m = spawn_at(0x364, 0, 0, z, false)
   m:set_dmg_dice(x)
   m:set_dmg_sides(y)
   m.timer = 30
   m.heartbeat_func="corpser_timer"   
   map=get_map_ptr(z)
   map:set_feat_val(x, y, 0)
end

function corpser_timer(m)
   -- timer
   m.timer = m.timer - 1
   if m.timer <= 0 then
      local x = m:get_dmg_dice()
      local y = m:get_dmg_sides()
      map=get_map_ptr(m.map_level)
      map:set_feat_val(x, y, 1)
      hurt(m.id,9999,"time is up")
   end
end
In the above, I'm aiming to set a direct ambush but don't know how to set the # or radius of the corpsers, don't know the IVPY shake effect - also, not sure about the player void ID? presume t = time, in seconds?

I'd also prefer a version so that the local msg is sent, there are two timers - one counts down 5 seconds before they burst, the other handles the reset.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Catherine wrote:This spawns a single goblin or single mobs at specific areas. Not what I was after - how do you set it as a spawner with a radius / multiple #s? Ideally, the # would be randomized as well. e.g. 4-10 spawn radius 4 centered on the stp trigger. Or is for i = 1,4 do a radius?
The for i = 1,4 do is a loop, means whatever is inside the loop is called, in this case, four times, hence four goblins are spawned. If you want a random number of mobs to be spawned than you could do something like this:

Code: Select all

	for i = 1,math.random(4) do
		m = spawn_at(0x200, x, y, z, false)
		simple_send_event(m.id,EVENT_MAGIC,0x25,m.x,m.y)
	end
math.random(4) will generate a random number between 1 and 4 in this case.
As to the spawn radius, you could set x,y manually for each spawn or again use math.random, e.g.:

Code: Select all

spawn_at(0x200, x+math.random(-5,5), y+math.random(-5,5), z, false)
Why did I wrote m = before spawn_at and egg did not in his example. The m is a pointer for the spawned mob and is need if you want to manipulate it (change stats) or like I did want to sent an event magic effect.
Catherine wrote:Also, why I asked for an EVENT_ list is that instead of the summoning bling, I'd like an earthquake. EVENT_"ivpy"? Just giving me the example "void" doesn't really help if I don't have the list of variables. :/
Void just means that you cannot extract information from said function, unlike int, boolean or string. To call an ivpy effect I used the following code:

Code: Select all

p=get_player_ptr(id)
send_event(p.map_level,p.id,p.x,p.y,EVENT_QUAKE1, 0 , p.x, p.y)
Instead of a mob calling that event it is the player who steps onto the stp-fea (I would use this approach as it does not matter effect wise if one (player) or more id's (mobs) call the ivpy event as ivpy blends over each other - but it would probably be easier on the performance).
Gonna try to answer the rest later - baby is crying...

Code: Select all

enum event_nums {

   EVENT_STEP=0, 
   EVENT_MAGIC, 
   EVENT_HIT, 
   EVENT_MISS, 
   EVENT_QUAKE1, 
   EVENT_QUAKE2, 
   EVENT_MISSLE, 
   EVENT_TRAP,
   EVENT_GUN,
   EVENT_LASER,
   EVENT_HIT2, 
   EVENT_WHIT, 
   EVENT_TELE,
   EVENT_TELEFRAG,
   EVENT_FDEATH,
   EVENT_MDEATH,
   EVENT_WDEATH,
   EVENT_BLOCKED,
   EVENT_PARRIED,
   EVENT_RIPOSTE,
   EVENT_PORTAL_UP,
   EVENT_PORTAL_DOWN,
   EVENT_STEAL,
   EVENT_SHOOT, // not gun!
   EVENT_THUNDERCLAP,
   EVENT_CRITICAL,
};
Catherine wrote:Also, is it possible to have two scripts attached to mobs? e.g. Stp spawner that can be modified by global heroic / epic versions? What about mobs that already have coded behaviours? (e.g. slimes, corpsers, gazers etc). Specifically - are mobs spawned by trigger events modded by global scripts? A bit useless if the heroic / epic versions spit out bog standard versions ;)
Mobs spawned by scripts are not affected by the heroic/epic scale script. However, you can use a trick to determine if you are in a heroic or epic instance respectively. Lets say you add a mapspawner via maped to your level at the coords 1'1" and let it be a again a dragon egg. Under normal instances this egg has hp = 1000. Within an instance it would be 3000 and 5000 respectively. If it is a boss the hp would be multiplied by 2 and if it is an unusual large boss it would be further multiplied by 3.

Code: Select all

-- coords of dragon egg - ms will be the pointer to the dragon egg
ms = get_mon_ptr(1, 1) 
-- get HP multiplier
local c = ms:get_hp_max() / 1000 
-- rectify hp multiplier if the egg is a boss (I doubt that can happen but you never know)
if ms.boss == true then 
	c = c / 2 
	--rectify hp multiplier further if the boss egg is large
	if ms.large == true then
		c = c / 3 
	end
end
-- calls a function to scale a creature. m is the pointer to the mob that is to be scaled, c is the multiplier, 0 would be the loot quality multiplier
scaleCreature(m, c, 0) 
As to the function you wrote:
For ivpy see above.
void make_paralyzed(int id, int 10) as said before void only indicates that the function make_paralyzed does not return any value. "int id" would be the player number you want to paralyze and the last "int" argument would probably be the time (never used this function to paralyse a player myself)
How I would do it:

Code: Select all

p=get_player_ptr(id)
set_health(p.id,HN_HELD,4)
The first line we only need if p was not defined earlier. The second line sets the player who stepped on the stp-fea to HELD for 4 seconds.

Note: to write scripts I recommend the use of notepad++ - when you save your file with the *.lua extension the program will recognize it as code and add color to it for better readability.
Note: did a slight change in the hurt() line in my above posted cat_timer function.
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

Woot! Thanks, looks like we can do what I intend (especially that egg hack to normalize for heroic etc, great stuff!). I think a sensible idea is I finish off x2 100x100's*, stuff them with scripts and use them as a testing base for all of this. That way we can progress quicker (less checking), have them in-game for people to tinker with and have a basis for a larger project.

One tiny, and one stupid question - how do I tint items? Not the maptile versions, but just normal items. e.g. moss is 5d1. However much I try, I cannot add a simple black tint to it (to change it from moss to soot). The triple hex code for black is 000, so I imagined it would have been easy. 0x0005d1 nor 0x5d1000 works :?


Ok, been doing my reading - can you attach scripts to items?

Code: Select all

function es_soot(m)

m:set=0x00005d1

end
Can this also be used to create split items? e.g.

Code: Select all

function es_floatingcrystal(m)

m:set=0x441c51e

end
I'm hoping that'd make a brazier base with a floating crystal on top, but can't check.




Stupid question - Quest NPCs. I've already worked out how to set a named, friendly patrolling NPC - but how to add the conversation trees? e.g. JOB > "I am a farmer". etc.


*One is complete already, with back-story, NPCs, theme etc all planned. Difficulty is ~roughly 10% harder than mino halls, but it's less of a hunting map atm than an interactive experience.

Code: Select all

function lvl001reset(id, px, py, z)

   for x=6,8 do
      for y=4,10 do
         set_and_send_new_tile(x,y,z,95) -- 95 is the red tile
      end
   end
   reset_trigger(7,3,z,1)

end

function lvl001wrong(id, x, y, z)

   -- reset all tiles
   -- lvl001reset(id,x,y,z)
   
   -- send plyr back to start
   send_player_to_xy(id,7,12,true) -- don't check trigs (may cause loop)
end

function lvl001green(id, x, y, z)

   set_and_send_new_tile(x,y,z,222) -- 222 is the green tile
end

function lvl001final(id, x, y, z)

   lvl001green(id,x,y,z)
   reset_trigger(7,3,z,0) -- disables the barrier
   
end
In Egg's original puzzle, I never understood how this knew what was a green and red tile, or the x,y locations of them. It seemed to be missing something? Also, the step function is the reset, could we make it timed?

Added to this, is there a way to set a function so that say, pulling a lever -> a friendly spawner becoming hostile? I know about mkevil, but I'm guessing the mob would have to be wiped then replaced with an evil equivalent? Obviously, there'd have to be a reset so the friendly mob eventually respawned.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Basics of tinting:
# If an avatar or an item has grey areas chances are these grey parts can be tinted. Everything not grey is not affected by tinting, e.g. moss. Still some grey areas may not tint cause the grey is not pure grey as values for RGB are not equal (see RGB colour space).

# There is a difference between avatar and item tinting. Avatars can be colored with any color avaiable in the triple hexcode color space. Note, while the triple hexcode for black is 0x000 this does not tint an avatar black. E.g. 0x000200 equals 0x200, so the digits that define tinting remain blank. The closets to black would be 0x100200.
Items do tint as a change of material (see ..\euo\dat\materials.txt). E.g. blackrock will return a blackish item, vamp a reddish item. It does not matter if you convert a mob avatar into an item - the tinting mechanic stay different. E.g. 0x134 is a skull, 0x7134 is a gold skull, 0xf134 is a crystal skull.

# Tinted avatars and items can be placed by Maped and should show their respective color change. Add item/avatar and left click again to change its code.

Splitavtars:
# Technically you can use an item as the head of a mob, but the feet need to be a mob sprite in any case. (there may be issues with drawing the item sprite, but I think it works atm without issues). A brazier base with a crystal on top should not work, unless egg adds a brazier mob to the mob list...

Convos:
# no real clue, other than the stuff I did post over in the Maped thread. Maybe I have some time next week to tinker with this.

Your script:
# have to go over it when I have a bit more time at hand.

Make Evil:
# no problem, though I cannot find a mkevil() function in the LUA API. Nevertheless, you can use m:set_align(ALIGN_EVIL) to make the mob evil after setting m = get_mon_ptr(x,y) with x,y being the coords of the NPC.
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

LordMortiferus wrote:Basics of tinting:
# If an avatar or an item has grey areas chances are these grey parts can be tinted. Everything not grey is not affected by tinting, e.g. moss. Still some grey areas may not tint cause the grey is not pure grey as values for RGB are not equal (see RGB colour space).

Ok, that's a shame. While I understand why the various sprites in MapEd have unique codes, there seems to be room to have a set of grey-scaled ones such as 5ca,5f2-4 for the common items such as gems, splats (147, 528 etc) and splashes (5d0,5d1).

File under: wishlist.

Related to this, a tiny nit-pick - the two free-floating 'flows' (5d2, 5d3) are slightly off-centre to the base tiles (26,27) - you can tell this by using the maptile, then placing one as an item on top of it.
User avatar
Catherine
English correct bastard.
Posts: 1254
Joined: Mon Sep 08, 2003 2:40 am

Re: the scripting thread

Post by Catherine »

Ok - is it possible to use the timer code to ensure that map alterations are reset after X time?

e.g.

Code: Select all

	-- spawn timer (should be placed at unreachable position of the map)
	m = spawn_at(0x364, 0, 0, z, false)	
	-- save x,y coords to timer
	m:set_dmg_dice(x)
	m:set_dmg_sides(y) 
	-- set timer
	m.timer = 10
	m.heartbeat_func="cat_timer"	
	-- deactivate stp-fea
	map=get_map_ptr(z)
	map:set_feat_val(x, y, 0)
end

function cat_timer(m)
	-- timer
	m.timer = m.timer - 1
	if m.timer <= 0 then

	-- retrieve x,y coords for stp-fea 
		local x = m:get_dmg_dice()
		local y = m:get_dmg_sides()	
		-- reactivate timer
		map=get_map_ptr(m.map_level)
		map:set_feat_val(x, y, 1)	
		-- kill off timer
		hurt(m.id,m.hp+1,"time is up")
	end
end
By inserting:

Code: Select all

 for x=6,8 do
      for y=4,10 do
         set_and_send_new_tile(x,y,z,95) -- 95 is the red tile
      end
 
The basic idea is to have a step trigger that changes a load of scenery that resets after time X, whatever the player's actions. e.g. Step -> tiles change -> timer is set -> timer ends, tiles reset automatically. I also know that a version of this exists in-game, in the Jungle map (has two walls crashing together).

Also - please, Egg, could you post some active examples. i.e.

1) The Jungle squish one - since this includes a timer as well as tile changes & a reset.
2) Any simple "Use lever > removes barrier". I'm being dumb but I cannot find a single example of this, barring: Found the <swi> feature. Derp. New question: can <swi> effect different levels? Is it possible to have a <swi> change something on a different map?

3) Dialogue - m.talk_line="Hello stranger!"; << This is obviously what the NPC says after you do a <t>alk. Is there a m.talk_line("job")="I'm a lumberjack"? e.g. How to trigger these. Do they even go in the LUA section? How do you do NPC dialogues? Edit: found a discussion by Lord that states it's out of LUA's control - manually writing them atm.

5) Use trigger - summon a portal that has a lxy attached. No idea how to do this. Or have any <a> switch --> tile change + <function>. e.g. Pull switch --> portal appears that can warp you elsewhere. I suspect this will require a script, like the brazier / sea monster puzzle.


[Edit: found the <swi> feature. I am dumb. Some stuff still needs work though]


TL;DR

I can't LUA.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Yeah you can change maptiles using the stp-script. There are at least two possible ways to do it. Either by using for-iterations as you have posted.
Alternatively, you could create an array of the the submap you want to past over the section of your map, e.g. cat_submap = {222,210,223,123} - you can paste the maptiles within this array using

Code: Select all

paste_sub_map (data,lvl,hx,hy,hw,hh,mask)
data = cat_submap
lvl = maplevel
hx = x-coord
hy = y-coord
hw = width of the submap, e.g. 2 tiles -> first row would be 222, 210
hh = height of the submap, e.g. 2 tiles -> second row would be 223, 123
mask = is a maptile that will not be exchanged, e.g. mask = 156 means that if the region of your map contains a maptile = 156 this will not be changed by the script.

Here is the complete function that is called by paste_sub_map (taken from mapfuncs.lua):

Code: Select all

function paste_sub_map (data,lvl,hx,hy,hw,hh,mask) 

	map=get_map_ptr(lvl)
	
	for x=0,hw-1 do
		for y=0,hh-1 do
		
			idx=y*hw+x+1
			t=data[idx]
			if t~=nil and t~=mask then
				map:set_tile(x+hx,y+hy,t)
			end
		end
	end
end
When you change maptiles in the line of sight of a player you probably have to call "update_everyones_fov(p)" -- p being the player who stepped onto the stp-fea in this case.

as for you other questions:
1) there is no timer involved with the squish trap.
2) not sure, especially if the map has not been loaded before
3) what I meant is that scripting convos with LUA is beyond my scope of experience, but I am sure you can use LUA to script convos with the functions from the API I posted elsewhere.
5) the following function will create a portal at x,y that teleports you to desx,desy on deslevel

Code: Select all

map:add_feat(x,y,TRIG_PORTAL,desx,desy,deslevel,Item(-1))
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 »

using morty's maped cut/paste hack I have made a merged version of the Mage Tower ...
lvl259small.png
You do not have the required permissions to view the files attached to this post.
User avatar
LordMortiferus
MACRO > me
Posts: 872
Joined: Tue Dec 01, 2009 10:23 pm

Re: the scripting thread

Post by LordMortiferus »

Here is the instruction for the copy&paste script add-on for Maped.

How to install:
1) Within your EUO folder create a subfolder called scripts.maps:
..\EUO\scripts.maps\
2) Either download the lua file directly from my dropbox or paste the script into an empty text file and save it with the *.lua extension. Eitherway the this lua script file goes into ..\EUO\scripts.maps\

What part of the script is of any importance to you:

Code: Select all

function load_map_666(lvl, load_on_the_fly) -- change map number if needed
Change the 666 into the maplevel number you want to copy or paste from, e.g. 001, 032, 260 (note it has to be a three digit number).
[code]   local func = "copy" -- copy or paste
   local xy_start = {0,0} -- {x,y} -- needs to be set for copy or paste
   local xy_end = {30,30} -- {x,y} -- only essential for copy
func = "copy" -- inbetween the quotes you either write copy or paste depending on what you want to do.
xy_start = {x,y} -- this defines the starting point (upper left corner) of the area you want to copy from or paste over something.
xy_end = {x,y} -- if you copy this defines the end point (lower right corner) of the area you want to copy.

Code: Select all

   local cp_tiles = true -- set to false if you do not want to copy&paste tiles
   local cp_items = true -- set to false if you do not want to copy&paste items
   local cp_feat = true -- set to false if you do not want to copy&paste features
   local cp_spawner = true -- set to false if you do not want to copy&paste spawners
Depending on what you want to copy or paste you can set cp_tiles, cp_items, cp_feat and cp_spawner to either true or false. If set to true it will be copy&pasted and if set to false it won't copy nor paste. Note: pasting spawner, items or features will result in overwriting the existing data instead of merging them.

How to copy:
1) open the script with an editor
2) enter the level number you want to copy from at "function load_map_xxx"
3) set func = "copy"
4) set xy_start and xy_end to the appropriate coordinates. Setting xy_end to "xy_end = {300,300} will copy the whole map (thanks max)
5) define what you type of data you want to copy (tiles, items, features, spawner)
6) save the script
7a) start Maped and open the map level you want to copy
7b) if Maped was already running go to the map level you want to copy and reload the map and scripts with "ctrl+r"
8) your euo folder should now contain a file called chunk_size.lua and depending on what you wanted to copy: tile_cache.lua, item_cache.lua, feat_cache.lua and/or spawner_cache.lua
9) done copying

How to paste:
2) enter the level number you want to paste to at "function load_map_xxx"
3) set func = "paste"
4) set xy_start to the appropriate coordinates you want to paste to (upper left corner of the area) - make sure you map is large enough for the chunk.
5) again define the data you want to paste by setting cp_tiles etc. to either false or true.
6) save the script
7) likely Maped is still running, go to the map level you want to paste into and reload the script by "ctrl+r"
8) The chunk should now be pasted into you map, make sure everything looks fine and save using "w" or by quit&save "q"

How to deactivate the script:
1) if you are done pasting change back func to func = "copy" to prevent accidental pasting!
2) also I recommend setting "function load_map_xxx" to some unused map level.
3) you may want to delete chunk_size.lua, tile_cache.lua, item_cache.lua, feat_cache.lua and spawner_cache.lua in your ..\euo\ folder

Protip: The cache files can be used to create sub map arrays for LUA scripts.
User avatar
Keighn
Stop posting already --;
Posts: 5509
Joined: Sat Jun 26, 2004 10:13 am
Location: Hey.... pssttt Back in Orgeon

Re: the scripting thread

Post by Keighn »

eggmceye wrote:using morty's maped cut/paste hack I have made a merged version of the Mage Tower ...
lvl259small.png
Is there still a limited map size or does this functional script bypass that?
ZUPS!!!!
Post Reply