Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
onUnequipItem = function(self,champion,slot)
if slot==1 or slot==2 then
local hascandle = false
for i = 1,4 do
local ch = party.party:getChampion(i)
if ch:getItem(1) == candle or ch:getItem(2) == candle then
hascandle = true
break
end
end
if hascandle == false then
party.candle:disable()
end
end
end,
But it seems that the onUnequipItem function is executed in the same moment the item is still equipped. Means: When I search for a champion having the item in a hand the one who unequips it still has it and the result will alway be hasItem == true. But I cannot leave the champion unequipping the item out because he could have that item in the other hand.
Has anyone an idea how to solve this?
THOM formaly known as tschrage _______________________________________________ My MOD (LoG1):Castle RingfortThread My MOD (LoG2):Journey To JusticeThread | Download
THOM wrote: ↑Fri Nov 27, 2020 11:49 am
But it seems that the onUnequipItem function is executed in the same moment the item is still equipped. Means: When I search for a champion having the item in a hand the one who unequips it still has it and the result will alway be hasItem == true. But I cannot leave the champion unequipping the item out because he could have that item in the other hand.
Has anyone an idea how to solve this?
You could use a counter.
onEquipItem:
- if item equipped in slot 1 or 2, increment counter
onUnequipItem:
- if item unequipped from slot 1 or 2, decrement counter
- if counter == zero then disable light
edit:
Instead of the numbers 1 and 2, I would use
ItemSlot.Weapon
ItemSlot.OffHand
It's not necessary, but it makes the code a little clearer.
bongobeat wrote: ↑Thu Nov 26, 2020 11:49 pm
Also these objects have been tested, many times since i published many version, and I or the testers didn't notice something like that.
How many objects does your mod have in total?
Maybe there are so many that the game decides to just drop some of them...
around 80k objects, up to 100k until all is spawned. Minus 7-8k with the items, if they are used or sold, etc..
Zo Kath Ra wrote: ↑Fri Nov 27, 2020 12:19 pm
You could use a counter.
onEquipItem:
- if item equipped in slot 1 or 2, increment counter
onUnequipItem:
- if item unequipped from slot 1 or 2, decrement counter
- if counter == zero then disable light
Thanx. Seems to work perfect.
THOM formaly known as tschrage _______________________________________________ My MOD (LoG1):Castle RingfortThread My MOD (LoG2):Journey To JusticeThread | Download
if monster and not monster:isImmuneTo("knockback") then
monster.go.animation:stop()
if monster.go.brain then
monster.go.brain:performAction("idle")
monster.go.brain:wait()
end
delayedCall("functions", 0.2, "knockback", monster.go.id, party.facing)
end
function knockback(id, facing)
local monster = id and findEntity(id).monster or nil
monster:knockback(facing)
end
But it's kinda awkward. Without the delay it fails half of the time, and sometimes I get "unknown monster action: "idle""
My candle item is finished so far. It works partly like a torch, but gives also light when the item ist put down.
At the moment it is an everburning candle, but I want to limit this (like it is with the torch). My first attempt was to give the gameobject a timer that destroys the item after ten minutes or so. But it seems that timers won't run when put into items. At least my construction didn't wanted to work.
Then I thought to create a timer on the map onInit of the candle. Not easy to give it a unique name, which is needed to progam it and connect it correct.
Or does anyone have an easier idea?
THOM formaly known as tschrage _______________________________________________ My MOD (LoG1):Castle RingfortThread My MOD (LoG2):Journey To JusticeThread | Download
THOM wrote: ↑Wed Dec 02, 2020 12:46 am
Okay, I must ask for some more help.
My candle item is finished so far. It works partly like a torch, but gives also light when the item ist put down.
You want the candle to burn when
- it's in a champion's weapon slot
and also
- when it's in the game world, i.e. when it can be found with findEntity(id)
?
Timers elapse when the map they're on updates. When an object is being carried (or is in a container), it's not on any maps, so a timer will never elapse time. Also, if the object is not on the same map as the party, the timer will elapse a lot slower, which is probably not what you want in this case.
If I'm understanding the question correctly, the easiest way to get the behaviour you want would be to
1. have a function that finds a candle with a specific id and destroys it. or3_manager.lua already has the code for finding an item with a specific id, so you can just reuse that.
2. make a delayedCall() to that function when the candle is lit. Remember delayedCall() passes arguments after the first three through to whatever function it ends up calling, so you can do something like delayedCall("candle_script",600,"destroyCandle",self.go.id)
Zo Kath Ra wrote: ↑Wed Dec 02, 2020 12:55 am
You want the candle to burn when
- it's in a champion's weapon slot
and also
- when it's in the game world, i.e. when it can be found with findEntity(id)
?
The candle burns in the champions attack hands and when put on the floor or elsewhere. You can find it with findEntity() then, yes.
Your thoughts are probably going into a similar direction like minmay's does. That solution is good and I will try it out. I just hoped I could solve this just from whithin the item itself. But it seems I have to need an external script entity. So it be.
THOM formaly known as tschrage _______________________________________________ My MOD (LoG1):Castle RingfortThread My MOD (LoG2):Journey To JusticeThread | Download