March 28 2024 13:07:12
Navigation
· Home
· Articles
· Downloads
· FAQ
· Discussion Forum
· Web Links
· News Categories
· Contact Me
· Photo Gallery
· Search
· Gameservers
Languages
Users Online
· Guests Online: 1

· Members Online: 0

· Total Members: 1,127
· Newest Member: Highl@nder
Teamspeak 3
Last Seen Users
· Intruder12:18:58
· Highl@nder17:04:13
· Silent Bob21:32:11
· desintegrator 1 day
· Jerry 2 days
· gus 2 days
· forrest747 3 days
· WEZ 3 days
· Sully 4 days
· doomed 1 week
· Terminator 1 week
· The ACE 1 week
· GONZO 2 weeks
· VictorMyson 3 weeks
· Don Turtuma 4 weeks

View Thread: MP synchronized object/helper scripts
Vietcong.Info » Vietcong General Discussion » Maps & Mapping
Who is here? 1 Guest
Current Rating: (Total: 5 ratings)  
 Print Thread
MP synchronized object/helper scripts
Ando
SSA (Sharp Shooter Assault) mode script

Idea for vietcong: apfelbaum

Script by: Ando

Mode description:
Fight with everybody. No teams, no rules. Weapon cycles to a random weapon after 20 seconds. Every player have same weapon simultaneously.
You will see remaining time for next cycle on screen.

Features
- show player in different color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- fade for restart
- fade to "Mission completed"
- best player in dark red when mission completed

Tutorial
- custom recover point id = 28 or waypoint name "SSA_'nr'" if none then using DM recovery points
- ENDRULE: Frags

Script: version 2.4 (updated 05.11.2015)
Spoiler:
Download source  Code

//   VIETCONG 1
//   SSA (Sharp Shooter Assault) script - compatible with synchronized objects
//   made by Ando
// v2.4

/*

   ______________DESCRIPTION:
SSA (Sharp Shooter Assault)
Sharp Shooter Assault - fight with everybody. No teams, no rules.
Weapon cycles to a random weapon and every player have same weapon.



   ______________TUTORIAL FOR EDITOR
ENDRULE:         Frags
RECOVERY POINT:      SSA or waypoint name "SSA_'nr'"  if none then using DM recovery points



*/

/*
//- text added to bottom left
//- 0.5 sec without weapon when change
//- bug with grenade fixed
//- no repeated random weapon choice
//- VC style time counter removed
//- removed invisible gun
//- cant drop weapon continuously
//- clean all 9 weapon slots
//- bug with random choice fixed
//- new weapon cant be one what was last 3 rounds
//- switch right weapon when picked wrong one from ground
//2.2
//- right weap after spawn
- custom recover point id = 28. Added to editor after batch 1.7
- added fade for restart
- show player in different color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- cleaned

- added gphase "GPHASE_MISSION_COMPLETED" (used when end condition reached)
- added text "Mission completed"   //#2026:    #tee   Mission completed
- added fade to "Mission completed"
- best player in dark red when mission completed
- one definition fix
*/


#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define SHOW_PLAYER_COLOR         1
#define SHOW_PLAYERS_COUNT         1

#define FADE_TIME               0.8
#define RESTART_TIMER            3   //time before actual restart
#define BEGIN_TIMER               3   //

//________________________________Global Variables for MP objects___
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable

//________________________________Global Variables__________________
#define GVAR_GPHASE         500      // important to use  game phase and channel 500 for synchronised objects
#define GVAR_GPHASE_TIME   501      
#define GVAR_CUR_WEAP      502
#define GVAR_WINNER         503    // winner handle

//________________________________Game phases_______________________
#define GPHASE_BEGIN            1   //objects are restarting
#define GPHASE_WAIT_PLAYERS         2   //wait players
#define GPHASE_START_GAME         3   //fade on and spawn
#define GPHASE_GAME               4   //game
#define GPHASE_MISSION_COMPLETED   5

//________________________________Recover___________________________
#define RECOVER_TIME      5.0f      // time to recover player after killed
#define NORECOV_TIME      3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME         "SSA_%d"      //
#define REC_MAX            64

//#define RECOVER_POINT_ID   28         //custom recower point id.
#ifndef SC_MP_RESPAWN_SSA
#define   SC_MP_RESPAWN_SSA   28   
#endif

#ifndef GVAR_MP_MISSIONTYPE_SSA   
#define   GVAR_MP_MISSIONTYPE_SSA   19
#endif
//__________________________________________________________________






#define ROUND_TIME      40      


#define LIST_COUNT               23      // count of weapons
int   WEAP_LIST[LIST_COUNT]      = {   1,      //M16
                           2,      //Ak-47
                           4,   // – M1 garand sniper rifle
                           6,   // – PPS-41 submachinegun
                           7,   // – Colt M1911 pistol
                           8,   // – Tokarev pistol
                           9,   // – Makarov pistol
                           10,   // – Revolver .38
                           11,   // – Remmington shotgun
                           12,   // – Winchester sniper rifle
                           14,   // – SVD Dragunov sniper rifle
                           15,   // – SKS Simonov rifle
                           17,   // – M60 machinegun
                           18,   // – Degtarjev machinegun
                           19,   // – USM3 submachinegun
                           21,   // – Thompson submachinegun
                           22,   // – S&W silenced pistol
                           23,   // – PPS-43 submachinegun
                           25,   // – M1 carabine
                           26,   // – Mosin Nagant rifle
                           28,   // – double barelled shotgun
                           29,      //Knife
                           59 };   //Grenade
   





#define RESTART_TIMER            5   //time before actual restart




dword gPhase =         GPHASE_BEGIN;
float gPhase_timer =   BEGIN_TIMER;




BOOL    fade_off = TRUE;
BOOL    weap_removed = TRUE;
dword    gEndRule;
dword    gEndValue;
dword    gPlayersConnected = 0;
dword    gRecs = 0;
float    delay_timer;
float    gRecTimer[REC_MAX];
float    gTime;
float    new_time;
float    Prev_time;
float    update_timer;
float   client_fade_timer = RESTART_TIMER;
float   complete_f_timer=0;
float    CLN_gPhase_timer;
float   fade_off_timer;
int      cur_weap=0;
int      CLN_cur_weap=0;
int    last_srv_weap_2=0;
int    last_srv_weap_3=0;
int    last_srv_weap_4=0;
int    last_srv_weap_5=0;
int    last_srv_weap=0;
int    last_weap=-1;
int    my_min;
int    my_sec;
s_SC_MP_Recover    gRec[REC_MAX];
s_SC_P_Create      get_weap_inf;
ushort             *player_s;




BOOL SRV_CheckEndRule(float time){
   int frags;
   dword win_pl;
   BOOL completed=FALSE;

   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
            SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
            if (gTime>gEndValue) completed=TRUE;
         break;
      case SC_MP_ENDRULE_FRAGS:
         win_pl = SC_MP_GetMaxFragsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
         }
         break;
      case SC_MP_ENDRULE_POINTS:
         win_pl = SC_MP_GetMaxPointsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
            
         }
         break;
      default:
         //SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   if(completed){   
      if(gPhase!=GPHASE_MISSION_COMPLETED){
         if(win_pl){
            SC_sgi(GVAR_WINNER,SC_MP_GetHandleofPl(win_pl));
         }
         gPhase=GPHASE_MISSION_COMPLETED;
         SC_sgi(GVAR_GPHASE,gPhase);
         SC_MP_LoadNextMap();
         return TRUE;
      }
   }
   return FALSE;
}// void SRV_CheckEndRule(float time)





int ScriptMain(s_SC_NET_info *info){
   char txt[32];
   dword i;
   int j,k;
   int max_point;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   s_SC_HUD_MP_icon icon[3];
   dword icons;
   ushort wtxt[128],wtxt2[64],*witxt,*my_witxt;
   float   sc_width,sc_height,val;

   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________   
         //gPlayersConnected = 64;
         SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL);

         gPhase_timer -= info->elapsed_time;
         //________________________________________________________________
         switch(gPhase){
         case GPHASE_BEGIN: //GPHASE_BEGIN is phase for object restart
            if (gPhase_timer <= 0.0f){
               SC_MP_SetInstantRecovery(TRUE);//
               gPhase_timer=0;
               gPhase=GPHASE_WAIT_PLAYERS;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_WAIT_PLAYERS:
            if (gPlayersConnected >1){
               gPhase_timer = RESTART_TIMER;
               gPhase = GPHASE_START_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_START_GAME:
            if (gPhase_timer <= 0.0f){
               SC_MP_SetInstantRecovery(FALSE);               
               gTime = 0;
               gPhase_timer=0;
               gPhase=GPHASE_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
               SC_MP_SRV_ClearPlsStats();
               SC_MP_SRV_InitGameAfterInactive();
               SC_MP_RecoverAllNoAiPlayers();   
               update_timer=11;//11= force update
            }
            break;
         case GPHASE_GAME:

            if (gPhase_timer <= 0.0f){
               last_srv_weap_3 = last_srv_weap_2;
               last_srv_weap_2 = last_srv_weap;
               last_srv_weap = cur_weap;
               do{
                  cur_weap = WEAP_LIST[(rand() % LIST_COUNT)];
               }while( (cur_weap == last_srv_weap)||(cur_weap == last_srv_weap_2) || (cur_weap == last_srv_weap_3));//||
               SC_sgi(GVAR_CUR_WEAP,cur_weap);
               gPhase_timer=ROUND_TIME;
            }
            
            update_timer+=info->elapsed_time;//update time for clients
            if(update_timer > 10){// will update after every 10 sec.
               SC_sgf(GVAR_GPHASE_TIME,gPhase_timer);//send new time update
               update_timer=0.0f;
            }      
            
            
            
            break;
         case GPHASE_MISSION_COMPLETED:   
            break;
         }


         //________________________________________________________________
         //gPlayersConnected = 64;
         //SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL);
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         break;
      case SC_NET_MES_CLIENT_TICK:
         switch(SC_ggi(GVAR_GPHASE)){
         case GPHASE_BEGIN:            //___________________________CLN______BEGIN
            break;
         case GPHASE_WAIT_PLAYERS:      //___________________________CLN______WAIT_PLAYERS
            witxt = SC_Wtxt(1076);//1076
            SC_GetScreenRes(&sc_width,&sc_height);
            val= sc_width - SC_Fnt_GetWidthW(witxt,1);          
            SC_Fnt_WriteW(val * 0.5f,15,witxt,1,0xffffffff);
            break;
         case GPHASE_START_GAME:       //___________________________CLN______START_GAME
            if (fade_off){
               client_fade_timer -= info->elapsed_time;
               if (client_fade_timer < (FADE_TIME + 0.1f)){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
                  client_fade_timer=RESTART_TIMER;
                  fade_off_timer=0;

                  //reset objexts and states
                  
                  Prev_time=-1;
               }
            }
            swprintf(wtxt,SC_AnsiToUni("%s %S", wtxt2),SC_Wtxt(6030)," - SSA (Sharp Shooter Assault)");
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);
            break;
         case GPHASE_GAME:
            //FADE OFF
            if (!fade_off){
               fade_off_timer += info->elapsed_time;
               if (fade_off_timer >  0.2f){// looks better so because spawn is with short delay
                  SC_FadeTo(FALSE, FADE_TIME);
                  fade_off=TRUE;



               }
            }   

         
            //if (SC_ggi(GVAR_SERVER) != 1){//not server
            CLN_cur_weap = SC_ggi(GVAR_CUR_WEAP);
            CLN_gPhase_timer -= info->elapsed_time;
            // update time
            new_time = SC_ggf(GVAR_GPHASE_TIME);
            if (Prev_time != new_time){//update if new time for update
               CLN_gPhase_timer = new_time;
               Prev_time = new_time;
            }
            //}

            if (last_weap != CLN_cur_weap){// new weapon
               if(SC_P_IsReady(SC_PC_Get())){
                  SC_P_ChangeWeapon(SC_PC_Get(), 0, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 1, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 2, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 3, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 4, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 5, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 6, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 7, 0);//cur_weap
                  SC_P_ChangeWeapon(SC_PC_Get(), 8, 0);//cur_weap
                  weap_removed=TRUE;
               }
               last_weap=CLN_cur_weap;
               delay_timer =0;
            }
            delay_timer+=info->elapsed_time;
            if (delay_timer > 0.6f){
               if (CLN_cur_weap != 0){
                  if(SC_P_IsReady(SC_PC_Get())){
                     if (SC_P_GetWeapons(SC_PC_Get(), &get_weap_inf)){
                        if(get_weap_inf.weap_main1 != CLN_cur_weap ){
                           if ((weap_removed==TRUE) && (get_weap_inf.weap_main1 == 0 ) ||  (weap_removed==FALSE)&& (get_weap_inf.weap_main1 != 0 )  || (get_weap_inf.weap_pistol != 0 )){
                              SC_P_ChangeWeapon(SC_PC_Get(), 0, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 1, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 3, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 4, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 5, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 6, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 7, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 8, 0);//cur_weap
                              SC_P_ChangeWeapon(SC_PC_Get(), 2, CLN_cur_weap);//cur_weap
                              SC_P_SetSelWeapon(SC_PC_Get(), 2);//
                              weap_removed=FALSE; // if droped after that then he dont get new weapon
                           }
                        }
                     }
                  }
               }
            }

            my_min = (int)((CLN_gPhase_timer+1)/60);   
            my_sec = (int)(CLN_gPhase_timer+1) - my_min;
            if (my_sec < 0){
               swprintf(wtxt,SC_AnsiToUni("", wtxt2));
            }else if (my_sec < 10){
               swprintf(wtxt,SC_AnsiToUni("%s:  %d:0%d", wtxt2),SC_Wtxt(8260), my_min, my_sec);
            }else{
               swprintf(wtxt,SC_AnsiToUni("%s:  %d:%d", wtxt2),SC_Wtxt(8260), my_min, my_sec);
            }
            SC_GetScreenRes(&sc_width,&sc_height);
            SC_Fnt_WriteW(50,(sc_height - 100),wtxt,1.1,0x85ffffff);
            break;
         case GPHASE_MISSION_COMPLETED:   
            if (fade_off){
               complete_f_timer -= info->elapsed_time;
               if (complete_f_timer < -6.0f){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
               }
            }         
            swprintf(wtxt,SC_AnsiToUni("%s", wtxt2),SC_Wtxt(2026));//#2026:    #tee   Mission completed
            SC_GetScreenRes(&sc_width,&sc_height);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);

            swprintf(wtxt,SC_AnsiToUni("Best player:  %S ", wtxt2), SC_P_GetName(SC_MP_GetPlofHandle(SC_ggi(GVAR_WINNER))));
            //SC_Fnt_WriteW((sc_width*0.5),35,wtxt,1.1,0x85ffffff);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);   
            SC_Fnt_WriteW(val,35,wtxt,1,0xffffffff);
            break;
         }
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_LEVELPREINIT:
         client_fade_timer=RESTART_TIMER;

         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_SSA);
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         SC_HUD_DisableRadar(TRUE);         
         SC_MP_SRV_SetClassLimitsForDM();   
         CLEAR(hudinfo);
         hudinfo.title = 1050;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_FRAGS;         
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_FRAGS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = 0;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(FALSE);
         SC_MP_AllowFriendlyFireOFF(FALSE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server   
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE_TIME);
               SC_MP_Gvar_SetSynchro(GVAR_CUR_WEAP);
               SC_MP_Gvar_SetSynchro(GVAR_WINNER);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 170
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_SSA,&gRec[gRecs],&i);
               gRecs += i;
