Page 366 of 396

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 27, 2020 11:49 am
by THOM
Okay, I have the following problem.

I have an item and when unequipping it I check if another instance of this item is in any attack hand of any champion in the party.

My code is this

Code: Select all

		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?

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 27, 2020 12:19 pm
by Zo Kath Ra
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.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 27, 2020 5:54 pm
by bongobeat
Zo Kath Ra wrote: Fri Nov 27, 2020 8:37 am
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..

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 27, 2020 7:23 pm
by THOM
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.

Re: Ask a simple question, get a simple answer

Posted: Mon Nov 30, 2020 2:41 am
by 7Soul
Does anyone know a good way to knockback monsters? I'm doing it like this:

Code: Select all

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""

Re: Ask a simple question, get a simple answer

Posted: Mon Nov 30, 2020 2:57 am
by minmay
The best way to forcibly interrupt a monster's action is to setPosition() it; see this similar question: http://www.grimrock.net/forum/viewtopic ... 92#p117892

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 02, 2020 12:46 am
by THOM
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.

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?

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 02, 2020 12:55 am
by Zo Kath Ra
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)
?

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 02, 2020 6:30 am
by minmay
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)

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 02, 2020 10:27 am
by THOM
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.