sample script (lua oop) textinput and buttons

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
comscript
Posts: 27
Joined: Tue Sep 18, 2012 6:05 pm
Location: France

sample script (lua oop) textinput and buttons

Post by comscript »

for those who are interested by an area of ​​text input
(example, open a secret door with a password)
Sample script
- connection between a pressure plate, and buttons in the interface (onDrawGui). (change properties of the buttons)
- input text
connection between a wall_button, textinput , secretdoor
to open the secret door, type "OPENSECRET" in the text area

you can use and modify this code
dungeon with source files
http://grimrock.nexusmods.com/mods/182
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: sample script (lua oop) textinput and buttons

Post by Komag »

wow, thanks for working up this proof of concept, good example of what can be done :)
Finished Dungeons - complete mods to play
comscript
Posts: 27
Joined: Tue Sep 18, 2012 6:05 pm
Location: France

Re: samples scripts (textinput, buttons trace projectile)

Post by comscript »

A simple function that can target a projectile
no timer, but the function ondrawGui

Code: Select all

cloneObject{
	name = "party",
	baseObject = "party",
	onDrawGui = function (g)
		script1.traceProjectile()
	end
}
example:
when the projectile passes under a wooden door, the door closes.
spawn your projectile with a id=myspell

Code: Select all

defineSpell{
	name = "myspell",
	uiName = "myspell",
	skill = "air_magic",
	level = 0,
	runes = "CH",
	manaCost = 10,
	onCast = function()
		script1.mySpell()
	end
}

function mySpell()
  local spell
  local dx, dy = getForward(party.facing)
  local x = party.x + dx
  local y = party.y + dy
  if x<0 then x=0 end
  if x>31 then x=31 end
  if y<0 then y =0 end
  if y>31 then y = 31 end
  spawn("lightning_bolt",party.level,party.x+dx,party.y+dy,party.facing,"myspell")
end
in your script1

Code: Select all

xt = 50
yt = 50
function traceProjectile()
  if myspell then
    local x=myspell.x   
    local y=myspell.y
    if xt ~= x or yt ~=y then  -- execute only if the coordinates are changed
      xt = x
      yt = y
      for i in entitiesAt(party.level,x,y) do
        if i.name ~= "lightning_bolt" then 
          hudPrint(i.name)
       end
        if i.name == "dungeon_door_wooden" then i:close() end
      end
  end
  else
    xt = 50
    yt = 50
  end
end
The projectile closes all the doors under which it passes and display the names of all entities on its way.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: sample script (lua oop) textinput and buttons

Post by Komag »

another very cool example, thanks! :)
Finished Dungeons - complete mods to play
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: sample script (lua oop) textinput and buttons

Post by Diarmuid »

This is the principle I've been using to track spells in exsp (viewtopic.php?f=14&t=4459). I do not know if you were aware of it or if you checked the code...

I track spellProjectiles by Id, creating a spell object with properties and methods which is handled oop-style across the different functions. It also includes detection algorithms for various collisions and a hooks system, effects, monster methods, helper functions...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: sample script (lua oop) textinput and buttons

Post by JKos »

That's a pretty cool script. I think that it would be a nice addition to the grimwidgets framework: https://github.com/xanathar/grimwidgets
Thread: viewtopic.php?f=14&t=4454

Would you like to participate and convert your script for the grimwidgets? We already have a similar 3D button made by Xanathar, but we don't have a text input field.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
comscript
Posts: 27
Joined: Tue Sep 18, 2012 6:05 pm
Location: France

Re: sample script (lua oop) textinput and buttons

Post by comscript »

You can use this code as you want, it's just an exemple it needs to be improved.
Post Reply