Announcement

Collapse
No announcement yet.

[Script] Simple TvT Ticket system

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Script] Simple TvT Ticket system

    Just a simple TvT ticket system, nothing to write home about, but I figure it might help out anybody new to mission making who wants to try things out, or if you're lazy and don't want to write your own TvT ticket system. Obviously, this is pretty simple no frills, if I were to modify this, I would generalize it a bit more to allow for quick and easy modification of tickets outside of player deaths. However, if you're not doing anything terribly fancy, it's fairly trivial to just change it outside the script.
    Code:
    ////////////////////////////////////////////////////////////////////////////
    // Name: tvttickets.sqf
    // Purpose: Handles the basic behavior of tickets in tvt. Does not
    //          handle ticket modification outside of player deaths. to
    //          modify those, use westTickets and eastTickets outside of
    //          this script. to modify the number of tickets, change the 
    //          value of the constants below.
    // Author: Original author unknown, expanded, modified for TvT, and
    //	     commented by Zonr_0.
    /////////////////////////////////////////////////////////////////////////////
    
    
    //Modify these values to change the ticket count.
    TICKETS_WEST = 30;
    TICKETS_EAST = 30;
    
    
    
    //If the player is not the server, then wait until they join,
    //then, add an event handler to fire whenever that player is killed.
    //This fires a CBA global event which is caught by the "playedKilled"
    //block.
    if (!isDedicated) then {
      waitUntil {!isNull player};
      player addEventHandler ["killed", {
        ["playedKilled"] call cba_fnc_globalEvent;
      }];
    };
    
    if (isServer) then {
      westTickets = TICKETS_WEST;
      eastTickets = TICKETS_EAST;
      
      //This whole block is an event handler for the server to
      //deal with the global event raised above. It is defining
      //the response to the "playedKilled" event.
      ["playedKilled", {
    	  killedPlayer = _this select 0;
    	  if (side killedPlayer == WEST) then {
    		  westTickets = westTickets - 1;
    		  };
    	  if (side killedPlayer == EAST) then {
    		  eastTickets = eastTickets - 1;
    		  };
        if (eastTickets <= 0) then {
          [-2, { 
          		hint "OPFOR is out of tickets";
          		sleep 10; 
          		endMission "END1"; 
          	}] call cba_fnc_globalExecute; //Execute on all machines
        };
        if (westTickets <= 0) then {
    		[-2, {
    			hint "BLUFOR is out of tickets";
    		    	sleep 10;
    		    	endmission "END2";
    		}] call cba_fnc_globalExecute;
    	}
      }] call cba_fnc_addEventHandler;
    };

  • #2
    Re: [Script] Simple TvT Ticket system

    Oops, I accidentally posted an outdated version of the script above. This one actually works.

    Code:
    ////////////////////////////////////////////////////////////////////////////
    // Name: tvttickets.sqf
    // Purpose: Handles the basic behavior of tickets in tvt. Does not
    //          handle ticket modification outside of player deaths. to
    //          modify those, use westTickets and eastTickets outside of
    //          this script. to modify the number of tickets, change the 
    //          value of the constants below.
    // Author: Original author unknown, expanded, modified for TvT, and
    //	     commented by Zonr_0.
    /////////////////////////////////////////////////////////////////////////////
    
    //Modify these values to change the ticket count.
    TICKETS_WEST = 30;
    TICKETS_EAST = 30;
    
    
    //If the player is not the server, then wait until they join,
    //then, add an event handler to fire whenever that player is killed.
    //This fires a CBA global event which is caught by the "playedKilled"
    //block.
    if (!isDedicated) then {
      waitUntil {!isNull player};
        
        
        sleep 1;
      
        if (side player == WEST) then
        {
            player addEventHandler["killed", {
                ["playedKilled", WEST] call cba_fnc_globalEvent;
            }];
        };
    
    //Kludgy, but private variables don't work for some reason.
        if (side player == EAST) then
        {
            player addEventHandler["killed", {
                ["playedKilled", EAST] call cba_fnc_globalEvent;
            }];
        };
    };
    
    if (isServer) then {
      westTickets = TICKETS_WEST;
      eastTickets = TICKETS_EAST;
      
      //This whole block is an event handler for the server to
      //deal with the global event raised above. It is defining
      //the response to the "playedKilled" event.
      ["playedKilled", {
          private ["_killedSide"];
    	  _killedSide = _this;
          
    	  if (_killedSide == WEST) then {
    		  westTickets = westTickets - 1;
    		  };
    	  if (_killedSide == EAST) then {
    		  eastTickets = eastTickets - 1;
    		  };
        if (eastTickets <= 0) then {
          [-2, { 
          		hint "OPFOR is out of tickets";
          		sleep 10; 
          		endMission "END1"; 
          	}] call cba_fnc_globalExecute; //Execute on all machines
        };
        if (westTickets <= 0) then {
    		[-2, {
    			hint "BLUFOR is out of tickets";
    		    	sleep 10;
    		    	endmission "END2";
    		}] call cba_fnc_globalExecute;
    	}
      }] call cba_fnc_addEventHandler;
    };

    Comment

    Connect

    Collapse

    TeamSpeak 3 Server

    Collapse

    Advertisement

    Collapse

    Twitter Feed

    Collapse

    Working...
    X