Scripts / How to Reset level and reset Npc start Position, ( Questions )

Author
Message
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 9th Mar 2020 19:16
Ok i know this has been discuss before , but as far as i know there were no true solution.

Question 1: If player dies , how do we reset the level, so it starts from scratch ? every thing on its place?

------------------------------------------------------

Question 2: If player dies how can we transport just the NPC ( ai_soldiers ) back to there original position?

I know you can have the player start from a check point if he dies, but some time the npc starts running up to the players last potion when he dies and when the player spawn / restart then the npc are right there were you are. its frustrating
I also know that we can spawn the player in different starting points to get around this problem, but this is not one i want to use now.



Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Mar 2020 20:31
Easiest way would be to tweak the AI scripts to detect player death and put the AI back at their start point.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 9th Mar 2020 21:02
yes i agree AmenMoses , but how do one get to do this, i have tried to use these function
if ai_start_x[e] == nil then
ai_start_x[e] = g_Entity[e]['x']
ai_start_z[e] = g_Entity[e]['z']
AISetEntityControl(EntObjNo,AI_MANUAL);
end
and things like
SetPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
but i did not succeed.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Mar 2020 21:08
Ahh, well first of all you need x,y & z for positions so you need to store all three.

Secondly you may need to set the AI mode to 'limbo' or whatever it's called before moving it otherwise GG will probably not play ball.
Also it's worth putting CollisionOff(e) and CollisionOn(e) calls around the repositioning (you may also want to reset the angle as well as the position btw).
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 9th Mar 2020 21:15 Edited at: 9th Mar 2020 21:19
lol, i did not think off all that, my brain is limited. hehe
edited:
does one have to ResetPosition first and then SetPosition, or the other way around
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Mar 2020 21:24
They are basically both the same thing, personally I use different commands: PositionObject() and RotateObject().

These take the object id rather than the entity id and work directly on the physics object so are more suited to the sort of scripts I write.

Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 9th Mar 2020 21:31
Sorry to ask but cant you help with the script , i know i am not the only one that would like to have such a script,
Only if you want and have the time please make some magic.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 9th Mar 2020 21:44
Have a crack at it yourself first, you had the basic idea after all, just need to polish it a bit.

If you can't get it working, post the effort so far and I'll take a bash at it.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 9th Mar 2020 21:48
ok cool
thanks
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 9th Mar 2020 23:00
https://github.com/TheGameCreators/GameGuruRepo/issues/613
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 10th Mar 2020 11:12 Edited at: 10th Mar 2020 12:57
Ok, i have tried but i cant get the script to work. i have modify ai_soldier.lua

Quote: "Secondly you may need to set the AI mode to 'limbo' or whatever it's called before moving it otherwise GG will probably not play ball."

I dont know how this works.

I also tried the function AISetEntityPosition, but it also don't work.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 10th Mar 2020 18:14 Edited at: 10th Mar 2020 18:19
@PCS

Good start. I see that you have this;
if ai_start_x[e] == nil then <<---========= Eliminate this line -- let's do it regardless.
ai_start_x[e] = g_Entity[e]['x']
ai_start_z[e] = g_Entity[e]['z']
ai_start_y[e] = g_Entity[e]['y'] -- keep this active also

Put those in the init part of the script. You want to make them
be sure they get a value assigned. You may have to assign that
more than once-- it's kinda hard to explain...

We just want to place the NPC down when reset whether it moves
or not: (Keep it simple)
eliminate this part:

-------mod for check if ai has move from start point
tDistX = g_Entity[e]['x'] - ai_start_x[e];
tDistZ = g_Entity[e]['z'] - ai_start_z[e];
DistToStart = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistToStart > 0 then
npc_moved = 1
else
npc_moved = 0
end----------------------------------------

You'll need the CollisionOff before the move, and like AmenMoses said,
you'll need to include the 'y' coordinate.
======>>CollisionOff(e) - or this might have to call the object #? Amen knows.
PositionObject(EntObjNo,ai_start_x[e],ai_start_z[e]) -- ( this does nothing )
CollisionOn(e)- or this might have to call the object #? Amen knows.

That should get you closer- not tested.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Mar 2020 20:02
PositionObject needs x,y & z coordinates!

