Nicolas Eymerich 0 Posted September 7, 2006 Hi guys:who can explain me how does the function "set" works? This is the problem: At the moment I've two array. In the first one it is stored the crew vehicle. In second one it is stored only the vehicle. Sounds like this: P_Tank = [] P_Crew = [] P_Tank = P_Tank + [_vehicle] P_Crew = P_Crew + [units _team] And _team and _vehicle are two local variable in the script. Now, any time the vehicle is destroyed, I've to reneitialise the array. P_Tank = [] Due to fact i'm using over 150 global variable It would be preferable to get one single array to store both: _team and _vehicle. Something like this P_Tank = [] P_Tank = P_Tank + [[_vehicle], [_team]] So when the vehicle is destroyed P_tank should look like this P_Tank = [[], [_team]] The question is how do i do this? I've thought about the set command but it's quite unclear for me. Thanks in advance... Share this post Link to post Share on other sites
kutya 0 Posted September 7, 2006 Didn't work with this, but I've seen some functions at OFPEC about this. You should look there (in the functions area). There is also some tut on processing functions which could come in handy if you didn't do it before. BTW It's Seth (the son) Share this post Link to post Share on other sites
UNN 0 Posted September 7, 2006 The most efficient way of doing it would be: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">P_Crew=P_Crew+[[units _team]] _CrewID=(Count P_Crew)-1 P_Tank=P_Tank+[[_Vehicle,(P_Crew Select _CrewID)]] _TankID=(Count P_Tank)-1 _Vehicle AddEventHandler ["killed",Format ["([%1]+_This) Exec {TankKilled.sqs}",_TankID]] TankKilled.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_TankID=_This Select 0 _Tank=_This Select 1 (P_Tank Select _TankID) Set [0,ObjNull] I'm setting just the destroyed tank to ObjNull, rather than removing the tank and the team from the array. Did you want to do something with the team after the tanks is destroyed? There are other ways that might be easier, but this is the most efficient. BTW I'm assuming you only have one vehicle per team? Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted September 8, 2006 Quote[/b] ]BTW It's Seth (the son) --> --> Thanks, I did'nt know his english real name... Thanks to both of us for the replies... About Unn ideas it ia a really good one... but it doesn't suit my need. That's because I've said only a part of the problem. Sorry... I'm trying fo fix some problem (before the realese) in the mission I'm working on. In particular, you're able to purchase differents vehicles. Now let's focus on the tank array (which is the same as apc, plane or chopper but not for infantry units). Once the vehicle (i.e: the tank) is destroyed, I reinitialise the related array. So: If you buy the tank the first time, you have this array: P_tank = [_vehicle] When the tank is destroyed the global array is P_Tank = [] And another global variable allow to purchase again the vehicle destroyed. When you purchase the second time the array is again P_Tank = [_vehcile] and so on... and any time the tank is destroyed the related array is: P_Tank = []. Okay, now, but this is due to a lack of my knowledge, if I set 0 the first element of the tank array, I don't know as I can use again the same array for a new tank. All I need is a function that removes the first element of the array making it looks like : P_Tank = [[],[units _team]] and another function that add an element to the first element of the array P_Tank = [[_vehicle], [units _team]] Please note: I've written "function" in the reply. If they're not too complicated I'm able to script them... In any case, I'd like to know how to realize this idea (unless, of course, if is it possible). About the crew vehicle (btw: did you realise that if put the vehicle's crew in an empty created unit, The function "crew" doesn't works?), well, it is nearly invincible. Due to the 63 side groups limitation, the crew is killed and instantly set on another part of the island. In this way, since you've already created the crew, I've avoided Flashpoint's lag related to the "createunit" function. And yes, Only one vehicle for unit (but it would be quite simple to adding more). Share this post Link to post Share on other sites
UNN 0 Posted September 8, 2006 Hi, It is a little confusing trying work out what you want to do, but I think that’s down to the way you have your arrays setup? When an array is written like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[[_vehicle], [units _team]] It suggest there will be more than one item in both elements i.e: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[[_vehicle1,_vehicle2,_vehicle3],[_team1,_team2,_team3]] Which is fine if there are, or you just want to add support for more than sooner rather than later. But as you start adding more vehicles using: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">P_Tank = P_Tank + [[_vehicle], [_team]] Your P_Tank array would look like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[[_vehicle1],[_team1],[_vehicle2],[_team2],[_vehicle3],[_team3]] Which would make it more complicated than, perhaps it needs to be? To make it easier to track down the Tank you want to change, I would structure the array like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[[_vehicle1,_team1],[_vehicle2,_team2],[_vehicle3,_team3]] And add new Tanks to it using this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">P_Tank = P_Tank + [[_vehicle,_team]] But without knowing how you use the P_Tank array elsewhere in your code, I can only guess. You may have set your array up like that for a reason? I can answer your original question, to a certain degree. To remove the Tank from your array where: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">P_Tank = [[_vehicle], [units _team]] You would use: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">(P_Tank Select 0) Set [0,[]] Hopefully that will solve your problem. But like I said, as soon as you start adding more tanks, it will be a pain to manage with scripts. If you could explain more about how you use P_Tank in the rest of your scripts. I'm sure you could simplify your scripts and make life a bit easier for yourself. Quote[/b] ]btw: did you realise that if put the vehicle's crew in an empty created unit, The function "crew" doesn't works There could be a few different reasons why this is happening, crewing an empty vehicle requires a valid group to add the units to with the createunit command. Otherwise they do not respond to any orders. When you display the result of the Crew command using a hint, does it return something like? Quote[/b] ][No Group,No Group,No Group] But if you have that side of things working there is probably no need to worry about it. Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted September 8, 2006 Really thanks for you reply... Quote[/b] ]It suggest there will be more than one item in both elements i.e: Code Sample [[_vehicle1,_vehicle2,_vehicle3],[_team1,_team2,_team3]] Which is fine if there are, or you just want to add support for more than sooner rather than later. This were the original idea. But due to a lack's time I was forced to semplify so I've added only one vehicle. Okay.. I'm going to show depper my scripts... By the action command, you can purchase differents objects. Any action launch a script which creates the related unit. _Vehicle = (Global Array) createvehicle getpos P_Tank = P_tank + [_vehicle] --> global array is choosen by the user in one of my script In this way, you can choose your own add ons to use on the battlefield. Any unit has its own personal array. So for tank1 you've P_tank1; for Tank2 you've P_tank2 and so 'till tank five. This is the same for any other units you purchase. In Those array, however, it is stored only the vehicle created. I've add another array which is called P_crew1 which store the crew for the array's related vehicle. So: You've 2 array for any unit: P_crew1 = [_driver, _gunner, _commander] P_Tank1 = [_vehicle] and so on P_crew2 = [_driver, _gunner, _commander] P_Tank2 = [_vehicle] I've used this idea for any (except infantry because there you don't need to have a 2d array) other unit you purchase. This were the fastest way to achieve my purpose. But as often happens, this is also the more complicated too (and infact, even if now is it all working, I've had several headache in debugging it). Once you've the information stored in a global array, it's quite simple to "control" them over the battlefield. Infact In the "move" action tree you've two option: Support and set waypoint (for any team you've purchased). Those actions, on the other hand, launch a general script which give the order to the troops and check the status of the vehicle. Those scripts are almost egual and infact, in the script itself, you've displayed something like that: (get the commander) \ get the tank vehicle _crew = P_crew select 2; _tank = P_tank1 select 0 Now... Since you're on a battlefield, there some condition inside a loop to check if unit is alive or dead (Unit is only vehicle because crew, once have been created can't die). So when the loop discover that the vehicle is dead or isn't moving then a variable remove the vehicle from the P_Tank1 and reinitialise it. P_Tank1 = [] In my original version of the script, I've used your first idea: Store in a global array the vehicle as well the crew. ;in the createunit script P_Tank = [] P_tank = P_tank + [_vehicle, units _team] And then, when the vehicle is destroyed on the battlefield i was use to write: {Deletevehicle _x} foreach P_Tank; P_tank = [] In this case, however, I've to create any time a crew squadron. Now, considering the limit of 63 group I was afraid player would reach it, when he was near to complete the mission. As I've said, createunit also give a lag which is not good for the game experience. So, due to my lack of knowledge about scripting, I've choosed the fastest way: Use two different global array (one for crew and the other for the vehicle). Now, the mission is almost finished and, since it works i wuold like to improve it. Having a look of some function I've noticed the Set function but it's own way of working still remain unclear... I hope it's more clear what I've tried to do. Share this post Link to post Share on other sites
UNN 0 Posted September 8, 2006 Quote[/b] ]I hope it's more clear what I've tried to do. Yeah, although I'm not sure how you create your global variables PTank1,PTank2...e.t.c at the start. Are they pre-defined or do you create the variables during the mission like this: AddVehicle.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Vehicle = (Global Array) createvehicle getpos P_Tank = P_tank + [_vehicle] Call {Format ["P_Tank%1=[_Vehicle]",Count P_Tank]} Which results in a global variable called P_Tank1, pointing to the first vehicle in the P_Tank array. With subsequent calls resulting in P_Tank2 pointing to the second tank in the array....and so on. Sorry I can only offer more questions instead of an answers atm. But it does help if I understand the bigger picture. Because you need the same data stored in two or three different variables. I'm trying to work out if there is a way to update them all, with one command launched from the killed event. Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted September 11, 2006 Thanks again for your reply and sorry for mine (I haven't internet so the only way I can use it is when i'm at work). Thanks also for trying to help me. I've really appreciated it. Quote[/b] ]Yeah, although I'm not sure how you create your global variables PTank1,PTank2...e.t.c at the start. Are they pre-defined or do you create the variables during the mission Any Global Array (P_tank1, P_tank2 ...; P_Apc1 P_apc2...) is intialisated at the beginning of the mission in the init file. It looks like this: P_Tank1= []; P_T_Crew1= [] P_Tank2 =[]; P_T_Crew2= [] P_Tank3 =[]; P_T_Crew3= [] P_Tank4= []; P_T_Crew4= [] P_Tank5= []; P_T_Crew5= [] P_apc1 = []; P_L_Crew1 = []; P_apc2 = []; P_L_Crew2 = []; P_apc3 = []; P_L_Crew3 = []; P_apc4 = []; P_L_Crew4 = []; P_apc5 = []; P_L_Crew5 = []; and so on (except for infantry unit. In this last case there's 1 gloabal array for a single group) Quote[/b] ]_Vehicle = (Global Array) createvehicle getpos P_Tank = P_tank + [_vehicle] Call {Format ["P_Tank%1=[_Vehicle]",Count P_Tank]} Which results in a global variable called P_Tank1, pointing to the first vehicle in the P_Tank array. With subsequent calls resulting in P_Tank2 pointing to the second tank in the array....and so on. Fine and interesting idea. One global array (P_tank) for all tank unit. But you've also 6 global variables. (P_tank + the different global variables created by the call function [AT least: I think so]). Instead I've used only 5 global variables. Besides, I've not understand, how can you reinitialise the array after that the related unit dies. By the way, I was forgetting something much important: Due to the fact that Action given are static (I mean you can't manipulated it as an array, but you've do define first the action and then the code to execute) any global array must be related to a specific action. In particular (in the Purchase Menu) "T-80" --> is related to the first Global Array (P_Tank1) "Black Eagle" --> is related to the second Global Array (P_Tank1) "M1A2" --> is related to the third Global Array (P_Tank1) So, If you want to purchase only the M1A2 the tank global array should look like this: P_Tank = [ [], [],[_vehicle], [], [] ] If you decide to purchase also the t-80 then the P_tank should look like this P_Tank = [ [_vehicle], [], [_vehicle], [], [] ] As far as I know, you can't do this with the function: P_tank = P_tank + [_vehicle] In this case, If you buy the first and the third tank (the t-80 and the m1a2) you 've something like this: P_tank = [ [_vehicle], [_vehicle],[], [],[] ] And when you launch the Move script it doesn't works (because any action is relate to a specific unit array). Quite complicated don't you think? And because of this I consider myself as a mediocre scripter  Regards Nicolas Share this post Link to post Share on other sites
UNN 0 Posted September 12, 2006 So the player has an option to purchase upto three tanks in one session, if he wants to? I say session, for want of a better word. It could be per mission or time period e.t.c He then has for example, options to issue orders to any of these tanks. Order T80 to Move to XYZ Order Black Eagle to Move to XYZ Order M1A2 to Move to XYZ Is this for Multi Player btw? I'm trying to work out if you have P_Tank1 assigned to a particular player or AI. Perhaps it would be better if you could send me the mission your working on? Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted September 13, 2006 Quote[/b] ]So the player has an option to purchase upto three tanks in one session, if he wants to? To be honest... up to five. At the moment only three are tested. However, user can choose to increase the number to 5 for any kind of units he wants (apc, Chopper, Plane, tank) Quote[/b] ]He then has for example, options to issue orders to any of these tanks. Order T80 to Move to XYZ Order Black Eagle to Move to XYZ Order M1A2 to Move to XYZ Yes... Btw, user can choose also the name of the unit he has choosen for this mission Quote[/b] ]Is this for Multi Player? At the momento no. Ofp Mp scriptin is a tricky beast... But with a little of work, it should be possible to convert the mission for mp. I'm not interested, at least at the moment, in doing that. Quote[/b] ]I'm trying to work out if you have P_Tank1 assigned to a particular player or AI. Sorry... Don't get it. The global variables (array) are all related to unit controlled by Pc (in other words, they aren't playable). Quote[/b] ]Perhaps it would be better if you could send me the mission your working on? There're two problems: 1) Altgough the mission isentered in Beta Stage, at the moment some things must be corrected (some actions aren't removed and some othr things aren't completed). 2) If you're interested as Beta Tester, send me a Pm Regards Nicolas p.s One more thing: I've just noticed a mistake in one of my post: I've written this: Quote[/b] ]"T-80" --> is related to the first Global Array (P_Tank1) "Black Eagle" --> is related to the second Global Array (P_Tank1) "M1A2" --> is related to the third Global Array (P_Tank1) Instead it is: "T-80" --> is related to the first Global Array (P_Tank1) "Black Eagle" --> is related to the second Global Array (P_Tank2) "M1A2" --> is related to the third Global Array (P_Tank3) p.p.s By the Way, Have a look here: http://www.flashpoint1985.com/cgi-bin....t=53594 Share this post Link to post Share on other sites