Alexandre Silva said:
Thanks there people, as for the links I will give a review if they really expired ... But I am still waiting for an expert in scripts to give me an example of how I can save the state of the character so he doesn't lose his weapon when he passes the stage or scenario. .. Thanks !!! ;D ???
Hi
Alexandre Silva! I'm not a script expert ;D but I will try to help.
I took a look in your code and I see that you used "shootnum" for weapon bullets. However, after a few tries I see that this property is not accessible by script. I suggest to use "MP" to bullet count instead of "shootnum" because MP property can be accessible by script. You can even save the current weapon model and reload it when the new level starts, but the "shootnum" property will be erased by the engine.
Speaking about properties that are accessible by scripts, we can save/load it by using global variables. Entity variables can work too but let's start with global variables and mp property first.
Here is an example. Basically, you will get the current player mp and store it in a variable when the level ends. You can use the files "endlevel.c" to run scripts when the any current level ends, and use the "level.c" to run scripts when any new level starts. So, create a file named "endlevel.c" in scripts folder and put a code like this:
Code:
void main()
{
void p1 = getplayerproperty(0, "entity"); //GET THE ENTITY OF PLAYER 1
void p2 = getplayerproperty(1, "entity"); //GET THE ENTITY OF PLAYER 2
void model1 = getentityproperty(p1, "model"); //GET PLAYER 1 CURRENT MODEL
void model2 = getentityproperty(p2, "model"); //GET PLAYER 2 CURRENT MODEL
int mp1 = getentityproperty(p1, "mp"); //GET PLAYER 1 CURRENT MP
int mp2 = getentityproperty(p2, "mp"); //GET PLAYER 2 CURRENT MP
setglobalvar("mp1", mp1); //SAVE CURRENT PLAYER 1 MP
setglobalvar("mp2", mp2); //SAVE CURRENT PLAYER 2 MP
setglobalvar("model1", model1); //SAVE CURRENT PLAYER 1 MODEL
setglobalvar("model2", model2); //SAVE CURRENT PLAYER 2 MODEL
}
After, you will need to load the saved value when the new level starts. Create a file named "level.c" in scripts folder and put a code like this:
Code:
void main()
{
void p1 = getplayerproperty(0, "entity"); //GET THE ENTITY OF PLAYER 1
void p2 = getplayerproperty(1, "entity"); //GET THE ENTITY OF PLAYER 2
void model1 = getglobalvar("model1"); //GET PLAYER 1 SAVED MODEL
void model2 = getglobalvar("model2"); //GET PLAYER 2 SAVED MODEL
int mp1 = getglobalvar("mp1"); //GET PLAYER 1 SAVED MP
int mp2 = getglobalvar("mp2"); //GET PLAYER 2 SAVED MP
if(mp1 != NULL()){ //CHECK IF THE MP VARIABLE IS NULL FOR PLAYER 1, OTHERWISE IT WILL CRASH THE GAME
changeentityproperty(p1, "mp", mp1); //LOAD AND CHANGE PLAYER 1 MP
changeentityproperty(p1, "model", model1, 1); //LOAD AND CHANGE PLAYER 1 MODEL
}
if(mp2 != NULL()){ //CHECK IF THE MP VARIABLE IS NULL FOR PLAYER 2, OTHERWISE IT WILL CRASH THE GAME
changeentityproperty(p2, "mp", mp2); //LOAD AND CHANGE PLAYER 2 MP
changeentityproperty(p2, "model", model2, 1); //LOAD AND CHANGE PLAYER 2 MODEL
}
}
Remember that you will need to clear these variables when the game ends to not start a new game with the saved variable. All you need to do is to put the command "clearglobalvar()" in the file update.c or updated.c and set it in title screen or menu screen, like this:
Code:
//TITLE SCREEN
if(openborvariant("in_titlescreen")){
clearglobalvar(); //CLEAR ALL GLOBAL VARIABLES AT THE TITLE SCREEN
}
This is a basic example only, you can modify as you want. Another problem that you have is about the model changing. You can save the current model by using the same way of the MP, and reload it when the level starts. But to manage models it will a bit more complicated, because when the mp ends the player will not reset to default model automatically. You will need to put a script (animation script, ondraw script, etc) to check it and change the current model to default. You can make it in some ways.
For example, you can make a script to hurt itself (damage 0, of course) when the mp ends and it will have the same effect as you get damaged by zombies and lose the current weapon, reseting it to default model. Another way is to make a scripted inventory to change and equip weapons, but we can talk about it later.
First you can make some tests with these examples and if need more help we can develop more solutions.