Pretty sure I said that already.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 10th Mar 2020 21:22 Edited at: 10th Mar 2020 21:28
Quote: "PositionObject needs x,y & z coordinates!"

Yes i know you said it , but when i use the y coordinate then i get an error.
ai_start_x[e] = nil
ai_start_z[e] = nil
--ai_start_y[e] = nil --( this gives error if used )

Please make a copy of my script i have posted, and test it out , then you will see what i mean about the error \with the y coordinates
maybe i have declared it wrong i don't know.? , but it does not want me to use the ai_start_y[e] = nil
or when i do this.:
----mod for Store ai starting point
if ai_start_x[e] == nil then
ai_start_x[e] = g_Entity[e]['x']
ai_start_z[e] = g_Entity[e]['z']
ai_start_y[e] = g_Entity[e]['y']
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Mar 2020 21:36
PositionObject( EntObjNo, ai_start_x[ e ], ai_start_y[ e ], ai_start_z[ e ] )

Ahh, you need:

ai_start_y = {}

at the top of the script.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 02:42
thanks AmenMoses,
i have tested your script , there is no errors, but Npc's do not move they stay on one place if they walk or run.

Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 11th Mar 2020 03:53
@ PCS
Wow- those fellas are deadly shooters!!
Where Amen posted--
PositionObject( EntObjNo, ai_start_x[ e ], ai_start_y[ e ], ai_start_z[ e ] )

Don't do this line the entire script-- it's only supposed to activate once
per reset of level. Maybe check and see if the original AI is still in place
running for the duration- and the line above just for restart.
Hope that's it!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Mar 2020 09:44 Edited at: 11th Mar 2020 09:46
Try this one:



Oh and increase the fire rate value for the NPCs to slow the shooting down so you live a little longer.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 10:42
with this one they move correctly but when i die i get this error

Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Mar 2020 11:17 Edited at: 11th Mar 2020 11:17
Somewhere you have an npc_moved = false which should be npc_moved[ e ] = false. (or maybe = true)

If it's not in that screipt change the lines at the top to:
local ai_start_y = {}
local npc_moved = {}
local p_dead = {}
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 12:00 Edited at: 11th Mar 2020 12:14
Thank you AmenMoses, its working 100% it was my mistake , i forgot to add the [e] at the npc_moved[ e ]
----mod for check if ai has move from start point
tDistX = Ent.x - ai_start_x[e]
tDistZ = Ent.z - ai_start_z[e]
DistToStart = tDistX*tDistX + tDistZ*tDistZ
npc_moved[ e ] = DistToStart > 1

Thank you so much, you are truly a script Guru.

So any ideas for me for Question1. before i start and break GameGuru lol
Question 1: If player dies , how do we reset the level, so it starts from scratch ? every thing on its place?
=== edited::: on second thoughts maybe it not feasible , i don't think its gone be possible with GG.


Again thank you so much AmenMoses, this was a big issue , it will make game play so much easier.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 12:58
Ok after testing this script with some of my maps, i found it to work very nice,
I did found out that the after the player died the ai will be moved back to the starting point , and then they will still make there way back to the last point were the player has died, i think its maybe because there state is still in aggro or something, but for now im happy because it takes them a while to move from there start point to were the player has died. And also if you have a check point then the player will spawn there so i am very happy.

Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Mar 2020 15:22
Yes it's very tough to get them to stop being in their old state.. you basically have to reset all the AI variables from their own scripts as well.. I had the same issue when I tried this years back
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 16:13
smallg, yes i see now difficult it is,
but for now, its not so bad if they get moved back to start point and then, it at least take them some time to get back to the player.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Mar 2020 21:07 Edited at: 11th Mar 2020 21:10
You could set the ai_bot_state list to put them back to their start state, I.e. ai_combattype_regular.

So add:
ai_bot_state[ e ] = ai_combattype_regular

That might work.
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 21:36
added ai_bot_state[ e ] = ai_combattype_regular , did not work
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Mar 2020 21:37
Well I did say 'might'
Been there, done that, got all the T-Shirts!
PM
PCS
7
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 11th Mar 2020 22:43
yes.
np , its fine the script works great for me.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11

Login to post a reply

Server time is: 2024-04-25 07:31:08
Your offset time is: 2024-04-25 07:31:08