ZZEZ 10 Posted February 3, 2012 Hey. I need to convert a string in to an array so it can be subtracted from the original array, any ideas how it can be done?I tried the format/call compile method but it kept returning "ANY" in the newly created array instead of SmokeShellGreen, heres the entire code: actualnumber = nil; _thetank = (vehicle player); _tankcargo = getMagazineCargo (vehicle player); player sidechat format ["ORIGINAL ARRAY %1", _tankcargo]; _classnames = _tankcargo select 0; _ammocount = _tankcargo select 1; player sidechat format ["CLASSNAMES %1", _classnames]; player sidechat format ["AMMOCOUNT %1", _ammocount]; _countclass = 0; { if(_x == "SmokeShellGreen") then { player sidechat "Smokeshellgreen IN ARRAY"; actualnumber = _countclass; player sidechat format ["position in array is %1", actualnumber]; } else { _countclass = _countclass +1; }; }forEach _classnames; if (isNil "actualnumber") then { player sidechat "actualnumber is nil, didnt find in ammo array, stopping scripts";} else { ////put fire code here player sidechat "assuming you are firing now"; _numberofammo = _ammocount select actualnumber; player sidechat format ["amount of greenshells is %1", _numberofammo]; _numberofammosubtracted = _numberofammo -1; player sidechat format ["subtracted by 1 is %1", _numberofammosubtracted]; if(1 > _numberofammosubtracted) then {//last shell player sidechat "this was the last shell, making final array"; _subtractammofinalarray = _tankcargo select 0; _subtractammosubtractfinal_string = _classnames select actualnumber; ////////////FIGURE OUT how to convert string to array otherwise this part wont work, cant subtract string from array player sidechat format ["subtracting from initial array %1", _subtractammosubtractfinal_string]; _ammofinalarray = _subtractammofinalarray - _subtractammosubtractfinal_string; player sidechat format ["final array is %1", _ammofinalarray]; ////remove all shit clearMagazineCargo _thetank; //now adding it back } else {//not last, remove 1 and readd all hint "not done"; }; }; My problem is the following line: _subtractammosubtractfinal_string = _classnames select actualnumber; It creates a string and I need it to be an array containing only that one variable, any ideas? Share this post Link to post Share on other sites
Muzzleflash 108 Posted February 3, 2012 You can use toArray which converts it to unicode code points: _letterArray = toArray "MyString"; If you do not want the letter numbers but the "actual" letters you can convert each number back into a 1-length string using toString: { _str = toString [_x]; _letterArray set [_forEachIndex, _str]; } forEach _letterArray; Share this post Link to post Share on other sites
ZZEZ 10 Posted February 4, 2012 I ended up using a different solution, editing the part of the array that I don't want and having a if check to exclude it. If anyone wants it heres a script that removes a specific item from vehicle magazine cargo[it actually removes everything and then re add all items minus 1], it will be redundant if we get a RemoveMagazineCargo ["xx",x] command but it has been over 10 years.... I ended up not using it because it will create too much network traffic and in low performance issues it would not remove/add items fast enough causing issues, with that being said unless your server fps is below 5 and your player count is over 40 you won't notice it. uo_mk3_actualnumber_mortar_script = nil; if (isNil "uo_mk3_mortar_countdown") then { uo_mk3_mortar_countdown = false;}; _thetank = (vehicle player); _tankcargo = getMagazineCargo (vehicle player); player sidechat format ["ORIGINAL ARRAY %1", _tankcargo]; _classnames = _tankcargo select 0; _ammocount = _tankcargo select 1; player sidechat format ["CLASSNAMES %1", _classnames]; player sidechat format ["AMMOCOUNT %1", _ammocount]; _countclass = 0; { if(_x == "SmokeShellGreen") then { player sidechat "Smokeshellgreen IN ARRAY"; uo_mk3_actualnumber_mortar_script = _countclass; player sidechat format ["position in array is %1", uo_mk3_actualnumber_mortar_script]; } else { _countclass = _countclass +1; }; }forEach _classnames; if (isNil "uo_mk3_actualnumber_mortar_script") then { player sidechat "NO AMMO FOUND, EXITING";} else { if !(uo_mk3_mortar_countdown) then { player sidechat "assuming you are firing now"; ////put fire code here WAIT UNTIL FIRE TO SUBTRACT AMMO _numberofammo = _ammocount select uo_mk3_actualnumber_mortar_script; player sidechat format ["amount of greenshells is %1", _numberofammo]; _numberofammosubtracted = _numberofammo -1; player sidechat format ["subtracted by 1 is %1", _numberofammosubtracted]; if(1 > _numberofammosubtracted) then {//last shell player sidechat "this was the last shell, making final array"; _subtractammofinalarray = _tankcargo select 0; _subtractammofinalarray set [uo_mk3_actualnumber_mortar_script, "DONOTHING"]; player sidechat format ["final item to add array is %1", _subtractammofinalarray]; //clear magazines from tanko clearMagazineCargo _thetank; //counting ammo _countedammoarray = { _x > 0 } count _subtractedammocount; player sidechat format ["counted ammo array is %1",_countedammoarray]; _2ndcounter = 0; { if(_x == "DONOTHING") then { _2ndcounter = _2ndcounter + 1; player sidechat format ["not adding anything 2ndcounter is %1", _2ndcounter]; }else { _theitem = _subtractammofinalarray select (_2ndcounter); _thecount = _ammocount select (_2ndcounter); player sidechat format ["adding %1 times %2", _theitem, _thecount]; (vehicle player) addMagazineCargo [_theitem, _thecount]; _2ndcounter = _2ndcounter + 1; player sidechat format ["2ndcounter is %1", _2ndcounter]; }; }forEach _subtractammofinalarray; ///done readding all the crap after firing last shell } else {//not last, remove 1 and readd all player sidechat "was not final round"; _classnamearray = _tankcargo select 0; player sidechat format ["classname array to addback is %1", _classnamearray]; _classcountarray = _tankcargo select 1; player sidechat format ["class number array to addback is %1", _classcountarray]; _classcountarray set [uo_mk3_actualnumber_mortar_script, (_classcountarray select uo_mk3_actualnumber_mortar_script) -1]; player sidechat format ["subtracted by 1 count array is %1",_classcountarray]; clearMagazineCargo _thetank; _3rdcounter = 0; { _2theitem = _classnamearray select (_3rdcounter); _2thecount = _classcountarray select (_3rdcounter); player sidechat format ["adding %1 times %2", _2theitem, _2thecount]; (vehicle player) addMagazineCargo [_2theitem, _2thecount]; _3rdcounter = _3rdcounter +1; }forEach _classnamearray; }; uo_mk3_mortar_countdown = true; sleep 7; uo_mk3_mortar_countdown = false; } else { player sidechat "Mortar is reloading";}; }; Share this post Link to post Share on other sites