Post by Chavez on Sept 6, 2008 10:08:42 GMT -8
This was passed on to me by SilentBob from the Ptero Forums, some of the coding work was done by Gandf and <Edlder> Bidi
Elder<>[MCF] Bidi sent me the scripts for synchronised doors in MP maps.
Unfortunatly he stopped makeing Maps for VC and moved over to Armed Assault.
Please discuss and test it, if we understand it we can provide a tutorial for all map makers.
Its 4 scripts in total
Level:
Coop:
Porte (door):
[edit:] The last two scripts are for dynamic objects that have to be created.
Thank you for providing helpful scripting information Silent Bob...
Elder<>[MCF] Bidi sent me the scripts for synchronised doors in MP maps.
Unfortunatly he stopped makeing Maps for VC and moved over to Armed Assault.
Please discuss and test it, if we understand it we can provide a tutorial for all map makers.
Its 4 scripts in total
Level:
//default level.c
We have Elders permission to publish but i guess we need to write a how-to-use tutorial.....
#include <inc\sc_global.h>
#include <inc\sc_def.h>
#include <inc\mplevel.inc>
dword gphase = 0;
int ScriptMain(s_SC_L_info *info){
float fl;
int i;
s_SC_initside initside;
s_SC_initgroup initgroup;
c_Vector3 vec;
char txt[32];
BOOL hide_weapons,hide_CTF_flags,teamgame,hideRW;
void *c4nod;
info->next_exe_time = 10.0f;
switch (info->message)
{
case SC_LEV_MES_INITSCENE:
InitScene(info);
// hide C4
c4nod = SC_NOD_GetNoMessage(NULL,"c4");
if (c4nod) SC_DUMMY_Set_DoNotRenHier2(c4nod,TRUE);
switch(SC_ggi(GVAR_MP_MISSIONTYPE)){
case GVAR_MP_MISSIONTYPE_ATG:
switch(SC_ggi(GVAR_MP_MISSIONSUBTYPE)){
case 1:SC_SetObjectScript("bombplace","ini\\multiplayer\\scripts\\atg_dobj.c");break;
case 2:SC_SetObjectScript("bombplace","ini\\multiplayer\\scripts\\bomb_dobj_vc.c");break;
}// switch(SC_ggi(GVAR_MP_MISSIONTYPE))
SC_SetObjectScript
("commande","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande.c");
SC_SetObjectScript
("porte","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte.c");
SC_SetObjectScript
("porte5","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte5.c");
SC_SetObjectScript
("commande3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande3.c");
SC_SetObjectScript
("porte3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte3.c");
SC_SetObjectScript
("commande2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande2.c");
SC_SetObjectScript
("porte2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte2.c");
SC_SetObjectScript
("commande4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande4.c");
SC_SetObjectScript
("porte4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte4.c");
break;
case GVAR_MP_MISSIONTYPE_COOP:
SC_SetObjectScript
("commande","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande.c");
SC_SetObjectScript
("porte","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte.c");
SC_SetObjectScript
("commande3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande3.c");
SC_SetObjectScript
("porte3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte3.c");
SC_SetObjectScript
("commande2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande2.c");
SC_SetObjectScript
("porte2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte2.c");
SC_SetObjectScript
("commande4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande4.c");
SC_SetObjectScript
("porte4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte4.c");
break;
case GVAR_MP_MISSIONTYPE_DM:
SC_SetObjectScript
("commande","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande.c");
SC_SetObjectScript
("porte","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte.c");
SC_SetObjectScript
("porte5","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte5.c");
SC_SetObjectScript
("commande3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande3.c");
SC_SetObjectScript
("porte3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte3.c");
SC_SetObjectScript
("commande2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande2.c");
SC_SetObjectScript
("porte2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte2.c");
SC_SetObjectScript
("commande4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande4.c");
SC_SetObjectScript
("porte4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte4.c");
break;
case GVAR_MP_MISSIONTYPE_TDM:
SC_SetObjectScript
("commande","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande.c");
SC_SetObjectScript
("porte","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte.c");
SC_SetObjectScript
("commande3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande3.c");
SC_SetObjectScript
("porte3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte3.c");
SC_SetObjectScript
("commande2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande2.c");
SC_SetObjectScript
("porte2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte2.c");
SC_SetObjectScript
("commande4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande4.c");
SC_SetObjectScript
("porte4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte4.c");
break;
case GVAR_MP_MISSIONTYPE_CTF:
SC_SetObjectScript
("commande","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande.c");
SC_SetObjectScript
("porte","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte.c");
SC_SetObjectScript
("commande3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande3.c");
SC_SetObjectScript
("porte3","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte3.c");
SC_SetObjectScript
("commande2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande2.c");
SC_SetObjectScript
("porte2","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte2.c");
SC_SetObjectScript
("commande4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\commande4.c");
SC_SetObjectScript
("porte4","Levels\\meecrob_dernier\\data\\meecrob\\scripts\\porte4.c");
break;
} //switch(SC_ggi(GVAR_MP_MISSIONTYPE))
break;
case SC_LEV_MES_TIME:
switch (gphase)
{
case 0: //first time init
//various inits
CLEAR(initside);
CLEAR(initgroup);
initside.MaxHideOutsStatus = 64; //init sides and groups
initside.MaxGroups = 8;
SC_InitSide(SC_P_SIDE_US,&initside);
initside.MaxHideOutsStatus = 64;
initside.MaxGroups = 8;
SC_InitSide(SC_P_SIDE_VC,&initside);
initgroup.SideId = SC_P_SIDE_US; //US a-team
initgroup.GroupId = 0;
initgroup.MaxPlayers = 64; // nemenit !!! Erik.
SC_InitSideGroup(&initgroup);
//VC Groups - for COOP mode
initgroup.SideId = SC_P_SIDE_VC; //generic Vietcong
initgroup.GroupId = 0;
initgroup.MaxPlayers = 22; // nemenit !!! Erik.
SC_InitSideGroup(&initgroup);
initgroup.GroupId = 1;
initgroup.MaxPlayers = 5;
SC_InitSideGroup(&initgroup);
initgroup.GroupId = 2;
initgroup.MaxPlayers = 10;
SC_InitSideGroup(&initgroup);
initgroup.GroupId = 3;
initgroup.MaxPlayers = 5;
SC_InitSideGroup(&initgroup);
initgroup.GroupId = 4;
initgroup.MaxPlayers = 17;
SC_InitSideGroup(&initgroup);
initgroup.GroupId = 5;
initgroup.MaxPlayers = 8;
SC_InitSideGroup(&initgroup);
gphase = 1;
break;
}// gphase switch
break;
case SC_LEV_MES_RADIOUSED:
switch(info->param1){
}
break;
case SC_LEV_MES_SPEACHDONE:
switch(info->param1)
{
}
break;
}//switch (info->message){
return 1;
}// int ScriptMain(void)
Coop:
/*
Eric multiplayer script - Coop
*/
#include <inc\sc_global.h>
#include <inc\sc_def.h>
#define GVAR_GPHASE 500
//#define RECOVER_TIME 15.0f // time to global recover
#define NORECOV_TIME 3.0f // disable time of recoverplace after recovering someone there
#define REC_WPNAME_US "USSpawn_coop_%d"
#define REC_MAX 64
#define NUMBER_OF_USE1 600
#define NUMBER_OF_USE2 602
#define NUMBER_OF_USE3 603
#define NUMBER_OF_USE4 604
dword gRecs = 0;
s_SC_MP_Recover gRec[REC_MAX];
float gRecTimer[REC_MAX];
float gNextRecover = 0.0f;
dword gEndRule;
dword gEndValue;
float gTime;
#define GPHASE_BEGIN 1
#define GPHASE_GAME 2
#define GPHASE_DONE 3
#define GPHASE_FAILED 4
dword gPhase = GPHASE_BEGIN;
float gPhase_timer = 5.0f;
dword gPhase_send = 0;
BOOL gValidSide0 = FALSE;
dword gRecoverTime = 0;
dword gRecoverLimit = 0;
float gAllNoAiRecover = 0.0f;
BOOL SRV_CheckEndRule(float time){
switch(gEndRule){
case SC_MP_ENDRULE_TIME:
if (gValidSide0) gTime += time;
SC_MP_EndRule_SetTimeLeft(gTime,gValidSide0);
if (gTime>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 SRV_CheckUpdate(void){
if (gPhase_send!=gPhase){
gPhase_send = gPhase;
SC_sgi(GVAR_GPHASE,gPhase);
}// if (gPhase_send!=gPhase)
}// void SRV_CheckUpdate(void)
int ScriptMain(s_SC_NET_info *info)
{
s_SC_MP_EnumPlayers enum_pl[64];
s_SC_MP_SRV_settings SRVset;
s_SC_MP_Recover *precov;
s_SC_MP_hud hudinfo;
s_SC_P_getinfo plinfo;
dword i, j, sideA, sideB, num;
BOOL valid[2];
BOOL alldeath;
char txt[32],*itxt;
ushort *witxt;
float val;
//
switch(info->message)
{
case SC_NET_MES_SERVER_TICK:
if (SRV_CheckEndRule(info->elapsed_time)) break;
for (j=0;j<2;j++)
for (i=0;i<gRecs;i++)
gRecTimer[i] -= info->elapsed_time;
if (gRecoverTime<0xffff){
gNextRecover -= info->elapsed_time;
if (gNextRecover<0.0f) gNextRecover = (float)gRecoverTime;
}// if (gRecoverTime<0xffff)
if (gAllNoAiRecover>0.0f){
gAllNoAiRecover -= info->elapsed_time;
if (gAllNoAiRecover<=0.0f)
SC_MP_RecoverAllNoAiPlayers();
break;
}// if (gAllNoAiRecover>0.0f)
else{
gAllNoAiRecover -= info->elapsed_time;
}
CLEAR(valid);
j = 64;
alldeath = FALSE;
if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL)){
alldeath = TRUE;
for (i=0;i<j;i++){
if (enum_pl[i].status==SC_MP_P_STATUS_INGAME){
if (enum_pl[i].side>1) SC_message("coop script wrong side: %d",enum_pl[i].side);
else{
valid[enum_pl[i].side] = TRUE;
}
}
if ((enum_pl[i].side==0)&&(enum_pl[i].status==SC_MP_P_STATUS_INGAME)) alldeath = FALSE;
}// for (i)
SC_Log(3,"Enum, v[0]: %d v[1]: %d alldeath: %d",valid[0],valid[1],alldeath);
}// if (SC_MP_EnumPlayers(enum_pl,&j,SC_MP_ENUMPLAYER_SIDE_ALL))
else SC_Log(3,"NoEnum");
if ((gPhase==GPHASE_GAME)&&(alldeath)&&(gPhase_timer<0.0f)){
if (gRecoverLimit==0){
// mission failed
SC_Log(2,"Set GPHASE_FAILED");
gPhase = GPHASE_FAILED;
gPhase_timer = 5.0f;
}
else {
// recover unlimited
if ((gRecoverTime>=0xffff)&&(gAllNoAiRecover<-5.0f)){
gAllNoAiRecover = 4.0f;
}
}
}// if ((alldeath)&&(gRecoverTime>=0xffff))
else gAllNoAiRecover = 0.0f;
gValidSide0 = valid[0];
switch(gPhase){
case GPHASE_BEGIN:
gPhase_timer -= info->elapsed_time;
if (gPhase_timer<0.0f)
if ((valid[0])&&(valid[1])){
SC_Log(2,"Set GPHASE_GAME");
gPhase_timer = 5.0f;
gPhase = GPHASE_GAME;
}
break;
case GPHASE_GAME:
gPhase_timer -= info->elapsed_time;
if (gPhase_timer<0.0f)
if (!valid[1]){
SC_Log(2,"Set GPHASE_DONE");
gPhase = GPHASE_DONE;
gPhase_timer = 8.0f;
}// if (!valid[1])
break;
case GPHASE_DONE:
case GPHASE_FAILED:
gPhase_timer -= info->elapsed_time;
if (gPhase_timer<0.0f){
SC_Log(2,"SC_MP_RestartMission");
SC_MP_RestartMission(); //restart
gPhase = GPHASE_BEGIN;
gPhase_timer = 5.0f;
}
break;
}// switch(gPhase)
SRV_CheckUpdate();
break;
case SC_NET_MES_CLIENT_TICK:
break;// SC_NET_MES_CLIENT_TICK
case SC_NET_MES_LEVELPREINIT:
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE1);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE2);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE3);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE4);
SC_sgi(GVAR_MP_MISSIONTYPE,GVAR_MP_MISSIONTYPE_COOP);
gEndRule = info->param1;
gEndValue = info->param2;
gTime = 0.0f;
SC_MP_EnableBotsFromScene(TRUE);
break;// SC_NET_MES_LEVELPREINIT
case SC_NET_MES_LEVELINIT:
SC_MP_SRV_SetForceSide(0);
SC_MP_SetItemsNoDisappear(TRUE);
SC_MP_SRV_SetClassLimit(18,0);
SC_MP_SRV_SetClassLimit(19,0);
SC_MP_SRV_SetClassLimit(39,0);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE1);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE2);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE3);
SC_MP_Gvar_SetSynchro(NUMBER_OF_USE4);
SC_MP_GetSRVsettings(&SRVset);
for (i=0;i<6;i++){
SC_MP_SRV_SetClassLimit(i+1,SRVset.atg_class_limit[i]);
SC_MP_SRV_SetClassLimit(i+21,SRVset.atg_class_limit[i]);
}// for (i)
CLEAR(hudinfo);
hudinfo.title = 1098;
hudinfo.sort_by[0] = SC_HUD_MP_SORTBY_KILLS;
hudinfo.sort_by[1] = SC_HUD_MP_SORTBY_DEATHS | SC_HUD_MP_SORT_DOWNUP;
hudinfo.sort_by[2] = SC_HUD_MP_SORTBY_PINGS | SC_HUD_MP_SORT_DOWNUP;
hudinfo.pl_mask = SC_HUD_MP_PL_MASK_KILLS | SC_HUD_MP_PL_MASK_DEATHS | SC_HUD_MP_PL_MASK_CLASS;
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.disableVCside = TRUE;
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);
SC_MP_SetChooseValidSides(1);
if (info->param2){
if (info->param1){
// it's server
SC_MP_GetSRVsettings(&SRVset);
gRecoverTime = SRVset.coop_respawn_time;
gRecoverLimit = SRVset.coop_respawn_limit;
SC_MP_SRV_InitWeaponsRecovery(-1.0f);
SC_MP_Gvar_SetSynchro(GVAR_GPHASE);
gRecs = 0;
for (i=0;i<REC_MAX;i++){
sprintf(txt,REC_WPNAME_US,i);
if (SC_NET_FillRecover(&gRec[gRecs],txt)) gRecs++;
}
#if _GE_VERSION_ >= 133
i = REC_MAX - gRecs;
SC_MP_GetRecovers(SC_MP_RESPAWN_COOP,&gRec[gRecs],&i);
gRecs += i;
#endif
if (gRecs==0) SC_message("no US recover place defined!");
CLEAR(gRecTimer);
}// if (info->param1)
}//if (info->param2)
if (info->param1)
{
//!!! ++ Reinit AI - NEW
num = 64;
SC_MP_EnumPlayers(enum_pl, &num, SC_P_SIDE_VC);
for (i = 0; i < num; i++)
{
SC_P_ScriptMessage(enum_pl[i].id, SCM_MP_REINIT, 0);
}
//-- Reinit AI - NEW
}
break;// SC_NET_MES_LEVELINIT
case SC_NET_MES_RENDERHUD:
switch(SC_ggi(GVAR_GPHASE)){
case GPHASE_DONE:
j = 1099;
break;
case GPHASE_FAILED:
j = 1049;
break;
default:j = 0;break;
}// switch(SC_ggi(GVAR_GPHASE))
if (j){
witxt = SC_Wtxt(j);
SC_GetScreenRes(&val,NULL);
val -= SC_Fnt_GetWidthW(witxt,1);
SC_Fnt_WriteW(val * 0.5f,15,witxt,1,0xffffffff);
}// if (j)
break;
case SC_NET_MES_SERVER_RECOVER_TIME:
if (info->param2){
info->fval1 = 0.1f;
}
else{
// killed
SC_P_GetInfo(info->param1,&plinfo);
if (plinfo.side==0){
if (gRecoverLimit>0){
if (gRecoverTime>=0xffff) info->fval1 = -1.0f;
else
if (gRecoverTime>0) info->fval1 = gNextRecover;
else info->fval1 = 4.0f;
}
else info->fval1 = -1.0f;
}
else info->fval1 = -1.0f;
}
break;
case SC_NET_MES_SERVER_RECOVER_PLACE:
if (info->param1!=0){
SC_message("No recover for VC");
break;
}
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:
break;// SC_NET_MES_SERVER_KILL
case SC_NET_MES_RESTARTMAP:
CLEAR(gRecTimer);
gNextRecover = 0.0f;
gTime = 0;
gPhase = GPHASE_BEGIN;
gPhase_timer = 5.0f;
gPhase_send = 0;
gValidSide0 = FALSE;
SC_MP_GetSRVsettings(&SRVset);
gRecoverTime = SRVset.coop_respawn_time;
gRecoverLimit = SRVset.coop_respawn_limit;
gAllNoAiRecover = 0.0f;
SC_MP_SRV_ClearPlsStats();
SC_MP_SRV_InitGameAfterInactive();
SC_MP_RecoverAllAiPlayers();
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)
Porte (door):
#include <inc\sc_global.h>
#include <inc\sc_def.h>
//Auteur : gandf
//version 1.21
//Script d'une porte dynamique qui s'ouvre grace à un autre objet scripté. Fonctionne ne multi.
//Optimisation complète des transmittions réseau.
//Le son de l'ouverture de la porte se joue correctement à l'endroit de la porte (et non du boîtier)
//L'écriture est correcte (indique que l'on peut ouvrir ou fermer la porte dans la langue de l'utilisateur)
#define NUMBER_OF_USE1 600 // 0 = porte fermée et 1 = porte ouverte + 2 quand mouvement
#define SOUND 601
#define TEMP_INIT 2.0f //Temps d'initialisation en secondes
#define OPENINGTIME 0.8f //Temps d'ouverture ou de fermeture de la porte en secondes
#define CLOSESOUND 2513 //Son de fermeture de porte
#define OPENSOUND 2514 //Son d'ouverture de porte
#define AngleDeRotation 115.0f //Angle de roration final de la porte.
int IN_USE_TIME = 0;
c_Vector3 vec2;
float val = 0.0f;
float rot = 0.0f;
s_SC_NOD_transform trans;
s_SC_NOD_transform orig_trans;
float timer = 0.0f;
int Temp = 0;
int Temp2 = 0; // autre variable avec un autre nom pour éviter un problème d'accès
int ScriptMain(s_SC_OBJ_info *info){
switch(info->event_type){
case SC_OBJ_INFO_EVENT_INIT:
SC_NOD_GetTransform(info->master_nod,&orig_trans);
// SC_MP_Gvar_SetSynchro(NUMBER_OF_USE1); //Synchronisation avec les autres joueurs
SC_sgi(NUMBER_OF_USE1,0); //initialisation (la porte est fermée)
SC_sgi(IN_USE_TIME,0);
SC_sgi(SOUND,0);
timer = 0;
IN_USE_TIME = 0;
return TRUE;
case SC_OBJ_INFO_EVENT_JUSTLOADED:
break;
case SC_OBJ_INFO_EVENT_RELEASE:
SC_NOD_SetTransform(info->master_nod,&orig_trans);
SC_sgi(NUMBER_OF_USE1,0); //initialisation (la porte est fermée)
SC_sgi(IN_USE_TIME,0);
SC_sgi(SOUND,0);
timer = 0;
IN_USE_TIME = 0;
break;
case SC_OBJ_INFO_EVENT_HIT:
break;
case SC_OBJ_INFO_EVENT_DOTICK:
if (SC_ggi(NUMBER_OF_USE1) > 0)
{
SC_NOD_GetWorldPos(info->master_nod,&vec2); // on joue le son d'ouverture ou de fermeture de la porte
Temp2 = SC_ggi(SOUND);
if (Temp2 == 1)
{
SC_SND_PlaySound3D(OPENSOUND,&vec2);
}
if (Temp2 == 2)
{
SC_SND_PlaySound3D(CLOSESOUND,&vec2);
}
SC_sgi(SOUND,0);
}
if (IN_USE_TIME == 1)
{
timer+=info->time;
trans=orig_trans;
Temp = SC_ggi(NUMBER_OF_USE1);
if (Temp == 0 || Temp == 2) // on teste le sens d'ouverture de la porte
{
trans.rot.z+=(DEG_TO_RAD(AngleDeRotation)*(OPENINGTIME-timer)/OPENINGTIME);
}
else {
trans.rot.z+=(DEG_TO_RAD(AngleDeRotation)*timer/OPENINGTIME);
}
SC_NOD_SetTransform(info->master_nod,&trans); //remet la porte en place
if ((timer/OPENINGTIME) >= 1)
{
IN_USE_TIME = 0;
timer=0;
if (Temp == 2 || Temp == 0) // on teste l'utilisation de la porte
{
SC_NOD_SetTransform(info->master_nod,&orig_trans);
}
if (Temp > 1)
{
Temp = Temp - 2;
SC_sgi(NUMBER_OF_USE1,Temp);
}
}
}
Temp = SC_ggi(NUMBER_OF_USE1);
if (Temp > 1 && IN_USE_TIME == 0)
{
timer=0;
IN_USE_TIME = 1;
}
break;
case SC_OBJ_INFO_EVENT_USED:
break;
}// switch(info->event_type)
return FALSE;
}// int ScriptMain(s_OBJ_info *info)
Commande (Key):
Code:
#include <inc\sc_global.h>
#include <inc\sc_def.h>
//Auteur : gandf
//version 1.21
//Script de la commande de la porte dynamique. Fonctionne ne multi.
//Optimisation complète des transmittions réseau.
//Le son de l'ouverture de la porte se joue correctement à l'endroit de la porte (et non du boîtier)
//L'écriture est correcte (indique que l'on peut ouvrir ou fermer la porte dans la langue de l'utilisateur)
#define NUMBER_OF_USE1 600 // 0 = porte fermée et 1 = porte ouverte + 2 quand mouvement
#define SOUND 601
#define TEMP_INIT 2.0f //Temps d'initialisation en secondes
#define OPENINGTIME 0.8f //Temps d'ouverture ou de fermeture de la porte en secondes
#define CLOSESTRING 2814 //texte qui est affiché quand on pointe l'objet indiquant que l'on peut fermer la porte
#define OPENSTRING 2813 //texte qui est affiché quand on pointe l'objet indiquant que l'on peut ouvrir la porte
float val = 0.0f;
int StringPorte = OPENSTRING;
int Temp = 0;
int Temp2 = 0;
int ScriptMain(s_SC_OBJ_info *info){
switch(info->event_type){
case SC_OBJ_INFO_EVENT_INIT:
// SC_MP_Gvar_SetSynchro(NUMBER_OF_USE1); //Synchronisation avec les autres joueurs
SC_sgi(NUMBER_OF_USE1,0); //initialisation (la porte est fermée)
SC_sgi(SOUND,0);
Temp2 = 0;
StringPorte = OPENSTRING;
return TRUE;
case SC_OBJ_INFO_EVENT_JUSTLOADED:
break;
case SC_OBJ_INFO_EVENT_RELEASE:
SC_sgi(NUMBER_OF_USE1,0); //initialisation (la porte est fermée)
SC_sgi(SOUND,0);
Temp2 = 0;
StringPorte = OPENSTRING;
break;
case SC_OBJ_INFO_EVENT_HIT:
break;
case SC_OBJ_INFO_EVENT_DOTICK:
val = SC_DOBJ_CameraLooksAt(info->master_nod,2);
if (val<1.0f){
SC_ACTIVE_Add(info->master_nod,2.0f*val,StringPorte);
}
Temp = SC_ggi(NUMBER_OF_USE1);
if (Temp == 2)
{StringPorte = OPENSTRING;
if (Temp2 != Temp)
{
Temp2 = Temp;
SC_sgi(SOUND,2);
}
}
if (Temp == 3)
{
StringPorte = CLOSESTRING;
if (Temp2 != Temp)
{
Temp2 = Temp;
SC_sgi(SOUND,1);
}
}
break;
case SC_OBJ_INFO_EVENT_USED:
Temp = SC_ggi(NUMBER_OF_USE1);
if (Temp == 0 || Temp == 2)
{Temp = 3; //on change le sens d'ouverture de la porte
SC_sgi(NUMBER_OF_USE1,Temp); // on lance l'ouverture de la porte
}
else {Temp = 2; //Fermeture de la porte
SC_sgi(NUMBER_OF_USE1,Temp);
}
break;
}// switch(info->event_type)
return FALSE;
}// int ScriptMain(s_OBJ_info *info)
[edit:] The last two scripts are for dynamic objects that have to be created.
Thank you for providing helpful scripting information Silent Bob...