Scripts / Vehicle Hits Player - Splat!

Author
Message
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 4th Nov 2015 23:59
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
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 5th Nov 2015 22:22
I got it work! Check this out:

https://youtu.be/Zp_0SaD0eOw
Julian
PM
Jerry Tremble
GameGuru TGC Backer
12
Years of Service
User Offline
Joined: 5th Nov 2012
Location: Sonoran Desert
Posted: 6th Nov 2015 04:07
That was great! Thank you!
MAME Cab PC: i7 4770@3.4Ghz (passmark 9945), 12GB RAM, Win 8.1/64, GeForce GTX645 (passmark 1898); Shiny new laptop: i7 4800MQ@2.7Ghz (passmark 8586), 16GB RAM, Win 8.1/64, GeForce GTX870M (passmark 3598); Old laptop: i5@2.3Ghz, 8GB RAM, Win 7/64, Intel 3000 graphics
PM
HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 6th Nov 2015 10:31
cool

Harry
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 6th Nov 2015 13:15
Great work ...That's going to be very handy
The only person ever to get all his work done by "Friday" was Robinson Crusoe..
PM
The Next
TGC Web Engineer
16
Years of Service
User Offline
Joined: 3rd Dec 2007
Location: United Kingdom
Posted: 6th Nov 2015 16:38
This should be in the scripts board and please use code tags.
Windows 7 Pro, Intel i7 3.8 GHz (Passmark: 9021), 16GB DDR3, NVIDIA GTX 780 4GB Superclocked (Passmark: 8056)
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 8th Nov 2015 02:09
Thanks so much for the feedback, guys!! Here's an update.

Coming along. Maybe getting TOO crazy!

https://www.youtube.com/watch?v=PtUi7XlL258#t=12

(Sorry - tried used script codes, can't work them nor can I figure out how to embed Youtube).
Julian
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 8th Nov 2015 02:13
[code lang=lua function movingcar2_init(e)
StartTimer(e)
end

function movingcar2_main(e)
MoveForward(e,600)
if GetPlayerDistance(e) < 200 and GetPlayerDistance(e) > 100 then
skid = 1
hit = 1
else
skid = 0
end
if GetPlayerDistance(e) < 100 and GetPlayerDistance(e) > 0 then
hit = 1
skid = 0
else
hit = 0
end

if skid == 1 then
PlaySoundIfSilent(e,0)
--Use a suitable skidding sound
skid = 0
end
if hit == 1 and skid == 0 then
HurtPlayer(e,10)
hit = 0
end
if GetTimer(e) > 10000 and GetPlayerDistance(e) > 1000 then
SetRotation(e,0,90,0)
-- RotateY(e,4859)
--StartTimer(e)
end
if GetTimer(e) > 20000 and GetPlayerDistance(e) > 1000 then
SetRotation(e,0,-90,0)
-- RotateY(e,4859)
StartTimer(e)
end


end ]
Julian
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 9th Nov 2015 00:40 Edited at: 9th Nov 2015 00:47
Julian
PM

Login to post a reply

Server time is: 2024-11-16 16:19:11
Your offset time is: 2024-11-16 16:19:11