Level Repeats?

Posted By: Siwler

Level Repeats? - 02/29/12 00:41


I have few levels that player will go back and fort, but when every time I go back to previous level that level starts from beginning. All my tasks that have been done you can do them again.

Can someone give me code example on how to stop level repeats?
Posted By: Uhrwerk

Re: Level Repeats? - 02/29/12 00:56

Looks like you're using level_load for changing levels. That means every time you load a level it will be exactly in its initial state. If you want to avoid that you have to save the game when leaving the level and later on load that game back when your player reenters that level.

The following commands might help you:
http://www.conitec.net/beta/asave.htm
http://www.conitec.net/beta/aload.htm
Posted By: darkinferno

Re: Level Repeats? - 02/29/12 01:13

or just write a function that resets all your variables, example:

level_load("MAP.wmb");

taskComplete=OFF;
aiKilled=OFF;
weedSmoked=OFF;

laugh
Posted By: Siwler

Re: Level Repeats? - 02/29/12 01:56

Thanks Uhrwerk asave.htm is samething that I was looking for.

But I still dont't get it, how do I call game_save and game_load from the same function and plus I have to do that for every lvl.

All game_saves I have to save them under the same STRING* name and number or do I have to save them under different STRING* name and number, same for game_load?

Do I have to call it throughout example:

Code:
while(level_load)
{
game_save("main", 1, SV-ALL);
else
game_load("main", 1);
}



I tried calling it as just
game_save("main", 1, SV-ALL); // before exiting level 1
and
game_load("main", 1);// after exiting level 2

that only works for one of the levels but the rest of levels still get reset.
Posted By: Siwler

Re: Level Repeats? - 02/29/12 02:07

Thanks darkinferno

I'll look into your example, all thou it looks more complexed then just trying to save and load before and after level_loads.
Posted By: FoxHound

Re: Level Repeats? - 02/29/12 04:55

Save_game is for when you need to exit the game and come back in a new game. If you use global vars they will not be reset when a new level is loaded.

from the manual "The current level is closed, the cache holding level entity files is purged. All current entities in the old level are removed, thus all entity pointers referring to them can't be used anymore."

Darkinferno knows what he's talking about, go his route.

Further, look at how your levels are set up, do you have the player model already in the level at the starting position but the reload level is at a different position? If so it is better to create the player with script along with his position, along with anything else for that level that is not always the same.
Posted By: Siwler

Re: Level Repeats? - 02/29/12 23:32

Yea I tried working with var and failed.

How do I check if entity is been removed and keep it removed on coming back from other levels.

Can someone give me a code example on this, Please?
Posted By: darkinferno

Re: Level Repeats? - 03/01/12 02:24

I dont think you need to check if the player was removed, level_load already removes all entities, so all you can run the same function every time you load a level;

You could have a function like:

Code:
function init_newLevel()
{

// create player
player= ent_create("player.mdl", spawnENT.x, playerFunc);
//reset vars
playerGotPistol =OFF;
playerGotShield =OFF;
}



now when you load a level, do:

Code:
level_load(newMap);
wait(3);
init_newLevel();


Posted By: FoxHound

Re: Level Repeats? - 03/01/12 03:14

Is this like of you have 5 monsters and if they are not killed you have to face them again when you return to the level. If so make a global avr for each monster and set it to 1. Now use that global var either in their while bracket or at the start of their function that they check to see if it is one and if not have them removed via script.
Posted By: Siwler

Re: Level Repeats? - 03/01/12 21:42

Yes FoxHound, its like you said if I have 5 monsters in level one and I kill them, then I can proceed to the next level.
But I want player to be able to go back to the first level and complete some other tasks without having to kill those 5 monsters again.

So I have to ent_create("monster1.mdl", vector(10, 20, 30), monstersFunction);//(Ican't bring those 5 monsters throughout WED?) and define 5 different monster names and turn them into global var and set global vars to 1, then check them to see if they have been accomplished/removed and set their vars to 0?

I felt like this could be done by game_save and game_load each level, I guess not.
Posted By: FoxHound

Re: Level Repeats? - 03/02/12 01:14

Var isbigbadmonster1killed =0;

......

Now after the while(health >0) loop put

Isbigbadmonster1killed =1;

Now put this at the Start of the function

If(isbigbadmonster1killed ==1)ent_remove(me);

Game_save will save these vars so that is not a problem but it can't save what was done in a level unless there is something to save.
Posted By: Uhrwerk

Re: Level Repeats? - 03/02/12 01:30

I don't get your point here, FoxHound. If you load level X and bigbadmonster gets killed and removed, then it will not be there even if you do a savegame, load another level and load the savegame later on. Why making it so complicated with additional variables and script effort?
Posted By: FoxHound

Re: Level Repeats? - 03/02/12 04:47

