Page 6 of 11

Re: Useful scripts repository

Posted: Sun Sep 30, 2012 2:04 am
by Neikun
Wall hooks as an alcove that only hold items that can fit on it

Code: Select all

    defineObject{
       name = "wall_hook_alcove",
       class = "Alcove",
      anchorPos = vec(0, 1.50, -0.1),
       targetPos = vec(0, 1.50, -0.1),
       targetSize = vec(0.6, 0.5, 0.6),
       model = "assets/models/env/metal_hooks_wall.fbx",
       onInsertItem = function(self, item)
          return item.name == "long_sword" and self:getItemCount() == 0
    or item.name == "shaman_staff" and self:getItemCount() == 0
    or item.name == "nex_sword" and self:getItemCount() == 0
    or item.name == "dismantler" and self:getItemCount() == 0
    or item.name == "lightning_blade" and self:getItemCount() == 0
    or item.name == "lightning_blade_empty" and self:getItemCount() == 0
    or item.name == "legionary_spear" and self:getItemCount() == 0
    or item.name == "fire_blade" and self:getItemCount() == 0
    or item.name == "fire_blade_empty" and self:getItemCount() == 0
       end,
       placement = "wall",
       replacesWall = false,
       editorIcon = 92,
    }
Other examples of custom alcoves here:
viewtopic.php?f=14&t=3411
-more creative alcoves here: viewtopic.php?f=14&t=3411

Re: Useful scripts repository

Posted: Mon Oct 01, 2012 3:56 am
by Lark
Exploding Barrel Block
Using the technique described earlier by Montis (thank you Montis), I created the exploding barrels I wanted. When they "die", they cause damage in all squares surrounding them and can even cause a chain reaction! I'm starting to learn a little!

Code: Select all

cloneObject{
   name = "exploding_barrel_block",
   baseObject = "barrel_crate_block",
   onDie = function(self)
      for i = -1, 1 do
        for j = -1, 1 do
          spawn("fireburst", self.level, self.x + i, self.y + j, 0)
        end
      end
   end
}
The above code was updated as per Petri's comment below. I did say I was learning a little and now I've learned more! Thank you Petri! -Lark

Re: Useful scripts repository

Posted: Mon Oct 01, 2012 8:09 am
by petri
No need to spawn a spawner to spawn the fireburst. You could just spawn("fireburst", ...)

Re: Useful scripts repository

Posted: Mon Oct 01, 2012 1:08 pm
by cromcrom
Get the Distance between two objects. (obj1 and obj2), in squares.

Code: Select all

function getDistance(obj1,obj2)
local distance = 0
local XNumber = math.max(obj1.x,obj2.x) - math.min(obj1.x,obj2.x)
local YNumber = math.max(obj1.y,obj2.y) - math.min(obj1.y,obj2.y)
distance = XNumber + YNumber
return distance
end

Re: Useful scripts repository

Posted: Fri Oct 05, 2012 4:06 pm
by Komag
Make a pit sequence puzzle
(such as the chamber of pits on level 5 of the original game)

- set up a room with nine or more pits with trapdoors
- on each side of the room make a button and a lever (name them, such as pitpuzbutton1, pitpuzlever1, etc)
- name all the pits in a logical order, such as pitpuz1 pizput2... through pitpuz15 or whatever
- in this example, we will have the correct "path" have nine steps. You don't have to use all the pits in the room.
- create a timer nearby and give it a name, such as pitpuztimer, set to maybe 1sec or 0.8sec
- create a script lua item near the room, with this code:

Code: Select all

steps = 9 -- CUSTOMIZE: HOW MANY STEPS YOU HAVE
namepart = "pitpuz" -- CUSTOMIZE: PARTIAL ID OF PITS (WITHOUT THE NUMBER)

