Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "rulesCore.as";
- #include "CTF_Structs";
- shared int decrementTickets(CRules@ this, int team){ //returns 1 if no tickets left, 0 otherwise
- print("decrement tickets for team: "+team);
- s16 numTickets;
- if(team==0){
- numTickets=this.get_s16("blueTickets");
- if(numTickets<=0)return 1;
- print("number tickets: "+numTickets);
- numTickets--;
- this.set_s16("blueTickets", numTickets);
- this.Sync("blueTickets", true);
- print("blue tickets: "+numTickets);
- return 0;
- }else if(team==1){
- numTickets=this.get_s16("redTickets");
- if(numTickets<=0)return 1;
- print("number tickets: "+numTickets);
- numTickets--;
- this.set_s16("redTickets", numTickets);
- this.Sync("redTickets", true);
- print("red tickets: "+numTickets);
- return 0;
- }
- return 1;
- }
- shared bool isPlayersLeft(CRules@ this, int team){ //checks if spawning players or alive players
- /*RulesCore@ core;
- this.get("core", @core);
- CTFTeamInfo@ teamInfo = cast<CTFTeamInfo@>(core.teams[team]);
- print("alive players left: "+teamInfo.alive_count);
- print("spawning player left: "+teamInfo.spawns.length());
- if(teamInfo.spawns.length()>0) return true;
- if(teamInfo.alive_count>0) return true;
- return false;*/
- if(team==0) return this.get_s8("aliveOrSpawningBlue")>0;
- if(team==1) return this.get_s8("aliveOrSpawningRed")>0;
- return false; //just incase
- }
- shared bool isSpawning( CRules@ this, CPlayer@ player ){
- RulesCore@ core;
- this.get("core", @core);
- CTFPlayerInfo@ info = cast<CTFPlayerInfo@>(core.getInfoFromPlayer(player));
- for (uint i = 0; i < core.teams.length; i++){
- CTFTeamInfo@ team = cast<CTFTeamInfo@>(core.teams[i]);
- int pos = team.spawns.find(info);
- if (pos != -1) {
- return true;
- }
- }
- return false;
- }
- shared s8 updateAliveOrSpawning(CRules@ this, int teamNum, s8 incrementBy){ //changes number of alive players on a team by incrementBy (can be negative)
- s8 aliveOrSpawning=0;
- if(teamNum==0){
- aliveOrSpawning=this.get_s8("aliveOrSpawningBlue");
- aliveOrSpawning=aliveOrSpawning+incrementBy;
- //if(aliveOrSpawning<0)aliveOrSpawning=0;
- this.set_s8("aliveOrSpawningBlue", aliveOrSpawning);
- this.Sync("aliveOrSpawningBlue", true);
- }else if(teamNum==1){
- aliveOrSpawning=this.get_s8("aliveOrSpawningRed");
- aliveOrSpawning=aliveOrSpawning+incrementBy;
- //if(aliveOrSpawning<0)aliveOrSpawning=0;
- this.set_s8("aliveOrSpawningRed", aliveOrSpawning);
- this.Sync("aliveOrSpawningRed", true);
- }
- print("updated alive or spawning, team: "+teamNum+" players alive: "+aliveOrSpawning);
- return aliveOrSpawning;
- }
- shared bool teamPlayersAlive(CRules@ this, int teamNum)
- {
- CBlob@[] team_blobs;
- CBlob@[] player_blobs;
- getBlobsByTag( "player", @player_blobs );
- for ( uint i = 0; i < player_blobs.length; i++ )
- {
- CBlob@ blob = player_blobs[i];
- if (blob !is null)
- {
- int team_num = blob.getTeamNum();
- if (team_num == teamNum)
- {
- team_blobs.push_back(blob);
- }
- else
- {
- // do nothing
- }
- }
- }
- return team_blobs.length > 0? true : false;
- }
- shared bool checkGameOver(CRules@ this, int teamNum)
- {
- bool blue_alive = teamPlayersAlive(this, 0);
- bool red_alive = teamPlayersAlive(this, 1);
- /*if (!isPlayersLeft(this, teamNum)) //check if any players left alive or are spawning
- {*/
- if (teamNum == 1 && !red_alive) //teams hardcoded -> if one is dead, other wins (no consideration for more teams)
- {
- print("checking red tickets left: " + this.get_s16("redTickets"));
- if (this.get_s16("redTickets") > 0)
- {
- return false;
- }
- else
- {
- this.SetTeamWon( 0 ); //game over!
- this.SetCurrentState(GAME_OVER);
- this.SetGlobalMessage( this.getTeam(0).getName() + " wins the game!" );
- return true;
- }
- }
- else if (teamNum == 0 && !blue_alive) //blue
- {
- print("checking blue tickets left: " + this.get_s16("blueTickets"));
- if (this.get_s16("blueTickets")>0)
- {
- return false;
- }
- else
- {
- this.SetTeamWon( 1 ); //game over!
- this.SetCurrentState(GAME_OVER);
- this.SetGlobalMessage( this.getTeam(1).getName() + " wins the game!" );
- return true;
- }
- }
- //}
- return false;
- }
- shared void addTicketSpawn(CRules@ this, CPlayer@ player){
- print("player requesting spawn: "+player.getUsername());
- int teamNum=player.getTeamNum();
- if(!isSpawning(this, player)){ //if they are already spawning, dont remove a ticket, but let them readd to the spawn list
- print("player requesting spawn accepted: "+player.getUsername());
- if(this.isMatchRunning()){ //check if build time
- if(decrementTickets(this, teamNum)==1){ //decrementTickets() returns 1 if team out of units
- print("players left: "+isPlayersLeft(this, teamNum));
- checkGameOver(this, teamNum);
- return;
- }
- }
- }
- //only reaches here if player should spawn - code taken from CoreHooks.as and commented out in the original position
- //this code taken from CoreHooks.as, and commented out in its original position
- print("spawning the player");
- if(!getNet().isServer())
- return;
- RulesCore@ core;
- this.get("core", @core);
- if (core !is null) {
- if(!isSpawning(this, player)) updateAliveOrSpawning(this, teamNum, 1);
- core.AddPlayerSpawn(player);
- }
- //print("numberPlayers: "+aliveOrSpawningRed+" "+aliveOrSpawningBlue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement