Page 1 of 1
Help a scripting newbie
Posted: Sun Nov 18, 2012 3:29 am
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
Re: Help a scripting newbie
Posted: Sun Nov 18, 2012 4:14 am
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
Re: Help a scripting newbie
Posted: Sun Nov 18, 2012 5:34 am
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.
Re: Help a scripting newbie
Posted: Sun Nov 18, 2012 5:54 am
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.
Re: Help a scripting newbie
Posted: Sun Nov 18, 2012 6:49 am
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.
Re: Help a scripting newbie
Posted: Sun Dec 02, 2012 7:44 am
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.
Re: Help a scripting newbie
Posted: Sun Dec 02, 2012 12:38 pm
by Komag
function spawnstone()
stone_altar:addItem(spawn("teleport_stone",nil,nil,nil,nil,"teleport_stone_1"))
end
Re: Help a scripting newbie
Posted: Sun Dec 02, 2012 1:38 pm
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.
Re: Help a scripting newbie
Posted: Sun Dec 02, 2012 2:17 pm
by Komag
if someone else hadn't shown it to me first I would never have thought of it myself

Re: Help a scripting newbie
Posted: Sat Dec 21, 2013 8:02 pm
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.