time = 1
function pitSequence()
  local thetimer = pitpuztimer -- CUSTOMIZE: ID OF THE TIMER
  local sequence = { pitpuz7, pitpuz4, pitpuz1, pitpuz2, pitpuz3, pitpuz6, pitpuz5, pitpuz8, pitpuz9 } -- CUSTOMIZE: IDS OF THE PITS YOU WANT TO CLOSE, IN ORDER
  if levercount == 2 then
    if time < steps + 1 then
      sequence[time]:deactivate() --close a pit in the sequence
    end
    if time > 2 then
      sequence[time-2]:activate() --and then open a pit again two steps behind
    end
    time = time + 1
    if time == steps + 3 then
      time = 1
      thetimer:deactivate()
    end
  elseif levercount == 1 then
    if time > 2 then
      sequence[time-2]:deactivate() --close a pit in the sequence
    end
    if time < steps + 1 then
      sequence[time]:activate() --and then open a pit again two steps behind
    end
    time = time - 1
    if time == 0 then
      time = steps + 2
      thetimer:deactivate()
    end
  end
end

levercount = 2
function leverPull()
  local thetimer = pitpuztimer -- CUSTOMIZE: ID OF THE TIMER
  local thelever1 = pitpuzlever1 -- CUSTOMIZE: ID OF THE FIRST LEVER
  local thelever2 = pitpuzlever2 -- CUSTOMIZE: ID OF THE SECOND LEVER
  if thelever1:getLeverState() == "activated" and
    thelever2:getLeverState() == "activated" then
      levercount = 2
      time = 1
  elseif thelever1:getLeverState() == "deactivated" and
    thelever2:getLeverState() == "deactivated" then
      levercount = 2
      time = 1
  else
    levercount = 1
    time = steps + 2
  end
  for i=1,steps do
    local pit = findEntity(namepart..i)
    if pit then
      pit:activate()
    end
  end
  thetimer:deactivate()
end
now the puzzle should work as intended, where you can toggle the levers to reverse the order, and press the button to trigger the sequence starting

-----
original thread for discussion/questions:
viewtopic.php?f=14&t=3381

Re: Useful scripts repository

Posted: Fri Oct 05, 2012 6:09 pm
by Komag
A corridor where players have to face/step backwards to proceed

example by Blichew
------------------------

Hey,
so one of my tricks is a not-so-long corridor that has to be walked-through backwards, otherwise - well, just copy and paste to check for yourselves.
Backwards might be a wrong word here, what I mean is that player has to turn around and start clicking "S" :P
First the layout:
Image

All hidden pressure plates, first and last runs the tpCleanUp() function
other plates run teleportBack() function.

Now, the code (feel free to modify/change/correct yada-yada :P ):

Note: This has been set to be passable going backwards from W to E.

Code: Select all

tp_index = 1
function teleportBack()
	if party.facing ~= 3 then
		x = party.x
		y = party.y
		l = party.level
		f = party.facing
		if findEntity("tp3_"..tp_index-1) then
			tpCleanUp()
		end
		hudPrint("Huh ?")
		spawn("teleporter",l,x,y,f,"tp3_"..tp_index)
		findEntity("tp3_"..tp_index):setInvisible(false)
		findEntity("tp3_"..tp_index):setHideLight(true)
		findEntity("tp3_"..tp_index):setSilent(true)
		findEntity("tp3_"..tp_index):setScreenFlash(false)
		findEntity("tp3_"..tp_index):setSilent(true)
		findEntity("tp3_"..tp_index):setTriggeredByParty(true)
		findEntity("tp3_"..tp_index):setTeleportTarget(x-1,y,f,l)
		tp_index = tp_index + 1
	else
		tpCleanUp()
	end
end

function tpCleanUp()
	if findEntity("tp3_"..tp_index-1) then
		findEntity("tp3_"..tp_index-1):destroy()
	end
end
-----
original thread for discussion/questions:
viewtopic.php?f=14&t=3439

Re: Useful scripts repository

Posted: Sat Oct 06, 2012 1:08 pm
by Komag
How to Add a Scroll With Text (or a sack with contents) on an Alcove

example by antti
---------------------
It is not possible to define parameters, like the text for a scroll, for items that are added on alcoves or inside containers by using the inspector alone but it is possible to work around these limitations by scripting. First, let’s place an alcove into the level and set its ID to scrollAlcove and then let’s add the following script into a script_entity:

Code: Select all

