Jump to content
Sign in to follow this  
Mr Groch

Using local variable in setvehicleinit

Recommended Posts

Hi!

I want to make something like this:

local.sqs (called by AddAction):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = this select 0

_object = "xxx" createvehicle position _unit

_unit setVehicleInit "this assignascargo _object; this moveincargo _object"

processInitCommands

clearVehicleInit _unit

Yes - I want to move remote unit (other player) into a vehicle...

But this is only an example, I have also other actions, that need

to use "local" object variables...

I tried make something like that:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call compile format ["_unit setVehicleInit ""this assignascargo %1; this moveincargo %1""",_object]

But I see that I can't use object or unit type in format[]...

Thx for help!

My ther question is...

How to retrieve all weapons and magazines from the WeaponHolder object?

I'm currently creating 2d table with all weapons and magazines that I have putted in my

created WeaponHolder, but this is nor a good solution, becouse if someone take a

weapon from WeaponHolder using Gear menu - my table isn't "up-to-date"...

And one more think - effects of addWeaponCargo are only local? Becouse it seems

that wepons are puted to WeaponHolder only on client computer when using that in local script...

Share this post


Link to post
Share on other sites

why not just have him move in, I don't think there is need for setVehicleInit.

Its through an action, _this select 0 is the person the action is attached to.

Soo...try

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = _this select 0;

_object = "xx" createvehicle (getpos player);

_unit moveincargo _object;

Share this post


Link to post
Share on other sites

Becouse that was just an example...

I have also other needs to use "local" object variable

in setvehicleInit statement...

PS. And one more think - how to remove player from vehicle?

leavevehicle and dogetout don't work on players...

action["eject",vehicle _unit] work, but is there a way to

remove player from vehicle, without playing "eject" anim?

Share this post


Link to post
Share on other sites

I don't believe so no.

//replace newplace with the name of the area you want your player to move to.

other than: _unit setPos (getPos newplace);

as far as your weaponholder, try kronzky's script:

Weapons Placer

and do something to get weapons like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

//the name of your weaponholder, change if needed

_weps = weapons weaponsholder

_mags = magazines weaponholder

{_crate1 addweaponcargo _x} foreach _weps;

{_crate1 addmagazinecargo _x} foreach _mags;

Share this post


Link to post
Share on other sites

You simply cannot use the local variables from the script, inside them because the vehicleInit's are ran in a new scope, esp since they are transferred to other computers.

You could use format["blablaba %1 blablalba %2", _val1, _val2];

etc but this only works if _object has a vehicleVarName set the same on every computer.

I don't have much time ATM, but I just wanted to tell you about addPublicVariableEventHandler:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"TST_SOMEPV" addPublicVariableEventHandler

{

  _ar = (_this select 1);

  (_ar select 0) call (_ar select 1);

};

TST_SOMEPV =

[

  [_unit, _object],

  {

      (_this select 0) assignAsCargo (_this select 1);

      (_this select 0) moveInCargo (_this select 1);

  };

];

publicVariable "TST_SOMEPV";

I guess this should get you under way a lil smile_o.gif

Share this post


Link to post
Share on other sites

@DaChevs

weapons weaponsholder

magazines weaponholder

Gives an empty array.. This is the problem...

I don't need Kroznky script, I know hot to put weapons in

WeaponHolder, I don't know how to retrieve it from there...

@Sickboy

Thx, I didn't know that I can call code inside an publicvariable biggrin_o.gif

But this is not for me - I am making an addon, and I want it to be

independent... addPublicVariableEventHandler will be ok, when

all players have this addon...

So I need setvehicleinit way... But thx anyway, becouse

you have mentioned about VehicleVarName. I think that

this should do it smile_o.gif

I have just a question - if I will do something like this:

init.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = this select 0;

_name = "";

_i = 0;

while{ !(isnil "_name") }do

{

_i=_i+1;

_name=(call compile format["Unit%1",_i])

};

_name=format["Unit%1",_i];

_unit setvehiclevarname _name;

_unit call compile format["%1=_this; publicVariable ""%1""",_name]

action_script.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = _this select 0

_caller = _this select 1

_name = VehicleVarName _unit

call compile format ["_caller setvehicleinit ""this DoSomethingOn %1""",_name]

processinitcommands

clearvehicleinit _caller

Will it work?

And how about name of the unit that have been set in mission editor? Will it be still accessable? Or setvehiclevarname will overwrite it?

Share this post


Link to post
Share on other sites
I have just a question - if I will do something like this:

...

Will it work?

And how about name of the unit that have been set in mission editor? Will it be still accessable? Or setvehiclevarname will overwrite it?

It might work however you dont need to call compile here:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call compile format ["_caller setvehicleinit ""this DoSomethingOn %1""",_name]

Should be just:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_caller setVehicleInit format["this DoSomethingOn %1", _name];

setVehicleVarName overwrites whatever is set at text / name field of units in editor.

Setting the names in the editor is just as good as using setVehicleVarName on them though.

Also, my method about publicVariableEventHandler is not exclusive to "Need to be installed on every machine".

You can use a vehicleInit that verifies if the addon exists on a computer, and if it doesnt, you execute the needed initializations like the PV-EH, through the vehicleInit smile_o.gif

Share this post


Link to post
Share on other sites

Look in SLX_Wounds\Drag.sqs to see how I originally did it Mr Groch, it seems to work fine in MP from my tests and shouldn't need any changes.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

SLX_Dragger=_dragger

publicvariable "SLX_Dragger";

_unit setVehicleInit "this assignascargo SLX_Dragger;[this] orderGetIn true;this moveincargo SLX_Dragger;";processInitCommands;clearVehicleInit _unit;

SLX_Dragger becomes a synchronized global variable that the vehicleinit can point to on all machines. While I like to avoid using global variables as much as possible, I think having just this one extra is okay. There may be a few more commands that could be run to make sure the AI's work correctly though.

And for getting the contents of the WeaponHolders, now you see why I made the SLX_WeaponHolders as "man" types, because the weapons and magazines can be queried from them. Trying to remake the SLX_Wounds code to use default WeaponHolders is going to be a big pain, when it will be a lot easier to just fix the models to work on the linux dedicated servers.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×