Home   Help Search Login Register  

Author Topic: vehicles spawned automatically have something in init field?  (Read 4048 times)

0 Members and 1 Guest are viewing this topic.

Offline danturn

  • Members
  • *
Ok, I want to use the cargo adds from RKSL, however, I want to be able to spawn vehicles in game.
Is it possible to add something to the init file for each vehicle so that the cargo and transport data will automatically be placed in the init field once the object is spawned.

Say for example I spawned a civlian ural. It's class name is "uralcivil". However when it is spawned its init field will be blank.

Is there away to add something to the init.sqs so that whenever a "uralcivil" is spawned, it will automatically add the data I need
Code: [Select]
[this, 40] call rksl_cargoadd; [this, 10] call rksl_transportadd; to its init field?

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: vehicles spawned automatically have something in init field?
« Reply #1 on: 06 Jun 2009, 15:41:36 »
You'll probably want to make use of the "Init" event handler.  It is fired at mission start, or when a vehicle is created on the fly using createVehicle.  I've never made any use of it in this particular context, but it looks like what you need.

Offline danturn

  • Members
  • *
Re: vehicles spawned automatically have something in init field?
« Reply #2 on: 06 Jun 2009, 16:15:07 »
will this work with the creation of vehicles through SPON money? Is their a tutorial or something for the init event handler?

thanks

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: vehicles spawned automatically have something in init field?
« Reply #3 on: 06 Jun 2009, 16:56:33 »
I don't know if it will work with SPON Money, as I've never used that particular SPON script.  As for an event handler tutorial, the Biki entry for addEventHandler should give you sufficient information to get started :)

I'm not sure there's a tutorial targeted at Init event handlers, but perhaps someone else with a bit more experience would be able to offer a better insight...

Offline i0n0s

  • Former Staff
  • ****
