I am a total Lua novice so please excuse my ignorance. But I'm enjoying the learning curve! Anyway, I've been trying to create a level in which the player must cross a busy motorway without getting hit. If he gets hit he probably dies. With my very limited knowledge of Lua I have created the below script and attached it to an entity to represent my vehicle.
I've been working on this all day and the latest script is probably the crudest because I'm kind of tired.
Initially, the main problem seemed to be getting the sound effect (a car hitting our player) to play before his/her energy reaches zero. I tried to get around this by making the sound play when the player was at a greater distance, then using the HurtPlayer command when closer. This didn't seem to help much.
Another problem is that the player gets killed repeatedly after respawning (in Test Game Mode). I've tried to use the Destroy(e) command to stop this but to no avail. I tried creating a state or flag: ('hit'), but didn't have any luck with it. Also, if I use TrasportToIfUsed(e) the player is relocated but the HurtPlayer command is then ignored even though placed above the transport command.
I would be most grateful for your help. Thanks in advance.
function movingcar_init(e)
hit = 0
end
function movingcar_main(e)
CollisionOn(e)
if GetPlayerDistance(e) > 100 then
MoveForward(e,300)
hit = 0
end
if GetPlayerDistance(e) < 250 and GetPlayerDistance(e) > 150 and hit == 0 then
PlaySound(e,0)
end
if GetPlayerDistance(e) < 100 then
HurtPlayer(e,500)
--TransportToIfUsed(e)
end
end
Julian