[Tutorial] Dynamic Places (Buildings) in GF
#1

At the top, create this..
This is the enum.. it stores all our info about the places.
pawn Code:
enum plInfo
{
    Float:plX,
    Float:plY,
    Float:plZ,
    plInt,
    Float:plIntX,
    Float:plIntY,
    Float:plIntZ,
    plText[256],
    plPick,
    Text3D:plLabel
}
new PlaceInfo[50][plInfo];
Alright, then under Public OnPropUpdate()
This is what saves the places... into the places.cfg file.
pawn Code:
idx = 0;
    while (idx < sizeof(PlaceInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%f|%f|%f|%i|%f|%f|%f|%s\n",
        PlaceInfo[idx][plX],
        PlaceInfo[idx][plY],
        PlaceInfo[idx][plZ],
        PlaceInfo[idx][plInt],
        PlaceInfo[idx][plIntX],
        PlaceInfo[idx][plIntY],
        PlaceInfo[idx][plIntZ],
        PlaceInfo[idx][plText]);
        if(idx == 0)
        {
            file2 = fopen("places.cfg", io_write);
        }
        else
        {
            file2 = fopen("places.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
After the sBizz's and before return 1;
Then, create this function that will load in the places.
pawn Code:
stock LoadPlace()
{
    new splitter[8][256];
    new strFromFile2[256];
    new File: file = fopen("places.cfg", io_read);
    if (file)
    {
        new idx;
        while (idx < sizeof(PlaceInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, splitter, '|');
            PlaceInfo[idx][plX] = floatstr(splitter[0]);
            PlaceInfo[idx][plY] = floatstr(splitter[1]);
            PlaceInfo[idx][plZ] = floatstr(splitter[2]);
            PlaceInfo[idx][plInt] = strval(splitter[3]);
            PlaceInfo[idx][plIntX] = floatstr(splitter[4]);
            PlaceInfo[idx][plIntY] = floatstr(splitter[5]);
            PlaceInfo[idx][plIntZ] = floatstr(splitter[6]);
            PlaceInfo[idx][plText] = splitter[7];
            idx++;
        }
        fclose(file);
    }
    return 1;
}
Anywhere in the script.
Here's the command.. and OnDialogResponse..
This is for managing the places...
pawn Code:
if(strcmp(cmd,"/aplace",true) == 0)
{
            tmp = strtok(cmdtext, idx);
            editingplace[playerid] = strval(tmp);
            if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid,COLOR_GRAD4,"You aren't a senior admin or higher.");
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /aplace [placeid]");
                return 1;
            }
            ShowPlayerDialog(playerid,2,DIALOG_STYLE_LIST,"House Editing","Place Entrance\nPlace Exit\nPlace Text","Ok","Cancel");
}
That is the command..
and under OnDialogResponse
pawn Code:
if(dialogid == 2)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    new Float:X,Float:Y,Float:Z;
                    GetPlayerPos(playerid,X,Y,Z);
                    new p = editingplace[playerid];
                    PlaceInfo[p][plX] = X;
                    PlaceInfo[p][plY] = Y;
                    PlaceInfo[p][plZ] = Z;
                    DestroyPickup(PlaceInfo[p][plPick]);
                    Delete3DTextLabel(PlaceInfo[p][plLabel]);
                    PlaceInfo[p][plPick] = CreatePickup(1318,28,PlaceInfo[p][plX],PlaceInfo[p][plY],PlaceInfo[p][plZ]);
                    new string[256];
                    format(string,sizeof(string),"%s\nID: %i",PlaceInfo[p][plText],p);
                    PlaceInfo[p][plLabel] = Create3DTextLabel(string,COLOR_YELLOW,PlaceInfo[p][plX],PlaceInfo[p][plY],PlaceInfo[p][plZ]+0.7,10.0,0,0);
                    OnPropUpdate();
                    SendClientMessage(playerid,COLOR_WHITE,"[Place] You have moved the entrance.");
                }
                case 1:
                {
                    new Float:X,Float:Y,Float:Z;
                    GetPlayerPos(playerid,X,Y,Z);
                    new p = editingplace[playerid];
                    PlaceInfo[p][plIntX] = X;
                    PlaceInfo[p][plIntY] = Y;
                    PlaceInfo[p][plIntZ] = Z;
                    PlaceInfo[p][plInt] = GetPlayerInterior(playerid);
                    OnPropUpdate();
                    SendClientMessage(playerid,COLOR_WHITE,"[Place] You have moved the exit.");
               
                }
                case 2:
                {
                    ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,"Place Text","Please enter what text you would like to appear on the place.","Ok","Cancel");
                }

            }
        }
    }
    if(dialogid == 3)
    {
        if(!strlen(inputtext)) return SendClientMessage(playerid,COLOR_WHITE,"You didn't enter anything..");
        new p = editingplace[playerid];
        format(PlaceInfo[p][plText],256,"%s",inputtext);
        OnPropUpdate();
        Delete3DTextLabel(PlaceInfo[p][plLabel]);
        new string[256];
        format(string,sizeof(string),"%s\nID: %i",PlaceInfo[p][plText],p);
        PlaceInfo[p][plLabel] = Create3DTextLabel(string,COLOR_YELLOW,PlaceInfo[p][plX],PlaceInfo[p][plY],PlaceInfo[p][plZ]+0.7,10.0,0,0);
        SendClientMessage(playerid,COLOR_WHITE,"[Place] You set the text..");
    }
Put this under OnGameModeInit(); To add the places pickups, and 3DTextLabels.
pawn Code:
for(new p = 0; p < sizeof(PlaceInfo); p++)
    {
        PlaceInfo[p][plPick] = CreatePickup(1318,28,PlaceInfo[p][plX],PlaceInfo[p][plY],PlaceInfo[p][plZ]);
        format(string,sizeof(string),"%s\nID: %i",PlaceInfo[p][plText],p);
        PlaceInfo[p][plLabel] = Create3DTextLabel(string,COLOR_YELLOW,PlaceInfo[p][plX],PlaceInfo[p][plY],PlaceInfo[p][plZ]+0.7,10.0,0,0);
        pickups++;
    }
And you are ready to make dynamic places.
Reply


Messages In This Thread
Dynamic Places (Buildings) in GF - by 1337connor - 19.03.2011, 20:23
Re: Dynamic Places (Buildings) in GF - by Jochemd - 19.03.2011, 20:25
Re: Dynamic Places (Buildings) in GF - by alpha500delta - 19.03.2011, 21:27
Re: Dynamic Places (Buildings) in GF - by 1337connor - 20.03.2011, 04:32
Re: Dynamic Places (Buildings) in GF - by Calgon - 20.03.2011, 04:33
Re: Dynamic Places (Buildings) in GF - by XFlawless - 20.03.2011, 04:35
Re: Dynamic Places (Buildings) in GF - by 1337connor - 20.03.2011, 06:40
Re: Dynamic Places (Buildings) in GF - by Jochemd - 20.03.2011, 08:43
Re: Dynamic Places (Buildings) in GF - by Skylar Paul - 22.03.2011, 23:25
Re: Dynamic Places (Buildings) in GF - by Pz - 23.03.2011, 07:22

Forum Jump:


Users browsing this thread: 1 Guest(s)