Scripts / [SOLVED] Need Help With Collection Scripts.

Author
Message
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 10th Oct 2020 17:36
Hi.

I have looked through the available script guides and I must say, there are quite a lot and it felt a little overwhelming looking for a specific script.
I would like to hereby request help with writing a script that requires the player to have collected an object (such as a key) to be able to collect another object like maybe a weapon. the problem here is linking to another collectable entity before collecting a specific one. For example: if the player has collected the key, then, allow player to collect the gun. Otherwise, prompt the collection of key.

I have pretty much got the pseudo-code for it, just need to implement it and they both have their own scripts, so I think my main problem here is linking them together in one script or maybe put a script in between. I am not sure.

Thank you,
Dudeson.

The author of this post has marked a post as an answer.

Go to answer
PM
smallg
Community Leader
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th Oct 2020 18:36
GG's default way of doing this is with the 'spawn at start' and 'ifused' fields so you would
1. set the 2nd object to 'spawn at start = no'
2. give the 2nd object a unique name
3. type the 2nd object's name in the 'ifused' field of the first object
4. add 'activateifused(e)' to the script when the first object is picked up
doing it this way does mean the 2nd object is not visible on the map until after the first object is collected though.

the alternative method is to set a variable to store the state of the first object and check that in an 'if' statement in the 2nd
i.e.
when you pick the first object set
keycollected = true
in the 2nd object is a script with this code
--check the key was collected
if keycollected == true then
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 10th Oct 2020 20:21
Hi smallg.

Thank you for your reply. I have tried the first method and it works even tho I had to look through the script guide on steam that you posted, thank you again. It is not convenient for the game I am trying to make but maybe I can make it work. the second method is the one giving me trouble, I have tried several codes and unfortunately, they did not work, I reached a point where I wrote a code and the engine was not showing any errors and it was not working I would just be able to pick up what I want without any order. the keycollected variable is used in both of my scripts that is how I am trying to connect them. I don't know if GG understands this.

in the second object's script, this is the code I wrore:
if key_collected == 1 then
SetActivated(e, 1)
end

in the first object's script I wrote the following:
key_collected = 0 -- at the top of the code.
inside the if g_KeyPressed == 1 loop i added key_collected = 1.

the scripts have other codes inside them.

maybe I need an else statement or the key_collected should be like key_collected(e).

Not sure.
PM
AmenMoses
GameGuru Master
4
Years of Service
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Oct 2020 21:25
g_KeyPressed wouldn't do anything.

Did you mean g_KeyPressE?
Been there, done that, got all the T-Shirts!
PM
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 10th Oct 2020 21:27
Yes that is what I meant: g_KeyPressE. Sorry.
PM
smallg
Community Leader
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Oct 2020 13:05
This post has been marked by the post author as the answer.
this should help get you in the right direction, you will want to adjust to suit your game
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 11th Oct 2020 16:12
Thank you smallg I will look into it and get back to you
PM
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 12th Oct 2020 20:35
Hello,

So I have tried the scripts provided in the video you linked and of course, watched the video, and noticed that there is a parameter where you put the name of the item you wish to unlock and I think this is not a feature of the older GG but one of GG Max, And I am unfortunately using GG. The scripts have no errors. When I tried to collect the locked item after collecting the prerequisite, it remained locked, I don't know if I had missed something in the code, where I provide the parameter of the locked item to the prerequisite, or it is just because of GG Max.

I tried to understand the code to my full extent but I feel there is a need to practice Lua with GG more.
Image 1 with Key
Image 2 key collected.

Thanks again.
PM
Belidos
3D Media Maker
5
Years of Service
Recently Online
Joined: 23rd Nov 2015
Location: Hertfordshire
Posted: 12th Oct 2020 21:23
Quote: "and I think this is not a feature of the older GG but one of GG Max, "


No it's definitely a feature of GG, has been for years

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Primary Laptop:
i5, NV1050 4GB, 8GB memory, 1x 1TB HDD, Win10.

Secondary Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
smallg
Community Leader
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Oct 2020 21:44
yes the new scripts are all for Max which has the ability to expose/change settings from within the editor so if you are using GG Classic you will need to set the values in the init(e) function manually and it should work fine
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 13th Oct 2020 00:01
Alright, it definitely works now, one problem tho, I can't use the item. I'm trying a gun and once I pick it up, I can't use it, I mean that the gun just vanishes.
PM
GubbyBlips
2
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 13th Oct 2020 03:06
@smallg
"all for Max which has the ability to expose/change settings from within the editor "

Sounds possibly confusing. But never used MAX yet, does it actually change the
script line.lua text, and re-save it? Is that how it works? Otherwise-- strange, or the
next time you load your level, it's still the original, unchanged script?

What do you see as the primary benefit of this system- just curious?
PM
AmenMoses
GameGuru Master
4
Years of Service
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Oct 2020 10:16
It's just a way of passing variables into the script, nothing really magical about it.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Oct 2020 11:24 Edited at: 13th Oct 2020 11:28
Quote: "Alright, it definitely works now, one problem tho, I can't use the item. I'm trying a gun and once I pick it up, I can't use it, I mean that the gun just vanishes."

what script do you have on the gun? you need to use AddPlayerWeapon(e) to the gun script for it to be usable - in my video i use the default weapon.lua script

Quote: "Sounds possibly confusing. But never used MAX yet, does it actually change the
script line.lua text, and re-save it? Is that how it works? Otherwise-- strange, or the
next time you load your level, it's still the original, unchanged script?"

max has an extra function called "properties" which works like the init(e) function except you can put in your own variables which will be exposed in the editor - so like the init() and main() functions pass in the 'e' or entity number you can use the properties() function to pass in your own data you type into the properties panel in the editor
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 13th Oct 2020 15:38
I added the AddPlayerWeapon command and everything seems to be working fine right now, thank you very much for your help. One last thing, are the scripts used freely?
PM
smallg
Community Leader
15
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Oct 2020 15:47
yes feel free to use my scripts in your game
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
dudeson
1
Years of Service
User Offline
Joined: 30th Mar 2019
Location:
Posted: 13th Oct 2020 15:56
Alright. Thank you very much, you have been a great deal of help, much appreciated. That pretty much settles this problem for me.
PM

Login to post a reply

Server time is: 2021-01-16 23:56:03
Your offset time is: 2021-01-16 23:56:03