| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- #tryinclude <colandreas>
- #if !defined COLANDREAS
- #endinput
- #endif
- #define MANGLE
- public OnFilterScriptInit()
- {
- CA_Init();
- #if defined MA_OnFilterScriptInit
- MA_OnFilterScriptInit();
- #endif
- return 1;
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit MA_OnFilterScriptInit
- #if defined MA_OnFilterScriptInit
- forward MA_OnFilterScriptInit();
- #endif
- new Float:GroupSlopeRX[MAX_PLAYERS], Float:GroupSlopeRY[MAX_PLAYERS];
- /* Debug Command
- YCMD:gs(playerid, arg[], help)
- {
- new Float:x, Float:y, Float:z, line[128];
- GetPlayerPos(playerid, x, y, z);
- CalcSlopeAtPoint(x, y, x, y);
- format(line, sizeof(line), "Slope X:%3.4f | Slope Y:%3.4f", x, y);
- SendClientMessage(playerid, -1, line);
- return 1;
- }*/
- // Load a prefab specify a filename
- YCMD:prefabsets(playerid, arg[], help)
- {
- if(help)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Load a prefabricated group of objects rotated according to the ground slope.");
- return 1;
- }
- MapOpenCheck();
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- if(isnull(arg)) ShowPrefabs(playerid);
- else
- {
- new mapname[128];
- format(mapname, sizeof(mapname), "tstudio/PreFabs/%s.db", arg);
- if(fexist(mapname))
- {
- PrefabDB = db_open_persistent(mapname);
- sqlite_LoadPrefab(playerid);
- db_free_persistent(PrefabDB);
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- //CalcSlopeAtPoint(x, y, GroupSlopeRX[playerid], GroupSlopeRY[playerid]);
- CA_RayCastLineAngle(x, y, 1200.0, x, y, -100.0, z, z, z, GroupSlopeRX[playerid], GroupSlopeRY[playerid], z);
- GroupRotate(playerid, GroupSlopeRX[playerid], GroupSlopeRY[playerid], 0.0);
-
- SendClientMessage(playerid, STEALTH_GREEN, "Prefab loaded and set to your group selection");
- }
- else SendClientMessage(playerid, STEALTH_YELLOW, "That prefab does not exist!");
- }
- return 1;
- }
- // Rotate group on ground slope
- YCMD:gsets(playerid, arg[], help)
- {
- if(help)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Rotate all currently selected objects accordingly to ground slope.");
- return 1;
- }
- MapOpenCheck();
- new time = GetTickCount();
- // We need to get the map center as the rotation node
- new bool:value, Float:gCenterX, Float:gCenterY, Float:gCenterZ;
- if(PivotPointOn[playerid])
- {
- new bool:hasgroup;
- foreach(new i : Objects)
- {
- if(GroupedObjects[playerid][i])
- {
- gCenterX = PivotPoint[playerid][xPos];
- gCenterY = PivotPoint[playerid][yPos];
- gCenterZ = PivotPoint[playerid][zPos];
- value = true;
- hasgroup = true;
- break;
- }
- }
- if(!hasgroup)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_YELLOW, "There is not enough objects for this command to work");
- }
- }
- else if(GetGroupCenter(playerid, gCenterX, gCenterY, gCenterZ)) value = true;
- if(value)
- {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- //CalcSlopeAtPoint(x, y, GroupSlopeRX[playerid], GroupSlopeRY[playerid]);
- CA_RayCastLineAngle(x, y, 1200.0, x, y, -100.0, z, z, z, GroupSlopeRX[playerid], GroupSlopeRY[playerid], z);
- // Loop through all objects and perform rotation calculations
- db_begin_transaction(EditMap);
- foreach(new i : Objects)
- {
- if(GroupedObjects[playerid][i])
- {
- SaveUndoInfo(i, UNDO_TYPE_EDIT, time);
-
- AttachObjectToPoint(i, gCenterX, gCenterY, gCenterZ, GroupSlopeRX[playerid], GroupSlopeRY[playerid], 0.0, ObjectData[i][oX], ObjectData[i][oY], ObjectData[i][oZ], ObjectData[i][oRX], ObjectData[i][oRY], ObjectData[i][oRZ]);
-
- SetDynamicObjectPos(ObjectData[i][oID], ObjectData[i][oX], ObjectData[i][oY], ObjectData[i][oZ]);
- SetDynamicObjectRot(ObjectData[i][oID], ObjectData[i][oRX], ObjectData[i][oRY], ObjectData[i][oRZ]);
- UpdateObject3DText(i);
- sqlite_UpdateObjectPos(i);
- }
- }
- db_end_transaction(EditMap);
- // Update the Group GUI
- UpdatePlayerGSelText(playerid);
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Group RZ rotation complete ");
- }
- else
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_YELLOW, "There is not enough objects for this command to work");
- }
- return 1;
- }
- // Edit a group
- YCMD:editgroups(playerid, arg[], help)
- {
- if(help)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Edit currently edited objects simultaneously.");
- SendClientMessage(playerid, STEALTH_GREEN, "Hold 'Walk Key' to set the group rotation pivot, you can only do this once per edit.");
- return 1;
- }
- MapOpenCheck();
- NoEditingMode(playerid);
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- if(PlayerHasGroup(playerid))
- {
- GetGroupCenter(playerid, LastPivot[playerid][xPos], LastPivot[playerid][yPos], LastPivot[playerid][zPos]);
- LastGroupPosition[playerid][xPos] = LastPivot[playerid][xPos];
- LastGroupPosition[playerid][yPos] = LastPivot[playerid][yPos];
- LastGroupPosition[playerid][zPos] = LastPivot[playerid][zPos];
- PivotOffset[playerid][xPos] = 0.0;
- PivotOffset[playerid][yPos] = 0.0;
- PivotOffset[playerid][zPos] = 0.0;
-
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- CA_RayCastLineAngle(x, y, 1200.0, x, y, -100.0, z, z, z, GroupSlopeRX[playerid], GroupSlopeRY[playerid], z);
- PivotObject[playerid] = CreateDynamicObject(1974, LastPivot[playerid][xPos], LastPivot[playerid][yPos], LastPivot[playerid][zPos], GroupSlopeRX[playerid], GroupSlopeRY[playerid], z, -1, -1, playerid);
- Streamer_SetFloatData(STREAMER_TYPE_OBJECT, PivotObject[playerid], E_STREAMER_DRAW_DISTANCE, 3000.0);
- SetDynamicObjectMaterial(PivotObject[playerid], 0, 10765, "airportgnd_sfse", "white", -256);
- Streamer_Update(playerid);
- EditingMode[playerid] = true;
- PivotReset[playerid] = true;
- SetEditMode(playerid, EDIT_MODE_OBJECTGROUP);
- EditDynamicObject(playerid, PivotObject[playerid]);
- SendClientMessage(playerid, STEALTH_GREEN, "Editing your group");
- }
- else SendClientMessage(playerid, STEALTH_YELLOW, "You must have at least one object grouped");
- return 1;
- }
- // Rotate object on ground slope
- YCMD:osets(playerid, arg[], help)
- {
- if(help)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Rotate currently selected object according to ground slope.");
- return 1;
- }
- MapOpenCheck();
- EditCheck(playerid);
- NoEditingMode(playerid);
- SaveUndoInfo(CurrObject[playerid], UNDO_TYPE_EDIT);
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- CA_RayCastLineAngle(x, y, 1200.0, x, y, -100.0, z, z, z, GroupSlopeRX[playerid], GroupSlopeRY[playerid], z);
-
- if(PivotPointOn[playerid])
- {
- new i = CurrObject[playerid];
- AttachObjectToPoint(i, PivotPoint[playerid][xPos], PivotPoint[playerid][yPos], PivotPoint[playerid][zPos], GroupSlopeRX[playerid], GroupSlopeRY[playerid], 0.0, ObjectData[i][oX], ObjectData[i][oY], ObjectData[i][oZ], ObjectData[i][oRX], ObjectData[i][oRY], ObjectData[i][oRZ]);
- SetDynamicObjectPos(ObjectData[i][oID], ObjectData[i][oX], ObjectData[i][oY], ObjectData[i][oZ]);
- SetDynamicObjectRot(ObjectData[i][oID], ObjectData[i][oRX], ObjectData[i][oRY], ObjectData[i][oRZ]);
- UpdateObject3DText(CurrObject[playerid]);
- }
- else
- {
- ObjectData[CurrObject[playerid]][oRX] += GroupSlopeRX[playerid];
- ObjectData[CurrObject[playerid]][oRY] += GroupSlopeRY[playerid];
- SetDynamicObjectRot(ObjectData[CurrObject[playerid]][oID], ObjectData[CurrObject[playerid]][oRX], ObjectData[CurrObject[playerid]][oRY], ObjectData[CurrObject[playerid]][oRZ]);
- }
- sqlite_UpdateObjectPos(CurrObject[playerid]);
- return 1;
- }
- /*
- // Load a prefab specify a filename adjust to facing angle
- YCMD:pmaf(playerid, arg[], help)
- {
- MapOpenCheck();
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- if(isnull(arg)) ShowPrefabs(playerid);
- else
- {
- new Float:zrot, mapname[128];
- if(sscanf(arg, "s[128]f", mapname, zrot)) return SendClientMessage(playerid, STEALTH_YELLOW, "Usage: /pmaf <prefab> <zrot>");
-
- format(mapname, sizeof(mapname), "tstudio/PreFabs/%s.db", mapname);
- if(fexist(mapname))
- {
- PrefabDB = db_open_persistent(mapname);
- sqlite_LoadPrefab(playerid, false);
- db_free_persistent(PrefabDB);
- new Float:x, Float:y, Float:z, Float:rx, Float:ry;
- // Find the slope
- GetPlayerPos(playerid, x, y, z);
- CalcSlopeAtPoint(x, y, rx, ry);
- // Translate new rotation offsets
- GroupRotate(playerid, 0.0, 0.0, zrot);
- // Translate new rotation to slope
- GroupRotate(playerid, rx, ry, 0.0);
- SendClientMessage(playerid, STEALTH_GREEN, "Prefab loaded and set to your group selection");
- }
- else SendClientMessage(playerid, STEALTH_YELLOW, "That prefab does not exist!");
- }
- return 1;
- }
- */
- YCMD:cobjectsets(playerid, arg[], help)
- {
- if(help)
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, "Creates a rotated object according to the map slope and selects it.");
- return 1;
- }
- MapOpenCheck();
- NoEditingMode(playerid);
- new modelid, Float:RZAngle;
- if(sscanf(arg, "iF(0.0)", modelid, RZAngle))
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_YELLOW, "Usage: /csobject <modelid>");
- return 1;
- }
- // Set the initial object position
- new Float:px, Float:py, Float:pz, Float:fa, Float:RXAngle, Float:RYAngle;
- new Float:colradius = GetColSphereRadius(modelid);
- GetPosFaInFrontOfPlayer(playerid, colradius + 1.0, px, py, pz, fa);
- pz -= 1.0;
- // Calculate rotation
- //CalcSlopeAtPoint(px, py, RXAngle, RYAngle);
- CA_RayCastLineAngle(px, py, 1200.0, px, py, -100.0, fa, fa, fa, RXAngle, RYAngle, RZAngle);
- //new Float:angle = float(random(360));
- //ObjectRotateZ(RXAngle, RYAngle, RZAngle, angle, RXAngle, RYAngle, RZAngle);
- // Create the object
- SetCurrObject(playerid, AddDynamicObject(modelid, px, py, pz, RXAngle, RYAngle, RZAngle));
- // Object was created
- if(CurrObject[playerid] != -1)
- {
- // Update the streamer for this player
- Streamer_Update(playerid);
- SaveUndoInfo(CurrObject[playerid], UNDO_TYPE_CREATED);
- // Show output message
- new line[128];
- new modelarray = GetModelArray(modelid);
- if(modelarray > -1) format(line, sizeof(line), "Created Object Index: %i Model Name: %s", CurrObject[playerid], GetModelName(modelarray));
- else format(line, sizeof(line), "Created Object Index: %i Model Name: Unknown", CurrObject[playerid]);
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_GREEN, line);
- }
- // Too many objects already created
- else
- {
- SendClientMessage(playerid, STEALTH_ORANGE, "______________________________________________");
- SendClientMessage(playerid, STEALTH_YELLOW, "You have too many objects created to create anymore!");
- }
- return 1;
- }
- tsfunc CalcSlopeAtPoint(Float:x, Float:y, &Float:RXAngle, &Float:RYAngle)
- {
- new Float:North[3], Float:South[3], Float:East[3], Float:West[3], Float:opposite, Float:hypotenuse;
- // Set slope positions
- North[0] = x;
- North[1] = y + 1;
- South[0] = x;
- South[1] = y - 1;
- East[0] = x + 1;
- East[1] = y;
- West[0] = x - 1;
- West[1] = y;
- // Use ColAndreas to get Z Values
- CA_FindZ_For2DCoord(North[0], North[1], North[2]);
- CA_FindZ_For2DCoord(South[0], South[1], South[2]);
- CA_FindZ_For2DCoord(East[0], East[1], East[2]);
- CA_FindZ_For2DCoord(West[0], West[1], West[2]);
- // Calculate Slope angles
- // North South RX
- hypotenuse = getdist3d(North[0], North[1], North[2], South[0], South[1], South[2]);
- opposite = getdist3d(North[0], North[1], North[2], North[0], North[1], South[2]);
- RXAngle = asin(floatdiv(opposite, hypotenuse));
- if(South[2] > North[2]) RXAngle *= -1;
- // West East RY
- hypotenuse = getdist3d(West[0], West[1], West[2], East[0], East[1], East[2]);
- opposite = getdist3d(West[0], West[1], West[2], West[0], West[1], East[2]);
- RYAngle = asin(floatdiv(opposite, hypotenuse));
- if(East[2] > West[2]) RYAngle *= -1;
- return 1;
- }
- tsfunc ObjectRotateZ(Float:RX, Float:RY, Float:RZ, Float:rot_z, &Float:NewRX, &Float:NewRY, &Float:NewRZ)
- {
- new
- Float:sinx,
- Float:siny,
- Float:sinz,
- Float:cosx,
- Float:cosy,
- Float:cosz;
- FloatConvertValue(RX, RY, RZ, sinx, siny, sinz, cosx, cosy, cosz);
- // Convert from one euler angle sequence (ZXY) to another and add the rotation
- FloatConvertValue(asin(cosx * cosy), atan2(sinx, cosx * siny) + rot_z, atan2(cosy * cosz * sinx - siny * sinz, cosz * siny - cosy * sinx * -sinz),
- sinx, siny, sinz, cosx, cosy, cosz);
- // Convert back to the original euler angle sequence and apply the new rotation to the object
- NewRX = asin(cosx * siny),
- NewRY = atan2(cosx * cosy, sinx),
- NewRZ = atan2(cosz * sinx * siny - cosy * sinz, cosy * cosz + sinx * siny * sinz);
- return 1;
- }
- tsfunc FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, &Float:sinx, &Float:siny, &Float:sinz, &Float:cosx, &Float:cosy, &Float:cosz)
- {
- sinx = floatsin(rot_x, degrees);
- siny = floatsin(rot_y, degrees);
- sinz = floatsin(rot_z, degrees);
- cosx = floatcos(rot_x, degrees);
- cosy = floatcos(rot_y, degrees);
- cosz = floatcos(rot_z, degrees);
- return 1;
- }
- /* MEDIT Prefab import
- // Import function
- // Load prefab
- #define MAX_MATERIAL_INDEX 16
- YCMD:cpf(playerid, arg[], help)
- {
- new dir:dHandle = dir_open("./scriptfiles/tstudio/medit/importpf/");
- new item[40], type;
- new extension[6];
- // Create a load list
- while(dir_list(dHandle, item, type))
- {
- if(type != FM_DIR)
- {
- // We need to check extension
- if(strlen(item) > 3)
- {
- format(extension, sizeof(extension), "%s%s%s%s%s", item[strlen(item) - 5], item[strlen(item) - 4], item[strlen(item) - 3], item[strlen(item) - 2],item[strlen(item) - 1]);
- // File is apparently a prefab
- new tempmap[64];
- strmid(tempmap, item, 0, strlen(item) - 6, 64);
-
- printf(tempmap);
-
-
- if(!strcmp(extension, "mpfab")) ConvertMeditPrefab(tempmap);
- }
- }
- }
- return 1;
- }
- // Old medit enum
- enum object_info {
- object_id,
- medit_modelid,
- Text3D:medit_Text3D[MAX_OBJECTS],
- Float:pfox,
- Float:pfoy,
- Float:pfoz,
- Float:pfrx,
- Float:pfry,
- Float:pfrz,
- Material_Index[MAX_MATERIAL_INDEX],
- Material_Color[MAX_MATERIAL_INDEX],
- usetext[MAX_MATERIAL_INDEX],
- Material_FontFace[MAX_MATERIAL_INDEX],
- Material_FontSize[MAX_MATERIAL_INDEX],
- Material_FontBold[MAX_MATERIAL_INDEX],
- Material_FontColor[MAX_MATERIAL_INDEX],
- Material_BackColor[MAX_MATERIAL_INDEX],
- Material_Alignment[MAX_MATERIAL_INDEX],
- Material_TextFontSize[MAX_MATERIAL_INDEX]
- }
- new DB: PrefabImportDB;
- new DBStatement:insertprefabimpstmt;
- new tempobject[object_info];
- new temp_Material_Object_Text[MAX_MATERIAL_INDEX][64];
- ConvertMeditPrefab(tempmap[64])
- {
- new templine[256];
- new Float:ZOffSet;
- new openmap[64];
- new opendb[64];
- // Create import database
- format(opendb, 64, "tstudio/medit/convertpf/%s.db", tempmap);
- PrefabImportDB = db_open_persistent(opendb);
- new NewImportString[512];
- strimplode(" ",
- NewImportString,
- sizeof(NewImportString),
- "CREATE TABLE IF NOT EXISTS `Objects`",
- "(ModelID INTEGER,",
- "xPos REAL,",
- "yPos REAL,",
- "zPos REAL,",
- "rxRot REAL,",
- "ryRot REAL,",
- "rzRot REAL,",
- "TextureIndex TEXT,",
- "ColorIndex TEXT,",
- "usetext INTEGER,",
- "FontFace INTEGER,",
- "FontSize INTEGER,",
- "FontBold INTEGER,",
- "FontColor INTEGER,",
- "BackColor INTEGER,",
- "Alignment INTEGER,",
- "TextFontSize INTEGER,",
- "ObjectText TEXT);"
- );
- db_exec(PrefabImportDB, NewImportString);
- // Prefab extra info
- db_exec(PrefabImportDB, "CREATE TABLE IF NOT EXISTS `PrefabInfo` (zOFF REAL);");
- db_exec(PrefabImportDB, "INSERT INTO `PrefabInfo` VALUES(0.0);");
- // Prepare query
- new ImportPrefabInsert[1024];
-
- strimplode(" ",
- ImportPrefabInsert,
- sizeof(ImportPrefabInsert),
- "INSERT INTO `Objects`",
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
- );
-
- // Prepare data base for writing
- insertprefabimpstmt = db_prepare(PrefabImportDB, ImportPrefabInsert);
-
- // Read in map info new style format and get the prefab center for correcting
- format(openmap, 64, "tstudio/medit/importpf/%s.mpfab", tempmap);
- new Float:pfx, Float:pfy, Float:pfz;
- GetPrefabCenter(openmap, pfx, pfy, pfz);
- new File:f;
- f = fopen(openmap,io_read);
- // Check Version
- fread(f,templine,sizeof(templine),false);
- // This is a new medit version use new load routine
- new index;
- // new version load
- if(!strcmp(strtok(templine,index), "420medit-Version:"))
- {
- ZOffSet = floatstr(strtok(templine,index));
- ZOffSet = floatstr(strtok(templine,index));
- format(templine, sizeof(templine), "ZOffSet: %f", ZOffSet);
- while(fread(f,templine,sizeof(templine),false)) {
- index = 0;
- tempobject[object_id] = INVALID_OBJECT_ID;
- tempobject[medit_modelid] = strval(strtok(templine,index));
- tempobject[pfox] = floatstr(strtok(templine,index))-pfx;
- tempobject[pfoy] = floatstr(strtok(templine,index))-pfy;
- tempobject[pfoz] = floatstr(strtok(templine,index))-pfz;
- tempobject[pfrx] = floatstr(strtok(templine,index));
- tempobject[pfry] = floatstr(strtok(templine,index));
- tempobject[pfrz] = floatstr(strtok(templine,index));
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++)
- {
- tempobject[Material_Index][i] = strval(strtok(templine,index));
- tempobject[Material_Color][i] = strval(strtok(templine,index));
- }
- // Load Text Data // Only only use first slot anyways
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++)
- {
- index = 0;
- fread(f,templine,sizeof(templine),false);
- tempobject[usetext][i] = strval(strtok(templine,index));
- tempobject[Material_FontFace][i] = strval(strtok(templine,index));
- tempobject[Material_FontSize][i] = strval(strtok(templine,index));
- tempobject[Material_FontBold][i] = strval(strtok(templine,index));
- tempobject[Material_FontColor][i] = strval(strtok(templine,index));
- tempobject[Material_BackColor][i] = strval(strtok(templine,index));
- tempobject[Material_Alignment][i] = strval(strtok(templine,index));
- tempobject[Material_TextFontSize][i] = strval(strtok(templine,index));
- new bool:done;
- temp_Material_Object_Text[i] = "";
- while(done == false)
- {
- new tmptext[64];
- tmptext = strtok(templine,index);
- if(!strcmp(tmptext, "E\r\n")) done = true;
- else format(temp_Material_Object_Text[i], 64, "%s%s ",temp_Material_Object_Text[i], tmptext);
- }
- }
- // Object read save object to new prefab format
- stmt_bind_value(insertprefabimpstmt, 0, DB::TYPE_INT, tempobject[medit_modelid]);
- stmt_bind_value(insertprefabimpstmt, 1, DB::TYPE_FLOAT, tempobject[pfox]);
- stmt_bind_value(insertprefabimpstmt, 2, DB::TYPE_FLOAT, tempobject[pfoy]);
- stmt_bind_value(insertprefabimpstmt, 3, DB::TYPE_FLOAT, tempobject[pfoz]);
- stmt_bind_value(insertprefabimpstmt, 4, DB::TYPE_FLOAT, tempobject[pfrx]);
- stmt_bind_value(insertprefabimpstmt, 5, DB::TYPE_FLOAT, tempobject[pfry]);
- stmt_bind_value(insertprefabimpstmt, 6, DB::TYPE_FLOAT, tempobject[pfrz]);
- stmt_bind_value(insertprefabimpstmt, 7, DB::TYPE_ARRAY, tempobject[Material_Index], MAX_MATERIALS);
- stmt_bind_value(insertprefabimpstmt, 8, DB::TYPE_ARRAY, tempobject[Material_Color], MAX_MATERIALS);
- stmt_bind_value(insertprefabimpstmt, 9, DB::TYPE_INT, tempobject[usetext][0]);
- stmt_bind_value(insertprefabimpstmt, 10, DB::TYPE_INT, tempobject[Material_FontFace][0]);
- stmt_bind_value(insertprefabimpstmt, 11, DB::TYPE_INT, tempobject[Material_FontSize][0]);
- stmt_bind_value(insertprefabimpstmt, 12, DB::TYPE_INT, tempobject[Material_FontBold][0]);
- stmt_bind_value(insertprefabimpstmt, 13, DB::TYPE_INT, tempobject[Material_FontColor][0]);
- stmt_bind_value(insertprefabimpstmt, 14, DB::TYPE_INT, tempobject[Material_BackColor][0]);
- stmt_bind_value(insertprefabimpstmt, 15, DB::TYPE_INT, tempobject[Material_Alignment][0]);
- stmt_bind_value(insertprefabimpstmt, 16, DB::TYPE_INT, tempobject[Material_TextFontSize][0]);
- stmt_bind_value(insertprefabimpstmt, 17, DB::TYPE_STRING, temp_Material_Object_Text[0], MAX_TEXT_LENGTH);
- stmt_execute(insertprefabimpstmt);
- }
- }
- // Old version load
- else
- {
- fclose(f);
- f = fopen(openmap,io_read);
- while(fread(f,templine,sizeof(templine),false)) {
- index = 0;
- tempobject[object_id] = INVALID_OBJECT_ID;
- tempobject[medit_modelid] = strval(strtok(templine,index));
- tempobject[pfox] = floatstr(strtok(templine,index))-pfx;
- tempobject[pfoy] = floatstr(strtok(templine,index))-pfy;
- tempobject[pfoz] = floatstr(strtok(templine,index))-pfz;
- tempobject[pfrx] = floatstr(strtok(templine,index));
- tempobject[pfry] = floatstr(strtok(templine,index));
- tempobject[pfrz] = floatstr(strtok(templine,index));
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++) { tempobject[Material_Index][i] = strval(strtok(templine,index)); }
- // Bind our reults
- stmt_bind_value(insertprefabimpstmt, 0, DB::TYPE_INT, tempobject[medit_modelid]);
- stmt_bind_value(insertprefabimpstmt, 1, DB::TYPE_FLOAT, tempobject[pfox]);
- stmt_bind_value(insertprefabimpstmt, 2, DB::TYPE_FLOAT, tempobject[pfoy]);
- stmt_bind_value(insertprefabimpstmt, 3, DB::TYPE_FLOAT, tempobject[pfoz]);
- stmt_bind_value(insertprefabimpstmt, 4, DB::TYPE_FLOAT, tempobject[pfrx]);
- stmt_bind_value(insertprefabimpstmt, 5, DB::TYPE_FLOAT, tempobject[pfry]);
- stmt_bind_value(insertprefabimpstmt, 6, DB::TYPE_FLOAT, tempobject[pfrz]);
- stmt_bind_value(insertprefabimpstmt, 7, DB::TYPE_ARRAY, tempobject[Material_Index], MAX_MATERIALS);
- stmt_bind_value(insertprefabimpstmt, 8, DB::TYPE_ARRAY, tempobject[Material_Color], MAX_MATERIALS);
- stmt_bind_value(insertprefabimpstmt, 9, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 10, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 11, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 12, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 13, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 14, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 15, DB::TYPE_INT, 0);
- stmt_bind_value(insertprefabimpstmt, 16, DB::TYPE_INT, 20);
- stmt_bind_value(insertprefabimpstmt, 17, DB::TYPE_STRING, "None", MAX_TEXT_LENGTH);
- stmt_execute(insertprefabimpstmt);
- }
- }
- fclose(f);
- db_free_persistent(PrefabImportDB);
- return 1;
- }
- tsfunc GetPrefabCenter(openmap[64], &Float:pfx, &Float:pfy, &Float:pfz)
- {
- new File:f;
- f = fopen(openmap,io_read);
- new templine[256];
- new Float:ZOffSet;
- new Float:highX = -9999999.0;
- new Float:highY = -9999999.0;
- new Float:highZ = -9999999.0;
- new Float:lowX = 9999999.0;
- new Float:lowY = 9999999.0;
- new Float:lowZ = 9999999.0;
- // Check Version
- fread(f,templine,sizeof(templine),false);
- // This is a new medit version use new load routine
- new index;
- // new version load
- if(!strcmp(strtok(templine,index), "420medit-Version:"))
- {
- ZOffSet = floatstr(strtok(templine,index));
- ZOffSet = floatstr(strtok(templine,index));
- format(templine, sizeof(templine), "ZOffSet: %f", ZOffSet);
- while(fread(f,templine,sizeof(templine),false)) {
- index = 0;
- tempobject[object_id] = INVALID_OBJECT_ID;
- tempobject[medit_modelid] = strval(strtok(templine,index));
- tempobject[pfox] = floatstr(strtok(templine,index));
- tempobject[pfoy] = floatstr(strtok(templine,index));
- tempobject[pfoz] = floatstr(strtok(templine,index));
- tempobject[pfrx] = floatstr(strtok(templine,index));
- tempobject[pfry] = floatstr(strtok(templine,index));
- tempobject[pfrz] = floatstr(strtok(templine,index));
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++)
- {
- tempobject[Material_Index][i] = strval(strtok(templine,index));
- tempobject[Material_Color][i] = strval(strtok(templine,index));
- }
- // Load Text Data // Only only use first slot anyways
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++)
- {
- index = 0;
- fread(f,templine,sizeof(templine),false);
- tempobject[usetext][i] = strval(strtok(templine,index));
- tempobject[Material_FontFace][i] = strval(strtok(templine,index));
- tempobject[Material_FontSize][i] = strval(strtok(templine,index));
- tempobject[Material_FontBold][i] = strval(strtok(templine,index));
- tempobject[Material_FontColor][i] = strval(strtok(templine,index));
- tempobject[Material_BackColor][i] = strval(strtok(templine,index));
- tempobject[Material_Alignment][i] = strval(strtok(templine,index));
- tempobject[Material_TextFontSize][i] = strval(strtok(templine,index));
- new bool:done;
- temp_Material_Object_Text[i] = "";
- while(done == false)
- {
- new tmptext[64];
- tmptext = strtok(templine,index);
- if(!strcmp(tmptext, "E\r\n")) done = true;
- else format(temp_Material_Object_Text[i], 64, "%s%s ",temp_Material_Object_Text[i], tmptext);
- }
- }
- // Calculate group center
- if(tempobject[pfox] > highX) highX = tempobject[pfox];
- if(tempobject[pfoy] > highY) highY = tempobject[pfoy];
- if(tempobject[pfoz] > highZ) highZ = tempobject[pfoz];
- if(tempobject[pfox] < lowX) lowX = tempobject[pfox];
- if(tempobject[pfoy] < lowY) lowY = tempobject[pfoy];
- if(tempobject[pfoz] < lowZ) lowZ = tempobject[pfoz];
- }
- }
- // Old version load
- else
- {
- fclose(f);
- f = fopen(openmap,io_read);
- while(fread(f,templine,sizeof(templine),false)) {
- index = 0;
- tempobject[object_id] = INVALID_OBJECT_ID;
- tempobject[medit_modelid] = strval(strtok(templine,index));
- tempobject[pfox] = floatstr(strtok(templine,index));
- tempobject[pfoy] = floatstr(strtok(templine,index));
- tempobject[pfoz] = floatstr(strtok(templine,index));
- tempobject[pfrx] = floatstr(strtok(templine,index));
- tempobject[pfry] = floatstr(strtok(templine,index));
- tempobject[pfrz] = floatstr(strtok(templine,index));
- for(new i = 0; i < MAX_MATERIAL_INDEX; i++) { tempobject[Material_Index][i] = strval(strtok(templine,index)); }
- // Calculate group center
- if(tempobject[pfox] > highX) highX = tempobject[pfox];
- if(tempobject[pfoy] > highY) highY = tempobject[pfoy];
- if(tempobject[pfoz] > highZ) highZ = tempobject[pfoz];
- if(tempobject[pfox] < lowX) lowX = tempobject[pfox];
- if(tempobject[pfoy] < lowY) lowY = tempobject[pfoy];
- if(tempobject[pfoz] < lowZ) lowZ = tempobject[pfoz];
- }
- }
- pfx = (highX + lowX) / 2;
- pfy = (highY + lowY) / 2;
- pfz = (highZ + lowZ) / 2;
- fclose(f);
- return 1;
- }
- */
|