#endif
               if (gRecs==0){
                  SC_message("no 'SSA' recover place added! Will use 'DM' recover place if exist.");
                  i = REC_MAX - gRecs;
                  SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
                  gRecs += i;
               }

               CLEAR(gRecTimer);
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:
         if(SC_KeyPressed(0x0F)){//TAB pressed
            if(SHOW_PLAYER_COLOR){
               SC_MP_HUD_SelectPl(SC_PC_Get(),0x1100ffff);
            }
            if (SHOW_PLAYERS_COUNT){
               SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d  %s", wtxt2),j,player_s);
               SC_Fnt_WriteW(100,25,wtxt,1,0xffffffff);
            }
         }else if(SC_ggi(GVAR_GPHASE)==GPHASE_MISSION_COMPLETED){
            if (SC_MP_GetMaxFragsPl(&max_point)){
               if(max_point > 0){
                  SC_MP_HUD_SelectPl(SC_MP_GetMaxFragsPl(&max_point),0x88440000);
               }
            }
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:

         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{// killed

            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;
         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];      
         break;
      case SC_NET_MES_RESTARTMAP:
         //___________________________________________________________
         gPhase_timer = BEGIN_TIMER;
         gPhase = GPHASE_BEGIN;   
         SC_sgi(GVAR_GPHASE,gPhase);   
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;
   }// switch(info->message)
   return 1;
}// int ScriptMain(void)




Edited by Ando on 05-11-2015 17:01
  x 1  x 2
 
Ando
GG (Gun Game) mode script

Idea for vietcong: apfelbaum

Script by: Ando

Mode description:
Fight with everybody. No teams. Every kill give you new level and new weapon. Who reaches to highest level is winner.
While pressing TAB, you will see weapon list and your level on screen. Player points will show reached levels.

Features
- show player in different color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- fade for restart
- fade to "Mission completed"
- best player in dark red when mission completed

Tutorial
- custom recover point id = 27 or waypoint name "GG_'nr'" if none then using DM recovery points
- ENDRULE: Points min:22 max:22 default:22


Script: version 2.2 (updated 05.11.2015)
Spoiler:
Download source  Code

//   VIETCONG 1
//   GG (Gun Game) script - compatible with synchronized objects
//   made by Ando
// v2.2

/*
   ______________DESCRIPTION:
GG (Gun Game) script

Gun Game - fight with everybody. No teams.
Every kill give you new level and new weapon. Who reaches to highest level is winner.



   ______________TUTORIAL FOR EDITOR
ENDRULE: Points  min:22 max:22 default:22
RECOVERY POINT:      GG or waypoint name "GG_'nr'"


//   NOTES:
- custom recover point id = 27. Added to editor after batch 1.7
- added fade for restart
- show player in different color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- added fade to "Mission completed"
- cleaned
- one definition fix
- "leaving player reset" fix

*/

#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define SHOW_PLAYER_COLOR         1
#define SHOW_PLAYERS_COUNT         1

#define FADE_TIME               0.8
#define RESTART_TIMER            3   //time before actual restart
#define BEGIN_TIMER               3   //

//________________________________Global Variables for MP objects___
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable

//________________________________Global Variables__________________
#define GVAR_GPHASE         500      // important to use  game phase and channel 500 for synchronised objects
#define GVAR_WINNER         501
#define GVAR_PLAYERS      300
#define GVAR_PL_POINTS      400

//________________________________Game phases_______________________
#define GPHASE_BEGIN            1   //objects are restarting
#define GPHASE_WAIT_PLAYERS         2   //wait plaiers if needed and respawn for start
#define GPHASE_START_GAME         3   //fade on and spawn
#define GPHASE_GAME               4   //game
#define GPHASE_MISSION_COMPLETED   6


//________________________________Recover___________________________
#define RECOVER_TIME   5.0f      // time to recover player after killed
#define NORECOV_TIME   3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME      "GG_%d"
#define REC_MAX         64

//#define RECOVER_POINT_ID   27         //custom recower point id.
#ifndef SC_MP_RESPAWN_GG
#define   SC_MP_RESPAWN_GG   27         // GG - 27
#endif

#ifndef GVAR_MP_MISSIONTYPE_GG   
#define   GVAR_MP_MISSIONTYPE_GG   18
#endif

//__________________________________________________________________

   





#define LIST_COUNT               22      // count of weapons
int   WEAP_LIST[LIST_COUNT]      = {   10,   //2206 –   Revolver 38
                           8,   //2208 –   Tokarev
                           15,   //2212 –   SKS Simonov
                           9,   //2207 –   Makarov
                           7,   //2205 –   Colt M1911

                           22,   //2218 –   S&W model 39
                           6,   //2204 –   PPS-41
                           19,   //2215 –   US-M3
                           11,   //2209 –   Remington 870
                           23,   //2219 –   PPS-43

                           21,   //2217 –   Thompson
                           1,   //2201 -   M16
                           2,   //2202 -   AK47
                           4,   //2203 –   M1 Garand
                           25,   //2220 –   M1 Carbine

                           17,   //2213 –   M60
                           12,   //2210 –   Winchester 70
                           14,   //2211 –   SVD Dragunov
                           26,   //2221 –   Mosin-Nagant
                           28,   //2223 –   Baikal IZH-43

                           59,   //2234 -   Grenade
                           29 };//2224 -   Knife
// weapon list for TAB info
char   *WEAP_NAME_LIST[LIST_COUNT]      = {   "Revolver 38",
                                 "Tokarev",
                                 "SKS Simonov",
                                 "Makarov",
                                 "Colt M1911",

                                 "S&W model 39",
                                 "PPS-41",
                                 "US-M3",
                                 "Remington 870",
                                 "PPS-43",

                                 "Thompson",
                                 "M16",
                                 "AK47",
                                 "M1 Garand",
                                 "M1 Carbine",

                                 "M60",
                                 "Winchester 70",
                                 "SVD Dragunov",
                                 "Mosin-Nagant",
                                 "Baikal IZH-43",

                                 "Grenade",
                                 "Knife" };



//___________________________

dword gPhase =         GPHASE_BEGIN;
float gPhase_timer =   BEGIN_TIMER;
//___________________________

ushort *player_s;



dword         cur_handle;
dword         PC_handle;
dword         killer_handle;

s_SC_P_Create   get_weap_inf;



int last_weap=-1;
int cur_weap=0;
int row;
int pl_slot;
int PL_points;
int CUR_PL_points;


dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];
BOOL player_added;
BOOL weap_removed=FALSE;


dword gEndRule;
dword gEndValue;
float gTime;
float delay_timer;

dword gPlayersConnected = 0;


BOOL    fade_off = TRUE;
float   client_fade_timer = RESTART_TIMER;
float   fade_off_timer;
float   complete_f_timer=0;

BOOL  EnumPls;



BOOL SRV_CheckEndRule(float time){
   int frags;
   dword win_pl;
   BOOL completed=FALSE;

   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
            SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
            if (gTime>gEndValue) completed=TRUE;
         break;
      case SC_MP_ENDRULE_FRAGS:
         win_pl = SC_MP_GetMaxFragsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
         }
         break;
      case SC_MP_ENDRULE_POINTS:
         win_pl = SC_MP_GetMaxPointsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
            
         }
         break;
      default:
         //SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   if(completed){   
      if(gPhase!=GPHASE_MISSION_COMPLETED){
         if(win_pl){
            SC_sgi(GVAR_WINNER,SC_MP_GetHandleofPl(win_pl));
         }
         gPhase=GPHASE_MISSION_COMPLETED;
         SC_sgi(GVAR_GPHASE,gPhase);
         SC_MP_LoadNextMap();
         return TRUE;
      }
   }
   return FALSE;
}// void SRV_CheckEndRule(float time)
int ScriptMain(s_SC_NET_info *info){
   char txt[32];
   dword i;
   int j,k;
   int max_point;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   s_SC_HUD_MP_icon icon[3];
   dword icons;
   ushort wtxt[128],wtxt2[64],*witxt,*my_witxt;
   float   sc_width,sc_height,val;

   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________   
         //gPlayersConnected = 64;
         EnumPls=FALSE;
         if (SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL)){
            EnumPls=TRUE;
         }


         gPhase_timer -= info->elapsed_time;
         switch(gPhase){
         case GPHASE_BEGIN: //GPHASE_BEGIN is phase for object restart
            if (gPhase_timer <= 0.0f){
               SC_MP_SetInstantRecovery(TRUE);//
               gPhase_timer=0;
               gPhase=GPHASE_WAIT_PLAYERS;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_WAIT_PLAYERS:
            if (gPlayersConnected >1){
               gPhase_timer = RESTART_TIMER;
               gPhase=GPHASE_START_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_START_GAME:
            
            if (gPhase_timer <= 0.0f){
               for (i=0;i<64;i++){
                  SC_sgi(GVAR_PL_POINTS + i, 0);
               }
               SC_MP_SetInstantRecovery(FALSE);               
               gTime = 0;
               gPhase=GPHASE_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
               SC_MP_SRV_ClearPlsStats();
               SC_MP_SRV_InitGameAfterInactive();
               SC_MP_RecoverAllNoAiPlayers();   
            }
            break;
         case GPHASE_GAME:
            if(EnumPls){
               for (i=0;i<64;i++){//CLEAN DATA if player lost
                  cur_handle = SC_ggi(GVAR_PLAYERS + i);
                  if (cur_handle != 0){//some handle here
                     if (SC_MP_GetPlofHandle (cur_handle) == 0){// not in game, clear data
                        SC_sgi(GVAR_PLAYERS + i, 0);
                        SC_sgi(GVAR_PL_POINTS + i, 0);
                     }
                  }
               }
               for (i=0;i<gPlayersConnected;i++){//IS PLAYER IN LIST
                  cur_handle = SC_MP_GetHandleofPl(enum_pl[i].id);
                  k=0;
                  player_added=FALSE;
                  do{// is player in list
                     if (cur_handle == SC_ggi(GVAR_PLAYERS + k)){
                        player_added = TRUE;
                     }
                     k++;
                  }while(!player_added && (k < 64) );//||

                  if (!player_added){// ADD PLAYER to list
                     k=0;
                     do{
                        pl_slot = SC_ggi(GVAR_PLAYERS + k);
                        if (pl_slot == 0){//slot free
                           SC_sgi(GVAR_PLAYERS + k, cur_handle);
                           SC_sgi(GVAR_PL_POINTS + k, 0);// clean data
                           player_added=TRUE;
                        }
                        k++;
                     }while(!player_added && (k < 64) );//||
                  }
               }
            }
            break;
         case GPHASE_MISSION_COMPLETED:   
            break;
         }
         //________________________________________________________________
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         break;
      case SC_NET_MES_CLIENT_TICK:
         switch(SC_ggi(GVAR_GPHASE)){
         case GPHASE_BEGIN:            //___________________________CLN______BEGIN
            //SC_Osi("GPHASE_BEGIN");
            break;
         case GPHASE_WAIT_PLAYERS:      //___________________________CLN______WAIT_PLAYERS
            //SC_Osi("GPHASE_WAIT_PLAYERS");
            witxt = SC_Wtxt(1076);//1076
            SC_GetScreenRes(&sc_width,&sc_height);
            val= sc_width - SC_Fnt_GetWidthW(witxt,1);          
            SC_Fnt_WriteW(val * 0.5f,15,witxt,1,0xffffffff);
            break;   
         case GPHASE_START_GAME:       //___________________________CLN______START_GAME
            //SC_Osi("GPHASE_START_GAME");
            if (fade_off){
               client_fade_timer -= info->elapsed_time;
               if (client_fade_timer < (FADE_TIME + 0.1f)){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
                  client_fade_timer=RESTART_TIMER;
                  fade_off_timer=0;

                  //reset objexts and states
                  if(SC_P_IsReady(SC_PC_Get())){
                     if (SC_P_GetWeapons(SC_PC_Get(), &get_weap_inf)){
                        if ((get_weap_inf.weap_pistol != 0 ) ||  (get_weap_inf.weap_main1 != 0 )){
                           SC_P_ChangeWeapon(SC_PC_Get(), 0, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 1, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 2, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 3, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 4, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 5, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 6, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 7, 0);
                           SC_P_ChangeWeapon(SC_PC_Get(), 8, 0);
                           weap_removed=TRUE; // if droped after that then he dont get new weapon
                        }
                     }
                  }
                  PL_points=0;
                  cur_weap=0;
               }
            }
            swprintf(wtxt,SC_AnsiToUni("%s %S", wtxt2),SC_Wtxt(6030)," - GG (Gun Game)");
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);
            break;
         case GPHASE_GAME:
            //FADE OFF
            if (!fade_off){
               fade_off_timer += info->elapsed_time;
               if (fade_off_timer >  0.2f){// looks better so because spawn is with short delay
                  SC_FadeTo(FALSE, FADE_TIME);
                  fade_off=TRUE;



               }
            }   




            if(SC_P_IsReady(SC_PC_Get())){
               PC_handle = SC_MP_GetHandleofPl(SC_PC_Get());
               player_added=FALSE;
               k=0;
               do{
                  if (PC_handle == SC_ggi(GVAR_PLAYERS + k)){
                     PL_points =  SC_ggi(GVAR_PL_POINTS + k);//get points
                     
                     cur_weap = WEAP_LIST[PL_points];
                     if (last_weap != cur_weap){
                        delay_timer = 0;
                        last_weap = cur_weap;
                        SC_P_ChangeWeapon(SC_PC_Get(), 0, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 1, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 2, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 3, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 4, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 5, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 6, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 7, 0);//cur_weap
                        SC_P_ChangeWeapon(SC_PC_Get(), 8, 0);//cur_weap
                        
                        weap_removed=TRUE;
                     }
                     //SC_sgi(GVAR_PL_POINTS + k, PL_points + 1 );// set points
                     player_added = TRUE;
                  }
                  k++;
               }while(!player_added && (k < 64) );//||
               
               delay_timer+=info->elapsed_time;
               if (delay_timer > 0.6f){
                  if (cur_weap != 0){
                     if(SC_P_IsReady(SC_PC_Get())){
                        //if (!SC_P_HasWeapon(SC_PC_Get(), cur_weap)){// not working with grenade and knife????
                        if (SC_P_GetWeapons(SC_PC_Get(), &get_weap_inf)){
                           if(get_weap_inf.weap_main1 != cur_weap ){
                              //SC_Osi("Here  weap: %d", cur_weap);
                              if ((weap_removed==TRUE) && (get_weap_inf.weap_main1 == 0 ) ||  (weap_removed==FALSE)&& (get_weap_inf.weap_main1 != 0 )  || (get_weap_inf.weap_pistol != 0 )){
                              //if (!SC_P_HasWeapon(SC_PC_Get(), cur_weap)){
                                 SC_P_ChangeWeapon(SC_PC_Get(), 0, 0);
                                 SC_P_ChangeWeapon(SC_PC_Get(), 1, 0);
                                 SC_P_ChangeWeapon(SC_PC_Get(), 3, 0);
                                 SC_P_ChangeWeapon(SC_PC_Get(), 4, 0);
                                 SC_P_ChangeWeapon(SC_PC_Get(), 5, 0);
                                 SC_P_ChangeWeapon(SC_PC_Get(), 6, 0);//cur_weap
                                 SC_P_ChangeWeapon(SC_PC_Get(), 7, 0);//cur_weap
                                 SC_P_ChangeWeapon(SC_PC_Get(), 8, 0);//cur_weap
                                 SC_P_ChangeWeapon(SC_PC_Get(), 2, cur_weap);//cur_weap
                                 SC_P_SetSelWeapon(SC_PC_Get(), 2);//
                                 weap_removed=FALSE; // if droped after that then he dont get new weapon
                              }
                           }
                        }
                     }
                  }
               }
            }
            //#8450:    #tee Level
            //if(SC_P_IsReady(SC_PC_Get())){
               swprintf(wtxt,SC_AnsiToUni("%s: %d of %d", wtxt2),SC_Wtxt(8450), PL_points , LIST_COUNT);
               SC_GetScreenRes(&sc_width,&sc_height);
               SC_Fnt_WriteW(50,(sc_height - 100),wtxt,1.1,0x85ffffff);
            //}
            break;
         case GPHASE_MISSION_COMPLETED:   
            if (fade_off){
               complete_f_timer -= info->elapsed_time;
               if (complete_f_timer < -6.0f){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
               }
            }
            swprintf(wtxt,SC_AnsiToUni("%s", wtxt2),SC_Wtxt(2026));//#2026:    #tee   Mission completed
            SC_GetScreenRes(&sc_width,&sc_height);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);

            swprintf(wtxt,SC_AnsiToUni("Best player:  %S ", wtxt2), SC_P_GetName(SC_MP_GetPlofHandle(SC_ggi(GVAR_WINNER))));
            //SC_Fnt_WriteW((sc_width*0.5),(sc_height*0.5),wtxt,1.1,0x85ffffff);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);   
            SC_Fnt_WriteW(val,35,wtxt,1,0xffffffff);
            break;
         }
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_SERVER_KILL:
         //info->param2//killer
         //info->param1//killed
         if ((info->param1 != info->param2) && (info->param2 != 0)) {
            SC_P_MP_AddPoints(info->param2, 1);
            player_added=FALSE;
            k=0;
            killer_handle = SC_MP_GetHandleofPl(info->param2);
            do{
               if (killer_handle == SC_ggi(GVAR_PLAYERS + k)){
                  CUR_PL_points =  SC_ggi(GVAR_PL_POINTS + k);//get points
                  SC_sgi(GVAR_PL_POINTS + k, CUR_PL_points + 1 );// set points
                  if((CUR_PL_points+1) >= LIST_COUNT){
                     SC_sgi(GVAR_WINNER, killer_handle );
                     //gPhase_timer=10;
                     //gPhase=GPHASE_WIN;
                     //SC_sgi(GVAR_GPHASE,gPhase);
                  }
                  player_added = TRUE;
               }
               k++;
            }while(!player_added && (k < 64) );//||
         }
         break;// SC_NET_MES_SERVER_KILL
      case SC_NET_MES_LEVELPREINIT:
         client_fade_timer=RESTART_TIMER;

         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_GG);
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         for (i=300;i<364;i++){   //custom global variables for player id's ( need to update from client side too)
            SC_MP_Gvar_SetSynchro(i);
         }

         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         
         //SC_MP_SRV_SetClassLimit(18,0);//PILOT US
         //SC_MP_SRV_SetClassLimit(19,0);//DM- US
         //SC_MP_SRV_SetClassLimit(39,0);//DM - NVA
         
         SC_HUD_DisableRadar(TRUE);         
         //SC_MP_SRV_SetClassLimitsForDM();   
         CLEAR(hudinfo);
         hudinfo.title = 1050;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_POINTS;         
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_POINTS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = 0;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(FALSE);
         SC_MP_AllowFriendlyFireOFF(FALSE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server   
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_MP_Gvar_SetSynchro(GVAR_WINNER);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               
               for (i=400;i<464;i++){   //for player points
                  SC_MP_Gvar_SetSynchro(i);
               }
               //_______________________________________________________________________________________
               



               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 170
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_GG,&gRec[gRecs],&i);
               gRecs += i;
