Home   Help Search Login Register  

Author Topic: Naming multiple vehicles using "createVehicle"?  (Read 1953 times)

0 Members and 1 Guest are viewing this topic.

Offline Andy

  • Members
  • *
Naming multiple vehicles using "createVehicle"?
« 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?


Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #1 on: 25 Jul 2007, 14:46:53 »
Code: [Select]
_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.

Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #2 on: 25 Jul 2007, 18:23:12 »
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.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #3 on: 25 Jul 2007, 18:38:09 »
The resulting global variables should be newcar1, newcar2, newcar3 ...

Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #4 on: 25 Jul 2007, 18:45:59 »
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?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #5 on: 25 Jul 2007, 19:00:02 »
Code: [Select]
_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"


Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #6 on: 25 Jul 2007, 19:20:54 »
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.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Naming multiple vehicles using "createVehicle"?
« Reply #7 on: 25 Jul 2007, 22:03:11 »
Need extra quotes around "Marker%1" ?

Code: [Select]
call (format["newcar%1", _i]) = "Police_car" createVehicle getMarkerPos format[""Marker%1"", _i]
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #8 on: 25 Jul 2007, 22:15:05 »
Nope, format already returns an string, which is the required parameter for getMarkerPos

Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #9 on: 26 Jul 2007, 18:03:18 »
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:
Code: [Select]
_i  = 1
#createcar
call [format["newcar%1 = ""Police_car"" createVehicle getMarkerPos format[""Marker%1""]", _i];
_i = _i + 1
? _i < 5: goto "createcar"


Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #10 on: 26 Jul 2007, 19:06:59 »
Then use a global instead of a local for _i, and initialize it outside that script, so this script only increments it.

Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #11 on: 26 Jul 2007, 19:11:33 »
Unfortunately, I don't really know how to do that.  Do you have an example?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #12 on: 26 Jul 2007, 19:18:15 »
Code: [Select]
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

Offline Andy

  • Members
  • *
Re: Naming multiple vehicles using "createVehicle"?
« Reply #13 on: 26 Jul 2007, 19:32:12 »
PERFECT!!! This worked beautifully.  Thank you very much.  Will this work in multiplayer?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Naming multiple vehicles using "createVehicle"?
« Reply #14 on: 26 Jul 2007, 20:47:55 »
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:

Code: [Select]
? !local nameofthelogic:exit

Do whatever you want to do only in the server here