Page 1 of 1

Problem with receptor spawned "on the fly"

Posted: Mon Oct 01, 2012 12:30 am
by Blichew
Hey,

so I've encountered another problem that I cannot solve at the moment so I'm sharing my idea in hope that someone could help me fix it :)

Image

Above image is kinda self-explanatory:

1. Spawner is irrelevant atm
2. Pressure plate at the top activates the timer (1 sec ticks)
3. 6 pits are open
4. receptors have no entity defined (it's defined automatically by the script)
5. counter set @5, on activate timer stops, one pit closes and door opens

What i was trying to do:
1. Player gets a wand that shoots modified "powerbolt" spell - changed the speed to 30 or so
2. Every 3 seconds there's one receptor that is randomly chosen - fx green light appears in front of it and receptor gets dynamically set to be activated by "powerbolt" and counter is dynamically set to decrement. Had to do it this way because if i set no entity on receptor it doesn't give a sh*t that I've set any actions on activate.
3. every succesfull hit counter should be decremented and after 5 hits everything should stop and party should be able to proceed.
SpoilerShow

Code: Select all

index = 1
activeRec = 0
tick_count = 0


function RandomFX()
	x = math.floor(math.random(14,18))
	spawn("fx",2,x,24,0,"second_L_"..index)
	findEntity("second_L_"..index):setLight(0,1,0.5,20,4,3,true)
	findEntity("second_L_"..index):translate(0,1.5,0.5)
	activateReceptor(x)
	index = index + 1
end

function tick()
	if (math.floor(tick_count%3)) == 1 then
		RandomFX()
	end
	tick_count = tick_count + 1
	hudPrint("Counter: "..second_counter:getValue()) -- this one sometimes prints "5" than after a few hits it prints "2" wtf ?
end

function activateReceptor(val)
	for i = 14,18 do
		if i == val then 
			findEntity("second_rec_"..i):setEntityType("powerbolt")
			findEntity("second_rec_"..i):addConnector("activate","second_counter","decrement")
--			findEntity("second_rec_"..i):addConnector("activate","second_script","printHit(i)")
			hudPrint("Receptor activated: "..val)
		else
			findEntity("second_rec_"..val):setEntityType("")
		end
	end
	activeRec = val
end

--function printHit(id)
	--hudPrint("Receptor no."..id.." hit !")
--end
It spawns correctly, Receptor activated message shows correctly, it's the receptor that isn't working...

Please help :)