Help a scripting newbie
- Soaponarope
- Posts: 180
- Joined: Thu Oct 04, 2012 3:21 am
Help a scripting newbie
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
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.
Re: Help a scripting newbie
The first one I think you need only one function if you just want to check the mouse for the "golden_orb":
The second should work like this:
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
Code: Select all
function checkCursor()
if getMouseItem() and getMouseItem().name == "golden_orb" then
print("success") else
print("fail")
end
endCode: 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,I didn't test either of these so good luck!
edit: tested, all works
- Soaponarope
- Posts: 180
- Joined: Thu Oct 04, 2012 3:21 am
Re: Help a scripting newbie
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.
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
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.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.
You were only getting one forward square's coordinate adjustments because you only passed self.facing to getForward and not all 4 cardinal directions.
- Soaponarope
- Posts: 180
- Joined: Thu Oct 04, 2012 3:21 am
Re: Help a scripting newbie
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.
- Soaponarope
- Posts: 180
- Joined: Thu Oct 04, 2012 3:21 am
Re: Help a scripting newbie
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.
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
function spawnstone()
stone_altar:addItem(spawn("teleport_stone",nil,nil,nil,nil,"teleport_stone_1"))
end
stone_altar:addItem(spawn("teleport_stone",nil,nil,nil,nil,"teleport_stone_1"))
end
Finished Dungeons - complete mods to play
- Soaponarope
- Posts: 180
- Joined: Thu Oct 04, 2012 3:21 am
Re: Help a scripting newbie
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.
Thank you Komag. I'll go sit in the corner with a dunce cap on now.
Re: Help a scripting newbie
if someone else hadn't shown it to me first I would never have thought of it myself 
Finished Dungeons - complete mods to play
Re: Help a scripting newbie
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. 
