Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

FPSC Classic Scripts / how to make itens apearing randomly?

Author
Message
wandering_eye
12
Years of Service
User Offline
Joined: 11th Oct 2012
Location:
Posted: 17th Oct 2012 19:45
Hey guys, I need some tips on what would be the best aproach to do this:

In my game, there's a point where the player must collect "X" (let's say 10) itens. But those itens appear at random places troughout the level (
). After the player finds the "10" itens, a message appear telling him to escape the place.

Seems simple, I supose. But what would be the best aproach to do it?

"Wherever you go, there you are."
Toffeemouse
14
Years of Service
User Offline
Joined: 29th Apr 2010
Location: United Kingdom
Posted: 18th Oct 2012 14:21 Edited at: 18th Oct 2012 14:23
I am currently looking into the same concept, i would need different types of crate to spawn every time a player attempted a level, so the same level has different outcomes every time.

I have not actually got to the stage where i should be figuring it out yet but I have given it a little thought and this is where I would start:


Choose your spawn points, say theres 30 different places in your level where the item could "randomly" spawn. Then place all 10 of your items at each location, set their spawn timers all to a couple of seconds BUT add a very short random variable in "spawn random" and set spawn at start to: no.

Then finally set "number to spawn" and "max at any time" to 1.

The item with the quickest spawn timer will be the first to spawn and all the rest wont be able to spawn due to the "max at any time".

The only issue I can foresee is the possibility that another of the same item may spawn in a different location as soon as you pick the item up. If FPSC could somehow still register the item still "existing" after its been picked up by the player that problem should be resolved. If there isn't a better way it might be worth now looking into a script that could do that. I sadly seem to be more of a stealer and modifier than an actual scripter.



Fenwolf
13
Years of Service
User Offline
Joined: 24th Oct 2011
Location: United States
Posted: 19th Oct 2012 02:11
I'm not sure if this is what you're looking for or not, but I'll give it a try.

I'd create a script named such as this: populatelevelx.fpi

X would be the level number that is to be populated. Following is a simple script with only three instances of two items.



Your map would contain three instances of each item. The items must be named in an unique manner as shown in the script. All items are set to not appear at start but to wait to be spawned. The script above would be applied to a trigger zone outside the area of play or assigned to a dynamic light. Upon execution of the level, the script will determine which "random" items to generate. Needless to say, the script could be much more complicated and address many more items.

Another script would be used to keep count of the items collected and to display the message you want. As with the above script, the count script would be attached to a trigger zone or dynamic light. Remember also that each item must have a pickup script attached to it and that these scripts must increment the count.

Life is about living.
maho76
13
Years of Service
User Offline
Joined: 31st May 2011
Location: universe-hub, playing the flute
Posted: 19th Oct 2012 12:36
Quote: "settargetname=Flower 1

settargetname=Grainbag A"


etc.

this naming wont work because of the spaceletters in it, you have to write "Flower_1" or "flower1" etc.

just for info.

Fenwolf
13
Years of Service
User Offline
Joined: 24th Oct 2011
Location: United States
Posted: 20th Oct 2012 06:15
@maho76
Not so. I get entities to generate properly even with a space in the entity name. I do agree, however, that good naming convention would dictate the use of the grave, as in Flower_1 or no space as in Flower1. Actually, I typically name entities as you indicate or by running words together, as in BuddingFlowers.

The code I posted was a script from one of my old games and was meant only as an example of how to populate a level randomly. I suppose I could have taken the time to write a new script or at least edit the old script before posting it. The script does, however, function as it should, although other methods of naming entities are certainly better than using spaces within the name. This I do not argue.

Life is about living.
wandering_eye
12
Years of Service
User Offline
Joined: 11th Oct 2012
Location:
Posted: 21st Oct 2012 20:11
Thx Fenwolf, that script of yours works like a charm! However, is it possible to keep track of the total number of collected itens, throughout diferent maps(lvls)?
I'm not sure I'm explaning myself well. In my game, I'll have like 3-4 maps, and after going in each one and collecting these special itens, the player must have a total of X (let's say 10 again) itens.

anyway, thx again for the populatelvl script!

"Wherever you go, there you are."
Fenwolf
13
Years of Service
User Offline
Joined: 24th Oct 2011
Location: United States
Posted: 22nd Oct 2012 05:53
@wandering_eye
Glad you found the populate script of use. Let's see what can be done for your additional questions.

Although it is ultimately up to the game developer to craft his game, I'll give you some guidance along the lines you request.

In order to fully implement what you want, you'll need to do the following:

