Save information
#1

Hi I want to know how to save the position, the health and armour and the weapons with their munition a player had before enter a mini game and he exit give to the player their information before entering the mini game. Thanks
Reply
#2

You can save them to file or use variables
Reply
#3

Anything more concret?
Reply
#4

Someone?
Reply
#5

Something like this maybe.....
PHP код:
new //Creating Variables to store the information for all player slots.
    
Float:Health[MAX_PLAYERS],//This is the float you'll save the player's health in.
    
Float:Armor[MAX_PLAYERS],//This is the float you'll save the player's armor in.
    
Float:playerpos[MAX_PLAYERS][4],//This is the float you'll save the player's position and facing angle in.
    
interior[MAX_PLAYERS],//This is where you'll save the player's current interior.
    
virtualworld[MAX_PLAYERS],//This is where you'll save the player's current virtual world.
    
weapondata[MAX_PLAYERS][13][2];//This is the array you'll save the player's weapon data in.
    
    
//Do whatever here to save their stuff, for example
YCMD:savedata(playerid,params[],help)
{
    
#pragma unused params, help
    
GetPlayerHealth(playeridHealth[playerid]);//You are storing the player's health into the float above.
    
GetPlayerArmour(playeridArmor[playerid]);//You are storing the player's armor into the float above.
    
GetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);//You are storing the player's position into the float above.
    
GetPlayerFacingAngle(playerid,playerpos[playerid][3]);//You are storing the player's facing angle into the float above.
    
interior[playerid] = GetPlayerInterior(playerid);//You are storing the interior above.
    
virtualworld[playerid] = GetPlayerVirtualWorld(playerid);//You are storing the player's virtual world.
    
for (new 0<= 12i++)//Looping through each weapon slot (13 slots) (Looping 0 -12)
    
{
        
GetPlayerWeaponData(playeridiweapondata[playerid][i][0], weapondata[playerid][i][1]);
        
//Every time the above loops, the slot number increases, as doing so, it's storing your weapon data into the array above.
    
}
    return 
1;
}
//Do whatever here to give their stuff back
YCMD:givedata(playerid,params[],help)
{
    
#pragma unused params, help
    
SetPlayerHealth(playeridHealth[playerid]);//You are setting the player's health back to what it was before the condition above.
    
SetPlayerArmour(playeridArmor[playerid]);//You are setting the player's armor back to what it was before the condition above.
    
SetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);//You are setting the player's position back to what it was before the condition above.
    
SetPlayerFacingAngle(playerid,playerpos[playerid][3]);//You are setting the player's facing angle to what it was before the condition above.
    
SetPlayerInterior(playerid,interior[playerid]);//You are setting the player's interior to what it was before the condition above.
    
SetPlayerVirtualWorld(playerid,virtualworld[playerid]);//You are setting the player's virtual world to what it was before the condition above.
    
for (new 0<= 12i++)
    {
        
GivePlayerWeapon(playerid,weapondata[playerid][i][0], weapondata[playerid][i][1]);
        
//Here, you are looping through the array we saved the player's weapon data in.  This is giving the player their weapons they had before.
    
}
    return 
1;

Reply
#6

Quote:
Originally Posted by Banana_Ghost
Посмотреть сообщение
Something like this maybe.....
PHP код:
new //Creating Variables to store the information for all player slots.
    
Float:Health[MAX_PLAYERS],//This is the float you'll save the player's health in.
    
Float:Armor[MAX_PLAYERS],//This is the float you'll save the player's armor in.
    
Float:playerpos[MAX_PLAYERS][4],//This is the float you'll save the player's position and facing angle in.
    
interior[MAX_PLAYERS],//This is where you'll save the player's current interior.
    
virtualworld[MAX_PLAYERS],//This is where you'll save the player's current virtual world.
    
weapondata[MAX_PLAYERS][13][2];//This is the array you'll save the player's weapon data in.
    
    
//Do whatever here to save their stuff, for example
YCMD:savedata(playerid,params[],help)
{
    
#pragma unused params, help
    
GetPlayerHealth(playeridHealth[playerid]);//You are storing the player's health into the float above.
    
GetPlayerArmour(playeridArmor[playerid]);//You are storing the player's armor into the float above.
    
GetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);//You are storing the player's position into the float above.
    
GetPlayerFacingAngle(playerid,playerpos[playerid][3]);//You are storing the player's facing angle into the float above.
    
interior[playerid] = GetPlayerInterior(playerid);//You are storing the interior above.
    
virtualworld[playerid] = GetPlayerVirtualWorld(playerid);//You are storing the player's virtual world.
    
