Scripts / Win the game when a particular group of enemies are all killed?

Author
Message
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 14:12
Hello, basically in my level, once the player kills all the normal enemies, he enters a trigger zone that spawns in one last group of enemies. I want the player to win the game when this particular group of enemies are killed. Is this possible? I'm hopeless with LUA (at the moment), so any help would be appreciated! Thanks.
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 15:18 Edited at: 17th Feb 2017 15:20
You could simply have a script which loops though the soldier list and check for any still having health, but that assumes you have to kill all enemies to end the game.

Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 15:28
Thank you! What would I add to the "... etc ..." to make that work? Or would I just leave it? And what exactly would I attach this script to?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 15:46
The .. etc ... bit is for whatever you planned to do to end the game, probably transport the player to an end game zone or something.

You can attach the script to a crate and make it always active so it doesn't matter where the crate is placed.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 19:04 Edited at: 17th Feb 2017 19:07
Could I use JumpToLevel(*levelname*) or FinishLevel() to replace that? I don't fully understand what you mean by transporting the player to an end game zone.

Also, would all of my enemies have to be named "Soldier" or is it searching for anything which is using the ai_soldier script? Sorry for all the questions!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 19:48
The ai_soldier_state list is used by all the soldier ai scripts to indicate when the characters are alerted or idle etc, I'm not sure if all ai characters use it though. You can take a look in the ai scripts for the characters you are using to see if they use it.

It may need tweaking to accomplish exactly what you want, I use a similar piece of code to display 'state' info on the radar/map, i.e. change the colour of the dots depending on state of the enemy around you.

Yep FinishLevel or JumpToLevel would probably work fine in there.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:00
Will FinishLevel or JumpToLevel only work when the game is exported as a standalone?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 20:06
Possibly, you could just put up a "Game Over" message for now so you know it's working.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:16
Yes good idea, thank you!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:29
Just tested this, and the script does not seem to be doing anything at all. I attached it to a box which is always active.
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 20:34
can you show your script?
if you use the script above you will need to remove the ...etc... part or naturally it won't work, other than that i think it should work
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:37
Here is the script I am using
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080

Attachments

Login to view attachments
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 20:43
^ lies
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:50
Keep forgetting to use that handy and convenient "Upload" button the script should be attached now. For future reference, how do I add a code snippet?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 20:52
You need to put the code in a function.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 20:53
you need to put the code inside a lua script so that it will be called in a function

for code snippets you use the button above the message box, highlight all your code and then click the "code" box (and select lua for format highlighting)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:57
Oh wow, its the most obvious things! Thanks guys, maybe one day I will see the light Thanks for the tips!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 20:59 Edited at: 17th Feb 2017 21:01
Hmm, the code still seems to be doing nothing. I'm lost for ideas...
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 21:13
Have you tried it with a single soldier?
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:14
No, I used 3 soldiers. Is it worth mentioning that I created these soldiers with the character creator? Although they are still using ai_soldier.
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 21:30
oh sorry, if you used my snippet it should look like this (i put the first variable outside the function)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 21:31
If they are using ai_soldier.lua then the ai_soldier_state list should have been set up for them, when you have killed all three (assuming they are the only 3 still 'alive') then the Prompt should be triggered.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:31
So how exactly would that affect the script not running at all? It seems by asking questions I'm hugely benefiting from all of this
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:33
Nope, its not displaying the message once all of my soldiers have been killed... will this only work with the default soldiers?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 21:35 Edited at: 17th Feb 2017 21:38
The Prompt is probably only displayed for one frame, make it a PromptDuration call.

Nope that can't be it, it must be finding some health for one of the soldiers even though they are dead.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 21:35 Edited at: 17th Feb 2017 21:37
the script works fine, i just tested it, it won't display anything until you kill ALL enemies though, best to just do a quick test with only a few soldiers
just make sure it's set on an always active object (incase you were to wander too far from the object checking) and it is set to static = no (as with all script objects)
it'll work with any script that has ai_soldier_state in it (so basically all of the stock AI)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:36
Would I also have to make that a toggle by using a variable like the one used in the other script (first_run) to stop it updating?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:37 Edited at: 17th Feb 2017 21:39
This seems too stupid to ask cause I even remember doing this, but how do I change the entity from static to dynamic again? I can't actually see any option for it xD

