Scripts / Random spawn location for objects

Author
Message
quake
7
Years of Service
User Offline
Joined: 10th Mar 2017
Location:
Posted: 14th Mar 2017 19:49
Hi all! I'm new on the GG's forum. I'm spending days building a beautiful map and now I need a LUA script (I suppose) to complete my game.
I would like to have a slenderman-like system: once you collect all the items in the map (eg. 8 paper pages) you win. The fact is that they should spawn in different locations every time you start a new game.

Do you have any idea? I could also pay some money if you can provide me the script if you want

PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Mar 2017 20:59 Edited at: 14th Mar 2017 21:00
probably best to set down more than you need in the editor at the desired locations and then only spawn random ones (i.e. have pages in many different locations but placed manually) rather than trying to spawn them in completely random locations (might lead to some weird locations otherwise).
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: 14th Mar 2017 21:01
Do you want the notes to lay flat or could they be at any angle?
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: 14th Mar 2017 22:59 Edited at: 14th Mar 2017 23:03
Ok, so here is one way of doing it, but it does require a bit of work.

Attach the get_pos.lua to a note entity, make it active etc. Extract it and make as many copies as you want random locations and place each one where you want the 'random' positions to be.

Now test game and visit each location (the order doesn't matter) and write down the x,y,x,ang values displayed. Transfer those details into the list in the second script.

Now delete the entities and place the 'real' notes but this time attach the second script, just plonk the enties down near the player start position and they will be randomly distributed around the positions you specified in the list (make sure you have more positions in the list than notes!). When the last note is collected the global variable g_all_notes_collected will be set true so you could use this to trigger whatever behaviour you want next.

(not quite sure how the ifused field works but that might be a neater way of triggering the next behaviour, maybe smallg can suggest how to tweak it to do it that way)

Edited to add that this assumes the notes are laying flat, if not you'll need to change it to add x & z angles as well.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 16th Mar 2017 19:34
No feedback at all? Did it do what you wanted?
Been there, done that, got all the T-Shirts!
PM
quake
7
Years of Service
User Offline
Joined: 10th Mar 2017
Location:
Posted: 18th Mar 2017 20:44
Sorry for my absence, sure I was thinking in this way to realize the task.

Quote: "Now test game and visit each location (the order doesn't matter) and write down the x,y,x,ang values displayed. Transfer those details into the list in the second script. "


I'm not able to figure out how to get coordinates. If I'm not wrong they should appear in this case: "if Ent ~= nil then" but I'm not able to figure out what I've to do!

Thank you all guys for the help, I'm glad to see such a good community around GG!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Mar 2017 21:27 Edited at: 19th Mar 2017 09:53
The script get_pos.lua should be attached to the entity you want to place (i.e. the note), make it active from the properties and then extract it and whilst holding down shift place a load of them around the map. Then position them where you want your 'random' spots to be selected from. Click the rocket and test the game, wander around to the various locations and at each one you should see the coordinates displayed on screen next to the notes.

The only editing of scripts you need to do is to change the test coordinates I put in the collect_note.lua script for the ones you wrote down (add as many as you need, just cut and paste one of the existing lines ending in a comma).

When you put your notes into the level for real you just attach the collect_note.lua script and only place however many need to be collected, the get_pos script is purely to allow you to find out the coordinates of all the 'random' spots.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Mar 2017 23:20
i actually need a script very similar to this so here you go.

place down a barrel or some other always active = yes object, give it random_note_spawner.lua
(change notes_to_collect and notes_to_spawn values in the script to match your desired gameplay)

place down a note and set to spawn at start = no, give it random_note.lua, now copy and paste it to all desired locations on the map in the editor - it will pick randomly which notes to activate in game if there are more notes placed than notes set to spawn.
(notes don't need to be always active)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
quake
7
Years of Service
User Offline
Joined: 10th Mar 2017
Location:
Posted: 22nd Mar 2017 15:47
Just tested few minutes the AmenMoses soulution and works great! I'll finish my map and then work on it. I'll look for a solution to end the game once all the items are collected but this doesen't seems too hard to do. Thank you very much!
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 22nd Mar 2017 18:10
Just tried smallg's script. Very easy to use! Thanks
PM

Login to post a reply

Server time is: 2024-12-23 04:56:59
Your offset time is: 2024-12-23 04:56:59