1. populate your levels with the random items.
2. declare a variable by use of a declare variables script.
3. assign a pickup script to each random item.
4. assign a script to determine if the needed items have been gathered.

Let's start with the script that will declare a variable to be used in your levels. The value that is held in this variable should be passed from level to level. For example, if the value of "items" is 4 upon leaving level 2, it will be 4 upon beginning level 3. Here is a sample script to declare a variable:



You might name this script DeclareVariables.fpi then attach it to a trigger zone of dynamic light so that the script activates at the beginning of the level. Variables MUST be declared before any action can be taken on that variable.

Now that we have a variable declared, in this case "items", we can create a script that will be attached to each random item that the player must gather. The script should be assigned to the "Main" of the random entities. You might name this script TakeItem.fpi. Here are a couple examples.

The first is quite simple:



The first script simply checks to see if the player is within close proximity to the item. If so, the item is taken and the variable is incremented.

This second script is somewhat more complicated and makes uses of the mouse button (note that you also can use the action key, which is the "ENTER" key, simply by editing the code:



When using the second script, the player is given a choice whether to pick up an item or not.

Note, however, that if the player carries a weapon, the script must be edited to put away the player weapon and disable its selection until a choice has been made concerning the item. Note further that when using a script such as the second example that the use of a small hand hud or some other hud assists in acquiring the item in the exact center of the screen. The hand hud would be assigned to the center of the screen so that he player can see when he has placed the hand directly over the item.

Okay, now we have a means to pick up items and to add the value of 1 each time an item is acquired. Next, we need to have a script check to see if the required items have been gathered.

You could name this script CheckCount.fpi:



Hope all this makes sense and will be of help. You can improve your scripting skills by reading the community guides and script syntax guides that are available. Watch the forums closely. Much can be learned from the responses to others questions. Good luck.

Life is about living.
wandering_eye
12
Years of Service
User Offline
Joined: 11th Oct 2012
Location:
Posted: 24th Oct 2012 04:30
Thx Fenwolf, you helped a lot! =D
I'm toying with the scripts right now, and trying to learn a thing or two from the community guides.
However, there's still one thing I don't get it: does global variables retain their values if you change lvls (maps)? A few threads say it does, while others deny it. I need to know cause in my game the player must collect those itens from diferent maps...

"Wherever you go, there you are."
Fenwolf
13
Years of Service
User Offline
Joined: 24th Oct 2011
Location: United States
Posted: 25th Oct 2012 00:32
Any named variable, such as those in a DeclareVariable.fpi script will continued from level to level and can be affected on each level. I've used this method for handling variables since named variables became available. Because the values will continue from level to level, you may encounter a problem if the player dies and a new game is begun. You can fix this by assigning null values to your variable script. Using the script in my previous post, you would adjust the second line to set the variable to 0.



Life is about living.
wandering_eye
12
Years of Service
User Offline
Joined: 11th Oct 2012
Location:
Posted: 31st Oct 2012 16:06
Thx again Fenwolf. Sorry for keeping asking stuff, but I changed your CheckCount.fpi to display some text, but the txt is not disapearing from screen. I don't know what's wrong with it..



"Wherever you go, there you are."
Fenwolf
13
Years of Service
User Offline
Joined: 24th Oct 2011
Location: United States
Posted: 31st Oct 2012 19:52
Hey wandering_eye, you're close on what you need. In the code snippet you posted, you have a couple mistakes. In the third instance of state=3 you have a : (colon) where you should have a , (comma). In addition, you have the etimerstart in the wrong place. The etimerstart needs to go in a previous state, such as:

:state=0,varequal=items 2:etimerstart,state=3

By placing the etimerstart in state=3, the etimer will start repeatedly, ie. whenever that line of script is read. Therefore, the etimer can never reach 500.

As for the line in general, it should be done in this manner:

:state=3,etimergreater=2000:state=4

Note that I increased the number for etimergreater. Using 500 means that the text will only display for half a second. That isn't enough time to read the text.

Back to the placing of the colon... Because etimergreater is a condition rather than a command, it must be paired with the state=3 condition. Lines of code are handled in this manner:

:conditions:commands

I also noticed that you generally spell "items" as "itens". Make sure your spelling is consistent when dealing with variables.

Make the changes I've suggested and your script should work properly.

Life is about living.
wandering_eye
12
Years of Service
User Offline
Joined: 11th Oct 2012
Location:
Posted: 31st Oct 2012 21:04
Truly. It worked flawlessly. Thx for the tips and all! You're really helped a lot!

"Wherever you go, there you are."

Login to post a reply

Server time is: 2024-11-23 20:10:16
Your offset time is: 2024-11-23 20:10:16