madmedic 0 Posted October 7, 2005 Here is the story... I have three different models of a destroyed tank. (actually three edited versions of the wrecked T72 from the AWESOME ICP T72 PACK) I have a script that will replace a live tank with a destroyed model when it is killed. (It is actually an edited version of one of the scripts from FAB's "tank effects" scripts) I am trying to add a line into the script that will replace the killed tank with one of the three destroyed models at random. If I leave out the "random" stuff, the script works great...(but then all of the dead tanks look exactly the same) With the "random" line that I attempted to write, it just deletes the killed tank, and shows an error saying "object expected" or something like that. I dont really understand the "random" command, so I need a little help here. Thanks in advance Here is what I am working with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_TankUnit = _this select 0 ; ------------------ Class name (name of model to replace original unit) ------------------------ _targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] _target = _targetarray select (random 3) ; ------------------------------------------------------ _TankUnitX = getPos _TankUnit select 0 _TankUnitY = getPos _TankUnit select 1 _TankDir = getDir _TankUnit #begining ; ------- remove old Tank and add new one ------- _TankDir = getDir _TankUnit _TankOld = _TankUnit deleteVehicle _TankOld _TankUnit = (_target) createVehicle [-10000, -10000, 10000] _TankUnit setPos [getPos _TankOld select 0, getPos _TankOld select 1] _TankUnit setDir _TankDir +180 [_TankUnit] exec "\dkmm_rsc\scripts\dkmm_rsc_veh_burner2.sqs" exit "Below is the original version" (the one that works, but only has one destroyed model to choose from) <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_TankUnit = _this select 0 ; ------------------ Class name (name of model to replace original unit) ------------------------ _Class = "icp_t72bwreck" ; ------------------------------------------------------ _TankUnitX = getPos _TankUnit select 0 _TankUnitY = getPos _TankUnit select 1 _TankDir = getDir _TankUnit #begining ; ------- remove old Tank and add new one ------- _TankDir = getDir _TankUnit _TankOld = _TankUnit deleteVehicle _TankOld _TankUnit = (_class) createVehicle [-10000, -10000, 10000] _TankUnit setPos [getPos _TankOld select 0, getPos _TankOld select 1] _TankUnit setDir _TankDir +180 [_TankUnit] exec "\dkmm_rsc\scripts\dkmm_rsc_veh_burner2.sqs" exit So...anybody got a solution? Share this post Link to post Share on other sites
Trapper 0 Posted October 7, 2005 You can do it like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; ------------------ Class name (name of model to replace original unit) ------------------------ _targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] _ran = random 3; _target = whatever if (_ran <= 1) then {_target = _targetarray select 0} if (_ran <= 2) then {_target = _targetarray select 1} if (_ran <= 3) then {_target = _targetarray select 2} ; ------------------------------------------------------ Random will be everything from 0.00000 to 3.00000 so you can't just say random 3 and expect only 1.0000, 2.0000, 3.0000. Share this post Link to post Share on other sites
thobson 38 Posted October 7, 2005 Quote[/b] ]if (_ran <= 1) then {_target = _targetarray select 0}if (_ran <= 2) then {_target = _targetarray select 1} if (_ran <= 3) then {_target = _targetarray select 2} I don't think this would work. Â The result will always be _targetarray select 2 whenever _ran is <= 3; and whatever if it is > 3I would do it this way (If you then find another model to make it four models then just add it to the array and all the code will still work): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] #again _targetindex = random (count _targetarray) _targetindex = _targetindex - (_targetindex % 1) if (_targetindex >= count _targetArray) then {goto"again"} _target = _targetarray select _targetindex Share this post Link to post Share on other sites
Trapper 0 Posted October 7, 2005 Quote[/b] ]if (_ran <= 1) then {_target = _targetarray select 0}if (_ran <= 2) then {_target = _targetarray select 1} if (_ran <= 3) then {_target = _targetarray select 2} I don't think this would work. The result will always be _targetarray select 2 whenever _ran is <= 3; and whatever if it is > 3 yes, there was missing something. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (_ran <= 1) then {_target = _targetarray select 0; goto "j1"} if (_ran <= 2) then {_target = _targetarray select 1; goto "j1"} if (_ran <= 3) then {_target = _targetarray select 2} #j1 Share this post Link to post Share on other sites
madmedic 0 Posted October 7, 2005 You can do it like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; ------------------ Class name (name of model to replace original unit) ------------------------ _targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] _ran = random 3; _target = whatever if (_ran <= 1) then {_target = _targetarray select 0} if (_ran <= 2) then {_target = _targetarray select 1} if (_ran <= 3) then {_target = _targetarray select 2} ; ------------------------------------------------------ Random will be everything from 0.00000 to 3.00000 so you can't just say random 3 and expect only 1.0000, 2.0000, 3.0000. I dont understand the "_target = whatever" part what goes in place of "whatever"? Share this post Link to post Share on other sites
madmedic 0 Posted October 7, 2005 Quote[/b] ]if (_ran <= 1) then {_target = _targetarray select 0}if (_ran <= 2) then {_target = _targetarray select 1} if (_ran <= 3) then {_target = _targetarray select 2} I don't think this would work.  The result will always be _targetarray select 2 whenever _ran is <= 3; and whatever if it is > 3I would do it this way (If you then find another model to make it four models then just add it to the array and all the code will still work): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] #again _targetindex = random (count _targetarray) _targetindex = _targetindex - (_targetindex % 1) if (_targetindex >= count _targetArray) then {goto"again"} _target = _targetarray select _targetindex I tried that...but it did not work It just deletes the original tank, and I get this error code: '(_exp select _i) createvehicle _x l#l' error type any, expected number here is what I put in the script:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_TankUnit = _this select 0 _targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] #again _targetindex = random (count _targetarray) _targetindex = _targetindex - (_targetindex % 1) if (_targetindex >= count _targetArray) then {goto"again"} _target = _targetarray select _targetindex #begining ; ------- remove old Tank and add new one  ------- _TankDir = getDir _TankUnit _TankOld = _TankUnit deleteVehicle _TankOld _TankUnit = (_target) createVehicle [-10000, -10000, 10000] _TankUnit setPos [getPos _TankOld select 0, getPos _TankOld select 1] _TankUnit setDir _TankDir +180 [_TankUnit] exec "\dkmm_rsc\scripts\dkmm_rsc_veh_burner2.sqs" exit Share this post Link to post Share on other sites
thobson 38 Posted October 8, 2005 Try changing the line: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] to <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = ["icp_t72bwreck","icp_t72bwreck2","icp_t72bwreck3"] Also for debugging purposes (ie you take it out when it is all working) I suggest you put a hint in the code as follows: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint  _target #begining Share this post Link to post Share on other sites
madmedic 0 Posted October 8, 2005 Try changing the line:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [icp_t72bwreck,icp_t72bwreck2,icp_t72bwreck3] to <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = ["icp_t72bwreck","icp_t72bwreck2","icp_t72bwreck3"] Also for debugging purposes (ie you take it out when it is all working) I suggest you put a hint in the code as follows: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint  _target #begining Tried it...didnt work. Now it either uses the first wrecked model "icp_t72wreck", OR it just deletes the original tank, and does not replace it with anything. Share this post Link to post Share on other sites
thobson 38 Posted October 9, 2005 What does the hint message tell you? Are the following correctly defined: ["icp_t72bwreck","icp_t72bwreck2","icp_t72bwreck3"] ? Share this post Link to post Share on other sites
madmedic 0 Posted October 11, 2005 What does the hint message tell you?Are the following correctly defined: ["icp_t72bwreck","icp_t72bwreck2","icp_t72bwreck3"] ? Problem corrected!!! I did, in fact, have my class names defined incorrectly. (in retrospect, all of the randomization ideas posted by people actually do work) Share this post Link to post Share on other sites