i just want one single hit switch, but what's the difference if i would like a multi use switch?
When I posted that I haven't figured out best trick to create multi use switch but now I've known how, it's easy to create single hit switch with it
Now, since this method requires entity and indexed variables, you need to create script.txt placed inside data folder, with these texts in it:
maxindexedvars 10
maxentityvars 10
Next, the switch itself, you can use type obstacle for it. Here's an example on how to create simple on/off switch:
Code:
name Drum2
health 10
type obstacle
gfxshadow 1
death 1
defense all 0
nodieblink 3
icon data/chars/misc/drumicon.gif
takedamagescript data/scripts/switch.c
diesound data/sounds/klunk.wav
anim idle
@script
void self = getlocalvar("self"); //Get calling entity.
void State = getentityvar(self,1);
if(State == 3){
setindexedvar(0, 1);
performattack(self, openborconstant("ANI_FOLLOW1"));
}
@end_script
loop 1 1 3
delay 100
offset 22 63
frame data/chars/misc/drum.gif
delay 10
bbox 0 -25 43 92
frame data/chars/misc/drum.gif
frame data/chars/misc/drum.gif
frame data/chars/misc/drum.gif
anim follow1
@script
void self = getlocalvar("self"); //Get calling entity.
void State = getentityvar(self,1);
if(State == NULL()){
setindexedvar(0, NULL());
setidle(self, openborconstant("ANI_IDLE"));
}
@end_script
loop 1 1 3
delay 100
offset 22 63
frame data/chars/misc/drum3.gif
delay 10
bbox 0 -25 43 92
frame data/chars/misc/drum3.gif
frame data/chars/misc/drum3.gif
frame data/chars/misc/drum3.gif
anim death
delay 10
offset 23 63
frame data/chars/misc/drum3.gif
frame data/chars/misc/drum3.gif
You can change the sprites, delay, bbox etc but the scripts and animation names
Create this file in data/scripts folder:
switch.c
Code:
void main()
{// Switches personal state
void self = getlocalvar("self"); //Get calling entity.
void State = getentityvar(self,1);
if(State == 3){
setentityvar(self, 1, NULL());
} else {
setentityvar(self, 1, 3);
}
}
This script is required by the switch to go on/off
Next is the switchable platform, here's a simple example:
Code:
name Crusher
type none
shadow 5
anim idle
@script
void self = getlocalvar("self"); //Get calling entity
void Status = getindexedvar(0);
if(Status == 1){
performattack(self, openborconstant("ANI_FOLLOW1"));
}
@end_script
loop 1
delay 2
offset 45 285
platform 40 295 -50 -50 50 50 20 5000
frame data/chars/misc/crusher.gif
frame data/chars/misc/crusher.gif
anim follow1
@script
void self = getlocalvar("self"); //Get calling entity
void Status = getindexedvar(0);
if(Status == NULL()){
setidle(self, openborconstant("ANI_IDLE"));
}
@end_script
loop 1
delay 2
offset 45 475
frame data/chars/misc/crusher.gif
frame data/chars/misc/crusher.gif
With these, hitting the switch will set indexed variable 0 to 1. This variable will be read by the crusher to change animation to FOLLOW1. IOW hitting the switch switches the crusher to move up
Last create this script in data/scripts folder too:
endlevel.c
Code:
void main()
{
setindexedvar(0, NULL());
}
This script will prevent switched on/off status be carried to next levels
The switch example above is multi use switch. If you want single use switch, just remove the script and/or remove the bbox in FOLLOW1 animation
Oh yes, the switch is indestructible BTW so don't worry about hitting it multiple times