Re: vehicles spawned automatically have something in init field?
« Reply #4 on: 06 Jun 2009, 17:01:28 »
You don't need to add it to it's init field, you need to get a reference to "uralcivil" (a variable pointing on it), then you run the code
Code: [Select]
[uralcivil, 40] call rksl_cargoadd; [uralcivil, 10] call rksl_transportadd;
on one client.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: vehicles spawned automatically have something in init field?
« Reply #5 on: 07 Jun 2009, 19:21:31 »
I think he wants to do it for every new vehicle of that class, hence why I suggested the init event handler. I may be wrong, though!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: vehicles spawned automatically have something in init field?
« Reply #6 on: 08 Jun 2009, 17:24:36 »
If you are talking regarding SPON Money, then you just need to put the line of code you need in manually. A very similar thing has been discussed at least twice in my release thread (one that I remember was to ensure that the inventory of ammo boxes wasn't cleared when you bought them, but that other vehicles did get cleared, which is what usually happens in SPON Money).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: vehicles spawned automatically have something in init field?
« Reply #7 on: 09 Jun 2009, 18:28:41 »
No james is right, for every vehicle class that is spawned into the game.

Thanks Spooner, had a look through the thread but really couldn't find what I was looking for, I admit I can be a bit blind sighted at times! How do you mean by entering it manually? Obviously once the game has started, say for example i bought a Ural, how would I manually enter something into it's init field then?  ???

look at the eventhandler biki, but not really sure how i would implement this.

obviously once the game is running I am not going to be able to edit init fields, so need a way that once a vehicle is spawned the eventhandler will recognise the classname and automatically reference and add the init line if that makes sense.
« Last Edit: 09 Jun 2009, 18:32:02 by danturn »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: vehicles spawned automatically have something in init field?
« Reply #8 on: 10 Jun 2009, 01:34:29 »
No, you are getting mixed up. The init field runs code on an object when it is created. You can't add this to an object that hasn't been created (before anyone says just use setVehicleInit, that only works if you have a reference to the object). You don't have to run the code in the vehicle's init field at all; you are just thinking of the way you do it in the editor, but scripts do things much differently than the "simplistic" way that using the editor allows. Just run the code in SPON Money after the vehicle has been created and you have the same effect as if it had been in the init field. As I said, this exact thing (performing code on newly created vehicles in SPON Money) has been asked and answered several times, so forgive me if I don't give it to you on a plate ::)
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: vehicles spawned automatically have something in init field?
« Reply #9 on: 10 Jun 2009, 01:43:59 »
Just run the code in SPON Money after the vehicle has been created and you have the same effect as if it had been in the init field.
That's what I was thinking.  Not entirely sure why the OP's 'desired result' is overtly different to what you've just described.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: vehicles spawned automatically have something in init field?
« Reply #10 on: 10 Jun 2009, 03:07:32 »
It is extremely common that people decide how something should be solved and ask for those in the know to help them complete this solution. What is usually much more useful is if they ask for help to achieve a specific goal and let the person who answers decide how that is best accomplished!

Using the former method of asking often ends up confusing people, since they will try to solve the problem using your suggested method, which may, in fact be completely wrong.

I'm in no way complaining about this thread or the original poster. I can understand that it is often very difficult to ask a question and the poster is often keen to provide suggestions on how to answer the question. Mentioning SPON Money in the first place might have helped a lot to tell people what was required though. Might even have encouraged other people not to answer and then me to answer as the original author of SPON Money ;)

To question answerers: if a question seems ambiguous or illogical, it can be more useful to ask for clarification rather than risk answering a completely different question than was asked and confusing the issue entirely.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: vehicles spawned automatically have something in init field?
« Reply #11 on: 29 Jun 2009, 15:15:53 »
Ok, not sure where this topic is now going, haha, however I'm still no further on.

@ Spooner

To perform commands on a newly created vehicle, edit SPON\Core\showShopDialog.sqf and change:
Code: [Select]
case TYPE_VEHICLE:
{
    _itemClass createVehicle (getPos player);
};

to:
Code: [Select]
case TYPE_VEHICLE:
{
    _veh = _itemClass createVehicle (getPos player);
    clearWeaponCargo _veh;
    clearMagazineCargo _veh;
};

I'll add a better way of doing this so you can automatically perform commands when a vehicle is created in the much promised new version of SPON Money...*coughs*

(I've told D.murphy man a possible way to fix the non-English language things, but I haven't been able to test that. Hopefully that issue will be resolved now).

I am assuming this is the section in the thread you are referring too? does _itemclass need to changed to reffer to the vehicle that you are changing the information for? So if for example it was the ural I wanted to change, would i use..

Code: [Select]
case TYPE_VEHICLE:
{
    _veh = [b]_ural[/b] createVehicle (getPos player);
    [_veh, 10] call rksl_transportadd;
    [_veh, 25] call rksl_cargoadd;

};

If this is correct, am i still able to refer to each vehicle type as _veh? or am i going to have to have each one with a number following as in _veh#?

Cheers

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: vehicles spawned automatically have something in init field?
« Reply #12 on: 29 Jun 2009, 16:27:51 »
No, you can't change _itemClass, otherwise you'll never create any vehicle type except urals!

Code: [Select]
case TYPE_VEHICLE:
{
    _veh = _itemClass createVehicle (getPos player);
    switch (typeOf _veh) do
    {
        case "Ural":
        {
            [_veh, 10] call rksl_transportadd;
            [_veh, 25] call rksl_cargoadd;
        };
        case "Bus":
        {
            [_veh, 88] call rksl_transportadd;
            [_veh, 2] call rksl_cargoadd;
        };
        // etc...
    };
};

Remember that you'll have to get the class name case correct ("Ural" != "ural") for this to work (or use toLower in the switch and only use lower case class names).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline danturn

  • Members
  • *
Re: vehicles spawned automatically have something in init field?
« Reply #13 on: 29 Jun 2009, 20:29:56 »
Ok, had a go, but with no luck.

Code: [Select]
case TYPE_VEHICLE:
{
_itemClass createVehicle (getPos player);
switch (typeof _veh) do
{
case "usec_c130":
{
[_veh, 50] call rksl_transportadd;
};
case "truck5topen":
{
[_veh, 10] call rksl_transportadd;
[_veh, 40] call rksl_cargoadd;
};
};

};

That is what I have so far, just tried testing the two vehicles for now. I also noticed that the folder isn't in the core folder but in the money folder unlike stated, does this matter? Could it be a problem with the letter case like with ural and Ural and where would I add the toLower to solve this problem.

Thanks
« Last Edit: 29 Jun 2009, 22:33:24 by danturn »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: vehicles spawned automatically have something in init field?
« Reply #14 on: 30 Jun 2009, 00:03:34 »
You failed to copy and paste the "_veh =" part of the script. It is probably easier to use:
Code: [Select]
_veh = _itemClass createVehicle (getPos player);
switch (toLower (typeof _veh)) do
and ensure that the names in the case strings are all lower-case. This saves worrying about case.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)