OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Andy on 24 Jul 2007, 20:45:47
-
I am using the createVehicle command to dynamically create police cars. I would like to link a marker to follow each car that is created, so when I go to map view I can see where they are. Since markers can't be dynamically created, I would already have them off to the side and relocated to the new car once created.
I know that I can set a name for my new car using the "newcar1 = "Police_car" createVehicle getMarkerPos Marker1" command. If I create a second car, that car can't have the same name, so how do I refer to it?
-
_i = 1
#createcar
call (format["newcar%1", _i]) = "Police_car" createVehicle getMarkerPos format["Marker%1", _i];
_i = _i + 1
? _i < 5: goto "createcar"
Will create newcar1 for marker1, newcar2 for marker2, newcar3 for marker3 and so on.
-
I tried the script and I was able to create the vehicles, but the names weren't created for them. I can't figure out what the game named it.
-
The resulting global variables should be newcar1, newcar2, newcar3 ...
-
I know that is what they are suppossed to be, but when I tried to refer to newcar1, nothing happened. Is there a hint line that could be added to the code that would tell me exactly what the global variable created is each time I execute it?
-
_i = 1
#createcar
call (format["newcar%1", _i]) = "Police_car" createVehicle getMarkerPos format["Marker%1", _i];
hint format["%1", typeof (call (format["newcar%1", _i]))]
_i = _i + 1
? _i < 5: goto "createcar"
-
I am getting the same result and I'm not receiving the hint. I also had to change the equals sign in front of "Police_car" to a double equals. I was getting an error before that.
-
Need extra quotes around "Marker%1" ?
call (format["newcar%1", _i]) = "Police_car" createVehicle getMarkerPos format[""Marker%1"", _i]
-
Nope, format already returns an string, which is the required parameter for getMarkerPos
-
OK, this last code worked pretty well, but what I need it to do is only create one vehicle each time. Right now it is creating four cars and naming them car1, car2, car3, and car4 all at once. What I am trying to get to is to create only one car at a time and each time I execute it will name the car the next number up. Changing the 5 to a 2 in the last line will create one car each time, but names it car1 each time.
This was the code that was used:
_i = 1
#createcar
call [format["newcar%1 = ""Police_car"" createVehicle getMarkerPos format[""Marker%1""]", _i];
_i = _i + 1
? _i < 5: goto "createcar"
-
Then use a global instead of a local for _i, and initialize it outside that script, so this script only increments it.
-
Unfortunately, I don't really know how to do that. Do you have an example?
-
call [format["newcar%1 = ""Police_car"" createVehicle getMarkerPos format[""Marker%1""]", my_global_index];
my_global_index = my_global_index + 1
Before anything, for example in the init field of the player, put: my_global_index = 1
-
PERFECT!!! This worked beautifully. Thank you very much. Will this work in multiplayer?
-
Everything works in MP. Just make sure you dont make it work more than once. You may run it only on the server side, create a logic, give it a name and make sure it is local, this way you ensure it is the server:
? !local nameofthelogic:exit
Do whatever you want to do only in the server here