#endif
               if (gRecs==0){
                  SC_message("no 'GG' recover place added! Will use 'DM' recover place if exist.");
                  i = REC_MAX - gRecs;
                  SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
                  gRecs += i;
               }




               CLEAR(gRecTimer);
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:

         if(SC_KeyPressed(0x0F)){//TAB pressed
            if(SHOW_PLAYER_COLOR){
               SC_MP_HUD_SelectPl(SC_PC_Get(),0x1100ffff);
            }
            if (SHOW_PLAYERS_COUNT){
               SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d  %s", wtxt2),j,player_s);
               SC_Fnt_WriteW(100,25,wtxt,1,0xffffffff);
            }
            SC_GetScreenRes(&sc_width,&sc_height);
            row=0;
            for (i=0;i<22;i++){
               swprintf(wtxt,SC_AnsiToUni("%d. %S", wtxt2), (i+1), WEAP_NAME_LIST[i]);
               if (i == PL_points){
                  SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ff0000);               
               }else{
                  SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ffffff);
               }
               row+=13;
            }
            
            // add some info
            /*         
            swprintf(wtxt,SC_AnsiToUni("%d._ %d", wtxt2), SC_ggi(GVAR_PLAYERS + 0), SC_ggi(GVAR_PL_POINTS + 0));
            SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ffffff);
            row+=13;
            swprintf(wtxt,SC_AnsiToUni("%d._ %d", wtxt2), SC_ggi(GVAR_PLAYERS + 1), SC_ggi(GVAR_PL_POINTS + 1));
            SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ffffff);
            row+=13;
            swprintf(wtxt,SC_AnsiToUni("%d._ %d", wtxt2), SC_ggi(GVAR_PLAYERS + 2), SC_ggi(GVAR_PL_POINTS + 2));
            SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ffffff);
            row+=13;
            swprintf(wtxt,SC_AnsiToUni("%d._ %d", wtxt2), SC_ggi(GVAR_PLAYERS + 3), SC_ggi(GVAR_PL_POINTS + 3));
            SC_Fnt_WriteW(10,(40+ row),wtxt,0.9,0x90ffffff);
            row+=13;
            
            */
            
            
            
            
         }else if(SC_ggi(GVAR_GPHASE)==GPHASE_MISSION_COMPLETED){
            if (SC_MP_GetMaxPointsPl(&max_point)){
               if(max_point > 0){
                  SC_MP_HUD_SelectPl(SC_MP_GetMaxPointsPl(&max_point),0x88440000);
               }
            }
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:
         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{// killed
            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;
         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];      
         break;
      case SC_NET_MES_RESTARTMAP:
         //___________________________________________________________
         gPhase_timer = BEGIN_TIMER;
         gPhase = GPHASE_BEGIN;   
         SC_sgi(GVAR_GPHASE,gPhase);
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;
   }// switch(info->message
   return 1;
}// int ScriptMain(void)





Edited by Ando on 05-11-2015 16:53
  x 1  x 2
 
Ando
HTF (Hold The Flag) mode script

Idea for vietcong: LG

Script by: Ando

Mode description:
Fight with everybody. No teams. You must capture the flag and hold it.
Some seconds, while you hold the flag, will give you one point.

Features
- show player in different color (Tab info) (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- fade for restart
- fade to "Mission completed"
- best player in dark red when mission completed
- added option to change time to get one point (now default is 2 here)
- radar will show player with flag (removed)
- added object what will show direction for player who is with flag

Tutorial
- custom recover point id = 29 or waypoint name "HTF_'nr'" if none then using DM recovery points
- Add object "mpic_vcflag" somevhere to map ( it will show flag player pos)
- ENDRULE: points
- RECOVERY POINT: HTF or waypoint name "HTF_'nr'"

Script: version 1.4 (updated 27.11.2015)
Spoiler:
Download source  Code

//   VIETCONG 1
//   HTF (Hold The Flag) script - compatible with synchronized objects
//   made by Ando
//   v1.4

//

/*
   ______________DESCRIPTION:
HTF (Hold The Flag)

Hold The Flag - fight with everybody. No teams.
Every second what you hold the flag, will give you one point.


   ______________TUTORIAL FOR EDITOR
- Add flag object from level items if you have latest mp_helpers.ini file
 or flag object:  "G\\Weapons\\Vvh_flag\\Vvh_flag_VC.bes" and name it as "HTF_flag".
 - Add object "mpic_vcflag" somevhere to map ( it will show flag player pos)
 
ENDRULE:         points
RECOVERY POINT:      HTF or waypoint name "HTF_'nr'"  if none then will use DM



//   NOTES:
- custom recover point id = 29. Added to editor after batch 1.7
- added fade for restart
- show player in different color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)
- fixed tab list order

- added gphase "GPHASE_MISSION_COMPLETED" (used when end condition reached)
- added text "Mission completed"   //#2026:    #tee   Mission completed
- added fade to "Mission completed"
- best player in dark red when mission completed

- added flag icon
- one definition fix
- added option to change time to get one point (now default is 2 here)
- added class and weapon choice and enabled radar(ver1.3)
- added new direction object to replage radar(ver1.4)
*/


#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define SHOW_PLAYER_COLOR         1
#define SHOW_PLAYERS_COUNT         1
#define SECONDS_FOR_POINT         2   // how much seconds player must hold the flag to get one point
#define SHOW_DIR_TIME            10   //seconds //time after what direction object is visible
#define FPL_CLOSE_DIST            10   //meters // closest distance to flag player when direction object is visible

#define FADE_TIME               0.8
#define RESTART_TIMER            3   //time before actual restart
#define BEGIN_TIMER               3   //


//________________________________Global Variables for MP objects___
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable

//________________________________Global Variables__________________
#define GVAR_GPHASE         500      // important to use  game phase and channel 500 for synchronised objects
#define GVAR_GPHASE_TIME   501      
#define GVAR_WINNER         503
#define GVAR_FLAG_PLAYER   504
#define GVAR_FLAG_STATUS            510

//________________________________Game phases_______________________
#define GPHASE_BEGIN            1//objects are restarting
#define GPHASE_WAIT_PLAYERS         2   //wait plaiers if needed and respawn for start
#define GPHASE_START_GAME         3   //fade on and spawn
#define GPHASE_GAME               4   //game
//#define GPHASE_FLAG_IN_BASE         4
//#define GPHASE_FLAG_ON_GROUND      5
//#define GPHASE_FLAG_ON_PLAYER      6
#define GPHASE_MISSION_COMPLETED   7

//________________________________Recover___________________________
#define RECOVER_TIME      5.0f      // time to recover player after killed
#define NORECOV_TIME      3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME         "HTF_%d"
#define REC_MAX            64

//#define RECOVER_POINT_ID   29         //custom recower point id.
#ifndef SC_MP_RESPAWN_HTF
#define   SC_MP_RESPAWN_HTF   29         //29   
#endif

#ifndef GVAR_MP_MISSIONTYPE_HTF   
#define   GVAR_MP_MISSIONTYPE_HTF   20
#endif


#define   ON_GROUND_TIME      20      // max time while droped flag is on ground
//__________________________________________________________________


#define FLAG_PH_INBASE            0
#define FLAG_PH_ONPLAYER         1
#define FLAG_PH_ONGROUND         2


#define PRELOADBES_FLAG_VC         2
#define DIR_OBJ_NAME            "mpic_vcflag"

//________________________________

dword gPhase =         GPHASE_BEGIN;
float gPhase_timer =   BEGIN_TIMER;

//___________________________
// for extra tab info
ushort *player_s;


s_SC_NOD_transform trans;
s_SC_NOD_transform orig_trans;
s_SC_NOD_transform trans_hide;


float on_player_timer;
float pl_dist;
float On_Ground_Timer=0;
float pl_total_time;
float pl_time;
float       Real_dist=0.0f;
float      Calc_y_rot;
float      Calc_z_rot;
float       P_rot;
float      show_flag_pos_timer=0.0;


float gCLN_MyFlagTimer;


void       *gFlagNod;
void      *dir_obj_id;

c_Vector3 OrigFlagPos;
c_Vector3 flag_pos;
c_Vector3 orig_flag_pos;
c_Vector3 vec;
c_Vector3      PChead;
c_Vector3      NEEDpos;
c_Vector3      rel_x_pos;


dword         pl_id;
dword         Flag_Ground_ID=0;
dword         Flag_Player_id;
dword         Flag_Player_handle;

dword         my_pl_inslot[64];
dword         my_pl_points[64];
dword         my_pl;
dword         cur_handle;
dword         PC_handle;
dword         killer_handle;
dword         last_flag_player;
dword         cln_Flag_Player_handle;



s_SC_P_Create   get_weap_inf;


int flag_phase;
int last_srv_weap=0;
int last_weap=-1;
int cur_weap=0;
int row;
int my_min;
int my_sec;
int pl_slot;
int PL_points;
int CUR_PL_points;


dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float   gRecTimer[REC_MAX];
BOOL   player_added;
BOOL   weap_removed=FALSE;
BOOL   Flag_Player_killed=FALSE;
BOOL   cln_flag_on_ground=FALSE;
BOOL   cln_flag_in_base=FALSE;
BOOL   start_game;
BOOL     EnumPls;


dword radar_color;
dword gEndRule;
dword gEndValue;
float gTime;
float Prev_time;
float update_timer;
float new_time;
float delay_timer;

dword gPlayersConnected = 0;


BOOL    fade_off = TRUE;
float   client_fade_timer = RESTART_TIMER;
float   fade_off_timer;
float   complete_f_timer=0;


BOOL SRV_CheckEndRule(float time){
   int frags;
   dword win_pl;
   BOOL completed=FALSE;

   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
            SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
            if (gTime>gEndValue) completed=TRUE;
         break;
      case SC_MP_ENDRULE_FRAGS:
         win_pl = SC_MP_GetMaxFragsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
         }
         break;
      case SC_MP_ENDRULE_POINTS:
         win_pl = SC_MP_GetMaxPointsPl(&frags);
         if (win_pl){
            if (frags>=gEndValue)completed=TRUE;
            
         }
         break;
      default:
         //SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   if(completed){   
      if(gPhase!=GPHASE_MISSION_COMPLETED){
         if(win_pl){
            SC_sgi(GVAR_WINNER,SC_MP_GetHandleofPl(win_pl));
         }
         gPhase=GPHASE_MISSION_COMPLETED;
         SC_sgi(GVAR_GPHASE,gPhase);
         SC_MP_LoadNextMap();
         return TRUE;
      }
   }
   return FALSE;
}// void SRV_CheckEndRule(float time)



