Home   Help Search Login Register  

Author Topic: Repeated object spawning  (Read 731 times)

0 Members and 1 Guest are viewing this topic.

Grunt249

  • Guest
Repeated object spawning
« on: 13 Mar 2005, 02:34:55 »
I am in the process of making some missions, and have thought of an idea to help reduce lag during those missions. I don't know if this idea has been mentioned before, I couldn't find anything like it either here or on the BI Forums. So if it has been discussed, please forgive this thread and provide a link to the previous post.


The idea is that objects placed on a map during a mission that are always there, such as base objects, can be spawned when the player is close by and removed when he leaves the area. A trigger will detect if the player returns to a certain distance within those objects and will spawn them only when he is close enough to see them. This is very similar to the method of spawning enemy soldiers on a mission to help reduce the lag as well.

I have seen scripts that allow you to create objects, but what about spawning them and removing them multiple times from the same mission? And how smoothly would something like this work? I think the best way is to detect if the player is out of range, and if so it delays say 10 seconds before the items are removed. If the player moves back into range, they are created instantly. This would repeat as often as needed, and would only be needed for objects, not personnel.

Making the scripts would be fairly easy in regards to items and positions. You just use the mission.sqm file for object locations and names. By doing it in sections, you will have multiple areas that use this method. Problem is that I don't know how to write a script to do this. Maybe someone has a little free time to help me out? Also, do you scripters think that a method like this would help reduce lag on some of the bigger missions?

Any help is appreciated, thanks in advance.

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Repeated object spawning
« Reply #1 on: 26 Mar 2005, 04:42:36 »
Hi Grunt

There are two scripts that use this effect with good results.

One is the uwar_grass script - definitely worth a download for the grass objects alone !  The script creates 50-100 grass objects centred on the player, then moves them as you move giving the effect of moving through endless undergrowth.  It doesn't work well in towns or moving across runways (  :P ) but looks great in a wilderness setting !

The second is a sandstorm script that creates a cloud of endlessly spawning semi transparent particles, again centred on the player.  This creates a very realistic sandstorm/rainstorm/duststorm/hailstorm effect (depending on how you set the particle variables), unfortunately in MP you need multiple version running which can cause some lag.

On another front, I am working on something like the scenario you mentioned for a mob-style assassination mission.  It will be based on Everon and will be played across the entire map.

I am going to have key figures at fixed spots throughout the island (arms suppliers, informants, goons for hire etc), with 3-4 "floating" groups of wandering civilians that will blink to wherever the players happen to be.

The civvie groups will automatically respawn any losses they take using a respawn script which will check their group count every 3 seconds or so, and will roam around town using a custom made "mingle" script that uses semi-random doMoves around a fixed spot.

The "blink" script will check the players' positions every 5 seconds or so (yes, this will be MP !) and will automatically move the entire group to the nearest town to each player.  If that town already has a civvie group assigned to it then the script will move the next civvie group to the next closest town, and so on.

The movement part won't be too hard to do.  I am going to place a named gamelogic in each town, each cycle the script will check the distance betwen the first player and each gamelogic and keep the co-ordinates of the closest one.  It will then blink in the leader of the first civvie group, record the offset from its origin to its destination, then apply this offset to each other member of the group.  Voila - instant group teleport !

The hard part is the check for the remaining players.  I have to check THEIR closest gamegic above, but if that is occupied then I will have to disregard this point.  This shouldn't be too hard but I just have to get my brain around the coding, not easy with three kids and heaps of RL work to distract me !

I think that four groups should do the job - if you check Everon you'll notice that here are very few places that you can stand that you can see more than four towns at once.  Of course, once the script is running I may find it easier to do more . . .

If you want a copy of it when it's done then ping me in about 2-3 weeks time.

cheers



roni

Grunt249

  • Guest
Re:Repeated object spawning
« Reply #2 on: 26 Mar 2005, 16:07:50 »
@Roni

Infortunately, the scripts you mentioned don't cover my situation. I need a script that will simply spawn a multiple set of objects at a given location when the player is within a trigger, and will remove them when player is out of the trigger. The objects will be placed in the same geographical spot each time, not around the player. There is no need for a looping script, the trigger activation will do fine for my needs which will also reduce chance of lag.

Mostly what I need is to have bases and towns set up in advance with buildings, objects, empty vehicles, etc. To reduce the number of units and objects on the map at any given time, this script will spawn objects only within range of the player. All other scripted areas will be empty until the player moves within range, and each area will have its own trigger and placement script.

In some areas, I would like to spawn groups of soldiers or civilians that have pre-set waypoints. Every time the units are respawned, they need to begin moving through those waypoints, to simulate activity in those bases and towns. So each spawn script will include the placement of objects and units, and to make sure that every time, those units have the same waypoints and actions. A seperate script would be used for each area, mostly the same thing each time just different objects and locations.


I guess right now I need help with how to do a few things.

1) How do I make a trigger activated by the player only, and not other units? In other words, instead of activated by West, East, etc. I want only the player to be able to activate the script, regardless if another unit happens to be present or not.

2) Are there any scripts or tutorials that I might have missed that include spawning buildings based on the data from the mission.sqm file (This includes object name, position, and direction)?

For the spawning of units with waypoints intact, I'll look at the unit spawn scripts again as I'm sure it's covered there.


I appreciate the help so far, and hope more people can contribute a few ideas or suggestions. Thanks.

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Repeated object spawning
« Reply #3 on: 27 Mar 2005, 00:35:33 »
Hi Grunt249

A couple of points.

First, AFAIK a trigger actually checks its activation criteria as fast as the system will allow - it's the same as putting a "@condition" line in a script.  You can save on CPU time by having a script running that loops every (say) 3-5 seconds instead.  Depending upon the number of these "instant bases" you want this may save quite some lag.

Second, the creation and removal of units on demand just seems to me to be very coding intensive.  Let's say you want to create an instand base with (say) three groups with 2-3 waypoints each, some objects and some static scenery (parked vehicles etc).

You may have 3-4 dozen objects to place.  Not too difficult, but you would have to record their types and starting locations and put this in to an array, which is "dumped" every time the condition is met.  Sort of like this -

_instantObjects = ["BMP", "BMP" etc . . .]
_instantObjectLocations = [[253,179,0],[333,456,0], etc . . .]

#awayLoop
~5
If player more than 300m from named gamelogic then goto "awayLoop"

<create and place all objects and waypoints>

#nearbyLoop
~5
If player still within 300m of named gamelogic then goto "nearbyLoop"

<remove all objects and waypoints>

goto "awayLoop"


That should do the trick.  I think the easiest way to get all the necessary data would be to put them in the mission, save the .sqm, go out of the game and cut and paste the units and their locations to a text file, then reformat them in to the .sqs file.  Then go back in to the game and delete them and let the script create them as and when required.

Alternatively, I just realised that you COULD have all units etc start in the game.  Then just have the above script delete everything that is more than the specified range away from the player and record these objects positions for later recreation.  A bit of lag at the start but this would save on a lot of coding . . .

Finally, there is a simple way to make just the player activate a trigger, but I'm not exacty sure of the syntax.  In the activation field of the trigger put something like - "player in _this".  Not sure if this is right but I do know that it's dead simple.

Cheers



roni