Door works but no sound is played. Uncomment lines in the "// Enter CLU's Command Ship:" section to try making the sounds work.
(213.02 KiB) Downloaded 868 times
Symptoms
A door opens when you approach it, after the long stairs. This works correctly, with the big code sample below.
However, I want it to play a sound when it opens and another when it closes. But if I uncomment this line, the door opens once and immediately closes forever:
//SET open_closed = 1 // opening sound is now playing
The effect is like the COUNTER for command_entry is being reset or broken? Why would changing the value of the COUNTER for open_closed do that, though?
So maybe there's a logic error in my code, or a tiny syntax problem? I was looking at it late at night and posted this quite frustrated; sorry I forgot to describe it properly!
Desired Behaviour
The door opens when you approach it. The door closes if you move away from it or pass through it. That works fine, until the line is uncommented.
Big Code Sample
Relevant parts of the code, to help focus bug-hunting.
[mis]// Objectives
COUNTER command_entry // door to CLU's Command Ship
COUNTER open_closed // 1 = opening, 2 = closing
SOUND door_sound // plays the sound
// Loop until JOB COMPLETE:
WHILE_EXEC (stage = 1)
// Player 1:
IF (CHECK_CHARACTER_HEALTH(p1, 0))
// Enter CLU's Command Ship:
IF (LOCATE_CHARACTER_ANY_MEANS(p1, 41.5,20.5,5.0, 1.0,1.0))
SET command_entry = 1 // central controller for door
ENDIF
ENDIF
// [all other players]
// Enter CLU's Command Ship:
// Central controller for door
IF (command_entry = 1)
// Open door to let player(s) in:
CHANGE_BLOCK SIDE (41,20,5) TOP
NOT_WALL NOT_BULLET NOT_FLAT NOT_FLIP
000 935
CHANGE_BLOCK SIDE (41,20,5) BOTTOM
NOT_WALL NOT_BULLET FLAT NOT_FLIP
000 935
// Stop the door closing sound:
/*
IF (open_closed = 2) // closing door sound is playing
DELETE_ITEM (door_sound)
SET open_closed = 0 // opening sound is now playing
ENDIF
*/
// Play the door opening sound:
IF (open_closed = 0) // no sounds are playing
DELETE_ITEM (door_sound)
door_sound = CREATE_SOUND (41.5,21.0,5.0) GARAGE_OPEN PLAY_INSTANT END
//SET open_closed = 1 // opening sound is now playing
ENDIF
ELSE
// Close door because no players are near it:
CHANGE_BLOCK SIDE (41,20,5) TOP
NOT_WALL NOT_BULLET NOT_FLAT NOT_FLIP
000 928
CHANGE_BLOCK SIDE (41,20,5) BOTTOM
WALL BULLET FLAT NOT_FLIP
000 928
// Play the door closing sound once:
/*
IF (open_closed = 1) // opening door sound is playing
DELETE_ITEM (door_sound)
door_sound = CREATE_SOUND (41.5,21.0,5.0) GARAGE_OPEN PLAY_INSTANT END
SET open_closed = 2 // closing sound is now playing
ENDIF
*/
ENDIF
SET command_entry = 0 // reset
ENDWHILE[/mis]
Some sort of tiny syntax error I've made, which the compiler doesn't mind? Or a logic problem?
(EDIT) Provide a link straight to the solution, for future coder convenience.
Last edited by BenMillard on 12 Apr 2012, 20:15, edited 3 times in total.
what is the problem? is the door sound not playing?
i can't really see a problem with that code but i have a working garage sound for a powerup pickup in tiny face off army
warning: long code (search for garage)
[mis]<%@ Template Language="C#" TargetLanguage="gta2mis" Description="Generates Tiny Face Off Army." %>
<%@ Property Name="PlayerCount" Type="System.Int32" Default="6" Category="Options" Description="This is the amount of players that this script should support." %>
<%@ Property Name="Author" Type="System.String" Default="anybody" Category="Options" Description="Author" %>
<%@ Property Name="Mapname" Type="System.String" Default="anymap" Category="Options" Description="Map name" %>
<%@ Property Name="Base" Type="System.String" Default="any" Category="Options" Description="base file name without extension" %>
<%@ Property Name="train" Type="System.Boolean" Default="true" Category="Options" Description="will the train be on the map" %>
<%@ Property Name="lite" Type="System.Boolean" Default="true" Category="Options" Description="will it be the lite version" %>
<% System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); %>
<script runat="template">
const int PU_NONE = -1;
const int PU_OBJECT = 0;
const int PU_INSTANT = 1;
const int PU_EVER = 2;
public struct pos{
public pos(double x,double y,double z){
this.x = x;
this.y = y;
this.z = z;
}
public double x;
public double y;
public double z;
public override string ToString(){
return(string.Format(" {0:0.00}, {1:0.00} , {2:0.00} ", x, y, z));
}
}
public struct powerup{
public powerup( string name, pos pos, int respawn, string obj, int soundtype, string sound){
this.name = name;
this.pos = pos;
this.respawn =respawn;
this.obj = obj;
this.soundtype = soundtype;
this.sound = sound;
}
public string name;
public pos pos;
public int respawn;
public string obj;
public int soundtype;
public string sound;
}
</script>
//{ //Header
// <%=Mapname%>
// script and map by <%=Author%>
// for details look at <%=Base%>_readme.txt
// <%=Base%>.mis Compiled by <%=Author%> on <%= DateTime.Now.ToLongDateString() %> with codesmith
IF( p<%=i%>_wantedlevel > max_wantedlevel )
SET p<%=i%>_wantedlevel = (max_wantedlevel + 0)
ALTER_WANTED_LEVEL (p<%=i%>, 5) //should be ALTER_WANTED_LEVEL (p<%=i%>, max_wantedlevel) but works for this map that way too
ENDIF
IF( p<%=i%>_wantedlevel > wantedlevel )
SET wantedlevel = (p<%=i%>_wantedlevel + 0)
ENDIF
//}
//SWAT
IF (p<%=i%>_tmr_swat > 1)
SET p<%=i%>_tmr_swat = ( p<%=i%>_tmr_swat - 1)
ENDIF
IF (p<%=i%>_tmr_swat = 1)
SET p<%=i%>_tmr_swat = 0
ALTER_WANTED_LEVEL (p<%=i%>, 4) //SWAT
ENDIF
//{ //Powerups
IF ((LOCATE_CHARACTER_BY_CAR ( p<%=i%> , 68.0, 199.5, 7.0 , 0.8 , 0.8 ))AND(col_armor = 0))
IF (p<%=i%>_armor > 1)
SET_CAR_NUMBER_GRAPHIC ( p<%=i%>_ffield1 , 8 )
SET_CAR_BULLETPROOF ( p<%=i%>_armor_v, OFF )
SET_CAR_ROCKETPROOF ( p<%=i%>_armor_v, OFF )
SET_CAR_FLAMEPROOF ( p<%=i%>_armor_v, OFF )
ENDIF
SET tmr_armor = 0
SET armor_ani = -3
SET p<%=i%>_armor = (armor_duration+0)
STORE_CAR_CHARACTER_IS_IN ( p<%=i%> , p<%=i%>_armor_v )
p<%=i%>_ffield1 = CREATE_CAR (1.0, 1.0, 0.0) 27 90 AMDB4 END
PUT_CAR_ON_TRAILER ( p<%=i%>_ffield1 , p<%=i%>_armor_v )
ENDIF
IF ((( HAS_CHAR_PUNCHED_SOMEONE ( p<%=i%> ) ) AND ( p<%=i%>_trg_punched = 0 ) ) AND ( p<%=i%>_expunch = 1))
STORE_LAST_CHAR_PUNCHED ( p<%=i%> , p<%=i%>_punched )
SET p<%=i%>_trg_punched = 1
ENDIF
IF (( p<%=i%>_trg_punched = 1 ) AND ( p<%=i%>_expunch = 1))
IF ( NOT ( DELAY ( 60 ) ) )
EXPLODE_SMALL (p<%=i%>_punched)
SET p<%=i%>_trg_punched = 0
ENDIF
ENDIF
IF ( p<%=i%>_blackbox=1 )
IF (IS_CHAR_PRESSING_HORN ( p<%=i%> ) ) //Player pressing HORN
IF (p<%=i%>_trg_horn=0)
SET p<%=i%>_trg_horn=1
ENDIF
ENDIF
IF (NOT(IS_CHAR_PRESSING_HORN ( p<%=i%> ) ))
IF (p<%=i%>_trg_horn=1)
ORDER_CHAR_TO_BACKDOOR(p<%=i%>,p<%=i%>_v)
p<%=i%>_blackbox_bot = CREATE_CHAR_INSIDE_CAR ( p<%=i%>_v ) 0 DRIVER END
SET p<%=i%>_blackbox=0
ENDIF
SET p<%=i%>_trg_horn=0
ENDIF
ENDIF
// remote
IF (p<%=i%>_tmr_remote > 1)
SET p<%=i%>_tmr_remote = ( p<%=i%>_tmr_remote - 1)
ENDIF
IF (p<%=i%>_tmr_remote = 1)
SET p<%=i%>_tmr_remote = 0
SET p<%=i%>_remote = 1
TAKE_REMOTE_CONTROL_OF_CAR (p<%=i%>, p<%=i%>_v)
ENDIF
// electro protection
IF((CHECK_WEAPON_TYPE_HIT_CHAR (p<%=i%>, BY_ELECTRO_WEAPON)) AND (p<%=i%>_electro_protection = 1))
SET_CHAR_INVINCIBLE( p<%=i%> , ON )
SET p<%=i%>_tmr_invulv = 100
EXPLODE_SMALL(p<%=i%>)
ENDIF
//{ // CARMODEL CHECK
IF ((IS_CHARACTER_IN_ANY_CAR ( p<%=i%> ) ) AND (p<%=i%>_remote=0) )
IF (p<%=i%>_trg_ic=1)
SET p<%=i%>_trg_ic=0
LAUNCH_MISSION(p<%=i%>_cmc.mis)
ENDIF
ENDIF
IF ((NOT(IS_CHARACTER_IN_ANY_CAR ( p<%=i%> ) )) AND (p<%=i%>_remote=0) )
IF (p<%=i%>_trg_ic=0)
Why dont you just use the DOOR_DATA thing... it opens door when you approach and closes when you get out. Rather hacky way to do the same thing as basic doors does...
T.M. wrote:Why dont you just use the DOOR_DATA thing... it opens door when you approach and closes when you get out. Rather hacky way to do the same thing as basic doors does...
If I remember with proper DOOR_DATA, if you fire a gun in the trigger zone (for the door to open/close) you won't see any bullets/rockets. Pretty trivial really, but if you really wanted to fight near a door then it'd affect you, hence making a 'fake' door (check if player/car/object destroyed then change the physical block the door tile is on and, if needs be, use sound on the door to fake it).
Also, by the looks of your COUNTERS in your declarations, you haven't given them an initial value but I doubt that'd affect it. You probably want to use a NOT along with a LOCATE_CHARACTER_ANY_MEANS for door control. Or just use a real door
not sure if that has anything to do with it but play instant sounds do not have to be deleted to stop them
and i can confirm that the garage close sound is working. maybe the open sound is not
Pyro wrote:Also, by the looks of your COUNTERS in your declarations, you haven't given them an initial value but I doubt that'd affect it.
While making the SCR decompiler, i noticed all uninitialized variables gets initialized to zero automatically, in fact, some commands are stored with "COUNTER some = 0" fashion instead of "COUNTER some", so decompiling them will reveal their initial values that way.
DOOR_DATA blocks all weapons. So if you are standing 'inside' it and shoot a rocket, it instantly hits an invisible forcefield and kills you. Same with throwing molotovs, etc. A key part of this level is that you shoot through the doorway when the two teams first encounter one another.
(It's also super weird to see this blocking effect at any time in a multiplayer level. Unless you're parking a stolen Pacifier in your own base.)
Elypter, the sound was repeating every cycle over itself in most versions of the code I tried. That was either with or without the DELETE_ITEM, as it turns out. Maybe we can test some versions tomorrow in 2-player? Forgot my power lead tonight, so not on for long.
Thanks for the help so far, dudes. I've attached the broken version to first message.
there are 2 types of sounds. the ones that only play if you execute a command each cycle, repeat automatically and stop immediately if you dont + the ones that play once instantly and cannot be stopped. those are hardcoded. it makes sense to only use the respective type in the script but it there might be exceptions. i didnt figure those out or forgot.
yours looks like the horn on bc_ac. the garage close sound on tyfo army plays once and has to be executed only once like you would expect.
BenMillard wrote:It's also super weird to see this blocking effect at any time in a multiplayer level. Unless you're parking a stolen Pacifier in your own base.
Not sure if that was a dig at Bootcamp or just coincidence
Gustavob shared a code he wrote to do this. Below is a full working .mis which I quickly adapted to work on pza.gmp with a custom .mmp. The door appears in the far South West corner of the arena.
Looks like the GOSUB he was using isn't actually necessary, so I inlined that code. Might re-use the GOSUB so it can be shared between players, though.
CHANGE_BLOCK SIDE only works when that block already has a side, either from the GMP or (presumably) from ADD_NEW_BLOCK.
// Gustavob Door Code
COUNTER doorsoundplayed = 0
COUNTER doorsoundplayed2 = 0
SOUND doorsound
playsound1:
doorsound = CREATE_SOUND (112.0,139.0,1.0) GARAGE_OPEN PLAY_INSTANT END //Obviously you'll change the coordinates here...
SET doorsoundplayed = 1
RETURN
playsound2:
doorsound = CREATE_SOUND (112.0,139.0,1.0) GARAGE_CLOSE PLAY_INSTANT END //...and here
SET doorsoundplayed = 0
RETURN
// End of objects...
LEVELSTART
// ...start of commands.
// Environment
SET_AMBIENT_LEVEL (0.75, 0) // reduce the value after you add lights
DECLARE_POLICELEVEL (4) // 4 = SWAT; 5 = FBI; 6 = Army
// Note: Army in multiplayer needs Vike's GTA2 v11.3 or newer.
// Main Loop
// Note: Only needed for missions, game modes and gimmicks.
WHILE_EXEC (stage = 1)
// DO_NOWT
// Gustavob Door Code
IF ( LOCATE_CHARACTER_ANY_MEANS(p1, 113.0,139.0,1.0, 2.0,2.0) ) //In front of door
CHANGE_BLOCK SIDE (113,139,1) TOP NOT_WALL NOT_BULLET FLAT NOT_FLIP 270 935 //Make it look open
CHANGE_BLOCK SIDE (112,139,1) TOP NOT_WALL NOT_BULLET FLAT NOT_FLIP 090 935
CHANGE_BLOCK SIDE (113,139,1) BOTTOM NOT_WALL NOT_BULLET NOT_FLAT NOT_FLIP 090 935
CHANGE_BLOCK SIDE (112,139,1) BOTTOM NOT_WALL NOT_BULLET NOT_FLAT NOT_FLIP 270 935
WHILE ( doorsoundplayed = 0 )
//GOSUB playsound1: //Here is where the sound is played
doorsound = CREATE_SOUND (112.0,139.0,1.0) GARAGE_OPEN PLAY_INSTANT END //Obviously you'll change the coordinates here...
SET doorsoundplayed = 1
ENDWHILE
ENDIF
IF ( NOT ( LOCATE_CHARACTER_ANY_MEANS(p1, 113.0,139.0,1.0, 2.0,2.0) ) )
CHANGE_BLOCK SIDE (113,139,1) TOP WALL BULLET FLAT NOT_FLIP 270 928 //Close it again when player leaves range
CHANGE_BLOCK SIDE (112,139,1) TOP WALL BULLET FLAT NOT_FLIP 090 928
CHANGE_BLOCK SIDE (113,139,1) BOTTOM WALL NOT_BULLET NOT_FLAT NOT_FLIP 090 928
CHANGE_BLOCK SIDE (112,139,1) BOTTOM WALL NOT_BULLET NOT_FLAT NOT_FLIP 270 928
WHILE ( doorsoundplayed = 1 )
//GOSUB playsound2: //Here is where the closing sound (which is actually just the same) plays
doorsound = CREATE_SOUND (112.0,139.0,1.0) GARAGE_CLOSE PLAY_INSTANT END //...and here
SET doorsoundplayed = 0
ENDWHILE
ENDIF
ENDWHILE
LEVELEND[/mis]
Last edited by BenMillard on 13 Apr 2012, 21:48, edited 1 time in total.