int ScriptMain(s_SC_NET_info *info){
   char txt[32];
   dword i;
   int j,k;
   int max_point;
   void *nod;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   s_SC_HUD_MP_icon icon[3];
   dword icons;
   ushort wtxt[128],wtxt2[64],*witxt,*my_witxt;
   float   sc_width,sc_height,val;

   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   

         //________________________________________________________________   
         //gPlayersConnected = 64;
         EnumPls=FALSE;
         if (SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL)){
            EnumPls=TRUE;
         }


         gPhase_timer -= info->elapsed_time;
         switch(gPhase){
         case GPHASE_BEGIN:
            if (gPhase_timer <= 0.0f){
               SC_MP_SetInstantRecovery(TRUE);//
               gPhase_timer=0;
               gPhase=GPHASE_WAIT_PLAYERS;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_WAIT_PLAYERS:
            if (gPlayersConnected >1){
               gPhase_timer = RESTART_TIMER;
               gPhase=GPHASE_START_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
            }
            break;
         case GPHASE_START_GAME:
            if (gPhase_timer <= 0.0f){
               SC_MP_SetInstantRecovery(FALSE);               
               gTime = 0;
               gPhase=GPHASE_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);
               
               SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_INBASE);
               
               SC_MP_SRV_ClearPlsStats();
               SC_MP_SRV_InitGameAfterInactive();
               SC_MP_RecoverAllNoAiPlayers();   
            }
            break;
            
         case GPHASE_GAME:
            flag_phase=SC_ggi(GVAR_FLAG_STATUS);
            switch(flag_phase){
            case FLAG_PH_INBASE: //_________
               flag_pos = orig_flag_pos;
            case FLAG_PH_ONGROUND: //_________
               Flag_Player_id = SC_GetNearestPlayer(&flag_pos,&pl_dist);
               if ((Flag_Player_id)&&(pl_dist<1.5f)){
                  Flag_Player_handle = SC_MP_GetHandleofPl(Flag_Player_id);   
                  update_timer=0;
                  SC_sgi(GVAR_FLAG_PLAYER, Flag_Player_handle);
                  SC_SRV_Item_Release(Flag_Ground_ID);// release   ground flag
                  SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_ONPLAYER);
                  //gPhase=GPHASE_FLAG_ON_PLAYER;
                  //SC_sgi(GVAR_GPHASE,gPhase);
               }else{// no players around
                  if (flag_phase==FLAG_PH_ONGROUND){
                     SC_Item_GetPos(Flag_Ground_ID,&flag_pos);// update flag pos because of dynamics
                     On_Ground_Timer-= info->elapsed_time;
                     if(On_Ground_Timer < 0 ){
                        SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_INBASE);
                        //gPhase=GPHASE_FLAG_IN_BASE;
                        //SC_sgi(GVAR_GPHASE,gPhase);
                     }
                  }
               }
               break;
            case FLAG_PH_ONPLAYER: //_________
               update_timer+= info->elapsed_time;
               if(update_timer>SECONDS_FOR_POINT){
                  SC_P_MP_AddPoints(Flag_Player_id,1);
                  update_timer=0;
               }
               if (!SC_P_IsReady(Flag_Player_id) ||  (Flag_Player_killed)){//exit game or dead 
                  Flag_Player_killed = FALSE;
                  update_timer=0;
                  if (SC_Item_GetPos(Flag_Ground_ID,&flag_pos)){ // flag on ground
                     SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_ONGROUND);
                     //gPhase=GPHASE_FLAG_ON_GROUND;
                     //SC_sgi(GVAR_GPHASE,gPhase);
                  }else {//no flag, add to base
                     SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_INBASE);
                     //gPhase=GPHASE_FLAG_IN_BASE;
                     //SC_sgi(GVAR_GPHASE,gPhase);
                  }
               }
               break;
            }
            break;
         case GPHASE_MISSION_COMPLETED:   
            break;
         }
         //________________________________________________________________
         //gPlayersConnected = 64;
         //SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL);
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         break;
      case SC_NET_MES_CLIENT_TICK:
         switch(SC_ggi(GVAR_GPHASE)){
         case GPHASE_BEGIN:            //___________________________CLN______BEGIN
            break;
         case GPHASE_WAIT_PLAYERS:      //___________________________CLN______WAIT_PLAYERS
            SC_NOD_SetTransform(dir_obj_id,&trans_hide); //hide dir object
            
            witxt = SC_Wtxt(1076);//1076
            SC_GetScreenRes(&sc_width,&sc_height);
            val= sc_width - SC_Fnt_GetWidthW(witxt,1);          
            SC_Fnt_WriteW(val * 0.5f,15,witxt,1,0xffffffff);
            break;
         case GPHASE_START_GAME:       //___________________________CLN______START_GAME
            if (fade_off){
               client_fade_timer -= info->elapsed_time;
               if (client_fade_timer < (FADE_TIME + 0.1f)){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
                  client_fade_timer=RESTART_TIMER;
                  fade_off_timer=0;
                  //reset objexts and states
                  SC_NOD_SetTransform(dir_obj_id,&trans_hide); //hide dir object
                  show_flag_pos_timer=0.0;
               }
            }
            swprintf(wtxt,SC_AnsiToUni("%s %S", wtxt2),SC_Wtxt(6030)," - HTF (Hold The Flag)");
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);
            break;
         case GPHASE_GAME:
            //FADE OFF
            if (!fade_off){
               fade_off_timer += info->elapsed_time;
               if (fade_off_timer >  0.2f){// looks better so because spawn is with short delay
                  SC_FadeTo(FALSE, FADE_TIME);
                  fade_off=TRUE;



               }
            }   
            
            switch(SC_ggi(GVAR_FLAG_STATUS)){
            case FLAG_PH_INBASE: //_________
               if(!cln_flag_in_base){
                  SC_NOD_SetTransform(dir_obj_id,&trans_hide); //hide dir object
                  show_flag_pos_timer=0.0;
                  
                  icon[0].color = 0xffffffff;            
                  icon[0].type = SC_HUD_MP_ICON_TYPE_NONE;
                  icon[0].icon_id = 3;
                  SC_MP_SetIconHUD(icon,1);
                  SC_DUMMY_Set_DoNotRenHier2(gFlagNod,FALSE);//show base flag
                  //SC_NOD_GetWorldPos(gFlagNod, &vec);
                  //SC_HUD_RadarShowPos(&vec, 0xff000000);//0xffffffff// white
                  swprintf(wtxt,SC_AnsiToUni("%s",wtxt2),SC_Wtxt(1069));//#1069:    #tee Flag returned!
                  SC_GameInfoW(wtxt);
                  last_flag_player=-1;
                  cln_flag_in_base=TRUE;
                  cln_flag_on_ground=FALSE;
               }
               break;
            case FLAG_PH_ONGROUND: //_________
               if(!cln_flag_on_ground){
                  SC_NOD_SetTransform(dir_obj_id,&trans_hide); //hide dir object
                  show_flag_pos_timer=0.0;
                  
                  icon[0].color = 0xffffffff;            
                  icon[0].type = SC_HUD_MP_ICON_TYPE_NONE;
                  icon[0].icon_id = 5;
                  SC_MP_SetIconHUD(icon,1);
                  SC_DUMMY_Set_DoNotRenHier2(gFlagNod,TRUE);// dont show base flag
                  cln_Flag_Player_handle = SC_ggi(GVAR_FLAG_PLAYER);
                  last_flag_player=-1;
                  if(cln_Flag_Player_handle){
                     pl_id = SC_MP_GetPlofHandle(cln_Flag_Player_handle);
                     SC_P_UnLink3pvEqp(pl_id,0);   
                     swprintf(wtxt,SC_AnsiToUni("%s  -  %S",wtxt2),SC_Wtxt(1068),SC_P_GetName(pl_id));//#1068:    #tee Flag dropped!
                     SC_GameInfoW(wtxt);
                  }
                  cln_flag_on_ground=TRUE;
                  cln_flag_in_base=FALSE;
               }
               break;
            case FLAG_PH_ONPLAYER: //_________
               cln_Flag_Player_handle = SC_ggi(GVAR_FLAG_PLAYER);
               pl_id = SC_MP_GetPlofHandle(cln_Flag_Player_handle);
               if(last_flag_player != cln_Flag_Player_handle){//flag on new player
                  SC_NOD_SetTransform(dir_obj_id,&trans_hide);
                  show_flag_pos_timer=0.0;
                  
                  icon[0].color = 0xffffffff;            
                  icon[0].type = SC_HUD_MP_ICON_TYPE_NONE;
                  icon[0].icon_id = 4;
                  SC_MP_SetIconHUD(icon,1);
                  
                  
                  last_flag_player = cln_Flag_Player_handle;
                  SC_DUMMY_Set_DoNotRenHier2(gFlagNod,TRUE);// dont show base flag
                  pl_id = SC_MP_GetPlofHandle(cln_Flag_Player_handle);
                  SC_P_Link3pvEqp(pl_id,0,PRELOADBES_FLAG_VC,"G\\WEAPONS\\Vvh_flag\\eqp\\Vvh_flag_VC_3pv.eqp");
                  if(pl_id == SC_PC_Get()){
                     SC_SND_PlaySound2D(10424);
                     //radar_color=0x99ffffff;
                  }else{
                     //radar_color=0xff000000;
                     swprintf(wtxt,SC_AnsiToUni("%s  -  %S",wtxt2),SC_Wtxt(1067),SC_P_GetName(pl_id));//#1067:    #tee Flag stolen!
                     SC_GameInfoW(wtxt);
                  }
                  cln_flag_on_ground=FALSE;
                  cln_flag_in_base=FALSE;
               }
               
               if((pl_id) && (pl_id == SC_PC_Get())){//flag on PC
                     gCLN_MyFlagTimer += info->elapsed_time;
                      while (gCLN_MyFlagTimer > 1.0f) gCLN_MyFlagTimer -= 1.0f;
                      if (gCLN_MyFlagTimer>0.5f) icon[0].color = (dword)(511.0f * (gCLN_MyFlagTimer-0.5f));
                        else icon[0].color = (dword)(511.0f * (0.5f-gCLN_MyFlagTimer));
                     icon[0].color <<= 24;
                     icon[0].color += 0x00ffffff;            
                     icon[0].type = SC_HUD_MP_ICON_TYPE_NONE;
                     icon[0].icon_id = 4;
                     SC_MP_SetIconHUD(icon,1);
                     
               }else{//flag not on PC
                  if (SC_PC_Get()){
                     show_flag_pos_timer+=info->elapsed_time;
                      if(show_flag_pos_timer>SHOW_DIR_TIME){// more than 10 sec on player
                        trans=orig_trans;
                        SC_GetCameraPos(&PChead);
                        SC_P_GetPos(pl_id, &NEEDpos);
                        NEEDpos.z+=2.2;
                        Real_dist = SC_2VectorsDist(&PChead, &NEEDpos);
                        if (Real_dist>FPL_CLOSE_DIST){
                           trans.scale.x=5;
                           trans.scale.y=5;
                           trans.scale.z=5;
                           //location
                           trans.loc.x=PChead.x+((NEEDpos.x-PChead.x)*(1/Real_dist));
                           trans.loc.y=PChead.y+((NEEDpos.y-PChead.y)*(1/Real_dist));
                           trans.loc.z=PChead.z+((NEEDpos.z-PChead.z)*(1/Real_dist))+0.0;
                           //rot
                           rel_x_pos.x = NEEDpos.x - PChead.x;
                           rel_x_pos.y = NEEDpos.y - PChead.y;
                           rel_x_pos.z = NEEDpos.z - PChead.z;
                           Calc_z_rot = atan2(rel_x_pos.y, 0 - rel_x_pos.x);
                           Calc_y_rot = atan2(0 - rel_x_pos.z, 0 - (rel_x_pos.x /cos(Calc_z_rot)));
                           trans.rot.z = Calc_z_rot - orig_trans.rot.z-PI/2;
                           trans.rot.y = Calc_y_rot;
                           //transform
                           SC_NOD_SetTransform(dir_obj_id,&trans);
                        }else{//hide
                           SC_NOD_SetTransform(dir_obj_id,&trans_hide);
                        }
                     }
                  }
                  
                  
               }
            
            
               break;
            }
            break;
         case GPHASE_MISSION_COMPLETED:   
            if (fade_off){
               complete_f_timer -= info->elapsed_time;
               if (complete_f_timer < -6.0f){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
               }
            }
            swprintf(wtxt,SC_AnsiToUni("%s", wtxt2),SC_Wtxt(2026));//#2026:    #tee   Mission completed
            SC_GetScreenRes(&sc_width,&sc_height);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);         
            SC_Fnt_WriteW(val,15,wtxt,1,0xffffffff);

            
            //SC_MP_GetMaxPointsPl(&max_point))
            
            swprintf(wtxt,SC_AnsiToUni("Best player:  %S ", wtxt2), SC_P_GetName(SC_MP_GetPlofHandle(SC_ggi(GVAR_WINNER))));
            //SC_Fnt_WriteW((sc_width*0.5),(sc_height*0.5),wtxt,1.1,0x85ffffff);
            val= (sc_width*0.5) - (SC_Fnt_GetWidthW(wtxt,1)*0.5);   
            SC_Fnt_WriteW(val,35,wtxt,1,0xffffffff);
            break;
         }
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_SERVER_KILL:
         //info->param2//killer
         //info->param1//killed
         
         pl_id = SC_MP_GetPlofHandle(Flag_Player_handle);


         if (info->param1==pl_id){ // killed player with flag
            SC_P_GetPos(pl_id,&vec);
            vec.z += 0.6f;
            Flag_Ground_ID = SC_Item_Create(146,&vec);
            On_Ground_Timer = ON_GROUND_TIME;
            Flag_Player_killed = TRUE;
         }


         break;// SC_NET_MES_SERVER_KILL
      case SC_NET_MES_LEVELPREINIT:
         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_HTF);
         
         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //flag player pos  object
         if (SC_NOD_GetNoMessage_Entity(DIR_OBJ_NAME)){
            dir_obj_id = SC_NOD_GetNoMessage_Entity(DIR_OBJ_NAME);
            SC_NOD_GetTransform(dir_obj_id,&orig_trans);
            trans_hide=orig_trans;
            trans_hide.loc.z-=1000;
         }else SC_message("Add object '%s'.",DIR_OBJ_NAME);

         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         
         SC_MP_SRV_SetClassLimit(18,0);//PILOT US
         SC_MP_SRV_SetClassLimit(19,0);//DM- US
         SC_MP_SRV_SetClassLimit(39,0);//DM - NVA
         
         
         SC_HUD_DisableRadar(FALSE);         
         //SC_MP_SRV_SetClassLimitsForDM();   
         CLEAR(hudinfo);
         hudinfo.title = 1050;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_POINTS;         
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_POINTS  | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = 0;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(FALSE);
         SC_MP_AllowFriendlyFireOFF(FALSE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){   
            // preload flag items
            SC_Item_Preload(146);

            // preload flag eqp items
            SC_PreloadBES(PRELOADBES_FLAG_VC,"G\\WEAPONS\\Vvh_flag\\Vvh_flag_VC_3pv.BES");

            nod = SC_NOD_Get(NULL,"HTF_flag");
            if (!nod) SC_message("'HTF_flag' not found 01");
            gFlagNod = SC_NOD_Get(nod,"Vlajka VC");
            if (!gFlagNod) SC_message("'HTF_flag' not found 02");
            SC_NOD_GetWorldPos(nod,&orig_flag_pos);


            if (info->param1){
               // it's server   
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE_TIME);
               //SC_MP_Gvar_SetSynchro(GVAR_CUR_WEAP);
               SC_MP_Gvar_SetSynchro(GVAR_WINNER);
               SC_MP_Gvar_SetSynchro(GVAR_FLAG_PLAYER);
               //SC_MP_Gvar_SetSynchro(GVAR_FLAG_TIMER);
               
               SC_MP_Gvar_SetSynchro(GVAR_FLAG_STATUS);
               SC_sgi(GVAR_FLAG_STATUS,FLAG_PH_INBASE);               
               

               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               for (i=300;i<364;i++){   //custom global variables for player id's
                  SC_MP_Gvar_SetSynchro(i);
               }
               //_______________________________________________________________________________________

               for (i=400;i<464;i++){   //for player points
                  SC_MP_Gvar_SetSynchro(i);
               }
               //_______________________________________________________________________________________
                        




               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 170
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_HTF,&gRec[gRecs],&i);
               gRecs += i;
