gr1D- 10 Posted May 25, 2015 I'm wondering how to find a variable (A good example is %s inside of systemChat, like systemChat ["Weapon Created: %s",_weapon]) inside of the string retrieved from ctrlText. I'm making a script for admins where you can spawn items in via Chat, like /spawn <insert classname>. I'm using a function made by Killzone Kid to find if the text /spawn is in the string, but I'm not sure how to find what is after /spawn. Here is my code so far: KK_fnc_inString = { /* Author: Killzone_Kid Description: Find a string within a string (case insensitive) Parameter(s): _this select 0: <string> string to be found _this select 1: <string> string to search in Returns: Boolean (true when string is found) How to use: _found = ["needle", "Needle in Haystack"] call KK_fnc_inString; */ private ["_needle","_haystack","_needleLen","_hay","_found"]; _needle = [_this, 0, "", [""]] call BIS_fnc_param; _haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param); _needleLen = count toArray _needle; _hay = +_haystack; _hay resize _needleLen; _found = false; for "_i" from _needleLen to count _haystack do { if (toString _hay == _needle) exitWith {_found = true}; _hay set [_needleLen, _haystack select _i]; _hay set [0, "x"]; _hay = _hay - ["x"] }; _found }; while {true} do { waitUntil {!isNull (findDisplay 24)}; disableSerialization; _display = findDisplay 24; if !(isNull _display) then { _textFind = _found = ["/spawn ", _text] call KK_fnc_inString; _classname = ??? (This is where I don't know what to do.) if (_textFind) then { private ["_object","_qty"]; _object = createVehicle ["WeaponHolder",position player,[],0,"CAN_COLLIDE"]; _object setVariable ["permaLoot",true]; _qty=1;_object addWeaponCargoGlobal [_classname,1]; systemChat ["Item Given: %s",_classname]; player selectWeapon _classname; (_display) closeDisplay 0; }; Any help would be appreciated. Share this post Link to post Share on other sites
Schatten 291 Posted June 7, 2015 (edited) KK_fnc_inString = { /* Author: Killzone_Kid [color="#FF0000"](modified by Schatten)[/color] Description: Find a string within a string (case insensitive) Parameter(s): _this select 0: <string> string to be found _this select 1: <string> string to search in Returns: [color="#FF0000"]Integer (position of where the needle exists relative to the beginning of the haystack string, -1 otherwise)[/color] How to use: _index = ["needle", "Needle in Haystack"] call KK_fnc_inString; */ private ["_needle","_haystack","_needleLen","_hay","_index"]; _needle = [_this, 0, "", [""]] call BIS_fnc_param; _haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param); _needleLen = count toArray _needle; _hay = +_haystack; _hay resize _needleLen; _index = -1; for "_i" from _needleLen to count _haystack do { if (toString _hay == _needle) exitWith {_index = _i - _needleLen}; _hay set [_needleLen, _haystack select _i]; _hay set [0, "x"]; _hay = _hay - ["x"] }; _index }; _haystack = "/spawn SCAR_L_STD_HOLO"; _needle = "/spawn "; _needleLen = count (toArray _needle); _index = [_needle, _haystack] call KK_fnc_inString; if (_index == 0) then { _haystack = toArray _haystack; for "_i" from 0 to (_needleLen - 1) do {_haystack set [_i, objNull]}; _type = toString (_haystack - [objNull]); _weaponHolder = createVehicle ["WeaponHolder", position player, [], 0, "CAN_COLLIDE"]; _weaponHolder addWeaponCargoGlobal [_type, 1]; }; Edited June 7, 2015 by Schatten Share this post Link to post Share on other sites