Siwler is setting his levels up in wed where he also sets up the monsters and attaches the script. So when he kills a monster and leaves a level and comes back then the monster would be back no matter how many times it was killed. My way sets it up to check to see if he was killed before, and now that I am at a computer and not an iphone i can write it out a bit better

var monster_1_alive = 1;

function monster_1_function()
{
//if i am dead then what am i doing here?
if(monster_1_alive == 0)
ent_remove(me);

//i guess im alive so i should have some health
my.health = 100;

//while i have that health i should hang around
while(my.health > 0
{

wait(1);
}

//guess i'm dead now
monster_1_alive = 0;

//goood bye cruel world
ent_remove(me);
}
Posted By: Uhrwerk

Re: Level Repeats? - 03/02/12 12:42

Originally Posted By: FoxHound
So when he kills a monster and leaves a level and comes back then the monster would be back no matter how many times it was killed.

That is the point I don't understand because from my point of view this is simply not true. If you remove an entity X from a level, do a save game and later on load that savegame entity X will still be gone.
Posted By: FoxHound

Re: Level Repeats? - 03/02/12 16:54

Correct, as long as you do not reload that level. Once you reload that level it will be exactly as it was the first time.

So kill all the monsters in a level, go to the next level and then go back all those monsters will be there because you are loading a level with monsters in them. Now if you had one giant level and never used level_load then you would not have to worry about that.
Posted By: Uhrwerk

Re: Level Repeats? - 03/02/12 23:42

I still think you didn't my suggestion. For every level you attempt to load first try to load a savegame for that level. If and only if loading a save game for that level fails then load the original level.

When you reload the level it will of cause be in it's initial state. The point is avoiding reloading by doing savegames when leaving the level and doing a game load instead of level loading when reentering the level.
Posted By: Siwler

Re: Level Repeats? - 03/03/12 04:47

Game_save and game_load its not working for when going back and fort between levels, here is why:

I'm in level 1 right now and I kill 5 main monsters then collect $500. From this point I can go to level 2 so I can kill more monsters collect more money and get better weapons.
So before I leave level 1 I game_save level 1 then load level 2 right? Now I kill 5 monsters collect another $500, now I have $1,000 and I have to go back to level 1, before I leave level 2 I have to save level 2 and then game_load level 1, sense I have to game_save all my progress under same string name and game_load from the same .SAV file I never leave level 2 it sends me to a loop, which is game_save before leaving level 2 then game_load from the same saved file which was last saved in level 2 it always game_loads me back to level 2 again and again?

But when I game_save and game_load under different .SAV name for level 1 and level 2 then I can't bring anything back from level 2 to level 1, because of saving and loading level 1 under different name.

I do appreciate you guys trying to help me out I have learned a lot from this.
Posted By: Uhrwerk

Re: Level Repeats? - 03/03/12 15:02

The basic idea is to have one save game per level. For instance if you have the levels cave.wmb, dungeon.wmb and town.wmb, then you should do three save games as well. cave0.sav when leaving cave.wmb, dungeon0.sav for dungeon.wmb etc.

Additionally to that you should save things like the player inventory, his stats etc. in an external file. Alternatively you can use info variables for this and use the save game mechanism for that as well.
Posted By: FoxHound

Re: Level Repeats? - 03/03/12 18:59

YOur idea is that it's better to have one save file per level plus one save file per game? That doesnt work on levels that need to change. Such as summer and winter levels or I'd you can enter a level from multiple points on top of the fact of how many levels you could have in game.
Posted By: Uhrwerk

Re: Level Repeats? - 03/03/12 19:37

If you have different versions of the .wmb files like summer or winter then it gets difficult, yes. Entering a level from several different positions is easy though. First load the game or level, then set the player to the desired position.

The advantage of my solution over yours is that it is generic. Once you realised it is done you don't need to bother about the issue any more. Your approach will generate work for every level and almost every actor inside the game world.

The advantage of your method is of cause the plus on felxibility you gain.
Posted By: FoxHound

Re: Level Repeats? - 03/03/12 20:50

We could go on like this all day. But in the end if it works it works.
Posted By: Uhrwerk

Re: Level Repeats? - 03/03/12 21:54

That's true. but as we're talking about the ideas I got fun and Siwler can get inspiration. :-)
Posted By: FoxHound

Re: Level Repeats? - 03/03/12 23:06

Out of curiosity have you made a large game using this approach
Posted By: Uhrwerk

Re: Level Repeats? - 03/04/12 00:55

No. Some years ago I did a quick prototype with this with only three levels. I got inspired when System Shock 2 was released. They had this feature that you could use bulks to switch levels and whatever you did was saved. There were not many games at that time which allowed you to go back to some place you already visited before.
Posted By: FoxHound

Re: Level Repeats? - 03/06/12 23:25

Back in the old days with c-script I would agree with this approach. With structs it would be simpler to make a struct to handle the info needed to be saved and then make one per level as needed.
© 2024 lite-C Forums