local message = spawn("scroll")
message:setScrollText("This is an important\nmessage!")
scrollAlcove:addItem(message)
The first line of script defines a local variable called message which contains a spawned entity: a scroll item. On the next line, we set the text for the entity in the message-variable. The \n in the middle of the string is a line break. Then, on the last line, we add the item onto the alcove.

This same method can be used to place items into containers such as sacks or wooden boxes too (the container can also subsequently be placed on an alcove too).

--------------
Komag examples:
-------------

I believe you can put it all on one line in the script:

Code: Select all

scrollAlcove:addItem(spawn("scroll"):setScrollText("This is an important\nmessage!"))
-------------------------------

Also, here are a couple versions of placing a sack with contents into an alcove:
- first of all, the only thing you actually create in the editor are the alcove and the script "lua"
- If you only want one item in the sack, you can do it all on one line:

Code: Select all

sackAlcove:addItem(spawn("sack"):addItem(spawn("dagger")))
- If you want multiple items in the sack, here is a way to set it up:

Code: Select all

local mysack = spawn("sack")
mysack:addItem(spawn("dagger"))
mysack:addItem(spawn("pitroot_bread"))
mysack:addItem(spawn("green_gem"))
sackAlcove:addItem(mysack)

Re: Useful scripts repository

Posted: Tue Oct 09, 2012 9:47 pm
by JKos
Asset-names in lua-table format

Not sure if this belongs here, but I grepped most asset-names from asset-pack to lua-tables, i'm sure this will be helpful to someone else too. So here goes:

Code: Select all

local monstersList = {
	"crab","crowern","cube","goromorg","green_slime","herder","herder_big",
	"herder_small","herder_swarm","ice_lizard","ogre","scavenger","scavenger_swarm",
	"shrakk_torr","skeleton_archer","skeleton_archer_patrol","skeleton_patrol",
	"skeleton_warrior","snail","spider","tentacles","uggardian","warden","wyvern"
}
local doorsList = { 
	"dungeon_door_iron","dungeon_door_metal","dungeon_door_ornament",
	"dungeon_door_portcullis","dungeon_door_wooden","dungeon_door_wooden_locked",
	"temple_door_iron","temple_door_metal","temple_door_ornament",
	"temple_door_portcullis","temple_door_wooden","temple_door_wooden_locked",
	"dungeon_secret_door","prison_secret_door","temple_secret_door",
	"dungeon_wall_grating","temple_wall_grating"
}
local itemsList = {
	weapons = { "torch","torch_everburning","machete","long_sword","cutlass","nex_sword","dismantler","cudgel","knoffer","warhammer","flail","ogre_hammer","icefall_hammer","hand_axe","battle_axe","great_axe","ancient_axe","knife","dagger","fist_dagger","assassin_dagger","legionary_spear","venom_edge","venom_edge_empty","lightning_blade","lightning_blade_empty","lightning_rod","lightning_rod_empty","fire_blade","fire_blade_empty","power_weapon"},
	shields = {"legionary_shield","round_shield","heavy_shield","shield_elements","shield_valor"},
	accessories = {"frostbite_necklace","bone_amulet","fire_torc","spirit_mirror_pendant","gear_necklace","hardstone_bracelet","bracelet_tirin","brace_fortitude","huntsman_cloak","tattered_cloak","scaled_cloak","diviner_cloak","serpent_bracer","pit_gauntlets","nomad_mittens","leather_gloves"},
	bombs = {"fire_bomb","shock_bomb","frost_bomb","poison_bomb"},
	food = {"snail_slice","herder_cap","pitroot_bread","rotten_pitroot_bread","rat_shank","boiled_beetle","baked_maggot","ice_lizard_steak","mole_jerky","blueberry_pie"},
	missileweapons = {  "sling","short_bow","crossbow","longbow","arrow","fire_arrow","cold_arrow","poison_arrow","shock_arrow","quarrel","fire_quarrel","cold_quarrel","poison_quarrel","shock_quarrel"},
	tomes = {"tome_health","tome_wisdom","tome_fire"},
	armors = {  "hide_vest","leather_brigandine","leather_greaves","leather_cap","leather_boots","ring_mail","ring_greaves","ring_gauntlets","ring_boots","legionary_helmet","iron_basinet","chitin_mail","chitin_greaves","chitin_boots","chitin_mask","plate_cuirass","plate_greaves","full_helmet","plate_gauntlets","plate_boots","cuirass_valor","greaves_valor","helmet_valor","gauntlets_valor","boots_valor"},
	clothes = {  "peasant_breeches","peasant_tunic","peasant_cap","loincloth","leather_pants","doublet","silk_hose","flarefeather_cap","conjurers_hat","circlet_war","lurker_pants","lurker_vest","lurker_hood","lurker_boots","sandals","pointy_shoes","nomad_boots"},
	herbs = {"grim_cap","tar_bead","cave_nettle","slime_bell","blooddrop_blossom","milkreed"},
	machineparts = {  "machine_part_north","machine_part_east","machine_part_south","machine_part_west","machine_junk1","machine_junk2","machine_junk3","machine_junk4","machine_junk5","machine_junk6"},
	potions = { "flask","water_flask","potion_healing","potion_energy","potion_poison","potion_cure_poison","potion_cure_disease","potion_rage","potion_speed"},
	staves = {"whitewood_wand","magic_orb","shaman_staff","zhandul_orb"},
	treasures = {"golden_chalice","golden_figure","golden_goromorg","golden_dragon","golden_crown","golden_orb","ancient_apparatus"},
	containers = {"sack","wooden_box","mortar"},
	keys = {"iron_key","brass_key","gold_key","round_key","ornate_key","gear_key","prison_key"},
	miscitems = { "skull","blue_gem","green_gem","red_gem","compass","remains_of_toorum"},
	scrolls = {  "scroll","note","scroll_light","scroll_darkness","scroll_fireburst","scroll_shock","scroll_fireball","scroll_frostbolt","scroll_ice_shards","scroll_poison_bolt","scroll_poison_cloud","scroll_lightning_bolt","scroll_enchant_fire_arrow","scroll_fire_shield","scroll_frost_shield","scroll_poison_shield","scroll_shock_shield","scroll_invisibility"},
	throwingweapons = { "rock","throwing_knife","shuriken","throwing_axe"},
}	
 local buttonsList = {"wall_button","dungeon_secret_button_large","dungeon_secret_button_small","temple_secret_button_large",
 "temple_secret_button_small","temple_secret_button_tiny","prison_secret_button_small"} 
