/* This is an example script using the e_objects dynamic objects library ================================================================================ Functions provided by the library: ================================================================================ InitObjectPool() - Must be called in order to set everything up, preferably from OnGameModeInit CreateDynamicObject(model, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ) - Creates an object for everyone, fairly obvious CreatePlayerDynamicObject(playerid, model, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ) - Creates an object for a single player (visible in all worlds for that player) CreateVWDynamicObject(virtualworld, model, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ) - Creates an object for all players in one world only CreatePlayerVWDynamicObject(playerid, virtualworld, model, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ) - Creates an object for one player in one world only DestroyDynamicObject(objectid) - Destroys a dynamic object (however you created the object (see above)) SetDynamicObjectPos(objectid, Float:X, Float:Y, Float:Z) - SetObjectPos equivalent SetDynamicObjectRot(objectid, Float:RX, Float:RY, Float:RZ) - SetObjectRot equivalent GetDynamicObjectPos(objectid, &Float:X, &Float:Y, &Float:Z) - GetObjectPos equivalent GetDynamicObjectRot(objectid, &Float:RX, &Float:RY, &Float:RZ) - GetObjectRot equivalent MoveDynamicObject(objectid, Float:X, Float:Y, Float:Z, Float:S) - MoveObject equivalent StopDynamicObject(objectid) - StopObject equivalent IsValidDynamicObject(objectid) - IsValidObject equivalent AddPlayerToObject(objectid, playerid) - Use with CreatePlayerDynamicObject / CreatePlayerVWDynamicObject to assign multiple specific players to an object exclusively AddVWToObject(objectid, virtualworld) - As AddPlayerToObject but with virtual worlds AddAllVWToObject(objectid) - Removes world exclusivity (Note: NOT the same as adding all worlds individually, this is faster but less flexible in processing) AddAllPlayersToObject(objectid) - As with AddAllVWToObject but with players (Note: NOT the same as adding all players individually, this is faster but less flexible in processing) RemovePlayerFromObject(objectid, playerid) - Opposite to AddPlayerToObject (does not work on objects not created with player specific functions or objects with AddAllPlayersToObject applied) RemoveVWFromObject(objectid, virtualworld) - Opposite to AddVWToObject (does not work on objects not created with world specific functions or objects with AddAllVWToObject applied) GetObject(objectid) - Returns the object data in an [OBJECT_DATA] array (see e_objects.inc) DistanceToOrigin(Float:X, Float:Y, Float:Z) - Not an object specific function but useful anyway, returns the 3d line distance from the provided co-ordinates to the world origin IsValidModel(modelid) - Not all object numbers exist in SA and incorrect ones will crash people use this to check to a model is valid before using it ================================================================================ Callbacks provided by the library: ================================================================================ public OnDynamicObjectMoved(objectid) Note: you shouln't use OnObjectMoved/OnPlayerObjectMoved anymore */ #define NO_OBJECTS_MOVE #define NO_PLAYER_ONLY #define MAX_WORLDS 0 #define E_OBJECT_ALL_WARNINGS //#define OBJECT_ARRAY_VISIBLE #define VIEW_DISTANCE 200.0 #define LOOP_GRANULARITY 10 #include #include /* This function extracts (not very nicely) the objects from an MTA .map file and adds them to the world. This will allow you to very easily test the whole system with a load of objects. */ Float:mtarad2deg(Float:radians) { if (radians == 0.0) { return 0.0; } new Float:retval = (360.0 + (radians / 0.0174532925)); while (retval >= 360.0) retval -= 360.0; while (retval < 0.0) retval += 360.0; return retval; } ParseMapFile(File:map) { new line[128]; new intag = 0; new Float:x , Float:y , Float:z ; new Float:rx, Float:ry, Float:rz; new model; while (fread(map, line)) { new index = 0; while (line[index] && line[index] < 'A') { index++; } if (!line[index]) continue; if (intag) { if (!strcmp(line[index], "object", true, 6)) { // We've collected all the data so create the object // NOTE: MTA map objects are in radians and we need degrees CreateDynamicObject(model, x, y, z, mtarad2deg(rx), mtarad2deg(ry), mtarad2deg(rz)); // Mark as done intag = 0; } else if (!strcmp(line[index], "position", true, 8)) { // Set pos to the first position new pos = index + (8 + 1); // Get the position x = floatstr(line[pos++]); // Find the next point pos = strfind(line, " ", .pos = pos); // Repeat y = floatstr(line[pos++]); pos = strfind(line, " ", .pos = pos); z = floatstr(line[pos]); } else if (!strcmp(line[index], "rotation", true, 8)) { // Set pos to the first rotation new pos = index + (8 + 1); // Get the rotation (actually rz - they're backwards) rz = floatstr(line[pos++]); // Find the next point pos = strfind(line, " ", .pos = pos); // Repeat ry = floatstr(line[pos++]); pos = strfind(line, " ", .pos = pos); rx = floatstr(line[pos]); } else if (!strcmp(line[index], "model", true, 5)) { // Get the model model = strval(line[index + (5 + 1)]); } } else { if (!strcmp(line[index], "object", true, 6)) { // We've reached an object so start saving the data intag = 1; } } } } #define COLOR_RED 0xFF0000AA #define dcmd(%1,%2,%3) if ((strcmp(%3, "/%1", true, %2 + 1) == 0) && (((%3[%2 + 1] == 0) && (dcmd_%1(playerid, ""))) || ((%3[%2 + 1] == 32) && (dcmd_%1(playerid, %3[%2 + 2]))))) return 1 main() { print("\n-----------------------------------"); print(" e_objects.inc library example use"); print(" by Alex \"Y_Less\" Cole"); print("-----------------------------------\n"); } public OnGameModeInit() { SetGameModeText("e_object example script"); AddStaticVehicle(522,-76.8972,117.8528,2.9721,58.4850,40,36); // AddStaticVehicle(522,-76.5305,118.2339,2.9721,160.6104,40,36); // AddStaticVehicle(522,-80.4842,107.0001,2.9721,160.6104,40,36); // AddStaticVehicle(522,-85.0823,95.0101,2.9718,152.1754,40,36); // AddStaticVehicle(522,-90.6765,81.4392,2.9721,157.7193,40,36); // AddStaticVehicle(541,-93.0459,75.6487,2.9698,157.7223,40,36); // AddStaticVehicle(541,-97.4271,64.3315,2.9703,159.7506,40,36); // AddStaticVehicle(541,-101.9507,52.0960,2.9681,159.7309,40,36); // AddStaticVehicle(541,-109.5472,30.5265,2.9684,160.5850,40,36); // AddStaticVehicle(541,-114.0184,17.8500,2.9720,160.5148,40,36); // AddStaticVehicle(429,-119.3475,2.7934,2.9721,160.4882,40,36); // AddStaticVehicle(429,-123.3487,-8.4983,2.9721,160.4883,40,36); // AddStaticVehicle(429,-127.4725,-20.1360,2.9722,160.4883,40,36); // AddStaticVehicle(429,-132.0323,-34.0427,2.9721,161.0629,40,36); // AddStaticVehicle(429,-136.9616,-48.3604,2.9721,161.9695,40,36); // AddStaticVehicle(451,-133.2597,-65.9225,2.9721,176.8096,40,36); // AddPlayerClass(0,-118.1531,-27.0937,3.1172,39.9715,0,0,0,0,0,0); // // This must be called here! InitObjectPool(); return 1; } public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { // Command to load a map file dcmd(loadmap, 7, cmdtext); return 0; } dcmd_loadmap(playerid, text[]) { if (text[0]) { new File:map; if ((map = fopen(text, io_read))) { ParseMapFile(map); fclose(map); return 1; } } SendClientMessage(playerid, COLOR_RED, "*** You must enter a valid map file"); return 1; } /* These functions are now redundant and will return random and incomplete results if anything at all as invisible objects don't move public OnObjectMoved(objectid) { return 1; } public OnPlayerObjectMoved(playerid, objectid) { return 1; } */