Server crashes when i create codes for saving health/armour
#1

So basically I've been trying to script a code to save health and armour, at first when i compile the script i get these two warnings

Код:
C:\Users\Abderrahemen.Abderrahmen-PC\Desktop\Basic RP Script Scratch FIX\gamemodes\U1.pwn(348) : warning 202: number of arguments does not match definition
C:\Users\Abderrahemen.Abderrahmen-PC\Desktop\Basic RP Script Scratch FIX\gamemodes\U1.pwn(349) : warning 202: number of arguments does not match definition
And then when I try to test it IG,I start with changing the armour using /setarmour. But when I type that cmd the server instantly crashes.


Down below the list of my the codes.

PHP код:
enum pInfo
{
    
pPass,
    
pCash,
    
pAdmin,
    
pSex,
    
pAge,
    
Float:pHealth,
    
Float:pArmour,
       
Float:pPos_x,
    
Float:pPos_y,
    
Float:pPos_z,
    
pSkin,
    
pTeam,
    
pAccent
}
new 
PlayerInfo[MAX_PLAYERS][pInfo]; 
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
       if(
dialogid == DIALOG_AGE)
    {
        if(!
response)
           {
             
Kick(playerid);
           }
           else
           {
            if(
strlen(inputtext))
            {
                new 
age strval(inputtext);
                if(
age 100 || age 16)
                {
                    
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"- Age -","How old are you??\n{FF0000}(( 16 - 100 ))","Answer","Quit");
                }
                else
                {
                    
PlayerInfo[playerid][pAge] = age;
                    new
                        
string64 ]
                    ;
                    
format(stringsizeof(string), "INFO: You're {3BB9FF}%d years old.",age);
                    
SendClientMessage(playerid, -1string);
                     
GivePlayerCash(playerid600);
                    
SaveAccountStats(playerid);
                    
SpawnPlayer(playerid);
                }
            }
            else
            {
                return 
0;
            }
        }
    }
    if(
dialogid == DIALOG_SEX)
    {
        if (!
response)
        {
            return 
Kick(playerid);
        }
        if (
response)
        {
              
PlayerInfo[playerid][pSex] = 1;
            
SendClientMessage(playerid, -1"INFO: You are {3BB9FF}male.");
            
SetPlayerSkin(playerid60);
            
PlayerInfo[playerid][pSkin] = 60;
            
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"- Age -","How old are you??\n{FF0000}(( 16 - 100 ))","Answer","Quit");
        }
        else
        {
            
PlayerInfo[playerid][pSex] = 2;
            
SendClientMessage(playerid, -1"INFO: You are {3BB9FF}female.");
            
SetPlayerSkin(playerid233);
            
PlayerInfo[playerid][pSkin] = 233;
            
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"- Age -","How old are you??\n{FF0000}(( 16 - 100 ))","Answer","Quit");
        }
    }
    switch( 
dialogid )
    {
        case 
DIALOG_REGISTER:
        {
            if (!
response) return Kick(playerid);
            if(
response)
            {
                if(!
strlen(inputtext)) return ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Registering...","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
                new 
INI:File INI_Open(UserPath(playerid));
                
INI_SetTag(File,"data");
                
INI_WriteInt(File,"Password",udb_hash(inputtext));
                
INI_WriteInt(File,"Cash",0);
                
INI_WriteInt(File,"Admin",0);
                
INI_WriteInt(File,"Sex",0);
                
INI_WriteInt(File,"Age",0);
                
INI_WriteFloat(File,"Health",100);
                
INI_WriteFloat(File,"Armour",0);
                
INI_WriteFloat(File,"Pos_x",0);
                
INI_WriteFloat(File,"Pos_y",0);
                
INI_WriteFloat(File,"Pos_z",0);
                    
INI_WriteInt(File,"Skin",0);
                    
INI_WriteInt(File,"Team",0);
                    
INI_WriteInt(File,"Accent",0);
                
INI_Close(File);
                
                
ShowPlayerDialog(playeridDIALOG_SEXDIALOG_STYLE_MSGBOX"- Sex -","What gender are you?","Male","Female");
            }
        }
        case 
DIALOG_LOGIN:
        {
            if ( !
response ) return Kick playerid );
            if( 
response )
            {
                if(
udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
                    new
                        
tmp2256 ],
                        
playername2MAX_PLAYER_NAME ]
                    ;
                    
GetPlayerName(playeridplayername2sizeof(playername2));
                       
format(tmp2sizeof(tmp2), "~w~Welcome ~n~~g~%s"playername2);
                    
GameTextForPlayer(playeridtmp250001);
                    
SetTimerEx("UnsetFirstSpawn"5000false"i"playerid);
                    
GivePlayerCash(playeridPlayerInfo[playerid][pCash]);
                       
SetSpawnInfo(playeridPlayerInfo[playerid][pTeam], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], 1.0, -1, -1, -1, -1, -1, -1);
                }
                else
                {
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 
1;
            }
        }
    }
    return 
