Scripts / shoot entity and spawn another entity- Need help please.

Author
Message
Disturbing 13
3D Media Maker
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Murder Capital of the World
Posted: 7th Aug 2015 01:02
Greetings all. Let me preface this by saying I am not a scripter in the least. In the past I have understood enough to piece together parts of scripts to get things going. Unfortunately this doesn't seem to work for me in LUA. Basicly what I am trying to do is shoot an object and spawn a different object when the initial objects health is zero. I was able to do this in FPSCclassic and tried to copy and paste LUA script parts to get this going. Could someone take a look at the script and tell me where I am going wrong? Here is the script. Thanks to all who help.


Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 7th Aug 2015 01:56
I would look at the soldier script. It handles health in the following way.

Variable are set up above the Init part to handle this.
A bit more then shown, but the way Lee explained it on Twitch was that the ai_Starting_health[e] was equal to the strength set in the FPE file, then you compare that and subtract it based on the variable.


-- Handle health
if ai_starting_heath[e] == nil then
ai_starting_heath[e] = g_Entity[e]['health']
end


ai_old_health[e] = g_Entity[e]['health']
[\code]


The other thing I noticed, is that the destroy command should be after the ActivateIfUsed(e) part or it will never get to the activateifused, because the entity will destroyed before the call.

Not much help, but maybe someone else can chime in.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit

Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 7th Aug 2015 11:54 Edited at: 7th Aug 2015 11:56


If you have more questions just ask
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 7th Aug 2015 12:09
Guys, I think he want spawn something when other being destroyed.

I've realize this 2 scripts that a least for me does the trick.

barrel_acid.lua - intended to be attached to the barrel being spawned. (barrel_acid)



spawnshot.lua - intended to be attached to the barrel (explosive)



In action



hth

3com

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 8.1 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 7th Aug 2015 12:18
ok now i understand
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Disturbing 13
3D Media Maker
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Murder Capital of the World
Posted: 7th Aug 2015 14:17 Edited at: 7th Aug 2015 14:19
That's perfect! Thank you guys for looking into this! I hate to ask but could it be brought one step further, to where when the spawned acid barrel is destroyed it produces a third entity and so on? The game I'm working on is predicated on that whole mechanic where you have to find things in a specific order. Could I just add what makes the explosive barrel work to the acid barrel script and have it spawn a third entity after that. This way I can make a more open world feel with missions that aren;t all spawned at once in a single level.

I'm not sure how malable LUA scripts are so I'm not sure if the old copy and paste function methods work. Would this work?
This attatched to the acid barrel



3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 7th Aug 2015 15:41
Easy way (therefore more work involved )

barrel_acid.lua



barrel_hazard.lua



dented_barrel.lua



empty_barrel.lua



In action



3 barrels I have taken as an example, each script has the name of its corresponding barrel, so it is easier to identify.

I just showed you the way to go, if you have further questions, feel free to do it, someone will come here with the answer, or even me.

3com




Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 8.1 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
Disturbing 13
3D Media Maker
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Murder Capital of the World
Posted: 7th Aug 2015 22:14
@3com- Thank you so much! I didn't realize a separate script would be needed for each item but hey if that's how lua works then that's how it works., but yeah you are right, it will help me keep track of my items much easier. Again thanks!


smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th Aug 2015 00:35
i think you can just put 'ActivateIfUsed(e)' in the exit(e) part of the script and then type the name of the entity to spawn in the ifused field
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Disturbing 13
3D Media Maker
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Murder Capital of the World
Posted: 8th Aug 2015 01:14
@ smallg- you would think so but I've tried so many variations of that before I asked for help on the script; it kept crashing GG. I was hoping it would have been something like that so I could just fill in the ifused field and use the same script for everything like in classic. But this method works so i'll go with it for now, just have to get it to work with non explodable objects now. It works on soldiers but many of the items i'm using it on will be just non exploding inanimate objects. If you find a way to make it simpler, I would love it, but I tried it this way and it works well.


3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 8th Aug 2015 15:00
The really solution would be GG done the chance to create/place/clone entities at fly, so we can create then just when needed.
When you spawn entity, you should to place them on the map before do nothing, and as bonus, they are wasting memory even so they are hidden/unspawned, so this does not reprent any memory gain.

But, if you've able to place a soldier (do not want to say create, since he already exists), in the place you want to, something like:
PlaceEntity("masked soldier",x, y, z, v), "v" being the amount of entities you want to. Even you could place one and clone instances as much as you want to.

