[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
#2

It's not a tutorial, you should explain what these functions do...
Reply
#3

Still using GF? You gotta be kidding me
Also you did not explain it like stated above.
Reply
#4

Quote:
Originally Posted by alpha500delta
View Post
Still using GF? You gotta be kidding me
Also you did not explain it like stated above.
Edited. And.. I'm just making a epic GF edit.. it's going to be the best one you've ever seen
Reply
#5

Absolute crap.

You haven't explained shit and you're promoting a crap script.
Reply
#6

100% useless.
Reply
#7

Quote:
Originally Posted by Calg00ne
View Post
Absolute crap.

You haven't explained shit and you're promoting a crap script.
Alright then, Troll.
Reply
#8

You'd better post this to the code snippets. Then it's very nice!
Reply
#9

Quote:
Originally Posted by 1337connor
View Post
Edited. And.. I'm just making a epic GF edit.. it's going to be the best one you've ever seen


You can't use best and Godfather in the same sentence.
Reply
#10

Quote:
Originally Posted by Skylar Paul
View Post


You can't use best and Godfather in the same sentence.
Agreed.

By the way, just to stay on topic, I don't even call this a tutorial, and by the way, even if you call this a tutorial, you might want to check out the script, its full of errors, and warnings. Yeah right, really nice...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)