I'm trying to use Ando's door script. Walk up to door ,enter, door opens but spins 360. Can hit enter and reverse revolution but still spins 360.
case SC_LEV_MES_INITSCENE:
// VIETCONG 1
// DOOR script v3.0
// Writen for custom object - DE_door.bes
// made by Ando
/*
______________DESCRIPTION:
MP synchronized door.
Player can use (open /close) door. Use option appears when player is near door and looking at it.
Door has some kind of collision with player. It means that door don’t move through player, it moves back to last position when player is on its way.
Also bots can use that door. Door open/close automatically when they are near enough.
_____________HISTORY:
//2.3 orig trans restored bug fixed
//2.4 completly new and better synchronization
//2.5 AI is using doors automatically
//2.6 created fake collision with player
//2.6 start state option
//2.7 automatic Global variable system
//3.0
int Temp = 0; //global object status
int Temp2 = -1; //local object status. -1 = unknown ststus (for start/restart)
int i_items,j;
int my_gvar_count;
int my_gvar;
BOOL startsound = FALSE;
s_SC_P_getinfo pl_info;
dword player;
dword list[32];
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_NOD_GetWorldPos(info->master_nod,&door_vec);
dum_sub_obj_id = SC_NOD_GetNoMessage(info->master_nod, dum_sub_obj);
return TRUE;
case SC_OBJ_INFO_EVENT_JUSTLOADED:
break;
case SC_OBJ_INFO_EVENT_RELEASE:
SC_NOD_SetTransform(info->master_nod,&orig_trans);
break;
case SC_OBJ_INFO_EVENT_HIT:
break;
case SC_OBJ_INFO_EVENT_DOTICK:
if (SC_ggi(GVAR_GPHASE) == 1){//restarting
Temp2 = -1; //restores unknown state for door
return TRUE;
break;
}//
//______________start/restart status for server____________
if (Temp2 == -1){ //restores stsrt state
if (SC_ggi(GVAR_SERVER) == 1){
SC_sgi(my_gvar,START_STATE); // status on start/restart
}
}
Temp = SC_ggi(my_gvar);
//_________________________________________AI is useing a door
if (SC_ggi(GVAR_SERVER) == 1){
player = SC_GetNearestPlayer(&door_vec, &dist);
if (dist < 2.8f){//was 2.5 before
SC_P_GetInfo(player, &pl_info);
if(pl_info.member_id != 255){
switch(Temp){
case 0: //
if (dist < 2){
SC_sgi(my_gvar,2);//opening
Temp =2;
}
break;
case 1: //
if (dist > 2.1){
SC_sgi(my_gvar,3);//closeing
Temp =3;
}
break;
}
}
}
}
//__________________________________________end of AI is useing a door
//______________use string__________
val = SC_DOBJ_CameraLooksAt(info->master_nod,2);
if (val<1.0f){
if (Temp == 0 || Temp == 3){
use_string = OPENSTRING;
}
if (Temp == 1 || Temp == 2){
use_string = CLOSESTRING;
}
SC_ACTIVE_Add(info->master_nod,2.0f*val,use_string);
}
//_____________CHANGE OBJECT STATUS________________
if (Temp != Temp2){ //temp- Global state Temp2 - Local state
switch(Temp){
case 0: //set door closed status
SC_NOD_SetTransform(info->master_nod,&orig_trans);
startsound = TRUE;//??????
timer=0;
Temp2=0;
break;
case 1: //set door opened status
trans=orig_trans;
trans.rot.z+= DEG_TO_RAD(ROT_ANGLE);
SC_NOD_SetTransform(info->master_nod,&trans);
startsound = TRUE;//?????
timer=0;
Temp2=1;
break;
case 2: //door is opening
if (Temp2==1){ //last state was oposite movement
timer = (OPENINGTIME-timer);//reverse movement time
}
Temp2=0;
if (startsound){
SC_SND_PlaySound3D(OPENSOUND,&door_vec);
startsound = FALSE;
}
timer+=info->time;
trans=orig_trans;
trans.rot.z+=(DEG_TO_RAD(ROT_ANGLE)*timer/OPENINGTIME);
SC_NOD_SetTransform(info->master_nod,&trans);
// ________FAKE COLLISION WITH PLAYER______________________________
if (SC_ggi(GVAR_SERVER) == 1){// only server
sph2.pos=door_vec;
sph2.rad=2;
i_items=32;
SC_GetPls(&sph2,list,&i_items);
for (j=0;j<i_items;j++) {
SC_P_GetInfo(list[j], &pl_info);
if(pl_info.member_id == 255){
SC_NOD_GetWorldPos(dum_sub_obj_id, &dum_pos);
SC_P_GetPos(list[j], &player_pos);
dist=SC_GetLineDist(&player_pos, &dum_pos,&door_vec);
if (dist < 0.33f){
SC_SND_PlaySound3D(COLL_SOUND,&player_pos); //collision sound
SC_sgi(my_gvar,3); //
}
}
}
}
//_________end of FAKE COLLISION______________________________________
if (timer >= OPENINGTIME){
if (SC_ggi(GVAR_SERVER) == 1) SC_sgi(my_gvar,1); //
}
break;
case 3: //door is closing
if (Temp2==0){ //last state was oposite movement
timer = (OPENINGTIME-timer);//reverse movement time
}
Temp2=1;
if (startsound){
SC_SND_PlaySound3D(CLOSESOUND,&door_vec);
startsound = FALSE;
}
timer+=info->time;
trans=orig_trans;
trans.rot.z+=(DEG_TO_RAD(ROT_ANGLE)*(OPENINGTIME-timer)/OPENINGTIME);
SC_NOD_SetTransform(info->master_nod,&trans);
// ________FAKE COLLISION___________________________________________________
if (SC_ggi(GVAR_SERVER) == 1){// only server
sph2.pos=door_vec;
sph2.rad=2;
i_items=32;
SC_GetPls(&sph2,list,&i_items);
for (j=0;j<i_items;j++) {
SC_P_GetInfo(list[j], &pl_info);
if(pl_info.member_id == 255){
SC_NOD_GetWorldPos(dum_sub_obj_id, &dum_pos);
SC_P_GetPos(list[j], &player_pos);
dist=SC_GetLineDist(&player_pos, &dum_pos,&door_vec);
if (dist < 0.33f){
SC_SND_PlaySound3D(COLL_SOUND,&player_pos); //collision sound
SC_sgi(my_gvar,2); //
}
}
}
}
//_________end of FAKE COLLISION______________________________________
if (timer >= OPENINGTIME){
if (SC_ggi(GVAR_SERVER) == 1) SC_sgi(my_gvar,0); //
}
break;
case 5: //
break;
}
}
break;
case SC_OBJ_INFO_EVENT_USED:
Temp = SC_ggi(my_gvar);
switch(Temp){
case 0: // door is closed
case 3: // door is closing
SC_sgi(my_gvar,2); // start opening
break;
case 1: // door is opened
case 2: // door is opening
SC_sgi(my_gvar,3); // start closing
break;
}
break;
}// switch(info->event_type)
return FALSE;
}// int ScriptMain(s_OBJ_info *info)
SGT PEPPER wrote:
I'm trying to use Ando's door script. Walk up to door ,enter, door opens but spins 360. Can hit enter and reverse revolution but still spins 360.
Probably mode script is without automatic sync. support.