Scripts / Game Over if you Kill Certain Characters

Author
Message
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 18th Feb 2015 18:48
Hi,,

I've been trying to modify ai_soldier.lua so that if the player kills the character it's game over. I haven't had any luck. Does anyone have any ideas? I'd be most grateful.

Thanks
Julian
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Feb 2015 20:41
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)

should do it (in a standalone anyway)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 18th Feb 2015 20:53
Thanks. Where in the script should I place this? Is this all the code I need? Sorry - I'm an absolute beginner!
Julian
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 18th Feb 2015 21:11
I know it's a big ask, but could you please show me the snippet in the complete script?
Julian
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Feb 2015 23:27
well if you are using the ai_soldier.lua file you could place this in the exit part

function ai_soldier_exit(e)
PlayCharacterSound(e,"onDeath")
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)
end
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 19th Feb 2015 00:26
It might work there (I know it's supposed to). I had trouble in the last version though ... it looked like the engine was just terminating the script on a sudden drop of character health below zero and not performing the exit(e) section. Hopefully it will work in this version though I think I had to trap the health drop under 100 (and add extra 100 to starting health) in 1.09. FinishLevel() might also work.
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 19th Feb 2015 12:13
Thanks for your help. That works. However, I also want to display a message before ending the game so I tried inserting a Prompt command, thus:

function ai_soldier_exit(e)
Prompt("You killed an ally - Game Over!"0
PlayCharacterSound(e,"onDeath")
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)
end

But the message never displays. Do you know how to fix it?
Julian
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Feb 2015 19:00 Edited at: 19th Feb 2015 19:04
that's not going to work with the current set up then, the issue would be that once the character is killed it'll no longer run the script (hence the exit)

you will need a new script which checks for the characters death i called this ally_dead.lua
set it on a dynamic object that's always active

function ally_dead_init(e)
dead = 0
local delay = 0
end

function ally_dead_main(e)

if dead == 1 then
PromptDuration("You killed an Ally!",2000)
delay = GetTimer(e) + 2000
dead = 2
elseif dead == 2 then
if GetTimer(e) > delay then
SetPlayerLives(e,0)
HurtPlayer(e,g_PlayerHealth)
dead = 3
end
end

end


and change the ai_soldier.lua exit part to this
function ai_soldier_exit(e)
PlayCharacterSound(e,"onDeath")
dead = 1
end


let me know if you have any issues

edit; code snippets not working correctly
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 19th Feb 2015 20:26
Thanks, very much. I'll check it out. In the meantime, I managed to kind of get it do what I want. [video=mp4]I
Julian

Attachments

Login to view attachments
PM

Login to post a reply

Server time is: 2025-01-02 13:26:04
Your offset time is: 2025-01-02 13:26:04