BEAKSBY 11 Posted August 31, 2014 HI All, Not sure if anyone has played with BIS_fnc_bleedTickets, but I want to deduct an certain number of bleed tickets from a player everytime they respawn. I'm still playing around with it but wondering if anyone has tried this yet? BIS_fnc_bleedTickets /* BIS_fnc_bleedTickets https://community.bistudio.com/wiki/BIS_fnc_bleedTickets Author: Karel Moricky Description: Initialize ticket bleeding. Works with sector modules. When a side holds majority of sectors, other non-friendly sides will start losing respawn tickets (set by BIS_fnc_respawnTickets) "dominantSideChanged" scripted event handler (see BIS_fnc_addScriptedEventHandler) is called every time the dominant side changes. Parameter(s): 0 (Optional): ARRAY of SIDEs - involved sides. Setting empty array will terminate ticket bleeding (default: all sides) 1 (Optional): NUMBER - dominance ratio in range 0-1, i.e., how large portion of sectors must a side hold for others to start bleeding (default: 0.5) 2 (Optional): NUMBER - how many tickets will be bled every step during full dominance (default: 3) 3 (Optional): NUMBER - delay in seconds between every bleeding step (default: 5) Returns: BOOL */ if !(isserver) exitwith {"BIS_fnc_bleedTickets can run only on server" call bis_fnc_error; false}; private ["_sides","_ticketBleedRatio","_ticketBleedMax","_delay","_sidesFiltered"]; _sides = [_this,0,missionnamespace getvariable ["bis_fnc_bleedTickets_sides",[east,west,resistance]],[[]]] call bis_fnc_param; _ticketBleedRatio = [_this,1,missionnamespace getvariable ["bis_fnc_bleedTickets_ticketBleedRatio",0.5],[0]] call bis_fnc_param; _ticketBleedMax = [_this,2,missionnamespace getvariable ["bis_fnc_bleedTickets_ticketBleedMax",3],[0]] call bis_fnc_param; _delay = [_this,3,5,[0]] call bis_fnc_param; //--- Remove duplicates and elements which are not sides _sidesFiltered = []; { if (typename _x == typename sideunknown) then { if !(_x in _sidesFiltered) then {_sidesFiltered set [count _sidesFiltered,_x];}; }; } foreach _sides; bis_fnc_bleedTickets_sides = _sidesFiltered; //--- Announce bis_fnc_bleedTickets_enabled = count _sides > 0; publicvariable "bis_fnc_bleedTickets_enabled"; //--- Terminate existing loop if !(isnil "bis_fnc_bleedTickets_loop") then {terminate bis_fnc_bleedTickets_loop;}; //--- Execute bleeding loop if (bis_fnc_bleedTickets_enabled) then { bis_fnc_bleedTickets_loop = [_ticketBleedRatio,_ticketBleedMax,_delay] spawn { _ticketBleedRatio = _this select 0; _ticketBleedMax = _this select 1; _delay = _this select 2; _dominantSide = sideunknown; while {true} do { _sectors = true call bis_fnc_moduleSector; _ticketBleedSectorLimit = count _sectors * _ticketBleedRatio; if (_ticketBleedSectorLimit != 0) then { _dominantSideOld = _dominantSide; _dominantSide = sideunknown; _dominantSideRatio = 0; //--- Get sector status _sides = +(missionnamespace getvariable ["bis_fnc_bleedTickets_sides",[east,west,resistance,civilian]]); { _side = _x; _sideTickets = _side call bis_fnc_respawnTickets; if (_sideTickets < 0) then { _sides set [_foreachindex,sideunknown]; //--- Remove sides without tickets } else { _sideSectorsCount = _side call bis_fnc_moduleSector; if(_sideSectorsCount > _ticketBleedSectorLimit) then { _dominantSide = _side; _dominantSideRatio = (_sideSectorsCount - _ticketBleedSectorLimit) / _ticketBleedSectorLimit; }; }; } foreach _sides; _sides = _sides - [sideunknown]; //--- Tickets bleeding _sectorTicketBleedRatio = -_ticketBleedMax * _dominantSideRatio; if (_sectorTicketBleedRatio != 0) then { { _side = _x; if (_side != _dominantSide && _dominantSide != sideunknown) then { [_side,_sectorTicketBleedRatio] call bis_fnc_respawnTickets; }; } foreach _sides; }; //--- Call custom code when the dominance changes if (_dominantSide != _dominantSideOld) then { [missionnamespace,"dominantSideChanged",[_dominantSide,_dominantSideOld,_sides]] spawn bis_fnc_callScriptedEventHandler; }; }; _time = time + _delay; waituntil {time > _time}; }; }; }; true Share this post Link to post Share on other sites
moricky 211 Posted September 1, 2014 Use BIS_fnc_respawnTickets Example, where 10 tickets are deducted form player's side: [side player,-10] call BIS_fnc_respawnTickets; Share this post Link to post Share on other sites
BEAKSBY 11 Posted September 2, 2014 (edited) Use BIS_fnc_respawnTicketsExample, where 10 tickets are deducted form player's side: [side player,-10] call BIS_fnc_respawnTickets; THanks Moricky, When I use [side player,-10] call BIS_fnc_respawnTickets; (or any negative value) the bleed tickets are immediately reduced from 500 (my default setting) to 0, and the game is forced to end. When I use [side player,-1, TRUE] call BIS_fnc_respawnTickets; the bleed tickets are reduced from 500 to 499, then 498, 497...etc. BIS_fnc_respawnTickets Description: Adjust number of respawn tickets. When player dies, the number is automatically decreased by 1; When number of tickets reaches 0, player's respawn is disabled. Parameter(s): 0: NAMESPACE, SIDE, GROUP or OBJECT - tickets space (e.g., it's possible to define two different ticket numbers for each side) BOOL - true to return number of tickets in all spaces (used for returning value only, won't set anything) ARRAY - return losing space from the passed list (elements can be of type NAMESPACE, SIDE, GROUP or OBJECT) 1: NUMBER - by how much will the ticket count be adjusted 2 (Optional): BOOL - true to autodetect tickets space. First param have to be an object. Used for modifying player's current tickets. Returns: NUMBER - remaining tickets after adjustment (-1 when no tickets were defined yet) ARRAY - when array was used as an argument, returned value is [<losingSpace>,<tickets>] */ private ["_varName","_varTotal","_input"]; _varName = "BIS_fnc_respawnTickets_value"; _varTotal = _varName + "total"; if (typename _this != typename []) then {_this = [_this];}; _input = [_this,0,objnull,[objnull,[],missionnamespace,sideunknown,grpnull,objnull,true]] call bis_fnc_param; //--- On respawn if (count _this > 3) exitwith { private ["_unit"]; _unit = _input; if (!isnull _unit && !isplayer _unit) exitwith {["Attempting to use the function on AI unit %1, can be used only on players."] call bis_fnc_error; 0}; private ["_respawnDelay"]; _respawnDelay = [_this,3,0,[0]] call bis_fnc_param; if !(alive _unit) then { private ["_deathTime","_respawnDisabled","_tickets"]; _deathTime = time; _respawnDisabled = false; //--- Decrease number of tickets (only when simulation is enabled, which is not the case in forced respawn) if (simulationenabled _unit) then { [_unit,-1,true] call bis_fnc_respawnTickets; }; //--- Death while {!alive player && !isnull player} do { _tickets = [_unit,0,true] call bis_fnc_respawnTickets; if (_tickets == 0) then { if !(_respawnDisabled) then { _respawnDisabled = true; setplayerrespawntime 1e10; }; } else { if (_respawnDisabled) then { _respawnDisabled = false; setplayerrespawntime ((_respawnDelay - (time - _deathTime)) max 1); }; }; sleep 1; }; } else { //--- Respawn /* _oldUnit = [_this,1,0,[objnull,0]] call bis_fnc_param; if !(isnull _oldUnit) then { [_unit,-1,true] call bis_fnc_respawnTickets; }; */ setplayerrespawntime _respawnDelay; }; }; switch (typename _input) do { case (typename missionnamespace); case (typename sideunknown); case (typename grpnull); case (typename objnull); case (typename true): { //private ["_respawnTemplates"]; //_respawnTemplates = getarray (missionconfigfile >> "respawnTemplates"); //if ({_x == "Tickets"} count _respawnTemplates == 0) exitwith {"""Tickets"" respawn template not used in the mission, cannot use respawn tickets." call bis_fnc_error; 0}; private ["_target","_value","_autodetect","_tickets"]; _target = _input; _value = round ([_this,1,0,[0]] call bis_fnc_param); _autodetect = [_this,2,false,[false]] call bis_fnc_param; if (typename _target == typename true) exitwith { missionnamespace getvariable [_varTotal,-1] }; if (_autodetect) exitwith { _target = [_this,0,player,[objnull,true]] call bis_fnc_param; _target = switch true do { case !(isnil {_target getvariable _varName}): {_target}; case !(isnil {(group _target) getvariable _varName}): {group _target}; case !(isnil {missionnamespace getvariable (_varName + str (_target call bis_fnc_objectSide))}): {_target call bis_fnc_objectSide}; case !(isnil {missionnamespace getvariable (_varName)}): {missionnamespace}; default {false}; }; if (typename _target == typename false) exitwith { //"No respawn tickets defined, use BIS_fnc_respawnTickets to add some." call bis_fnc_error; -1 }; [_target,_value] call bis_fnc_respawnTickets; }; //--- Update the tickets count _tickets = -1; switch (typename _target) do { case (typename missionnamespace); case (typename sideunknown): { if (typename _target == typename sideunknown) then {_varName = _varName + str _target; _target = missionnamespace;}; _tickets = _target getvariable [_varName,-1]; if (_value != 0) then { _tickets = _tickets max 0; _tickets = (_tickets + _value) max 0; _target setvariable [_varName,_tickets]; publicvariable _varName; }; }; case (typename grpnull); case (typename objnull): { _tickets = _target getvariable [_varName,-1]; if (_value != 0) then { _tickets = _tickets max 0; _tickets = (_tickets + _value) max 0; _target setvariable [_varName,_tickets,true]; }; }; }; //--- Update total tickets count (used for measuring whether there are any tickets left at all) if (_value != 0) then { private ["_ticketsTotal"]; _ticketsTotal = missionnamespace getvariable [_varTotal,0]; _ticketsTotal = (_ticketsTotal + _value) max 0; _ticketsTotal = missionnamespace setvariable [_varTotal,_ticketsTotal]; publicvariable _varTotal; //--- Tickets exhaused - trigger a scripted event if (_tickets == 0) then { [[missionnamespace,"respawnTicketsExhausted",[_target]],"bis_fnc_callscriptedeventhandler",false] call bis_fnc_mp; }; }; _tickets }; case (typename []): { private ["_minTickets","_target"]; _minTickets = 1e10; _target = sideunknown; { private ["_tickets"]; _tickets = _x call bis_fnc_respawnTickets; if (_tickets < _minTickets && _tickets >= 0) then { _target = _x; _minTickets = _tickets; }; } foreach _input; if (_target == sideunknown) then {_minTickets = -1;}; [_target,_minTickets] }; }; Edited September 2, 2014 by BEAKSBY Share this post Link to post Share on other sites
uncookedzebra 13 Posted January 9, 2015 Hi guys I am having a bit of trouble with tickets as well. I set up a Sector Control map and am using the spawn AI module to send AI to attack each sector. My trouble is when I (being on west side) kill a AI (being on east side) it doesn't take away a ticket. I used an eventhandler but I don't think they get included because they are spawned with the Spawn AI module. Basically is there a way for me to apply this logic to AI when they are killed or spawned with the module? Share this post Link to post Share on other sites
dr death jm 117 Posted January 10, 2015 id like to see this work per kill, instead of once bleed tickets is activated it just continues negitive scoring till mission ends, ie: 100 kills ends the game . instead of it being a timer.. (would be awesome on DM) Share this post Link to post Share on other sites