#endif
               if (gRecs==0){
                  SC_message("no 'HTF' recover place added! Will use 'DM' recover place if exist.");
                  i = REC_MAX - gRecs;
                  SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
                  gRecs += i;
               }


               CLEAR(gRecTimer);
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:

         if(SC_KeyPressed(0x0F)){//TAB pressed
            if(SHOW_PLAYER_COLOR){
               SC_MP_HUD_SelectPl(SC_PC_Get(),0x1100ffff);
            }
            if (SHOW_PLAYERS_COUNT){
               SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d  %s", wtxt2),j,player_s);
               SC_Fnt_WriteW(100,25,wtxt,1,0xffffffff);
            }
         }else if(SC_ggi(GVAR_GPHASE)==GPHASE_MISSION_COMPLETED){
            if (SC_MP_GetMaxPointsPl(&max_point)){
               if(max_point > 0){
                  SC_MP_HUD_SelectPl(SC_MP_GetMaxPointsPl(&max_point),0x88440000);
               }
            }
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:

         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{// killed

            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;
         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];      
         break;
      case SC_NET_MES_RESTARTMAP: //___________________________________________________________
         gPhase_timer = BEGIN_TIMER;
         gPhase = GPHASE_BEGIN;   
         SC_sgi(GVAR_GPHASE,gPhase);
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;
   }// switch(info->message)
   return 1;
}// int ScriptMain(void)





Edited by Ando on 28-11-2015 01:25
  x 1  x 2
 
Ando
DM script with automatic global variable system

details compared with original DM:
- added automatic global variable system

Script:
Spoiler:
Download source  Code

//   VIETCONG 1
//   DM script - compatible with synchronized objects
//   modified by Ando
// v2.0


//   NOTES:
// 1.0 modyfied for global vriables
// 1.2 - added variable for server (600) to detect server from object scripts
// 1.2 - new G-var system (object scripts counting g-vars to channel 601 )
// 1.3 - added game phase for object scripts resets
// 2.0 - successfully tested with L|DC-78

#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define RECOVER_TIME   5.0f      // time to recover player after killed
#define NORECOV_TIME   3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME      "DM%d"
#define REC_MAX         64


//________________________________
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable
//________________________________

#define GVAR_GPHASE 500      // important to use  game phase and channel 500 for synchronised objects
//________________________________




//___________________________

#define GPHASE_BEGIN 1
#define GPHASE_GAME 2
//#define GPHASE_DONE 3
//#define GPHASE_FAILED 4

dword gPhase = 0;
float gPhase_timer = 3.0f;
//___________________________



dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];


dword gEndRule;
dword gEndValue;
float gTime;
dword gPlayersConnected = 0;

BOOL SRV_CheckEndRule(float time){
   int frags;
   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
         SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
         if (gTime>gEndValue){
            SC_MP_LoadNextMap();
            return TRUE;
         }
         break;
      case SC_MP_ENDRULE_FRAGS:
         if (SC_MP_GetMaxFragsPl(&frags)){
            if (frags>=gEndValue){
               SC_MP_LoadNextMap();
               return TRUE;
            }
         }
         break;
      default:
         SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   return FALSE;
}// void SRV_CheckEndRule(float time)

int ScriptMain(s_SC_NET_info *info){
   char txt[32];
   dword i;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________
         if (gPhase==1){
            gPhase_timer -= info->elapsed_time;
            if (gPhase_timer <= 0.0f){
               gPhase=2;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart_________________________________________
            }
         }
         //________________________________________________________________
         gPlayersConnected = 64;
         SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL);         
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         break;
      case SC_NET_MES_CLIENT_TICK:
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_LEVELPREINIT:
         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_DM);
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         SC_HUD_DisableRadar(TRUE);         
         SC_MP_SRV_SetClassLimitsForDM();   
         CLEAR(hudinfo);
         hudinfo.title = 1050;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_FRAGS;         
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_FRAGS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = 0;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(FALSE);
         SC_MP_AllowFriendlyFireOFF(FALSE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server   
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 133
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
               gRecs += i;
#endif
               SC_Log(3,"DM respawns: %d",gRecs);
               if (gRecs==0) SC_message("no recover place defined!");
               CLEAR(gRecTimer);
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:
         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{// killed
            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;
         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];      
         break;
      case SC_NET_MES_RESTARTMAP:
         //___________________________________________________________
         gPhase=GPHASE_BEGIN;
         gPhase_timer = 3.0f;
         SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
         //___________________________________________________________


         gTime = 0;
         SC_MP_SRV_ClearPlsStats();
         SC_MP_SRV_InitGameAfterInactive();
         SC_MP_RecoverAllNoAiPlayers();         
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;
   }// switch(info->message)
   return 1;
}// int ScriptMain(void)




Edited by Ando on 24-10-2015 06:20
 
Ando
DM script with automatic global variable system (advanced)

details compared with original DM:
- added automatic global variable system
- restart with fade
- show player in fifferent color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)


Script:
Spoiler:
Download source  Code

//   VIETCONG 1
//   DM script (with automatic global variables for synchronized objects)
//   modified by Ando
//   v3.1


//   NOTES:
// 1.0 - modyfied for global vriables
// 1.2 - added variable for server (600) to detect server from object scripts
// 1.2 - new G-var system (object scripts counting g-vars to channel 601 )
// 1.3 - added game phase for object scripts resets
// 2.0 - successfully tested with L|DC-78
// 3.0 - added fade for restart
// 3.1 - show player in fifferent color (on/off option in script)
// 3.1 - show players count when "TAB" is pressed (on/off option in script)

#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define SHOW_PLAYER_COLOR         1
#define SHOW_PLAYERS_COUNT         1




#define FADE_TIME         0.8
//________________________________
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable
//________________________________

#define GVAR_GPHASE 500      // important to use  game phase and channel 500 for synchronised objects
//________________________________

#define RECOVER_TIME   5.0f      // time to recover player after killed
#define NORECOV_TIME   3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME      "DM%d"
#define REC_MAX         64

//___________________________

#define GPHASE_BEGIN            1
#define GPHASE_GAME               2
#define GPHASE_BEFORE_RESTART      6
#define GPHASE_RESTARTING         7   


#define RESTART_TIMER            6   //time before actual restart


dword gPhase = 1;
float gPhase_timer = 3.0f;
//___________________________
// for extra tab info
ushort *player_s;


dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];



dword gEndRule;
dword gEndValue;
float gTime;
dword gPlayersConnected = 0;



BOOL    fade_off = TRUE;
float   client_fade_timer;
float   fade_off_timer;


BOOL SRV_CheckEndRule(float time){
   int frags;
   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
         SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
         if (gTime>gEndValue){
            SC_MP_LoadNextMap();
            return TRUE;
         }
         break;
      case SC_MP_ENDRULE_FRAGS:
         if (SC_MP_GetMaxFragsPl(&frags)){
            if (frags>=gEndValue){
               SC_MP_LoadNextMap();
               return TRUE;
            }
         }
         break;
      default:
         SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   return FALSE;
}// void SRV_CheckEndRule(float time)

int ScriptMain(s_SC_NET_info *info){
   char txt[128],*itxt;
   ushort wtxt[128],wtxt2[64],*witxt;
   dword i,j;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________
         gPhase_timer -= info->elapsed_time;
         switch(gPhase){
         case GPHASE_BEGIN:
            if (gPhase_timer <= 0.0f){
               gPhase = GPHASE_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart_________________________________________
            }
            break;// GPHASE_BEGIN
         case GPHASE_GAME:

            break;
         case GPHASE_BEFORE_RESTART:
            if (gPhase_timer<0.0f){   //wait before restart
               gPhase = GPHASE_RESTARTING;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
            }
            break;
         case GPHASE_RESTARTING:
            gTime = 0;
            gPhase=GPHASE_BEGIN;
            gPhase_timer = 3.0f;
            SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
            SC_MP_SRV_ClearPlsStats();
            SC_MP_SRV_InitGameAfterInactive();
            SC_MP_RecoverAllNoAiPlayers();      
            break;
         }
         //________________________________________________________________
         gPlayersConnected = 64;
         SC_MP_EnumPlayers(enum_pl,&gPlayersConnected,SC_MP_ENUMPLAYER_SIDE_ALL);         
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         break;
      case SC_NET_MES_CLIENT_TICK:
         switch(SC_ggi(GVAR_GPHASE)){
         case GPHASE_BEGIN:
            if (!fade_off){
               fade_off_timer += info->elapsed_time;
               if (fade_off_timer >  0.2f){// looks better so because spawn is with short delay
                  SC_FadeTo(FALSE, FADE_TIME);
                  fade_off=TRUE;
               }
            }
            break;
         case GPHASE_BEFORE_RESTART:
            if (fade_off){
               client_fade_timer -= info->elapsed_time;
               if (client_fade_timer < (FADE_TIME + 0.1f)){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
                  client_fade_timer=RESTART_TIMER;
                  fade_off_timer=0;
               }
            }
            break;
         case GPHASE_RESTARTING:
            break;
         }// switch(gPhase)
         //_____________________________
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_LEVELPREINIT:
         client_fade_timer=RESTART_TIMER;

         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_DM);
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         SC_HUD_DisableRadar(TRUE);         
         SC_MP_SRV_SetClassLimitsForDM();   
         CLEAR(hudinfo);
         hudinfo.title = 1050;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_FRAGS;         
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_FRAGS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = 0;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(FALSE);
         SC_MP_AllowFriendlyFireOFF(FALSE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server   
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 133
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
               gRecs += i;
#endif
               SC_Log(3,"DM respawns: %d",gRecs);
               if (gRecs==0) SC_message("no recover place defined!");
               CLEAR(gRecTimer);
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:

// EXTRA TAB INFO
         if(SC_KeyPressed(0x0F)){//TAB pressed
            if(SHOW_PLAYER_COLOR){
               SC_MP_HUD_SelectPl(SC_PC_Get(),0x1100ffff);
            }
            if (SHOW_PLAYERS_COUNT){
               SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d  %s", wtxt2),j,player_s);
               SC_Fnt_WriteW(100,25,wtxt,1,0xffffffff);
            }
         }
// end of extra tab info

         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:
         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{// killed
            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;
         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];      
         break;
      case SC_NET_MES_RESTARTMAP:
         //___________________________________________________________
         gPhase_timer = RESTART_TIMER;
         gPhase = GPHASE_BEFORE_RESTART;   
         SC_sgi(GVAR_GPHASE,gPhase);

         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;
   }// switch(info->message)
   return 1;
}// int ScriptMain(void)



 
Ando
TDM script with automatic global variable system (simple)

details compared with original TDM:
- added automatic global variable system

Script:
Spoiler:
Download source  Code

//   VIETCONG 1
//   TDM script - compatible with synchronized objects
//   modified by Ando
// v2.0


//   NOTES:
// 1.0 modyfied for global vriables
// 1.2 - added variable for server (600) to detect server from object scripts
// 1.2 - new G-var system (object scripts counting g-vars to channel 601 )
// 1.3 - added game phase for object scripts resets
// 2.0 - successfully tested with L|DC-78

#include <inc\sc_global.h>
#include <inc\sc_def.h>


#define RECOVER_TIME   5.0f      // time to recover player after killed
#define NORECOV_TIME   3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME      "DM%d"
#define REC_MAX         64

#define GVAR_SIDE0FRAGS            501
#define GVAR_SIDE1FRAGS            502

//________________________________
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable
//________________________________

#define GVAR_GPHASE 500      // important to use  game phase and channel 500 for synchronised objects
//________________________________


//___________________________

#define GPHASE_BEGIN 1
#define GPHASE_GAME 2
//#define GPHASE_DONE 3
//#define GPHASE_FAILED 4

dword gPhase = 0;
float gPhase_timer = 3.0f;
//___________________________



dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];


float gNextRecover = 0.0f;

int gSideFrags[2] = {0,0};
int gCLN_SideFrags[2];

dword gEndRule;
dword gEndValue;
float gTime;

dword gPlayersConnected = 0;


BOOL SRV_CheckEndRule(float time){

   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:

         if (gPlayersConnected>0) gTime += time;
         SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);

         if (gTime>gEndValue){
            SC_MP_LoadNextMap();
            return TRUE;
         }

         break;

      case SC_MP_ENDRULE_FRAGS:

         if (((gSideFrags[0]>0)&&(gSideFrags[0]>=gEndValue))
            ||((gSideFrags[1]>1)&&(gSideFrags[1]>=gEndValue))){
            SC_MP_LoadNextMap();
            return TRUE;
         }

         break;

      default:
         SC_message("EndRule unsopported: %d",gEndRule);
         break;

   }// switch(gEndRule)

   return FALSE;

}// void SRV_CheckEndRule(float time)




void UpdateSideFrags(void){
   SC_sgi(GVAR_SIDE0FRAGS,gSideFrags[0]);
   SC_sgi(GVAR_SIDE1FRAGS,gSideFrags[1]);
}


int ScriptMain(s_SC_NET_info *info){
   char txt[32];
   dword i,j,sideA,sideB;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_P_getinfo plinfo;
   s_SC_HUD_MP_icon icon[2];
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;

   switch(info->message){
      
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________
         if (gPhase==1){
            gPhase_timer -= info->elapsed_time;
            if (gPhase_timer <= 0.0f){
               gPhase=2;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart_________________________________________
            }
         }
         //________________________________________________________________
   
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         j = 64;
         if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL)){
            if ((j==0)&&((gSideFrags[0]+gSideFrags[1])!=0)){
               gSideFrags[0] = 0;
               gSideFrags[1] = 0;
               UpdateSideFrags();
            }// if ((side[0]+side[1])==0)
         }// if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL))
         gPlayersConnected = j;
         break;
      case SC_NET_MES_CLIENT_TICK:

         gCLN_SideFrags[0] = SC_ggi(GVAR_SIDE0FRAGS);
         gCLN_SideFrags[1] = SC_ggi(GVAR_SIDE1FRAGS);

         SC_MP_SetSideStats(0,gCLN_SideFrags[0],0);
         SC_MP_SetSideStats(1,gCLN_SideFrags[1],0);

         for (i=0;i<2;i++){
            icon[i].type = SC_HUD_MP_ICON_TYPE_NUMBER;
            icon[i].icon_id = 3*i;
            icon[i].value = gCLN_SideFrags[i];
            icon[i].color = 0xffffffff;
         }

         SC_MP_SetIconHUD(icon,2);

         break;// SC_NET_MES_CLIENT_TICK


      case SC_NET_MES_LEVELPREINIT:
         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_TDM);

         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;

         SC_MP_EnableBotsFromScene(FALSE);

         break;// SC_NET_MES_LEVELPREINIT

      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         SC_MP_SRV_SetClassLimitsForDM();
         CLEAR(hudinfo);
         hudinfo.title = 1051;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_FRAGS;
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_FRAGS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = TRUE;
         hudinfo.side_name[0] = 1010;
         hudinfo.side_color[0] = 0x440000ff;
         hudinfo.side_name[1] = 1011;
         hudinfo.side_color[1] = 0x44ff0000;
         hudinfo.side_mask = SC_HUD_MP_SIDE_MASK_FRAGS;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(TRUE);
         SC_MP_AllowFriendlyFireOFF(TRUE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server      
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               SC_MP_Gvar_SetSynchro(GVAR_SIDE0FRAGS);
               SC_MP_Gvar_SetSynchro(GVAR_SIDE1FRAGS);
               UpdateSideFrags();
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 133
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
               gRecs += i;
#endif
               SC_Log(3,"TDM respawns: %d",gRecs);
               if (gRecs==0) SC_message("no recover place defined!");
               CLEAR(gRecTimer);               
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:
         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{
            // killed
            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;

         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];
                  
         break;
         

      case SC_NET_MES_SERVER_KILL:

         SC_P_GetInfo(info->param1,&plinfo);      
         sideA = plinfo.side;

         if (info->param2){
            SC_P_GetInfo(info->param2,&plinfo);      
            sideB = plinfo.side;
         }
         else sideB = 0xffffffff;

         if (sideA==sideB){
            gSideFrags[sideB]--;
         }
         else{
            if (sideB!=0xffffffff) gSideFrags[sideB]++;               
         }

         UpdateSideFrags();
         

         break;// SC_NET_MES_SERVER_KILL

      case SC_NET_MES_RESTARTMAP:
         //___________________________________________________________
         gPhase=1;
         gPhase_timer = 3.0f;
         SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
         //___________________________________________________________


         gTime = 0;
         CLEAR(gSideFrags);
         UpdateSideFrags();
         SC_MP_SRV_ClearPlsStats();
         SC_MP_SRV_InitGameAfterInactive();
         SC_MP_RecoverAllNoAiPlayers();         
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;

               
   }// switch(info->message)
   

   return 1;

}// int ScriptMain(void)




