Jump to content

gr1D-

Member
  • Content Count

    2
  • Joined

  • Last visited

  • Medals

Posts posted by gr1D-


  1. 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.


  2. Since I can't create my own thread I'm just going to post here.

    I've been trying to use addMPEventHandler to run a script upon the player respawning, because TFAR for some reason, when you respawn you spawn with a radio. It seems that the event handler isn't running the script and has failed at some point or another.

    init.sqf:

    true spawn {
       waitUntil {player == player};
    
       player addEventHandler ["Respawn", {
    	_this execVM "fix.sqf"
       }];
    };  

    fix.sqf:

    sleep 10;
    removeBackpack player;
    hint "test";

    sorry for sort of derailing the thread

    EDIT: did some research and apparently i'm dumb. sleep runs too long and doesn't take effect or something. thanks for the info guys

×