Help a scripting newbie

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Help a scripting newbie

Post by Soaponarope »

All questions currently solved.





function mouseitemCheck(item)
if party.getMouseitem ~= nil then
item = party.getMouseitem.name
end
end

function checkCursor()
if mouseitemCheck("golden_orb") then
hudPrint("success")
else print("fail")
end
end

Also I want to make a "exploding monster" and thought this would do it, but it only seems to fire on facing side, instead of all around.

onDie = function(self)
local dx,dy = getForward(self.facing)
spawn("fireburst", self.level, self.x+dx, self.y+dy, 0)
spawn("fireburst", self.level, self.x+dx, self.y+dy, 1)
spawn("fireburst", self.level, self.x+dx, self.y+dy, 2)
spawn("fireburst", self.level, self.x+dx, self.y+dy, 3)
end
Last edited by Soaponarope on Sun Dec 02, 2012 2:03 pm, edited 3 times in total.
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Help a scripting newbie

Post by Batty »

The first one I think you need only one function if you just want to check the mouse for the "golden_orb":

Code: Select all

function checkCursor()
   if getMouseItem() and getMouseItem().name == "golden_orb" then
      print("success") else
      print("fail")
   end
end
The second should work like this:

Code: Select all

onDie = function(self)
   for i = 0, 3 do
      local dx, dy = getForward(i)
      spawn("fireburst", self.level, self.x + dx, self.y + dy, 0)
   end
end,
Facing shouldn't matter with fireburst as it blows up in the entire square I think, I've never seen one spawned. You need to get the four different getForwards (one for each direction).

I didn't test either of these so good luck! :)

edit: tested, all works
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Re: Help a scripting newbie

Post by Soaponarope »

Thank you Batty, this works well.

My first one was a mess, I don't understand why the second didn't work though. It makes sense facing shouldn't matter, but I thought it should still fire in each direction. Trouble understanding scripting logic sometimes.
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Help a scripting newbie

Post by Batty »

Soaponarope wrote:Thank you Batty, this works well.

My first one was a mess, I don't understand why the second didn't work though. It makes sense facing shouldn't matter, but I thought it should still fire in each direction. Trouble understanding scripting logic sometimes.
The monster only has one self.facing at any given moment. Supposing it was 0 and the monster was at 5, 5 then the forward square would be 5, 4 so getForward would return 0 for dx and -1 for dy and when added to self.x and self.y, you get the coordinates for the forward square.

You were only getting one forward square's coordinate adjustments because you only passed self.facing to getForward and not all 4 cardinal directions.
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Re: Help a scripting newbie

Post by Soaponarope »

Thanks again. I thought I could just get the one forward square's coordinates and the direction at the end changed it to spawn in that direction instead.
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Re: Help a scripting newbie

Post by Soaponarope »

I must be overlooking something simple here, cause I can't seem to figure out how to spawn a unique id into an alcove.

function spawnstone()
stone_altar:addItem(spawn("teleport_stone",1,18,4,2,"teleport_stone_1"))
end

For example using a common spawn script to add id also requires the (level,x,y,facing), but with it, it states the entity is already added to the map since it was spawned on the altar. I tried to define the id locally using .name, but can't get it to work when spawned on the altar. Frustrated, I know I'm going to feel stupid seeing the answer.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Help a scripting newbie

Post by Komag »

function spawnstone()
stone_altar:addItem(spawn("teleport_stone",nil,nil,nil,nil,"teleport_stone_1"))
end
Finished Dungeons - complete mods to play
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Re: Help a scripting newbie

Post by Soaponarope »

Arrgh! I can't believe this works. I can't believe I didn't try this. The answer was even simpler than I imagined.

Thank you Komag. I'll go sit in the corner with a dunce cap on now.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Help a scripting newbie

Post by Komag »

if someone else hadn't shown it to me first I would never have thought of it myself :?
Finished Dungeons - complete mods to play
Glew
Posts: 74
Joined: Sat Dec 21, 2013 7:57 pm

Re: Help a scripting newbie

Post by Glew »

Thanks a lot for this one! It helped me immensely. So simple and makes things so simple. Made it possible to carry out my idea for a puzzle. :mrgreen:
Post Reply