Home   Help Search Login Register  

Author Topic: Crate addweapon cargo:P  (Read 2869 times)

0 Members and 1 Guest are viewing this topic.

Offline Martin Kuka

  • Members
  • *
Crate addweapon cargo:P
« on: 10 Aug 2006, 14:22:23 »
I see this is an embarassing question, but I`m new to scripting and all I done before was by using a huge amount of triggers. So my 1st script is about weaponcrate, creating it is pretty easy but why then editor returns an error?

"_crate = _this Select 0" , type object has to be pole hmmm....

When I put whatever title or number in this line, just like "_Shopbox = _this select 1"
It is still not working...So I dont know if my script editor is buggy or I dont understand what it wants from me.
« Last Edit: 10 Aug 2006, 14:24:06 by Martin Kuka »
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #1 on: 10 Aug 2006, 14:34:38 »
Can you show how you call your script and the contents of the whole script, please. I guess your syntax is wrong, but it would help to see how you wrote it initially...

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #2 on: 10 Aug 2006, 14:43:40 »
; ***********************************************************************
; **** Custom crate script for Operation Flashpoint
; **** Generated by Chris' OFP Script Editor
; **** Version 3.1.0000
; ****
; **** ORIGINAL FILE NAME: CRATE_44.sqs
; **** INSTRUCTIONS: Run script from the INITIALIZATION box of the crate
; **** RUN CODE: [this] Exec "CRATE_44.sqs"
; ***********************************************************************

; Get the crate parameter given
_crate = _this Select 0
; Remove the stock items from the crate
ClearMagazineCargo _crate
ClearWeaponCargo _crate

#AddGunsSjb
; Add the items to the crate
_crate AddWeaponCargo ["SJB_TOS_M4", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_CQB", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_Sniper", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_SD_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4", 1]
_crate AddMagazineCargo ["SJB_TOS_M16A4_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_CAR15_ACOG", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_LR300", 1]
_crate AddMagazineCargo ["SJB_TOS_LR300_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M14_DMR_SD", 1]
_crate AddMagazineCargo ["SJB_TOS_M14_DMR_SD_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4_M203", 1]
_crate AddMagazineCargo ["SJB_TOS_M203_Grenade", 10]

Exit

This is the whole script, guess error must be in init line.
 And then it is generated script.... ;D
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #3 on: 10 Aug 2006, 15:04:45 »
That script is meant to be used like this:

1) Make sure your custom crate script has only entries (weapons and magazines) which actually exist in your loaded addons.
2) You place an ammo crate from the editor to the mission, like "Side:Empty Class:Ammo Unit:Ammo Crates (West)
3) Then you write to the initialization field of the ammo crate: [this] Exec "CRATE_44.sqs"


Of course, if you named your script something else than CRATE_44.sqs, then number 3 needs adjustment as you probably know already.

Do you already see where your error is?

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #4 on: 10 Aug 2006, 15:39:22 »
Oh yeah I get it now ;D
I didnt put in crate`s init "[This]" but only "this".

Thanx a lot, maybe may gunshop will work at all [ Boxes are filled already ;D]
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #5 on: 10 Aug 2006, 16:00:33 »
Actually you were doing it in a better way than how the script has originally been done. You can skip this explanation for now if you want but anyway, here it comes:

If you write this Exec "CRATE_44.sqs" into the initialization field, then in the script you could delete the line _crate = _this Select 0 completely and replace all occurrences of _crate with _this and you would get a shorter and faster working script. That's how I would write such a script.

Explanation of how the script from Chris' OFP Script Editor originally works:

1) [this] Exec "CRATE_44.sqs" the brackets [] around this creates an array variable called _this with one item.
2) _crate = _this select 0 takes the first item from the array passed for the script, and places that item into a variable called _crate
3) Now we have used two variables (_this and _crate) when we infact need only one (_this).

To make it clear, the arguments you give to your scripts will end up in a variable called _this.

An array can have multiple items, like [this, that] and so on. Then you go and pick one of those items in your script with _this select 0 (gives 'this') like it is done in the script, or _this select 1 (gives 'that'). But when we have only one item to pass for the script, we really need not to create an array for only one item but we can (and should) only use this.

If that didn't say much to you now, don't worry it'll be clear for you once you get more into scripting. Great that you got your script working!
« Last Edit: 10 Aug 2006, 16:05:32 by Baddo »

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #6 on: 10 Aug 2006, 16:45:02 »
If I understood it well [hope so].
I can create various box loadouts from one script...?
If its so, you helped me much to save time I can use doing other details ;D
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #7 on: 10 Aug 2006, 17:23:39 »
Oh yes you can do that. You could pass the script two arguments: 1) the crate 2) what loadout you want for it.

So the initialization field could look something like this:

Code: [Select]
[this, "AddGunsSjb"] exec "CRATE_44.sqs"
Then your script could look like this:

Code: [Select]
; ***********************************************************************
; **** INSTRUCTIONS: Run script from the INITIALIZATION box of the crate
; **** RUN CODE: [this, <label for the loadout>] Exec "CRATE_44.sqs"
; ***********************************************************************

; Get the crate parameter given
_crate = _this Select 0
; Remove the stock items from the crate
ClearMagazineCargo _crate
ClearWeaponCargo _crate

goto (_this select 1)

#AddGunsSjb
; Add the items to the crate
_crate AddWeaponCargo ["SJB_TOS_M4", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_CQB", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_Sniper", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_SD_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4", 1]
_crate AddMagazineCargo ["SJB_TOS_M16A4_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_CAR15_ACOG", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_LR300", 1]
_crate AddMagazineCargo ["SJB_TOS_LR300_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M14_DMR_SD", 1]
_crate AddMagazineCargo ["SJB_TOS_M14_DMR_SD_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4_M203", 1]
_crate AddMagazineCargo ["SJB_TOS_M203_Grenade", 10]
Exit

#AddGunsStandard
; Add the items to the crate
_crate AddWeaponCargo ["M16", 1]
_crate AddMagazineCargo ["M16", 25]
Exit

I recall the Chris' OFP Script Editor which you are using, could create a script like this for you? I don't have it installed now so can't check.


Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #8 on: 10 Aug 2006, 18:34:02 »
Why goto command?
I thought about replacing weapon and magazine names with another ones and renaming the scriptfile
so It will look like this:

Box1 init: This exec "crate_44.sqs"

Then

Box2 init: This exec "crate_45.sqs" Where Crate_45.sqs is only modified 44.
Lets get rocked

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #9 on: 10 Aug 2006, 19:31:27 »
Since im making a gunshop in a warehouse I want all weapons sorted by functions, side, upgrades and prices.
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #10 on: 10 Aug 2006, 19:41:42 »
Quote
I can create various box loadouts from one script...?

I understood that like you wanted to use the same script file for all your crates. And did you sort your data or not, it doesn't matter imho. Of course you can put them into separate files too :)

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #11 on: 10 Aug 2006, 20:22:30 »
 ;D Oki now tell me for what purpose is there that Goto command.
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #12 on: 10 Aug 2006, 21:27:36 »
You can choose a different loadout from the same file.

Code: [Select]
[this, "AddGunsSjb"] exec "CRATE_44.sqs"
will make the script run these commands:

Code: [Select]
; Add the items to the crate
_crate AddWeaponCargo ["SJB_TOS_M4", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_CQB", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M4_Sniper", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_SD_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4", 1]
_crate AddMagazineCargo ["SJB_TOS_M16A4_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_CAR15_ACOG", 1]
_crate AddMagazineCargo ["SJB_TOS_M4_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_LR300", 1]
_crate AddMagazineCargo ["SJB_TOS_LR300_mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M14_DMR_SD", 1]
_crate AddMagazineCargo ["SJB_TOS_M14_DMR_SD_Mag", 25]
_crate AddWeaponCargo ["SJB_TOS_M16A4_M203", 1]
_crate AddMagazineCargo ["SJB_TOS_M203_Grenade", 10]
Exit

...and this:

Code: [Select]
[this, "AddGunsStandard"] exec "CRATE_44.sqs"
will make the script run these commands:

Code: [Select]
; Add the items to the crate
_crate AddWeaponCargo ["M16", 1]
_crate AddMagazineCargo ["M16", 25]
Exit

...so that way you can put different loadouts into the same file and then use an argument in your script call to direct OFP into correct section of the file. The exit command plays an important part here: it makes the script exit before running into the next loadout. The goto command needs a string as an argument so that's why I am passing a string as second argument for the script. The labels #AddGunsSjb and #AddGunsStandard are the points in the script where the goto command jumps execution into. So the goto command makes jumps inside the script file. The jumps can be either forwards or backwards in the file.

Offline Martin Kuka

  • Members
  • *
Re: Crate addweapon cargo:P
« Reply #13 on: 11 Aug 2006, 07:40:46 »
Ah so it`s that simple?
Well is it possible to have one general script for more boxes?
Like:

1st Box will run the SJB section : [this, "AddGunsSjb"] exec "CRATE_44.sqs"

And

2nd Box can run : [this, "AddGunsStandard"] exec "CRATE_44.sqs"

So then we need the inital script line back and all _This changed back to _crate?
Lets get rocked

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Crate addweapon cargo:P
« Reply #14 on: 11 Aug 2006, 14:11:55 »
Yes. You can do a general script for many boxes like in my example. Just write more sections with labels like #AddGunsSjb and so on, and then use the second argument (matches the label, without the #) in your script call to direct OFP into correct section of the file, just like in the example I gave you. Don't forget the exit command from between the sections so you'll only get one loadout for one box.

Alternatively to _crate you could also have _this select 1 but it is maybe better to have the _crate now, because using select many times in your script is very likely slower than putting the value into a variable and then using that variable throughout the script.