for (new 0<= 12i++)//Looping through each weapon slot (13 slots) (Looping 0 -12)
    
{
        
GetPlayerWeaponData(playeridiweapondata[playerid][i][0], weapondata[playerid][i][1]);
        
//Every time the above loops, the slot number increases, as doing so, it's storing your weapon data into the array above.
    
}
    return 
1;
}
//Do whatever here to give their stuff back
YCMD:givedata(playerid,params[],help)
{
    
#pragma unused params, help
    
SetPlayerHealth(playeridHealth[playerid]);//You are setting the player's health back to what it was before the condition above.
    
SetPlayerArmour(playeridArmor[playerid]);//You are setting the player's armor back to what it was before the condition above.
    
SetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);//You are setting the player's position back to what it was before the condition above.
    
SetPlayerFacingAngle(playerid,playerpos[playerid][3]);//You are setting the player's facing angle to what it was before the condition above.
    
SetPlayerInterior(playerid,interior[playerid]);//You are setting the player's interior to what it was before the condition above.
    
SetPlayerVirtualWorld(playerid,virtualworld[playerid]);//You are setting the player's virtual world to what it was before the condition above.
    
for (new 0<= 12i++)
    {
        
GivePlayerWeapon(playerid,weapondata[playerid][i][0], weapondata[playerid][i][1]);
        
//Here, you are looping through the array we saved the player's weapon data in.  This is giving the player their weapons they had before.
    
}
    return 
1;

Thank you very much
Reply
#7

Hi I have some problems with that code it partly work but, sometimes when I exit mini game I die and also other times I exit the mini game it saves the weapons I had before and the weapons of the mini game. What's the problem? Thanks for reading
Reply
#8

When they exit the minigame, use ResetPlayerWeapons to reset the weapons they currently have, and then give their weapons back. The part on dying, something has to be in your script causing them to die, unless their health isn't being saved in the Health float for some reason.

under savedata, place all of that before you send them to the minigame,
under givedata, place all of that after the player exits the minigame, and add ResetPlayerWeapons before giving the player their weapons back.
Reply
#9

Thank you for answer, I will try it.
Reply
#10

I still having problems about the death the strange thing is that with a minigame works but with the duel, it kills the player. What is the problem? Here is the code.

Код:
if(!strcmp("/duelo",cmdtext))
    {
    GetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);
    GetPlayerFacingAngle(playerid,playerpos[playerid][3]);
    interior[playerid] = GetPlayerInterior(playerid);
    virtualworld[playerid] = GetPlayerVirtualWorld(playerid);
    SetPlayerPos(playerid, 1314.6309, 2184.8245, 11.0234);
    SetPlayerHealth(playerid, 100);
    SetPlayerArmour(playerid, 100);
    SetPlayerInterior(playerid,0);
    SetPlayerVirtualWorld(playerid,0);
    return 1;
    }
    
    if(!strcmp("/dm1",cmdtext))
    {
    GetPlayerHealth(playerid, Health[playerid]);
    GetPlayerArmour(playerid, Armor[playerid]);
    GetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);
    GetPlayerFacingAngle(playerid,playerpos[playerid][3]);
    interior[playerid] = GetPlayerInterior(playerid);
    virtualworld[playerid] = GetPlayerVirtualWorld(playerid);
    for (new i = 0; i <= 12; i++)
    {
    GetPlayerWeaponData(playerid, i, weapondata[playerid][i][0], weapondata[playerid][i][1]);
    }
    SetPlayerPos(playerid,1412.639892,-1.787510,1000.924377);
    SetPlayerVirtualWorld(playerid,1);
    SetPlayerInterior(playerid,1);
    ResetPlayerWeapons(playerid);
    GivePlayerWeapon(playerid, 26,1000);
    GivePlayerWeapon(playerid,32,1000);
    SetPlayerHealth(playerid,100);
    SetPlayerArmour(playerid,100);
    
    return 1;
	}
	
	if(!strcmp("/dm",cmdtext))
	{
	SetPlayerHealth(playerid, Health[playerid]);
    SetPlayerArmour(playerid, Armor[playerid]);
    SetPlayerPos(playerid,playerpos[playerid][0],playerpos[playerid][1],playerpos[playerid][2]);
    SetPlayerFacingAngle(playerid,playerpos[playerid][3]);
    SetPlayerInterior(playerid,interior[playerid]);
    SetPlayerVirtualWorld(playerid,virtualworld[playerid]);
    ResetPlayerWeapons(playerid);
    for (new i = 0; i <= 12; i++)
    {
    GivePlayerWeapon(playerid,weapondata[playerid][i][0], weapondata[playerid][i][1]);
    }
    return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)