local leversList =  {"lever"}  
local pressurePlatesList =  {"dungeon_pressure_plate","temple_pressure_plate","prison_pressure_plate","pressure_plate_hidden"} 
local alcovesList = {"dungeon_alcove","temple_alcove","prison_alcove", "eye_socket_left","eye_socket_right","mouth_socket"}   
local torchHoldersList =  {"torch_holder"} 
local lightSourcesList = {"temple_ceiling_lamp","prison_ceiling_lamp"}  
local pitsList = {"dungeon_pit","temple_pit","prison_pit"} 
local teleportersList = {"teleporter"}
local stairsList = {"dungeon_stairs_down","dungeon_stairs_up","temple_stairs_down","temple_stairs_up","prison_stairs_down","prison_stairs_up"}
local wallTextsList = {"dungeon_wall_text","dungeon_wall_text_long","temple_wall_text","temple_wall_text_long","prison_wall_text","prison_wall_text_long"} 
local decorationsList = { "daemon_head_eye_slots","dungeon_floor_drainage","dungeon_wall_drainage","temple_floor_drainage",
"temple_wall_drainage","prison_floor_drainage","dungeon_ceiling_shaft","temple_ceiling_shaft","prison_ceiling_shaft",
"daemon_head","prison_bench","floor_corpse","floor_dirt","dungeon_spider_web_1",
"dungeon_spider_web_2","dungeon_spider_web_3","dungeon_spider_web_4",
"dungeon_ivy_1","dungeon_ivy_2","dungeon_ceiling_root_1", "dungeon_ceiling_root_2","dungeon_ceiling_root_3",
"dungeon_wall_dirt_1", "dungeon_wall_dirt_2","dungeon_cave_in_ceiling","temple_cave_in_ceiling","prison_cave_in_ceiling",
"dungeon_goromorg_statue","temple_goromorg_statue","prison_goromorg_statue", 
"temple_gladiator_statue_spear", "temple_gladiator_statue_flail", "temple_gladiator_statue_sword",
"temple_gladiator_statue_axe","dungeon_catacomb_empty","dungeon_catacomb_skeleton_up","dungeon_catacomb_skeleton_down",
"temple_catacomb_empty","temple_catacomb_skeleton_up","temple_catacomb_skeleton_down","dungeon_pillar","temple_pillar",
"prison_pillar", "temple_mosaic_wall_1", "temple_mosaic_wall_2", "temple_glass_wall_1", "temple_glass_wall_2", "temple_glass_wall_3",
"prison_wall_1","prison_wall_2", "prison_wall_3", "prison_wall_4", "prison_wall_5", "prison_wall_6", "prison_wall_7"}