@ Disturbing 13
you are welcome.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 8.1 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 10:39
could this be applied to the Ai solder or maybe even the zombies so it will spawn a zombie once one dies
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2015 20:20 Edited at: 22nd Sep 2015 20:26
Quote: "could this be applied to the Ai solder or maybe even the zombies so it will spawn a zombie once one dies"


im using an always active object to control respawning of enemies and it works fine.

you need an array to trigger when the AI dies in their respective exit(e) part
i.e. isDead[e] = 1

then in the always active entity script use a loop to check for
isDead == 1
note it's best to use a timer here so you can allow the ragdoll and player to pick up the weapons etc - but not too long or the body will get "cleaned" by the engine and the spawn wont work (might also be possible to set all AI to always active but it's generally a bad idea to keep too much always active, especially as we're talking about large waves of zombies)
if the first (body removal) timer is past then hide the body and respawn it (*important to respawn it now*) but set it's state to something that makes it inactive
now check the second condition is true and really "spawn" (technically just show") the zombie again (remember to place it first) and reset it's state back to active

some notes to remember are to get a position for the new placement (store the original starting location maybe) and to make sure you use AIEntityGoToPosition rather than or as well as SetPosition when you have the zombie hidden so that it wont try to run back to it's death location when it's reactivated (as it'll ignore the player until it gets there)
also it's best to turn collision off while it's hidden just incase the player walks into it

i used a custom AI script while doing this but as long as you adjust the ai_soldier_state it should be fine.
and this is of course to spawn the same zombie again, if you're talking about a new / different one then all you really need to do is use the Spawn(#) command


edit:
for the original question all you need is this
spawn_when_dead.lua


apply it to all barrels etc, set them dynamic and type the name of the object(s) to spawn next in the 'ifused' field
set all objects to be "spawned" as 'spawn at start' = no
kill the barrel... 1 script will work on as many objects as you wish, just keep the names used for each object unique depending on which barrel/object will spawn them
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 20:32
could you give me an explain of what you just stated please as i am not good with the AI scripts yet and i am hoping to get better thanks smallg for that tips
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2015 21:20
the end result will look something like this



& the isDead[e] = 1 at the final part of the AI script
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 21:40
i am bit confused on where all this goes i tried placing it in the AI zombie script it didnt work
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2015 21:41 Edited at: 22nd Sep 2015 21:42
nope, it would be a seperate script called by an always active object

Quote: "you need an array to trigger when the AI dies in their respective exit(e) part
i.e. isDead[e] = 1

then in the always active entity script use a loop to check for
isDead == 1"
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 22:11
so like this because i get getting isdead is nil error
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2015 22:17 Edited at: 22nd Sep 2015 22:18
you need to declare isDead first


now at the bottom of your zombie scripts you'll need to add this (depending on which script you use the exit(e) name is different of course)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 22:45
thanks so much sorry i am so tired and trying to program i am making noobish errors
PM
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 22nd Sep 2015 22:53
crap now my respawn cords arnt working idk why something about a number value
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Sep 2015 19:02
You are changing variables you haven't defined (px rather than px[a]). Change px and pz to px[a] and pz[a]. I think that should sort the issue.


SPECS: Q6600 CPU. Nvidia 660GTX. 8 Gig Memory. Win 7.
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 23rd Sep 2015 21:57
ok i got it working but after i kill the first ai solder they re spawn mags quick and they don't do the death disappear body thing and they keep re spawning faster then you could kill them also this script doesn't work on zombies for some reason i dont understand what i am doing wrong

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 26th Sep 2015 12:04
ah you need to set isDead[e] = 0 in the init(e) part of the AI script
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 27th Sep 2015 07:06
i keep getting this error every time now

error trying to index global index is_dead (a nil value)





PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Sep 2015 10:30 Edited at: 27th Sep 2015 10:32
Maybe I have is_Dead[e] = 0 inside the main(e)part of the AI script then, although not sure why that would be the problem as you have already declared it... Are you sure you were still running the respawner entity on the map?
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AstrobloodKnight
8
Years of Service
User Offline
Joined: 3rd Aug 2015
Location:
Posted: 27th Sep 2015 11:42
yes i am sure i am i have no idea why it keeps doing this could you post your respawn script so i can try it on my entities see if its my script or if its my gameguru bugging out
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Sep 2015 17:36
sorry, it's a miss-placed end statement in the respawner (i wrote it here so didn't get to test it until now)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-05-05 06:03:24
Your offset time is: 2024-05-05 06:03:24