SA-MP Forums Archive
Saving Health - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving Health (/showthread.php?tid=362572)



Saving Health - Gumica - 24.07.2012

When player spawns it kills him even if he has 1+ health.
I meant I used printf and it said 78 hp(string), but it killed me when I used float and integer, if I use string SetPlayerHealth arguments get bugged.
pawn Код:
public LoginLoadingData(playerid)
{
    new savingstring[20],temp[12],hp;
    //new amount;
    /*mysql_format(connectionHandle,query,"SELECT * FROM playerdata WHERE user = '%s'", pname);
    mysql_function_query(connectionHandle,query,false,"","");*/

    mysql_store_result();                         //Store a result because it's a SELECT statement.
//We use while so that it does a single query, not multiple
//Especially when we have more variables. If there is more
//Variables, you should just split the line with sscanf. To
//Make it easier.
    mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
    mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
    mysql_fetch_field_row(savingstring, "health"); HealthGiven[playerid] = strval(savingstring);
    cache_get_field_content(0, "health", temp);
//If you are wondering why I'm using savingstring instead
//Of a variable like using MoneyGiven right away, it's because
//mysql_fetch_field_row requires a string.
    mysql_free_result();                          //We must always free a stored result
                                                  //Sends the client a message.
    SendClientMessage(playerid, -1, "You have been logged in!");
    SetPVarString(playerid,"hp",temp);
    //SetPVarFloat(playerid,"health",hp);
    SetPlayerHealth(playerid,hp);
    Logged[playerid] = 1;                         //Sets our logged in variable to one
    return 1;
}