Page 1 of 2
help: recreating digging + special shovel action
Posted: Tue Feb 24, 2015 1:25 am
by THOM
I am trying to create a special shovel. If you dig with it on a certain tile a special function should be triggered. Therefore the tile in my case is not a floortile but an invisible platform, I cannot dig in the predefined way.
I have to recreate digging.
What should happen is: digging, fade-out, a black screen for a very short time, fade in - having a dighole if there was nothing or my specials. Everything like normal digging...
But it won't work

If I am clicking on my shovel nothing happens.
Has someone an idea?
I have placed 2 timers on my map that triggers after 0.5sec the events for "found nothing" and "found it". I am trying to start one of this timers by the following code, attached to the shovel-definition:
Code: Select all
onAttack = function (champion, self)
-- define locals
local dx,dy = 0,0
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check what is in front of the party
local checkedCell = entitiesAt(party.level, party.x + dx, party.y + dy)
-- interate through all objects on cell
for object in checkedCell do
if object.id == "invisible_platform_diggout" then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_digOut.timer:enable()
else
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_foundNothing.timer:enable()
spawn("dig_hole", party.level, party.x + dx, party.y + dy, 0, party.elevation)
end
end
end,
Re: help: recreating digging + special shovel action
Posted: Tue Feb 24, 2015 1:57 am
by bongobeat
did you try with onUseItem = function(self) ?
Re: help: recreating digging + special shovel action
Posted: Tue Feb 24, 2015 2:26 am
by THOM
yes - same result. nothing happened...
Re: help: recreating digging + special shovel action
Posted: Tue Feb 24, 2015 2:37 am
by Skuggasveinn
What I did was to combine the shovel with the horn.
Code: Select all
defineObject{
name = "sx_shovel",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/shovel.fbx",
},
{
class = "Item",
uiName = "The Spade of Ace",
description = "This simple but reliable tool is favored by masons, farmers and treasure hunters alike.",
gfxIndex = 404,
impactSound = "impact_blade",
weight = 3,
primaryAction = "dig",
traits = { "usable" },
},
{
class = "DiggingTool",
name = "dig",
uiName = "Dig",
cooldown = 4.5,
onUseItem = function(self)
for e in party.map:entitiesAt(party.x, party.y) do
if e.script and e.script.specialDigPlace then
e.script:specialDigPlace()
end
end
end,
},
},
}
So when I had the Spade of Ace shovel and I was digging where there was a script entity with the function specialDigPlace() then I could trigger whatever I wanted.
best regards.
Skuggasveinn.
Re: help: recreating digging + special shovel action
Posted: Tue Feb 24, 2015 11:58 am
by THOM
Thanks Skuggasveinn. You brought me on my way.
Sadly I still can't get it to work.
I managed to get the shovel to trigger a script. By adding print-orders I could backtrack that the script itself is triggered.
But something seems to be wrong with the line
for e in party.map:entitiesAt(party.level, party.x + dx, party.y + dy) do
after that nothing is executed...
That's written in my script:
Code: Select all
function diggingTHOM()
-- print("test")
-- define locals
local dx,dy = 0,0
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check what is in front of the party
for e in party.map:entitiesAt(party.level, party.x + dx, party.y + dy) do
--print("check Cell")
if e.id == "invisible_platform_diggout" then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_digExtra.timer:enable()
else
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_foundNothing.timer:enable()
end
end
end
Re: help: recreating digging + special shovel action
Posted: Wed Feb 25, 2015 7:28 pm
by THOM
Ahem - anyone who can help me?
Re: help: recreating digging + special shovel action
Posted: Sun Mar 01, 2015 3:27 pm
by THOM
I am still trying to figure this out.
I could improve my script, but it's still away from finished.
The problem now is: My script runs all commands for every entity found on the target-cell. I want it running just once. If there is no object or item on the cell it doesn't run at all.
I am totaly lost with this because I am not very skilled in scripting. Anyone who has a hint for me?
Code: Select all
function diggingTHOM(self)
--print("test script")
-- define locals
local dx,dy = 0,0
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check what is in front of the party
-- interate through all objects on cell
for e in party.map:entitiesAt(party.x + dx, party.y + dy) do
--print (e.id)
--print("check Cell")
if e == nil then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_foundNothing.timer:enable()
end
if e.id == "invisible_platform_diggout" then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_digExtra.timer:enable()
else
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_foundNothing.timer:enable()
end
end
end
Re: help: recreating digging + special shovel action
Posted: Sun Mar 01, 2015 6:26 pm
by Azel
Right, so if there are no items in the cell then there is no "e" based on your code. On the opposite side of that equation, because "e" is a placeholder for any and all items on the cell, your Dig Code will continue to execute for every "e" in that cell.
What I would do using your approach:
Situation A) If you only want to allow digging on certain tiles:
1) Pick one Game Object that you will always use to represent a "dig spot." Let's choose the Forest Altar for this example.
2) Put a Forest Altar in the spot where you want digging to occur. Remove all Component properties (clicable, obstacle, projectcollider, model). Give it a unique ID, dig_spot_1.
3) In your "e" loop replace "if e == nil" with, "if e.id == dig_spot_1"
4) Your script will trigger digging every time you hit a "dig spot" altar. You can get fancier with the script to avoid hardcoding the number at the end of the dig_spot_
Situation B) If you want to allow digging in all unique tilesets
1) Only allow digging if there are absolutely no objects in that tile. Add a variable to your function, local itemCounter = 0
2) Inside your "e" loop simply increment it: itemCounter = itemCounter + 1;
3) Optionally, as soon as "e" evaluates once (ItemCounter becomes 1), enter a "break;" command to stop the loop.
4) If ItemCounter is greater than 0 then inform the user that there is something not allowing them to dig: hudPrint("You can't dig here at this time")
5) At the end of the function allow digging only if itemCounter is still 0; "if itemCounter == 0 then DoDig();"
6) You won't need the "if e == nil" line at all in this scenario
Not sure if this is exactly what you're needing, but based on what I understood this is most likely what I'd do. Hope it helps!
Re: help: recreating digging + special shovel action
Posted: Sun Mar 01, 2015 7:08 pm
by THOM
Hi Azel - thanks for the reply.
I am not at home at the moment so I can't try out your suggestion. But I will do later in the evening.
Anyway - my digging-script must work in all 3 cases:
1 - there is an empty tile in front of the party -> digging and finding nothing
2 - there are objects/items in front of the party -> digging and finding nothing
3 - there is my special target in front of the party -> digging and finding bonus
To differentiate between 1 and 2 is not nessecary - it is just a fact, that my script-approach reacts different in this two cases. At least if I don't tell it somehow to do not...
Re: help: recreating digging + special shovel action
Posted: Sun Mar 01, 2015 8:26 pm
by Azel
This should do it:
Code: Select all
function diggingTHOM(self)
-- define locals
local dx,dy = 0,0;
local digExtra = "false"
-- get position modificators, to find cell in front of the party
if party.facing == 0 then dy = -1
elseif party.facing == 1 then dx = 1
elseif party.facing == 2 then dy = 1
elseif party.facing == 3 then dx = -1
end
-- check for digExtra location
for e in party.map:entitiesAt(party.x + dx, party.y + dy) do
if e.id == "invisible_platform_diggout" then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_digExtra.timer:enable()
digExtra = "true"
break;
end
end
-- if not digExtra, show nothing
if digExtra == "false" then
playSound("party_dig")
hudPrint("Digging...")
GameMode.fadeOut(0x0,1.5)
timer_foundNothing.timer:enable()
end
end