Home   Help Search Login Register  

Author Topic: Createtanks  (Read 1479 times)

0 Members and 1 Guest are viewing this topic.

Offline Mad Pup

  • One Who Asks A Lot.
  • Members
  • *
  • OFPEC Is Awesome
Createtanks
« on: 11 Mar 2012, 04:40:39 »
I'm making a mission, where you walk up to a garage, and you get the option to create a tank. Now the create tank is no problem, but how do I detect how many have been made, and keep track of the tank seperately.

So basically I want script(s) to be able to create 3 "M1Abramsauto"s, but once three have been created, nobody can create anymore. However, once one is destroyed, tanks can be created again.

Sorry if this is confusing, if you have questions, ask.

Thanks!

-Mad Pup
"The object of war is not to die for your country, but to make the other poor bastard die for his" - General Patton
[SH]MadPup
[SH]Squad

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: Createtanks
« Reply #1 on: 11 Mar 2012, 10:02:11 »
Ok, you use the 'createvehicle' command. To keep track of how many have been made, a variable is created. Once this variable reaches a certain amount (in this instance, 3) then the script will then exit. That's essentially what you want.

So, let's begin with the 'addaction':

Code: [Select]
player addaction ["Create Tank","Assemble.sqs"]
You can put that in a trigger near where you want the tanks to be created.

So, now for 'assemble.sqs':

Code: [Select]

;this is a global variable. 'createtank' is defined in the init.sqs. More about that further down
createtank = createtank + 1

;this is the complicated part
;max_tanks is the global variable which determines how many tanks you can create
;this too is defined in the init.sqs
? createtank >= max_tanks: hint "No more tanks available"; exit

;now to create a tank
;'tankspawn' is the marker where you want the tanks to spawn
_tank = "M1Abrams" createVehicle getmarkerpos "tankspawn"
;the line below is optional, you can put the marker where you want and leave it at that if you want
;you input the x,y,z yourself
_tank setpos [x,y,z]


;this is optional:
hint format["Number of tanks left: - %1", (max_tanks - createtank)]
;that will tell the player how many tanks left he can create

exit


The script will end if the player has created all that he can create. The addaction will still be there, but no more tanks can be created. I've put a hint stating that no more tanks can be created. You could try removing the action but I'm not 100% sure how to do that for this one.

Now about those global variables:

In init.sqs...

Code: [Select]

createtank = 0
max_tanks = 3


Now, I'm afraid I'm not sure how to keep track of whether a createvehicle'd vehicle has been destroyed or not. But, it uses the same principal of checking whether a globalvariable has decreased at all. I hate leaving a question unanswered, but hopefully what I've put here will put you on the right track  :)

Hope this helps

Gruntage
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re: Createtanks
« Reply #2 on: 24 Mar 2012, 01:22:34 »
Mad Pup,

Check out the attached demo mission to see how you can do it with just one script and no init file. The demo actually has two scripts, but the killTank.sqs script is just to test the tracking of destroyed tanks.

Put the unzipped folder in your user mission folder. The default path is: C:\Program Files\Codemasters\Operation Flashpoint\Users\Mad Pup\Missions. I'm assuming you used "Map Pup" for your OFP user id.