Edited by Ando on 24-10-2015 06:57
 
Ando
TDM script with automatic global variable system (advanced)

details compared with original TDM:
- added automatic global variable system
- restart with fade
- show player in fifferent color (on/off option in script)
- show players count when "TAB" is pressed (on/off option in script)

Script:
Spoiler:
Download source  Code

//   VIETCONG 1
//   TDM script (with automatic global variables for synchronized objects)
//   modified by Ando
//   v3.1


//   NOTES:
// 1.0 modyfied for global vriables
// 1.2 - added variable for server (600) to detect server from object scripts
// 1.2 - new G-var system (object scripts counting g-vars to channel 601 )
// 1.3 - added game phase for object scripts resets
// 2.0 - successfully tested with L|DC-78
// 3.0 - added fade for restart
// 3.1 - show player in fifferent color (on/off option in script)
// 3.1 - show players count when "TAB" is pressed (on/off option in script)


#include <inc\sc_global.h>
#include <inc\sc_def.h>

#define SHOW_PLAYER_COLOR         1
#define SHOW_PLAYERS_COUNT         1


#define FADE_TIME         0.8
//________________________________
//global variable system for object synchro
#define GVAR_SERVER         600    //   server  ( dont add SC_MP_Gvar_SetSynchro for that) 0 - not server, 1 - server
#define GVAR_COUNT         601    //  count of object variables ( dont add SC_MP_Gvar_SetSynchro for that)
#define GVAR_USE_start      602       //start      Global variable
//________________________________

#define GVAR_GPHASE 500      // important to use  game phase and channel 500 for synchronised objects
//________________________________

#define RECOVER_TIME   5.0f      // time to recover player after killed
#define NORECOV_TIME   3.0f      // disable time of recoverplace after recovering someone there
#define REC_WPNAME      "DM%d"
#define REC_MAX         64

#define GVAR_SIDE0FRAGS            501
#define GVAR_SIDE1FRAGS            502
//___________________________

#define GPHASE_BEGIN 1
#define GPHASE_GAME 2
//#define GPHASE_DONE 3
//#define GPHASE_FAILED 4

#define GPHASE_BEFORE_RESTART      6
#define GPHASE_RESTARTING         7   


#define RESTART_TIMER      6   //time before actual restart


dword gPhase = 0;
float gPhase_timer = 3.0f;
//___________________________

// for extra tab info
ushort *player_s;


dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];

float gNextRecover = 0.0f;
int gSideFrags[2] = {0,0};
int gCLN_SideFrags[2];

dword gEndRule;
dword gEndValue;
float gTime;
dword gPlayersConnected = 0;

BOOL    fade_off = TRUE;
float   client_fade_timer;


BOOL SRV_CheckEndRule(float time){

   switch(gEndRule){
      case SC_MP_ENDRULE_TIME:
         if (gPlayersConnected>0) gTime += time;
         SC_MP_EndRule_SetTimeLeft(gTime,gPlayersConnected>0);
         if (gTime>gEndValue){
            SC_MP_LoadNextMap();
            return TRUE;
         }
         break;
      case SC_MP_ENDRULE_FRAGS:
         if (((gSideFrags[0]>0)&&(gSideFrags[0]>=gEndValue))
            ||((gSideFrags[1]>1)&&(gSideFrags[1]>=gEndValue))){
            SC_MP_LoadNextMap();
            return TRUE;
         }
         break;
      default:
         SC_message("EndRule unsopported: %d",gEndRule);
         break;
   }// switch(gEndRule)
   return FALSE;
}// void SRV_CheckEndRule(float time)

void UpdateSideFrags(void){
   SC_sgi(GVAR_SIDE0FRAGS,gSideFrags[0]);
   SC_sgi(GVAR_SIDE1FRAGS,gSideFrags[1]);
}


int ScriptMain(s_SC_NET_info *info){
   char txt[128],*itxt;
   ushort wtxt[128],wtxt2[64],*witxt;
   dword i,j,sideA,sideB;
   s_SC_MP_Recover *precov;
   s_SC_MP_hud hudinfo;
   s_SC_P_getinfo plinfo;
   s_SC_HUD_MP_icon icon[2];
   s_SC_MP_EnumPlayers enum_pl[64];
   s_SC_MP_SRV_settings SRVset;
   switch(info->message){
      case SC_NET_MES_SERVER_TICK:   
         //________________________________________________________________
         switch(gPhase){
         case GPHASE_BEGIN:
         
            gPhase_timer -= info->elapsed_time;
            if (gPhase_timer <= 0.0f){
               gPhase = GPHASE_GAME;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart_________________________________________
            }
            break;// GPHASE_BEGIN
         case GPHASE_GAME:

            break;
         case GPHASE_BEFORE_RESTART:
            gPhase_timer -= info->elapsed_time;
            if (gPhase_timer<0.0f){   //wait before restart
               gPhase = GPHASE_RESTARTING;
               SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
            }
            break;
         case GPHASE_RESTARTING:
            gTime = 0;
            gPhase=GPHASE_BEGIN;
            gPhase_timer = 3.0f;
            SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart
            CLEAR(gSideFrags);
            UpdateSideFrags();
            SC_MP_SRV_ClearPlsStats();
            SC_MP_SRV_InitGameAfterInactive();
            SC_MP_RecoverAllNoAiPlayers();      
            break;

         }
         //________________________________________________________________
   
         if (SRV_CheckEndRule(info->elapsed_time)) break;
         for (i=0;i<gRecs;i++)
            gRecTimer[i] -= info->elapsed_time;
         j = 64;
         if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL)){
            if ((j==0)&&((gSideFrags[0]+gSideFrags[1])!=0)){
               gSideFrags[0] = 0;
               gSideFrags[1] = 0;
               UpdateSideFrags();
            }// if ((side[0]+side[1])==0)
         }// if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL))
         gPlayersConnected = j;
         break;
      case SC_NET_MES_CLIENT_TICK:
         switch(SC_ggi(GVAR_GPHASE)){
         case GPHASE_BEGIN:
            if (fade_off == FALSE){
               SC_FadeTo(FALSE, FADE_TIME);
               fade_off=TRUE;
            }
            break;
         case GPHASE_BEFORE_RESTART:
            if (fade_off == TRUE){
               client_fade_timer -= info->elapsed_time;
               if (client_fade_timer < FADE_TIME){   
                  SC_FadeTo(TRUE, FADE_TIME);
                  fade_off=FALSE;
                  client_fade_timer=RESTART_TIMER;
               }
            }
            break;
         case GPHASE_RESTARTING:
            break;
         }// switch(gPhase)
         //_____________________________

         gCLN_SideFrags[0] = SC_ggi(GVAR_SIDE0FRAGS);
         gCLN_SideFrags[1] = SC_ggi(GVAR_SIDE1FRAGS);
         SC_MP_SetSideStats(0,gCLN_SideFrags[0],0);
         SC_MP_SetSideStats(1,gCLN_SideFrags[1],0);
         for (i=0;i<2;i++){
            icon[i].type = SC_HUD_MP_ICON_TYPE_NUMBER;
            icon[i].icon_id = 3*i;
            icon[i].value = gCLN_SideFrags[i];
            icon[i].color = 0xffffffff;
         }
         SC_MP_SetIconHUD(icon,2);
         break;// SC_NET_MES_CLIENT_TICK
      case SC_NET_MES_LEVELPREINIT:
         client_fade_timer=RESTART_TIMER;

         SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_TDM);
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;

         SC_MP_EnableBotsFromScene(FALSE);
         break;// SC_NET_MES_LEVELPREINIT
      case SC_NET_MES_LEVELINIT:
         //_____________________________________automatic custom global variables_________________
         for (i=GVAR_USE_start;i<GVAR_USE_start+SC_ggi(GVAR_COUNT)+1;i++){   //custom global variables
            SC_MP_Gvar_SetSynchro(i);
         }
         //_______________________________________________________________________________________
         
         SC_MP_SRV_SetForceSide(0xffffffff);
         SC_MP_SetChooseValidSides(3);
         SC_MP_SRV_SetClassLimitsForDM();
         CLEAR(hudinfo);
         hudinfo.title = 1051;
         hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_FRAGS;
         hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_KILLS;
         hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.sort_by[3] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
         hudinfo.pl_mask = SC_HUD_MP_PL_MASK_FRAGS | SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS;
         hudinfo.use_sides = TRUE;
         hudinfo.side_name[0] = 1010;
         hudinfo.side_color[0] = 0x440000ff;
         hudinfo.side_name[1] = 1011;
         hudinfo.side_color[1] = 0x44ff0000;
         hudinfo.side_mask = SC_HUD_MP_SIDE_MASK_FRAGS;
         SC_MP_HUD_SetTabInfo(&hudinfo);
         SC_MP_AllowStPwD(TRUE);
         SC_MP_AllowFriendlyFireOFF(TRUE);
         SC_MP_SetItemsNoDisappear(FALSE);
         if (info->param2){
            if (info->param1){
               // it's server      
               //_______________________________________________________________________________________
               SC_sgi(GVAR_SERVER,1);
               SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
               SC_sgi(GVAR_GPHASE,gPhase);
               //_______________________________________________________________________________________
               

               SC_MP_GetSRVsettings(&SRVset);
               SC_MP_SRV_InitWeaponsRecovery((float)SRVset.dm_weap_resp_time);
               SC_MP_Gvar_SetSynchro(GVAR_SIDE0FRAGS);
               SC_MP_Gvar_SetSynchro(GVAR_SIDE1FRAGS);
               UpdateSideFrags();
               gRecs = 0;
               for (i=0;i<REC_MAX;i++){      
                  sprintf(txt,REC_WPNAME,i);         
                  if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
               }               
#if _GE_VERSION_ >= 133
               i = REC_MAX - gRecs;
               SC_MP_GetRecovers(SC_MP_RESPAWN_DM,&gRec[gRecs],&i);
               gRecs += i;
#endif
               SC_Log(3,"TDM respawns: %d",gRecs);
               if (gRecs==0) SC_message("no recover place defined!");
               CLEAR(gRecTimer);               
            }// if (info->param1)
         }//if (info->param2)
         break;// SC_NET_MES_LEVELINIT
      case SC_NET_MES_RENDERHUD:
// EXTRA TAB INFO TEST
         if(SC_KeyPressed(0x0F)){//TAB pressed
            
            if(SHOW_PLAYER_COLOR){
               SC_MP_HUD_SelectPl(SC_PC_Get(),0x1100ffff);
            }

            if (SHOW_PLAYERS_COUNT){
               SC_MP_EnumPlayers(enum_pl,&j,SC_P_SIDE_US);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d %s  %s", wtxt2),j,SC_Wtxt(102),player_s);
               SC_Fnt_WriteW(100,25,wtxt,1,0xffffffff);

               SC_MP_EnumPlayers(enum_pl,&j,SC_P_SIDE_VC);
               if (j==1) player_s = SC_Wtxt(350); else player_s = SC_Wtxt(7001);
               swprintf(wtxt,SC_AnsiToUni("%d %s  %s", wtxt2),j,SC_Wtxt(103),player_s);
               SC_Fnt_WriteW(100,65,wtxt,1,0xffffffff);
            }
         }
// end of extra tab info
         break;
      case SC_NET_MES_SERVER_RECOVER_TIME:
         if (info->param2){
               info->fval1 = 0.1f;
         }
         else{
            // killed
            info->fval1 = RECOVER_TIME;
         }
         break;
      case SC_NET_MES_SERVER_RECOVER_PLACE:
         precov = (s_SC_MP_Recover*)info->param2;

         i = SC_MP_SRV_GetBestDMrecov(gRec,gRecs,gRecTimer,NORECOV_TIME);
         
         gRecTimer[i] = NORECOV_TIME;
         *precov = gRec[i];
                  
         break;
         

      case SC_NET_MES_SERVER_KILL:
         SC_P_GetInfo(info->param1,&plinfo);      
         sideA = plinfo.side;
         if (info->param2){
            SC_P_GetInfo(info->param2,&plinfo);      
            sideB = plinfo.side;
         }
         else sideB = 0xffffffff;
         if (sideA==sideB){
            gSideFrags[sideB]--;
         }
         else{
            if (sideB!=0xffffffff) gSideFrags[sideB]++;               
         }
         UpdateSideFrags();
         break;// SC_NET_MES_SERVER_KILL
      case SC_NET_MES_RESTARTMAP:
         gPhase_timer = RESTART_TIMER;
         gPhase = GPHASE_BEFORE_RESTART;   
         SC_sgi(GVAR_GPHASE,gPhase);//(1 = begin) For sync. objects.  server restart   
         break;// SC_NET_MES_RESTARTMAP
      case SC_NET_MES_RULESCHANGED:         
         gEndRule = info->param1;
         gEndValue = info->param2;
         gTime = 0.0f;
         break;      
   }// switch(info->message)
   return 1;
}// int ScriptMain(void)




 
Ando
PC_M151 script

Description:


Tutorial for editor:


Known bugs:
- player (client) will be kicked of from server with high speed (Cheat #2)
- was more bugs but I dont remember now.


Object
Object is attached to this post.


Script:
Spoiler:
Download source  Code


#include <inc\sc_global.h>
#include <inc\sc_def.h>


#define HELP_nod_1      "axis_x"
#define HELP_nod_2      "axis_y"
#define veh_nod_name      "M151_interier"

#define MP_PC_DIRVER         1   //0 disabled
#define MP_CAR_SEATS         3   //
//_________________________________________________________________________

#define GVAR_SERVER            600       // 0 - not server, 1 - server
#define GVAR_COUNT            601       // Channel for G-var count
#define GVAR_GPHASE            500
//_________________________________________________________________________



s_SC_NOD_transform trans;
s_SC_NOD_transform orig_trans;
s_SC_NOD_transform orig_car_trans;



int my_gvar_count;
int my_gvar;
int my_gvar_seat_[3];


float my_gvar_pos_x;
float my_gvar_pos_y;
float my_gvar_pos_z;
float my_gvar_rot_x;
float my_gvar_rot_y;
float my_gvar_rot_z;
float my_gvar_steer;
float my_gvar_steer_LR;


float CAR_world_rot;


float timer = 0.0f;
float driver_timer;
float start_pos_timer = 0.0f;
float car_stil_move_timer;
float check_timer=0.0f;

c_Vector3      car_vec;
c_Vector3      last_car_vec;
c_Vector3      player_pos;
c_Vector3      base_vec;
c_Vector3      help_1_vec;
c_Vector3      help_2_vec;
c_Vector3      start_1_vec;
c_Vector3      start_2_vec;
c_Vector3      start_3_vec;
c_Vector3      rel_help_1_vec;
c_Vector3      rel_help_2_vec;
c_Vector3      axis_2_vec;
c_Vector3      rel_x_pos;
c_Vector3      rel_y_pos;


s_SC_P_getinfo   pl_info;

dword       player;
dword       list[32];
dword       PC_entry;

dword      cur_pl_handle;

dword      PC_car_id;

void   *car;
void   *steer_wheel_id;
void   *steer_wheel_pos_id;
void   *wheel_id;



char   *CAR_name;
char   *entry_name[3];
int      PC_in_cur_car=-1;
int      Temp2;

dword   pl_in_car[3];
dword   Cur_player;
dword      Player_CAR;
int      cur_entry;

BOOL get_start_pos_after_physics= TRUE;

float last_x=0, cur_x=0, last_xr=0, cur_xr=0;
float last_y=0, cur_y=0, last_yr=0, cur_yr=0;
float last_z=0, cur_z=0, last_zr=0, cur_zr=0;


float      Calc_x_rot;
float      Calc_y_rot;
float      Calc_z_rot;

float      Calc_x_rot_deg;
float      Calc_y_rot_deg;
float      Calc_z_rot_deg;


float      start_x_rot;
float      start_y_rot;
float      start_z_rot;

float      temp_f;
void      *nod;

void Send_car_pos(s_SC_OBJ_info *info){

   SC_NOD_GetWorldPos(nod, &car_vec);
   SC_sgf(my_gvar_pos_x,car_vec.x);
   SC_sgf(my_gvar_pos_y,car_vec.y);
   SC_sgf(my_gvar_pos_z,car_vec.z);

   SC_NOD_GetWorldPos(nod, &base_vec);
   SC_NOD_GetWorldPos(SC_NOD_Get(info->master_nod,HELP_nod_1), &help_1_vec);
   SC_NOD_GetWorldPos(SC_NOD_Get(info->master_nod,HELP_nod_2), &help_2_vec);

   rel_x_pos.x=help_1_vec.x - base_vec.x;
   rel_x_pos.y=help_1_vec.y - base_vec.y;
   rel_x_pos.z=help_1_vec.z - base_vec.z;

   rel_y_pos.x=help_2_vec.x - base_vec.x;
   rel_y_pos.y=help_2_vec.y - base_vec.y;
   rel_y_pos.z=help_2_vec.z - base_vec.z;

   Calc_z_rot = atan2(rel_x_pos.y, 0- rel_x_pos.x);
   Calc_z_rot+=PI;
   //test
   //Calc_z_rot-=orig_trans.rot.z;

   Calc_y_rot = atan2(0 - rel_x_pos.z, 0 - (rel_x_pos.x /cos(Calc_z_rot)));
   Calc_y_rot+=PI;
   Calc_x_rot = atan2((rel_y_pos.z /cos(Calc_y_rot)),   0-(rel_y_pos.y/cos(Calc_z_rot)));
   Calc_x_rot+=PI;
   
   SC_sgf(my_gvar_rot_x,Calc_x_rot);
   SC_sgf(my_gvar_rot_y,Calc_y_rot);
   SC_sgf(my_gvar_rot_z,Calc_z_rot);

}
void Get_car_pos(s_SC_OBJ_info *info){

   SC_NOD_GetTransform(nod,&trans); 
   last_x = cur_x;
   last_y = cur_y;
   last_z = cur_z;

   last_xr = cur_xr;
   last_yr = cur_yr;
   last_zr = cur_zr;

   cur_x = SC_ggf(my_gvar_pos_x)- orig_trans.loc.x;
   cur_y = SC_ggf(my_gvar_pos_y)- orig_trans.loc.y;
   cur_z = SC_ggf(my_gvar_pos_z)- orig_trans.loc.z;

   cur_xr = SC_ggf(my_gvar_rot_x);
   cur_yr = SC_ggf(my_gvar_rot_y);
   cur_zr = SC_ggf(my_gvar_rot_z);

   trans.loc.x = cur_x;
   trans.loc.y = cur_y;
   trans.loc.z = cur_z;
   trans.rot.x = cur_xr;
   trans.rot.y = cur_yr;
   trans.rot.z = cur_zr;
   SC_NOD_SetTransform(nod,&trans); 
}

int ScriptMain(s_SC_OBJ_info *info){
   void *susp,*wheel;   
   s_SC_Car_AddWheel winfo;
   s_SC_Car_Init cinfo;
   s_SC_Car_AddEntry einfo;
   float fl_arr1[8];
   float fl_arr2[8];
   float fl_arr3[6];
   float fl_arr4[8];
   float ride_height;
   dword i;
   int j;

   char   txt[32],*itxt;
   ushort wtxt[128],wtxt2[64],*witxt,*my_witxt;
   float   sc_width,sc_height,val;



   switch(info->event_type){
      case SC_OBJ_INFO_EVENT_RELEASE:
         SC_NOD_SetTransform(nod,&orig_car_trans);
         SC_NOD_SetTransform(info->master_nod,&orig_trans);
         break;
      case SC_OBJ_INFO_EVENT_INIT:   
         //________creating global variable
         my_gvar_count = 1+ SC_ggi(GVAR_COUNT);
         my_gvar_seat_[0] = 601 + my_gvar_count++;//++ dont affect that line(if i=1;  x=i++;   then x=1 ant after that tine i=2)
         my_gvar_seat_[1] = 601 + my_gvar_count++;
         my_gvar_seat_[2] = 601 + my_gvar_count++;
         //my_gvar_steer = 601 + my_gvar_count++;
         //my_gvar_steer_LR = 601 + my_gvar_count++;
         my_gvar_pos_x = 601 + my_gvar_count++;
         my_gvar_pos_y = 601 + my_gvar_count++;
         my_gvar_pos_z = 601 + my_gvar_count++;
         my_gvar_rot_x = 601 + my_gvar_count++;
         my_gvar_rot_y = 601 + my_gvar_count++;
         my_gvar_rot_z = 601 + my_gvar_count;//

         SC_sgi(GVAR_COUNT,my_gvar_count);// new count
         //________END OF creating global variable


         CLEAR(pl_in_car);

         CAR_world_rot = SC_NOD_GetWorldRotZ(info->master_nod);
         CAR_name = SC_NOD_GetName(info->master_nod);
         nod = SC_NOD_Get(info->master_nod,veh_nod_name);
         SC_NOD_GetTransform(nod,&orig_car_trans);
         SC_NOD_GetTransform(info->master_nod,&orig_trans);

         trans=orig_trans;
         trans.rot.x=0;
         trans.rot.y=0;
         trans.rot.z=0;
         SC_NOD_SetTransform(info->master_nod,&trans);

         trans=orig_car_trans;
         trans.rot.z=CAR_world_rot;
         SC_NOD_SetTransform(nod,&trans);





         
         cinfo.master_nod = info->master_nod;
         

         //steer_wheel_id= SC_NOD_Get(info->master_nod,"volant_LOD1");
         //steer_wheel_pos_id= SC_NOD_Get(info->master_nod,"volant_dummy");
         //wheel_id = SC_NOD_Get(info->master_nod,"M151_LF_LOD1");



         cinfo.steeringwheel_nod = SC_NOD_Get(info->master_nod,"volant_LOD1");
         cinfo.steeringwheel_max_rot = 1.5f;

         cinfo.steer_max = 0.4f;   
         cinfo.steer_speed = 1.5f;
         cinfo.steer_backspeed = 5.0f;
         
         cinfo.steer_max_mult_at10mpersec = 0.6f;
         cinfo.steer_speed_mult_at10mpersec = 0.4f;
         cinfo.steer_backspeed_mult_at10mpersec = 1.0f;

         cinfo.steer_curse[0] = 0.0f;
         cinfo.steer_curse[1] = 0.05f;
         cinfo.steer_curse[2] = 0.1;
         cinfo.steer_curse[3] = 0.2f;
         cinfo.steer_curse[4] = 0.3f;
         cinfo.steer_curse[5] = 0.5f;
         cinfo.steer_curse[6] = 0.7f;
         cinfo.steer_curse[7] = 0.8f;
         cinfo.steer_curse[8] = 0.9f;
         cinfo.steer_curse[9] = 0.95f;
         cinfo.steer_curse[10] = 1.0f;
         
         cinfo.brake_power = 3500.0f;

         cinfo.eng_max_revs = 3000;
         cinfo.eng_freewheel_revs = 600;
         cinfo.eng_revs_slowdown = 900.0f;
         cinfo.eng_min_revs = 1800.0f;
         cinfo.eng_val_steps = 7;
         cinfo.eng_Nm = fl_arr1;   
         cinfo.eng_kW = fl_arr2;

         fl_arr1[0] = 450;
         fl_arr1[1] = 460;
         fl_arr1[2] = 470;
         fl_arr1[3] = 480;
         fl_arr1[4] = 490;
         fl_arr1[5] = 500;
         fl_arr1[6] = 490;         

         for (i=0;i<8;i++)
            fl_arr1[i] *= 0.4f;

         fl_arr2[0] = 35;
         fl_arr2[1] = 40;
         fl_arr2[2] = 50;
         fl_arr2[3] = 55;
         fl_arr2[4] = 60;
         fl_arr2[5] = 50;
         fl_arr2[6] = 40;
         

         for (i=0;i<8;i++)
            fl_arr2[i] *= 0.5f;

         cinfo.trns_delay = 1.2f;
         cinfo.trns_gears = 4;
         cinfo.trns_gear = fl_arr3;
         
         fl_arr3[0] = -4.5f;
         fl_arr3[1] = 4.3f;
         fl_arr3[2] = 2.5f;
         fl_arr3[3] = 1.3f;
         fl_arr3[4] = 0.9f;
         fl_arr3[5] = 0.5f;

         // apply final ratio
         for (i=0;i<cinfo.trns_gears;i++)
               cinfo.trns_gear[i] *= 5.5f;

         

         susp = SC_NOD_Get(info->master_nod,"enginesound");
         SC_NOD_GetPosInOtherSpace(nod,susp,&cinfo.eng_sound_pos);

      
         // engine sound

         cinfo.eng_snd_id = 1900;

         cinfo.eng_freqmult_revs1 = 400;
         cinfo.eng_freqmult_revs2 = 3000;
         cinfo.eng_freqmult_1 = 0.5f;
         cinfo.eng_freqmult_2 = 2.0f;
         cinfo.eng_sound_volume = fl_arr4;

         fl_arr4[0] = 1.0f;
         fl_arr4[1] = 1.0f;
         fl_arr4[2] = 1.0f;
         fl_arr4[3] = 1.0f;
         fl_arr4[4] = 1.0f;
         fl_arr4[5] = 1.0f;
         fl_arr4[6] = 1.0f;         



         car = SC_CAR_Create(nod,&cinfo);

         // init wheels
         
         
         winfo.body_vector.x = 0.0f;
         winfo.body_vector.y = 0.0f;
         winfo.body_vector.z = -1.0f;
         
         winfo.spring_tmin = 0.05f;
         winfo.spring_tmax = 0.15f;
         winfo.spring_t = 0.15f;

/*
         winfo.spring_tmin = 1.1f;
         winfo.spring_tmax = 2.52f;
         winfo.spring_t = 0.2f;
*/
         winfo.spring_absorber = 1.0f;
         winfo.spring_looser = 3.0f;
         winfo.spring_rate = 55000.0f;
         winfo.wheel_radius = 0.40f;

         winfo.wheel_fr_min = 2.0f;
         winfo.wheel_fr_dspd =0.05*3.14f;

         winfo.wheel_friction =10.0f;
         winfo.wheel_aspd = 0;
         winfo.wheel_with_drive =TRUE;
         winfo.steering = TRUE;

         winfo.left_side = TRUE;
         
         ride_height = 0.2f;
         
//predni napravy

         winfo.ptc_v0_mult = 1.0f;
         winfo.ptc_v1_mult = 1.0f;
      //leva
         susp = SC_NOD_Get(info->master_nod,"zavesLF");
         SC_NOD_GetPosInOtherSpace(nod,susp,&winfo.body_point);
         wheel = SC_NOD_Get(info->master_nod,"M151_LF_LOD1");
         winfo.spring_tmin = 0.10f - ride_height;
         winfo.spring_tmax = 0.25f - ride_height;
         winfo.spring_t = 0.15f - ride_height;
         winfo.spring_rate = 43000.0f;
         winfo.spring_looser = 5.0f;
         winfo.spring_absorber = 0.5f;
         SC_CAR_WheelAdd(car,wheel,&winfo);
      
      //prava   
         winfo.left_side = FALSE;
         
         susp = SC_NOD_Get(info->master_nod,"zavesRF");
         SC_NOD_GetPosInOtherSpace(nod,susp,&winfo.body_point);
         wheel = SC_NOD_Get(info->master_nod,"M151_RF_LOD1");
         winfo.spring_tmin = 0.10f - ride_height;
         winfo.spring_tmax = 0.25f - ride_height;
         winfo.spring_t = 0.15f - ride_height;
         winfo.spring_rate = 43000.0f;
         winfo.spring_looser = 5.0f;
         winfo.spring_absorber = 0.5f;
         SC_CAR_WheelAdd(car,wheel,&winfo);

//zadni napravy
         winfo.ptc_v0_mult = 1.0f;
         winfo.ptc_v1_mult = 2.5f;
      //leva
         winfo.left_side = TRUE;
         winfo.steering = FALSE;
         winfo.wheel_with_drive = TRUE;

         susp = SC_NOD_Get(info->master_nod,"zavesLR");
         SC_NOD_GetPosInOtherSpace(nod,susp,&winfo.body_point);
         wheel = SC_NOD_Get(info->master_nod,"M151_LR_LOD1");
         winfo.spring_tmin = 0.10f - ride_height;
         winfo.spring_tmax = 0.25f - ride_height;
         winfo.spring_t = 0.15f - ride_height;
         winfo.spring_rate = 43000.0f;
         winfo.spring_looser = 5.0f;
         winfo.spring_absorber = 0.5f;
         SC_CAR_WheelAdd(car,wheel,&winfo);
         
      //prava   
         winfo.left_side = FALSE;
         winfo.wheel_with_drive = TRUE;

         susp = SC_NOD_Get(info->master_nod,"zavesRR");
         SC_NOD_GetPosInOtherSpace(nod,susp,&winfo.body_point);
         wheel = SC_NOD_Get(info->master_nod,"M151_RR_LOD1");
         winfo.spring_tmin = 0.10f - ride_height;
         winfo.spring_tmax = 0.25f - ride_height;
         winfo.spring_t = 0.15f - ride_height;
         winfo.spring_rate = 43000.0f;
         winfo.spring_looser = 5.0f;
         winfo.spring_absorber = 0.5f;
         SC_CAR_WheelAdd(car,wheel,&winfo);

// init driver

         CLEAR(einfo);
         susp = SC_NOD_Get(info->master_nod,"driverentry");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.entry);
         susp = SC_NOD_Get(info->master_nod,"driverpos");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.target);
         susp = SC_NOD_Get(info->master_nod,"driverview");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.view);
         einfo.entry_dist = 1.0f;
         einfo.entry_name_nr = 2105;
         einfo.exit_name_nr = 2107;
         einfo.function = 1;//SC_CAR_ENTRY_FUNC_SEAT//SC_CAR_ENTRY_FUNC_DRIVER
         einfo.stg_dir = "M151_1";
         einfo.can_shoot = FALSE;//TRUE will show double hands for driver
         einfo.min_rx = DEG_TO_RAD(-40.0f);
         einfo.max_rx = DEG_TO_RAD(60.0f);
         einfo.min_rz = DEG_TO_RAD(-120.0f);
         einfo.max_rz = DEG_TO_RAD(120.0f);   
         SC_CAR_EntryAdd(car,&einfo);


         susp = SC_NOD_Get(info->master_nod,"pasentry");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.entry);
         susp = SC_NOD_Get(info->master_nod,"paspos");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.target);
         susp = SC_NOD_Get(info->master_nod,"pasview");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.view);
         einfo.entry_dist = 1.0f;
         einfo.entry_name_nr = 2106;
         einfo.exit_name_nr = 2107;
         einfo.function = SC_CAR_ENTRY_FUNC_SEAT;
         einfo.stg_dir = "M151_2";
         einfo.can_shoot = TRUE;
         einfo.min_rz = -DEG_TO_RAD(120.0f);
         einfo.max_rz = DEG_TO_RAD(120.0f);         
         einfo.min_rx = -DEG_TO_RAD(50.0f);
         einfo.max_rx = DEG_TO_RAD(50.0f);         
         einfo.shoot_min_rz = DEG_TO_RAD(-30.0f);
         einfo.shoot_max_rz = DEG_TO_RAD(155.0f);
         einfo.min_rz = einfo.shoot_min_rz;
         einfo.max_rz = einfo.shoot_max_rz;
         einfo.switch_3pv_anim_dir = 5;   
         SC_CAR_EntryAdd(car,&einfo);


         susp = SC_NOD_Get(info->master_nod,"pas2entry");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.entry);
         susp = SC_NOD_Get(info->master_nod,"pas2pos");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.target);
         susp = SC_NOD_Get(info->master_nod,"pas2view");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.view);
         einfo.entry_dist = 1.0f;
         einfo.entry_name_nr = 2106;
         einfo.exit_name_nr = 2107;
         einfo.function = SC_CAR_ENTRY_FUNC_SEAT;
         einfo.stg_dir = "M151_4";
         einfo.can_shoot = TRUE;
         einfo.min_rz = -DEG_TO_RAD(120.0f);
         einfo.max_rz = DEG_TO_RAD(120.0f);         
         einfo.min_rx = -DEG_TO_RAD(50.0f);
         einfo.max_rx = DEG_TO_RAD(50.0f);         
         einfo.shoot_min_rz = DEG_TO_RAD(-269.0f);
         einfo.shoot_max_rz = DEG_TO_RAD(90.0f);
         einfo.min_rz = einfo.shoot_min_rz;
         einfo.max_rz = einfo.shoot_max_rz;
         einfo.switch_3pv_anim_dir = 3;
         SC_CAR_EntryAdd(car,&einfo);

