I don't asking about 3pspawn and 4pspawn. I'm asking about anything similar to 2pgroup 3pgroup 4pgroup... You understand? Sorry, I think I did not explain myself wellSame commands, just with 3~ or 4~.
DC
I don't know if it can work for your game, but SOR2X has a random spawn system for enemies that checks how many players are alive and other conditions too.Could I create those scripts directly in the level file associated to a temporary and invisible entity? It would be more convenient to manage
Another question: Is there a variable that returns the number of players in play? Or do I have to ask the script to check one by one?
name JetX
type none
lifespan 0.001
shadow 0
alpha 1
onspawnscript data/scripts/onspawn/jetx.c
remap data/chars/random/empty.gif data/chars/random/alter1.gif
remap data/chars/random/empty.gif data/chars/random/alter2.gif
remap data/chars/random/empty.gif data/chars/random/alter3.gif
remap data/chars/random/empty.gif data/chars/random/alter4.gif
anim idle
loop 0
delay 1
offset 50 72
frame data/chars/random/empty.gif
void main()
{
jetX();
}
void jetX()
{//Spawn enemy according player count
void difficulty = getglobalvar("difficulty");
void partner = getglobalvar("partnerAlive");
int set = openborvariant("current_set");
int branch = openborvariant("current_branch");
int pCount = openborvariant("count_players");
if(partner > 0){pCount = pCount+partner;}
if(set == 0 || set == 2){
if(branch == "sor2_st2c"){
if(difficulty != "mania"){
if(pCount >= 2){enemyX("JetB", 0, 0, 0, 0, 0, 1);}
}
if(difficulty == "mania"){
enemyX("JetB", 0, 0, 0, 0, 0, 1);
}
}
if(branch == "sor2_st5c"){
if(difficulty != "mania"){
if(pCount >= 1 && pCount <= 2){enemyX("JetB", 0, 0, 0, 0, 0, 2);}else
if(pCount >= 3 && pCount <= 4){enemyX("JetB", 0, 0, 0, 0, 0, 2);enemyX("JetB", 50, 0, 0, 1, 0, 3);}
}
if(difficulty == "mania"){
enemyX("JetB", 0, 0, 0, 0, 0, 2);
enemyX("JetB", 50, 0, 0, 1, 0, 3);
}
}
if(branch == "sor2_st7b"){
if(difficulty != "mania"){
if(pCount >= 1 && pCount <= 2){enemyX("JetB", 0, 0, 0, 0, 0, 5);}else
if(pCount >= 3 && pCount <= 4){enemyX("JetB", 0, 0, 0, 0, 0, 5);enemyX("JetB", 50, 0, 0, 1, 0, 4);}
}
if(difficulty == "mania"){
enemyX("JetB", 0, 0, 0, 0, 0, 5);
enemyX("JetB", 50, 0, 0, 1, 0, 5);
}
}
}
}
void enemyX(void vName, float dx, float dy, float dz, int iDir, int boss, int map)
{//Spawns random enemy next to caller (DEFAULT, FOR SUB-BOSSES OR BOSSES)
void self = getlocalvar("self");
void vSpawn;
loadmodel(vName);
clearspawnentry();
setspawnentry("name", vName);
setspawnentry("boss", boss);
setspawnentry("map", map);
vSpawn = spawn();
bindentity(vSpawn, self, dx, dz, dy, iDir);
return vSpawn;
}
spawn ghosttime
@script
void main()
{
setlocalvar("leveln","1lvl");
}
@end_script
spawnscript data/scripts/spawn2p.c
health 20
coords 850 440
at 100
void main()
{
void level = getlocalvar("leveln");
int pCount = openborvariant("count_players");
if(pCount > 1){
if(level == "1lvl"){enemyX("kraven", 10, 10, 0, 0, 2);enemyX("brock", 20, 20, 0, 0, 2);enemyX("ren", 30, 30, 0, 0, 2);enemyX("fatguy", 40, 40, 0, 0, 2);}
}
}
void enemyX(void vName, float dx, float dy, float dz, int iDir, int map)
{//Spawns enemy next to caller
void self = getlocalvar("self");
void vSpawn;
loadmodel(vName);
clearspawnentry();
setspawnentry("name", vName);
setspawnentry("map", map);
vSpawn = spawn();
bindentity(vSpawn, self, dx, dz, dy, iDir);
return vSpawn;
}
if (level == "1lvl") {
I'm trying to do it in a simple way, and I've tried the following, but it doesn't work. Only one step fails, see if anybody can help me.
First I create a temporary entity that lasts a few seconds, ghosttime. Then I declare a local variable that indicates what level it is. And I call the script.
C#:spawn ghosttime @script void main() { setlocalvar("leveln","1lvl"); } @end_script spawnscript data/scripts/spawn2p.c health 20 coords 850 440 at 100
The content of the file spawn2p.c is as follows:
C#:void main() { void level = getlocalvar("leveln"); int pCount = openborvariant("count_players"); if(pCount > 1){ if(level == "1lvl"){enemyX("kraven", 10, 10, 0, 0, 2);enemyX("brock", 20, 20, 0, 0, 2);enemyX("ren", 30, 30, 0, 0, 2);enemyX("fatguy", 40, 40, 0, 0, 2);} } } void enemyX(void vName, float dx, float dy, float dz, int iDir, int map) {//Spawns enemy next to caller void self = getlocalvar("self"); void vSpawn; loadmodel(vName); clearspawnentry(); setspawnentry("name", vName); setspawnentry("map", map); vSpawn = spawn(); bindentity(vSpawn, self, dx, dz, dy, iDir); return vSpawn; }
This condition, doesn't works, without this, enemies spawn correctly.
C#:if (level == "1lvl") {
I need this condition to be able to add all spawns to the same spawn2p.c file, for convenience.
What am I doing wrong, or what is missing?
@ToranksIt also doesn't work with setglobalvar / getglobalvar
My only alternative now is use a different script file for each spawn 2pspawn01.c, 2pspawnXX.c ... etc, repeating the same code
spawn BlockadeZ 1
@script
void main()
{
setglobalvar("leveln","1lvl");
}
@end_script
flip 1
coords 0 470 0
at 0
spawn FakeWall 1
spawnscript data/scripts/levelspawn/music_boss1.c
flip 1
coords 588 384 0
at 0
void main()
{
if(getglobalvar("leveln") == "1lvl"){musicBoss1();}
}
spawn FakeWall 1
spawnscript data/scripts/levelspawn/music_boss1.c
flip 1
coords 588 384 0
at 0
spawn FakeWall 1
spawnscript data/scripts/levelspawn/music_boss2.c
flip 1
coords 588 384 0
at 0
spawn FakeWall 1
spawnscript data/scripts/levelspawn/music_boss3.c
flip 1
coords 588 384 0
at 0
#import "data/scripts/levelspawn/main_music.c"
void main()
{
if(getglobalvar("leveln") == "1lvl"){musicBoss1();}
}
#import "data/scripts/levelspawn/main_music.c"
void main()
{
if(getglobalvar("leveln") == "2lvl"){musicBoss2();}
}
#import "data/scripts/levelspawn/main_music.c"
void main()
{
if(getglobalvar("leveln") == "3lvl"){musicBoss3();}
}
Method 1 works and is very simple, thanks!@Toranks
Tested your script in SOR2X and it really didn't work, but I found the problem. It seems that you can't use in-line scripts together with "spawnscripts" in the same spawn occurrence. At this point, we have two options:
spawn ghost1
@script
void main()
{
setglobalvar("leveln","1lvl");
}
@end_script
coords 850 440
at 100
spawn ghosttime
health 20
spawnscript data/scripts/spawn3p.c
coords 850 340
at 100
void main()
{
void level = getglobalvar("leveln");
int pCount = openborvariant("count_players");
if(pCount > 2){
if(level == "1lvl"){enemyX("kraven", 10, 10, 0, 0, 2);enemyX("brock", 20, 20, 0, 0, 2);enemyX("ren", 30, 30, 0, 0, 2);enemyX("fatguy", 40, 40, 0, 0, 2);}
}
}
void enemyX(void vName, float dx, float dy, float dz, int iDir, int map)
{//Spawns enemy next to caller
void self = getlocalvar("self");
void vSpawn;
loadmodel(vName);
clearspawnentry();
setspawnentry("name", vName);
setspawnentry("map", map);
vSpawn = spawn();
bindentity(vSpawn, self, dx, dz, dy, iDir);
return vSpawn;
}