How to load a .ini file when the server starts.
#8

Here:
pawn Код:
#define PAYPHONES "payphones.cfg"
#define MAX_PAYPHONES   10

#define PayPhoneObjectID    1216
#define PickupType  1

enum PayPhones
{
    Float:PhoneX,
    Float:PhoneY,
    Float:PhoneZ
}
new PayPhoneInfo[MAX_PAYPHONES][PayPhones];
new PayPhonePickup[MAX_PAYPHONES];
new PhoneCount = 0;

public OnFilterScriptInit()
{
    LoadPayPhones(PAYPHONES);
    return 1;
}

CreatePayPhone(Float:XPos, Float:YPos, Float:ZPos)
{
    PhoneCount ++;
    PayPhoneInfo[PhoneCount][PhoneX] = XPos;
    PayPhoneInfo[PhoneCount][PhoneY] = YPos;
    PayPhoneInfo[PhoneCount][PhoneZ] = ZPos;
    PayPhonePickup[PhoneCount] = CreatePickup(PayPhoneObjectID, PickupType, XPos, YPos, ZPos, -1);
    return PhoneCount;
}

stock LoadPayPhones(FileName[])
{
    if(!fexist(FileName)) return 0;

    new
        File:PPhone,
        Float:PLoc[3],
        pTotal,
        Line[60];

    PPhone = fopen(FileName, io_read);
    while(fread(PPhone , Line))
    {
        sscanf(Line, "p<|>fff", PLoc[0], PLoc[1], PLoc[2]);
        CreatePayPhone(PLoc[0], PLoc[1], PLoc[2]);

        pTotal++;
    }
    fclose(PPhone);
    printf("%i Pay Phones loaded", pTotal);
    return pTotal;
}

CMD:cpp(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        if(!fexist(PAYPHONES)) return SendClientMessage(playerid, COLOR_RED, "Cannot find the PayPhone file!");

        new
        File:PayPhone = fopen(PAYPHONES, io_append),
        Float:Pos[3],
        gStr[60];

        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);

        format(gStr, sizeof(gStr), "%.2f|%.2f|%.2f\r\n",
        Pos[0],
        Pos[1],
        Pos[2]);
       
        CreatePayPhone(Pos[0], Pos[1], Pos[2]);

        fwrite(PayPhone, gStr);
        fclose(PayPhone);
        SendClientMessage(playerid, COLOR_TEAL, "A new Pay Phone has been created.");
        return 1;
    }
    else return 0;
}
Reply


Messages In This Thread
How to load a .ini file when the server starts. - by Haydz - 15.01.2011, 02:04
Re: How to load a .ini file when the server starts. - by coole210 - 15.01.2011, 04:25
Re: How to load a .ini file when the server starts. - by Haydz - 15.01.2011, 04:51
Re: How to load a .ini file when the server starts. - by [L3th4l] - 15.01.2011, 05:16
Re: How to load a .ini file when the server starts. - by Haydz - 15.01.2011, 05:27
Re: How to load a .ini file when the server starts. - by [L3th4l] - 15.01.2011, 05:37
Re: How to load a .ini file when the server starts. - by Haydz - 15.01.2011, 05:49
Re: How to load a .ini file when the server starts. - by [L3th4l] - 15.01.2011, 06:04

Forum Jump:


Users browsing this thread: 4 Guest(s)