/*      
// init spolujezdec vzdu vlevo
         susp = SC_NOD_Get(info->master_nod,"pas3entry");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.entry);

         susp = SC_NOD_Get(info->master_nod,"pas3pos");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.target);

         susp = SC_NOD_Get(info->master_nod,"pas3view");
         SC_NOD_GetPosInOtherSpace(nod,susp,&einfo.view);

         einfo.entry_dist = 1.0f;
         einfo.entry_name_nr = 2106;
         einfo.exit_name_nr = 2107;
         einfo.function = SC_CAR_ENTRY_FUNC_SEAT;
         einfo.stg_dir = "M151_3";
         einfo.can_shoot = TRUE;

         einfo.shoot_min_rz = DEG_TO_RAD(-90.0f);
         einfo.shoot_max_rz = DEG_TO_RAD(269.0f);
         einfo.min_rz = einfo.shoot_min_rz;
         einfo.max_rz = einfo.shoot_max_rz;

         einfo.switch_3pv_anim_dir = 7;
         
         SC_CAR_EntryAdd(car,&einfo);

         SC_CAR_SetAirResistance(car,10.0f,5.0f,20.0f);
*/
         break;
      case SC_OBJ_INFO_EVENT_DOTICK:
         if (SC_ggi(GVAR_GPHASE) == 1){//restarting
            Temp2 = -1;   
            return TRUE;
            break;
         }//switch(gPhase)
         //______________start/restart status for server____________
         if (Temp2 == -1){ //restores stsrt state
            //if (SC_ggi(GVAR_SERVER) == 1){   
            //}
            //SC_NOD_GetTransform(nod,&orig_car_trans);
            
            get_start_pos_after_physics = TRUE;
            Temp2 =0;
         }

// sync for first pos
         if (get_start_pos_after_physics){
            //start_pos_timer+=info->time;
            if (SC_ggi(GVAR_SERVER) == 1){
               //if (start_pos_timer>0.5){
               //   SC_NOD_GetWorldPos(nod, &car_vec);
               //   if(last_car_vec.z == car_vec.z){// in position
               //      Send_car_pos(info);
               //      get_start_pos_after_physics = FALSE;
               //   }
               //   last_car_vec.z = car_vec.z;
               //}
            }else{//client
               //if (start_pos_timer>3.0){
                  //Get_car_pos(info);
                  //get_start_pos_after_physics = FALSE;
               //}
            }
            trans=orig_trans;
            trans.rot.x=0;
            trans.rot.y=0;
            trans.rot.z=0;
            SC_NOD_SetTransform(info->master_nod,&trans);

            trans=orig_car_trans;
            trans.rot.z=CAR_world_rot;
            SC_NOD_SetTransform(nod,&trans);

            get_start_pos_after_physics = FALSE;
            //clear seats
            for (j=0;j<MP_CAR_SEATS;j++) {
               SC_sgi(my_gvar_seat_[j],0);
            }

            return TRUE;
         }
//end of




         check_timer+=info->time;
         car_stil_move_timer-=info->time;

         //___PLAYER IN/OUT SYNCHRO_____________
         player = SC_PC_Get();

         //test // still crach when player is dead
         /*
         if (!SC_P_IsReady(player)) {
            susp = SC_NOD_Get(info->master_nod,"pasentry");
            SC_NOD_GetWorldPos(susp,&car_vec);
            SC_P_ExitHeli(player,&car_vec);
            //SC_message("player dead");
            return TRUE;
         
         }*/


         if (player){
            PC_car_id = SC_P_IsInCarEx(player, &PC_entry);
            if (PC_car_id){// PC is on car
               if (PC_car_id == car){ // PC is in current car
                  if (PC_in_cur_car > -1){// was already in
                  }else{// just entered
                     PC_in_cur_car=PC_entry;
                     if ( SC_ggi(my_gvar_seat_[PC_entry])!= SC_MP_GetHandleofPl(player)){// update only when needed
                        SC_sgi(my_gvar_seat_[PC_entry],SC_MP_GetHandleofPl(player));
                        //SC_P_SetSelWeapon(player, 1);
                     }
                  }
                  if(check_timer>0.5){
                     if( PC_entry == 0){//PC is driver
                        //Send car pos
                        Send_car_pos(info);
                        
                        /*
                        //steering
                        SC_NOD_GetTransform(steer_wheel_id,&trans);
                        SC_sgf(my_gvar_steer,trans.rot.y);
                        //SC_Osi("wheel x: %2.3f y: %2.3f z: %2.3f",trans.rot.x,trans.rot.y,trans.rot.z);
                  
                        //front wheel
                        SC_NOD_GetTransform(wheel_id,&trans);
                        SC_sgf(my_gvar_steer_LR,trans.rot.z);
                        //SC_Osi("wheel x: %2.3f y: %2.3f z: %2.3f",trans.rot.x,trans.rot.y,trans.rot.z);
                        
                        */
                        driver_timer=0;
                     }
                  }
               }
            }else{// PC isnt in car
               if (PC_in_cur_car == 0 ){// was using driver seat
                  if ( pl_in_car[0]== 0){//nobady in driver seat
                     driver_timer+=info->time;
                     if (driver_timer < 4){// update car pos 4 sec after triver left it and no other driver
                        if(check_timer>0.5){
                           Send_car_pos(info);
                        }
                     }else{
                        SC_sgi(my_gvar_seat_[PC_in_cur_car],0);// removed from Gvar
                        PC_in_cur_car=-1;//
                     }
                  }
               }
               else if( PC_in_cur_car >= 0 ){   //____is PC left from car
                  if ( SC_ggi(my_gvar_seat_[PC_in_cur_car])== SC_MP_GetHandleofPl(player)){// was PC there?
                     SC_sgi(my_gvar_seat_[PC_in_cur_car],0);// removed from Gvar
                     PC_in_cur_car=-1;//
                  }
               }
            }
         }
         //SC_Osi("S1: %d s2: %d s3: %d", SC_ggi(my_gvar_seat_[0]),SC_ggi(my_gvar_seat_[1]),SC_ggi(my_gvar_seat_[2]));
      
         if(check_timer>0.5){
            check_timer=0;
            //______________________________CHECK ALL SEATS___________
            for (j=0;j<MP_CAR_SEATS;j++) {
               
               cur_pl_handle = SC_ggi(my_gvar_seat_[j]);
               //______________________________EXIT PLAYER IF NEEDED__________
               if (pl_in_car[j] > 0){//pl was in car


                  Cur_player = SC_MP_GetPlofHandle(pl_in_car[j]);
                  if(pl_in_car[j] != cur_pl_handle){// not in car and same slot anymore
                     sprintf(txt, "S_Entry_%d", j+1);
                     //susp = SC_NOD_Get(info->master_nod,txt);
                     susp = SC_NOD_Get(info->master_nod,"pasentry");
                     SC_NOD_GetWorldPos(susp,&car_vec);
                     SC_P_ExitHeli(Cur_player,&car_vec);
                     pl_in_car[j]=0;
                     if (SC_ggi(GVAR_SERVER) == 1){   // its server
                        if (j==0){// driver seat
                           SC_P_GetPos(Cur_player, &car_vec);
                           SC_P_Recover(Cur_player, &car_vec, SC_P_GetRot(Cur_player));
                        }
                     }
                  }
               }
               //_____________________________ADD PLAYER IF NEEDED____________
               if (cur_pl_handle>0){
               

                  Cur_player = SC_MP_GetPlofHandle(cur_pl_handle);
                  Player_CAR = SC_P_IsInCarEx(Cur_player, &cur_entry);
                  if (Player_CAR == car){//player is  already in current car
                     //___somebody drive(not pc), and need to get car pos+rot
                     if ((j==0) && ( Cur_player != player)){// player is driver  AND  not PC
                        //get new pos
                        Get_car_pos(info);
                        car_stil_move_timer=4;


                        /*
                        SC_NOD_GetTransform(steer_wheel_pos_id,&trans);
                        //trans.rot.x = SC_ggf(my_gvar_steer);
                        //trans.rot.y = SC_ggf(my_gvar_steer);
                        trans.rot.z = SC_ggf(my_gvar_steer);
                        SC_NOD_SetTransform(steer_wheel_pos_id,&trans);


                        //wheel
                        SC_NOD_GetTransform(wheel_id,&trans);
                        trans.rot.x = SC_ggf(my_gvar_steer_LR);
                        trans.rot.y = SC_ggf(my_gvar_steer_LR);
                        trans.rot.z = SC_ggf(my_gvar_steer_LR);
                        SC_NOD_SetTransform(wheel_id,&trans);
                        */
                     }
                  }else if (Cur_player != player){ //need to add him
                     //SC_Osi("need to add him");
                     SC_P_SetToCar(Cur_player, CAR_name, j);  // add to car
                     pl_in_car[j]=cur_pl_handle;//
                  }
               }
            }
            //___OBJECT MOVEMENT AFTER SOMEBODY USED IT_____________
            if (car_stil_move_timer > 0){// somebody was driving les than 4 sec ago
               if (( pl_in_car[0]== 0) && (PC_in_cur_car != 0)){//nobady in driver seat && pc not and wasnt in car
                  SC_Osi("get car pos");
                  Get_car_pos(info);
               }
            }
         }


         //_____________VEHICLE MOVEMENT BETWEEN SYNCHRO_________
         if ((car_stil_move_timer > 0) && (PC_in_cur_car != 0)){
            SC_NOD_GetTransform(nod,&trans); 
            trans.loc.x = last_x + ((cur_x - last_x)* check_timer /0.5);
            trans.loc.y = last_y + ((cur_y - last_y)* check_timer /0.5);
            trans.loc.z = last_z + ((cur_z - last_z)* check_timer /0.5);
            temp_f= cur_xr - last_xr;
            if (temp_f > PI){
               temp_f-=2*PI;
            }else if(temp_f < (0-PI) ){
               temp_f+=2*PI;
            }
            trans.rot.x = last_xr + (temp_f* check_timer /0.5);
            temp_f= cur_yr - last_yr;
            if (temp_f > PI){
               temp_f-=2*PI;
            }else if(temp_f < (0-PI) ){
               temp_f+=2*PI;
            }
            trans.rot.y = last_yr + (temp_f * check_timer /0.5);
            temp_f= cur_zr - last_zr;
            if (temp_f > PI){
               temp_f-=2*PI;
            }else if(temp_f < (0-PI) ){
               temp_f+=2*PI;
            }
            trans.rot.z = last_zr + (temp_f * check_timer /0.5);
            //trans.rot.x = last_xr + ((cur_xr - last_xr)* timer /0.5);
            //trans.rot.y = last_yr + ((cur_yr - last_yr)* timer /0.5);
            //trans.rot.z = last_zr + ((cur_zr - last_zr)* timer /0.5);
            SC_NOD_SetTransform(nod,&trans); 
            //SC_Osi("UPDATE POS ");
         }
         break;
   }// switch(info->event_type)
   return FALSE;
}// int ScriptMain(s_OBJ_info *info)



Ando attached the following file:
_mp_m151.zip [210.7 kB, 428 Downloads]
Edited by Ando on 24-10-2015 07:26
  x 1
 
KostiCZ
Ando wrote:
PC_M151 script

Description:


Tutorial for editor:


Known bugs:
- player (client) will be kicked of from server with high speed (Cheat #2)
- was more bugs but I dont remember now.



I think Brchi made fix for it, special vcded.exe where is modified speedcheck (VCGUARD?). This fix is used serverside only so clients don't need to have it.
Signature________________________________________________

2LT William Theolinus "KostiCZ" Boner Jr.
LRRP Squad Baker, Delta Team
cache.www.gametracker.com/player/KostiCZ/63.143.47.189:2302/b_560x95.png
  x 1  x 1
 
Teamrespawn.cz
Jump to Forum:
Similar Threads
Thread Forum Replies Last Post
How to edit a Grow type object? Maps & Mapping 11 04-03-2023 18:07
MEXICO SCRIPTS PROBLEM Vietcong Tech Talk 5 19-02-2016 09:58
I don't say to create a object with 3ds max Maps & Mapping 4 24-08-2015 21:19
***New Grass*** Object BES's for editor Maps & Mapping 1 02-04-2012 02:51
3d MAX Object not solid Maps & Mapping 7 14-03-2012 18:06
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Render time: 0.87 seconds - 73 Queries 4,880,944 unique visits