local locksList = { "lock","lock_round","lock_ornate","lock_golden","lock_gear","lock_prison"}
local blockagesList = {"barrel_crate_block","spider_eggs","metal_junk_block","dragon_statue","goromorg_fourway","goromorg_fourway_dark","dungeon_cave_in","temple_cave_in","prison_cave_in"}
local receptorsList = {"receptor","receptor_hidden"}
local spellsList = {"fireburst","shockburst","frostburst","fireball","fireball_greater","poison_bolt","poison_bolt_greater","frostbolt","improved_frostbolt","ice_shards","lightning_bolt","lightning_bolt_greater","powerbolt","poison_cloud","blob"}


Re: Useful scripts repository

Posted: Wed Oct 10, 2012 5:55 am
by Lark
LED Digital Wall Display: 0 - 99
I posted a new script that displays numbers between 0 and 99 on a wall using red LEDs. I put it in it's own thread to get comments or enhancements requests. A sample display is given below with the link to the script:

Image

The script is at viewtopic.php?f=14&t=3625.

Please enjoy, -Lark

Re: Useful scripts repository

Posted: Wed Oct 10, 2012 2:58 pm
by Grimwold
Create Anti-Magic Zones
create grid spaces in your dungeon where spells will not function.
initial idea - Delak
Contributions - JohnWordsworth; Wolfrug; Grimwold
Discussion in this thread: viewtopic.php?f=14&t=3577


FIRST - Add a custom object to objects.lua to signify the spaces where magic will not work

Code: Select all

cloneObject{
   name = "antimagic_zone",
   baseObject = "pressure_plate_hidden",
   editorIcon = 96,
}
I've gone back to using the original suggestion of a hidden pressure plate even though it adds unnecessary triggers to the dungeon.lua file, because using Decoration class objects presented clipping problems even if set to hidden. I used the editor icon for the blocker to make it clear in the editor where these zones are.
If you wish to add a particle system to more clearly indicate the anti-magic zones to the player you can possibly clone the teleporter object and use either the teleporter particle system, or a custom particle.


SECOND - Create a clone of the party in init.lua to add an onCastSpell hook (or add the hook to an existing party clone if you use one)

Code: Select all

cloneObject{
   name = "party",
   baseObject = "party",
   onCastSpell  = function(caster,spell)
      return antimagic_script.spellCheck(caster,spell)
   end,
}
THIRD - In your dungeon create a script entity called antimagic_script and add the following function

Code: Select all

function spellCheck(caster,spell)
  -- hudPrint(caster:getName() .. " casts " .. spell)
  for i in entitiesAt(party.level,party.x,party.y) do
    -- hudPrint(i.name .. " with id = " .. i.id)
    if i.name == "antimagic_zone"
    then
      hudPrint(caster:getName() .. "'s spell fizzles because of the surrounding anti-magic energies")
      return false
    end
  end
  return true
end

FINALLY - Place your newly defined antimagic_zone objects on your map in the places where you wish to deny spellcasting.


When a player attempts to cast a spell while stood on one of these spaces the spell will fail and a message will be printed to the hud saying why the spell fizzled.