1;

PHP код:
function SaveAccountStats(playerid)
{
    if(
Logged[playerid] == 1)
    {
    new
        
INI:File INI_Open(UserPath(playerid))
    ;
    
INI_SetTag(File,"data");
    
PlayerInfo[playerid][pHealth] = GetPlayerHealth(playerid);
    
PlayerInfo[playerid][pArmour] = GetPlayerArmour(playerid);
       
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    
PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
       new
           
Float:x,
        
Float:y,
        
Float:z
    
;
    
GetPlayerPos(playerid,x,y,z);
    
PlayerInfo[playerid][pPos_x] = x;
    
PlayerInfo[playerid][pPos_y] = y;
    
PlayerInfo[playerid][pPos_z] = z;
    
    
INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    
INI_WriteFloat(File,"Health",PlayerInfo[playerid][pHealth]);
    
INI_WriteFloat(File,"Armour",PlayerInfo[playerid][pArmour]);
    
INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]);
    
INI_Close(File);
    }
    return 
1;
}
function 
SaveAccounts()
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            
SaveAccountStats(i);
          }
    }
}
function 
GameModeExitFunc()
{
     
GameModeExit();
    return 
1;
}
function 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Password",PlayerInfo[playerid][pPass]);
    
INI_Int("Cash",PlayerInfo[playerid][pCash]);
    
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    
INI_Int("Sex",PlayerInfo[playerid][pSex]);
    
INI_Int("Age",PlayerInfo[playerid][pAge]);
    
INI_Float("Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_Float("Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_Float("Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    
INI_Int("Team",PlayerInfo[playerid][pTeam]);
    
INI_Float("Health",PlayerInfo[playerid][pHealth]);
    
INI_Float("Armour",PlayerInfo[playerid][pArmour]);
    
INI_Int("Accent",PlayerInfo[playerid][pAccent]);
    return 
1;

Can someone tell me what's the problem here?
Reply
#2

Can you mark lines 348 and 349, so we can figure out which line you are talking about?
Reply
#3

Oh yeah sure.

The warning are in the SavingAccountStats function:
Код:
function SaveAccountStats(playerid) 
{ 
    if(Logged[playerid] == 1) 
    { 
    new 
        INI:File = INI_Open(UserPath(playerid)) 
    ; 
    INI_SetTag(File,"data"); 
    PlayerInfo[playerid][pHealth] = GetPlayerHealth(playerid); 
    PlayerInfo[playerid][pArmour] = GetPlayerArmour(playerid); 
       PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid); 
    PlayerInfo[playerid][pCash] = GetPlayerCash(playerid); 
       new 
           Float:x, 
        Float:y, 
        Float:z 
    ; 
    GetPlayerPos(playerid,x,y,z); 
    PlayerInfo[playerid][pPos_x] = x; 
    PlayerInfo[playerid][pPos_y] = y; 
    PlayerInfo[playerid][pPos_z] = z; 
     
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]); 
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]); 
    INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]); 
    INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]); 
    INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]); 
    INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]); 
    INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]); 
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]); 
    INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]); 
    INI_WriteFloat(File,"Health",PlayerInfo[playerid][pHealth]); 
    INI_WriteFloat(File,"Armour",PlayerInfo[playerid][pArmour]); 
    INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]); 

    INI_Close(File); 
    } 
    return 1; 
}
Those two lines[
Reply
#4

That's not how you do it.

pawn Код:
GetPlayerHealth( playerid, PlayerInfo[playerid][pHealth] ) ;
GetPlayerArmour( playerid, PlayerInfo[playerid][pArmour] ) ;
That is the correct code and that is how it should be used. Remember to check the Wiki before posting here.
Reply
#5

https://sampwiki.blast.hk/wiki/GetPlayerHealth
https://sampwiki.blast.hk/wiki/GetPlayerArmour

These functions doesn't return the value you're looking for. Instead, you should use them like this:

PHP код:
GetPlayerHealth(playerid,yourfloat); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)