EDIT: I found it, ignore me! You guys make this community great! Just to check, the "Level complete triggered" is being displayed because of the FinishLevel()?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Feb 2017 21:39 Edited at: 17th Feb 2017 21:42
click properties when you have the object selected and then under it's name is static mode = yes/no
(to quickly tell - if the object is green when highlighted this is 'no' or dynamic and will run scripts, if it's red then it's 'yes' or static and won't run scripts)
or extract the object and press Y to toggle static mode on/off

yes, the prompt is because of the finish level call, it wouldn't be shown in the standalone and will simply end the level (the prompt is only for test mode purposes)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:43
Oooh okay, I was wondering what the difference of those was, no wonder, the entity was static the whole time! Well, I can only apologise for effectively accidentally time wasting, thanks again guys!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 21:43
Just add it to a crate near the last few enemies.

You could make a simple addition to this, set a count variable to 0 and then increment it in the loop in place of the 'break' command.

Then add an else to the if End_Game which calls a prompt to display the count. That way you can see the number of enemies left to kill.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:45
So add a variable above the break command? Or replace the break command? I'm sorry, I'm still getting used to all this!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 21:48 Edited at: 17th Feb 2017 21:50
Replace the break command, break just quits out of the loop but if you want to count all the healthy enemy you need to stay in the loop.

Like this:

Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:51 Edited at: 17th Feb 2017 21:51
So your saying replace break with something like "enemycount = "? I can't visualise how I would go about doing this. Like I know all the coding basics (studied Python for a year) but LUA seems to be confusing me, so if you could be more specific so I could remember this and learn that would be great!

EDIT: I never saw your snippet... ignore me... again
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 21:53
Would the enemy count not override the toggle HUD and the dialogue ive got in my game though? Is it possible to put the count a line above/below the default place for prompts?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:00 Edited at: 17th Feb 2017 22:08
Yes it would, you next need to investigate the Text commands! TextCenterOnXColor(x,y,size,txt,r,g,b) for example.

Another good one is Panel(x,y,x2,y2)

I've attached a very simple example I did a year ago when I was learning Lua, it was part of a ball game I wrote where you used the sniper rifle to 'persuade' balls to go into a goal zone. This script checked how many balls were in the zone.

btw, x,y for these commands is the percentage across and down the screen respectively, same system is used for sprites so it's well worth learning it.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:04
Hmmm is that hard to learn, or just a kinda add one line of code thing? Which line is better: panel or textcenteronxcolor? I have no idea what any of it means in the brackets, my best guess is the coordinates, but what coordinates would go in the brackets? How would I find out the original coordinates (so I know not to put those coordinates again) and the coordinates where the text would need to go? Hahahaha my brain is officially fried after all this!

Thanks for attaching the script, I'll take a look, see if it makes any sense to me
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:04


There is an example of what you can do with sprites.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:05
Also, what is "for k, v in pairs(ball_in_zone) do..."? I noticed this is used in my script for the soldiers, what does the "in pairs" mean? And what is with all the uses of K and V?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:21
Lua has a very small number of 'types', instead of arrays and structures and records, like other languages, Lua only has lists.

A list is sort of like a hash if you are familiar with those, you have a key and a value, so for example:

alist ={a = 1, 2 = "hello", 'T' = {another list}}

is a perfectly valid list.

Prompt(alist.2) would result in hello

pairs is how you iterate through a list so for k,v in pairs(alist) would give

a, 1
2, hello
T, <list pointer>

If all you want to do is find out the keys for a list for k,_ pairs(alist) would just give those (like in the soldier example, just using a list to find out the entity numbers for all the soldiers).

You will see a lot of scripts just using lists as if they are arrays, this is fine if you know what you are doing but it is always best to remember they are certainly not arrays!

if you say alist={"one","two","three"."four","five","six"} (maybe for a dice game?), the interpreter will insert keys for you, so alist[1] will result in the value "one" etc, but you could quite validly now do alist['rubbish'] = 42 and as you can appreciate your nice array picture goes out of the window!

Lua is extremely powerful and flexible, I've spent 40 years coding in over 50 different languages and this baby is by far my favourite so far.

Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:28
Wow, what an answer! I've touched on arrays, but lists have always confused me, I was not aware that you were referring to lists. I'm still confused on why the word "pairs" is used as there seems to be no relevance to anything being in twos or in "pairs" unless I've missed something? And I do not remember looking at keys and values, or hashes, which is a shame. I'm coming up to my GCSEs, so everything I know is by taking Computer Science but they refuse to teach more than Python to avoid unnecessary confusion, so I kinda gotta teach myself outside of school.
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:34
I just found this script from cybernescence:

InfoHUDMessage = "It's getting cold at this altitude Captain!"
Panel(20,5,80,10)
TextCenterOnXColor(50,8,1,"SPEAKING TUBE: " .. InfoHUDMessage .. " (Health: " .. g_PlayerHealth .. ")",255,0,0)

This is meant to display text at the top of the screen along with a panel. How can I incorporate this into our enemy count?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:42
Ahh, a young pedewan.

'pairs' just refers to the fact that all lists have a key and a value combination, hash tables work in a similar way and you will come across them in other languages.

It doesn't have to be k,v btw, that's just a convention I use. Youy could say 'for fred, betty in pairs(list) do' and it will work the same.

The is another variant called ipairs this does exactly the same but will iterate the list in the order of the keys so if you had a list with numerical key values it would give them to you in the numerical order. 'pairs' gives them back in the order they were defined.

So

A={}

A[1] = "one"
A[3] = "three"
A[5] = "five"
A[2] = "two"
A[4] = "four"

for k, v in pairs(A) would give you back
k v
1 "one"
3 "three"
etc

whereas
for k, v in ipairs(A) would give you back
k v
1 "one"
2 "two"
3 "three"
etc

Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:46
I'll let you figure that one out, start by adding it as it is to see what it does, then tweak the x,y values till it is positioned correctly, finally alter it to show the count variable.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:48
Oh so K and V are there just to represent key and values? Oooh, so would ipairs be more helpful to use then?
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 22:51
pairs is safer as ipairs will stop if it hits a 'nil' value. For simply counting the number of something it doesn't really matter what order you iterate the list.

Play around with them yourself and make sure you understand how they work.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 22:55
Will do, thanks! I'm assuming you understand the code i found a few posts back from somebody else, one last thing, I just want to know how to put the enemy count in a panel at the top of the screen, using the code somebody posted as a basis, cause it would be so much better as i cant even see the prompts to open gates, pick up weapons, dialogue etc.
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 17th Feb 2017 23:11
Sure, it's basically the same as the code from my ball game, as I said just copy it into your script to see what it does then tweak it to display the counts.
Been there, done that, got all the T-Shirts!
PM
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 23:13
Okay will do, thank you!
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080
ZephaHD
8
Years of Service
User Offline
Joined: 19th Mar 2016
Playing:
Posted: 17th Feb 2017 23:18
I think I've got it! Thanks for all the help
GTX 970 Strix, Intel I7 870 (4 cores) -2.9GHz, 16GB RAM, 1920x1080

Login to post a reply

Server time is: 2024-04-19 19:48:22
Your offset time is: 2024-04-19 19:48:22