19.03.2011, 20:23
(
Last edited by 1337connor; 20/03/2011 at 04:31 AM.
)
At the top, create this..
This is the enum.. it stores all our info about the places.
Alright, then under Public OnPropUpdate()
This is what saves the places... into the places.cfg file.
After the sBizz's and before return 1;
Then, create this function that will load in the places.
Anywhere in the script.
Here's the command.. and OnDialogResponse..
This is for managing the places...
That is the command..
and under OnDialogResponse
Put this under OnGameModeInit(); To add the places pickups, and 3DTextLabels.
And you are ready to make dynamic places.
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];
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);
}
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;
}
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");
}
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..");
}
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++;
}