GarObject.pwn 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. //==============================================================================
  2. // GarObject v1.3 by [03]Garsino!
  3. //==============================================================================
  4. // - Credits to DracoBlue for dini, dcmd and dudb.
  5. // - Credits to Y_Less for sscanf2.
  6. // - Thanks to everyone who gave me ideas for this object editing system (Admins on Garsino's Funserver).
  7. // - Thanks to everyone who helped me find bugs.
  8. //==============================================================================
  9. // Changelog
  10. //==============================================================================
  11. // - [Fixed] Fixed problem with editing objects after loading them from a file.
  12. // - [Added] Added /startobjectloop - it will move your object from point (A) to point (B). When arrived at point (B) it will go back to point (A) like a loop.
  13. // - [Added] Added /startallobjectloop - it will move all your objects from point (A) to point (B). When arrived at point (B) they will go back to point (A) like a loop.
  14. // - [Added] Added /sol - shortcut command for /startobjectloop.
  15. // - [Added] Added /sallol - shortcut command for /startallobjectloop.
  16. // - [Added] Added /stopobjectloop - it will stop the current ongoing object loop for your object.
  17. // - [Added] Added /stopallobjectloop - it will stop the current ongoing object loop for all your objects.
  18. // - [Added] Added /stopol - shortcut command for /stopobjectloop.
  19. // - [Added] Added /stopallol - shortcut command for /stopallobjectloop.
  20. // - [Added] Added /getmypos (only works if you have defined GO_DEBUG_CMDS).
  21. //==============================================================================
  22. // Includes
  23. //==============================================================================
  24. #include <a_samp> // Credits to the SA:MP Developement Team
  25. //==============================================================================
  26. // Configuration
  27. //==============================================================================
  28. #undef MAX_PLAYERS
  29. #define MAX_PLAYERS 500 // Change it to the amount of server slots!!
  30. //#define G_OBJ_AUTOSAVE // Uncomment to enable autosave of objects on disconnect/filterscript exit. Objects will be saved in <PlayerName>.txt
  31. //#define G_OBJ_USE_SHORTCUTS // Unomment to enable command shortcuts.
  32. //#define GO_DEBUG_CMDS // Uncomment to enable debug commands like /getmypos.
  33. #define GOBJ_MAX_OBJECTS_CREATED 400 // Max objects an admin can create (Remember the limit is 400 in SA:MP 0.3b/0.3c...)
  34. #define G_OBJ_DID 12357
  35. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  36. #define Loop(%0,%1) for(new %0 = 0; %0 < %1; %0++)
  37. new Objects[MAX_PLAYERS][GOBJ_MAX_OBJECTS_CREATED], ObjectCreator[MAX_OBJECTS];
  38. new Float:oOffset[MAX_OBJECTS][3], Float:oRot[MAX_OBJECTS][3], Float:oPos[MAX_OBJECTS][3], ModelID[MAX_OBJECTS];
  39. new Float:oStart[MAX_OBJECTS][3], Float:oEnd[MAX_OBJECTS][3], oMoving[MAX_OBJECTS], oLap[MAX_OBJECTS], Float:oMSpeed[MAX_OBJECTS];
  40. new AttachedVehicle[MAX_OBJECTS], AttachedPlayer[MAX_OBJECTS];
  41. new Float:X, Float:Y, Float:Z;
  42. //==============================================================================
  43. // Colours
  44. //==============================================================================
  45. #define COLOUR_INFO 0x00FFFFFF
  46. #define COLOUR_SYSTEM 0xB60000FF
  47. //==============================================================================
  48. // Awesomeness
  49. //==============================================================================
  50. public OnFilterScriptInit()
  51. {
  52. Loop(obj, MAX_OBJECTS)
  53. {
  54. ObjectCreator[obj] = INVALID_PLAYER_ID;
  55. ModelID[obj] = -1;
  56. }
  57. Loop(i, MAX_PLAYERS)
  58. {
  59. Loop(o, GOBJ_MAX_OBJECTS_CREATED)
  60. {
  61. Objects[i][o] = INVALID_OBJECT_ID;
  62. }
  63. }
  64. print("\n>> GarObject v1.3 By [03]Garsino Loaded <<\n");
  65. return 1;
  66. }
  67. public OnFilterScriptExit()
  68. {
  69. #if defined G_OBJ_AUTOSAVE
  70. new filename[MAX_PLAYER_NAME+4];
  71. Loop(i, MAX_PLAYERS)
  72. {
  73. if(!IsPlayerAdmin(i) || !IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
  74. format(filename, sizeof(filename), "%s.txt", pNick(i));
  75. SaveObjectsToFile(i, filename, 0);
  76. SaveHObjectsToFile(i, filename, 0);
  77. }
  78. #endif
  79. Loop(obj, MAX_OBJECTS)
  80. {
  81. if(ObjectCreator[obj] != INVALID_PLAYER_ID && ModelID[obj] != -1)
  82. {
  83. DestroyObject(obj);
  84. ModelID[obj] = -1;
  85. }
  86. }
  87. print("\n>> GarObject v1.3 By [03]Garsino Unloaded <<\n");
  88. return 1;
  89. }
  90. public OnPlayerConnect(playerid)
  91. {
  92. Loop(o, GOBJ_MAX_OBJECTS_CREATED)
  93. {
  94. Objects[playerid][o] = INVALID_OBJECT_ID;
  95. }
  96. return 1;
  97. }
  98. public OnPlayerDisconnect(playerid, reason)
  99. {
  100. #if defined G_OBJ_AUTOSAVE
  101. if(IsPlayerAdmin(playerid))
  102. {
  103. new filename[MAX_PLAYER_NAME+4];
  104. format(filename, sizeof(filename), "%s.txt", pNick(playerid));
  105. SaveObjectsToFile(playerid, filename, 0);
  106. SaveHObjectsToFile(playerid, filename, 0);
  107. }
  108. #endif
  109. Loop(o, MAX_OBJECTS)
  110. {
  111. if(ObjectCreator[o] == playerid)
  112. {
  113. if(ModelID[o] != -1)
  114. {
  115. DestroyObject(o);
  116. ModelID[o] = -1;
  117. }
  118. ObjectCreator[o] = INVALID_PLAYER_ID;
  119. }
  120. }
  121. Loop(o2, GOBJ_MAX_OBJECTS_CREATED)
  122. {
  123. Objects[playerid][o2] = INVALID_OBJECT_ID;
  124. }
  125. return 1;
  126. }
  127. public OnPlayerCommandText(playerid, cmdtext[])
  128. {
  129. dcmd(stopallobjectloop, 17, cmdtext);
  130. dcmd(stopobjectloop, 14, cmdtext);
  131. dcmd(startallobjectloop, 18, cmdtext);
  132. dcmd(startobjectloop, 15, cmdtext);
  133. dcmd(createobject, 12, cmdtext);
  134. dcmd(rotateobject, 12, cmdtext);
  135. dcmd(attachpobject, 13, cmdtext);
  136. dcmd(deattachpobject, 15, cmdtext);
  137. dcmd(attachvobject, 13, cmdtext);
  138. dcmd(deattachvobject, 15, cmdtext);
  139. dcmd(rotateallobject, 15, cmdtext);
  140. dcmd(destroyobject, 13, cmdtext);
  141. dcmd(destroyallobject, 16, cmdtext);
  142. dcmd(stopobject, 10, cmdtext);
  143. dcmd(stopallobject, 13, cmdtext);
  144. dcmd(moveobject, 10, cmdtext);
  145. dcmd(moveallobject, 13, cmdtext);
  146. dcmd(getobject, 9, cmdtext);
  147. dcmd(getallobject, 12, cmdtext);
  148. dcmd(objecttele, 10, cmdtext);
  149. dcmd(sethobj, 7, cmdtext);
  150. dcmd(stophobj, 8, cmdtext);
  151. dcmd(stopallhobj, 11, cmdtext);
  152. dcmd(saveobject, 10, cmdtext);
  153. dcmd(loadobject, 10, cmdtext);
  154. dcmd(savehobject, 11, cmdtext);
  155. dcmd(loadhobject, 11, cmdtext);
  156. dcmd(copyobject, 10, cmdtext);
  157. dcmd(garobject, 9, cmdtext);
  158. #if defined G_OBJ_USE_SHORTCUTS
  159. dcmd(oc, 2, cmdtext); // /createobject
  160. dcmd(or, 2, cmdtext); // /rotateobject
  161. dcmd(apo, 3, cmdtext); // /attachpobject
  162. dcmd(deapo, 5, cmdtext); // /deattachpobject
  163. dcmd(avo, 3, cmdtext); // /attachvobject
  164. dcmd(deavo, 5, cmdtext); // /deattachvobject
  165. dcmd(orall, 5, cmdtext); // /rotateallobject
  166. dcmd(od, 2, cmdtext); // /destroyobject
  167. dcmd(odall, 5, cmdtext); // /destroyallobject
  168. dcmd(os, 2, cmdtext); // /stopobject
  169. dcmd(osall, 5, cmdtext); // /stopallobject
  170. dcmd(om, 2, cmdtext); // /moveobject
  171. dcmd(omall, 5, cmdtext); // /moveallobject
  172. dcmd(og, 2, cmdtext); // /getobject
  173. dcmd(ogall, 5, cmdtext); // /getallobject
  174. dcmd(ot, 2, cmdtext); // /objecttele
  175. dcmd(setho, 5, cmdtext); // /sethobj
  176. dcmd(stopho, 6, cmdtext); // /stophobj
  177. dcmd(stopallho, 9, cmdtext); // /stopallhobj
  178. dcmd(so, 2, cmdtext); // /saveobject
  179. dcmd(lo, 2, cmdtext); // /loadobject
  180. dcmd(sho, 3, cmdtext); // /savehobject
  181. dcmd(lho, 3, cmdtext); // /loadhobject
  182. dcmd(co, 2, cmdtext); // /copyobject
  183. dcmd(sallol, 6, cmdtext); // /startallobjectloop
  184. dcmd(sol, 3, cmdtext); // /startobjectloop
  185. dcmd(stopallol, 6, cmdtext); // /stopallobjectloop
  186. dcmd(stopol, 3, cmdtext); // /stopobjectloop
  187. dcmd(gobj, 4, cmdtext); // /garobject
  188. #endif
  189. #if defined GO_DEBUG_CMDS
  190. dcmd(getmypos, 8, cmdtext);
  191. #endif
  192. return 0;
  193. }
  194. dcmd_createobject(playerid, params[])
  195. {
  196. if(IsPlayerAdmin(playerid))
  197. {
  198. new modelid, Float:rX, Float:rY, Float:rZ, string[128], objid = GetFreeObjectID(playerid);
  199. if(sscanf(params, "dF(0)F(0)F(0)", modelid, rX, rY, rZ)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /createobject (object id) (rotX) (rotY) (rotZ)");
  200. if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT && !IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "You need to spawn to be able to use this command.");
  201. if(GetTotalNativeObjects() >= (MAX_OBJECTS-1)) return SendClientMessage(playerid, COLOUR_SYSTEM, "The SA:MP object limit has been reached. You can not spawn any more objects.");
  202. if(objid < 0) return SendClientMessage(playerid, COLOUR_SYSTEM, "You can not spawn any more objects. Please delete one of the current ones first.");
  203. else
  204. {
  205. GetPlayerPos(playerid, X, Y, Z);
  206. Objects[playerid][objid] = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
  207. new o = Objects[playerid][objid];
  208. ModelID[o] = modelid;
  209. ObjectCreator[o] = playerid;
  210. oPos[o][0] = X, oPos[o][1] = Y, oPos[o][2] = Z;
  211. oRot[o][0] = rX, oRot[o][1] = rY, oRot[o][2] = rZ;
  212. AttachedVehicle[o] = INVALID_VEHICLE_ID, AttachedPlayer[o] = INVALID_PLAYER_ID;
  213. format(string, sizeof(string), "Object ID %d created. Modelid: %d. Rotation: X: %0.2f | Y: %0.2f | Z: %0.2f.", objid, modelid, rX, rY, rZ);
  214. SendClientMessage(playerid, COLOUR_INFO, string);
  215. }
  216. return 1;
  217. }
  218. else return 0;
  219. }
  220. dcmd_copyobject(playerid, params[])
  221. {
  222. if(IsPlayerAdmin(playerid))
  223. {
  224. new string[128], objectid, objid = GetFreeObjectID(playerid);
  225. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /copyobject (objectid)");
  226. if(GetTotalNativeObjects() >= (MAX_OBJECTS-1)) return SendClientMessage(playerid, COLOUR_SYSTEM, "The SA:MP object limit has been reached. You can not spawn any more objects.");
  227. if(objid < 0) return SendClientMessage(playerid, COLOUR_SYSTEM, "You can not spawn any more objects. Please delete one of the current ones first.");
  228. else
  229. {
  230. new o2 = Objects[playerid][objectid];
  231. Objects[playerid][objid] = CreateObject(ModelID[o2], oPos[o2][0], oPos[o2][1], oPos[o2][2], oRot[o2][0], oRot[o2][1], oRot[o2][2]);
  232. new o = Objects[playerid][objid];
  233. ModelID[o] = ModelID[o2];
  234. ObjectCreator[o] = playerid;
  235. oPos[o][0] = oPos[o2][0], oPos[o][1] = oPos[o2][1], oPos[o][2] = oPos[o2][2];
  236. oRot[o][0] = oRot[o2][0], oRot[o][1] = oRot[o2][1], oRot[o][2] = oRot[o2][2];
  237. AttachedVehicle[o] = AttachedVehicle[o2], AttachedPlayer[o] = AttachedPlayer[o2];
  238. if(AttachedVehicle[o] != INVALID_VEHICLE_ID)
  239. {
  240. oOffset[o][0] = oOffset[o2][0], oOffset[o][1] = oOffset[o2][1], oOffset[o][2] = oOffset[o2][2];
  241. oRot[o][0] = oRot[o][0], oRot[o][1] = oRot[o2][1], oRot[o][2] = oRot[o2][2];
  242. AttachObjectToVehicle(o, AttachedVehicle[o], oOffset[o2][0], oOffset[o2][1], oOffset[o2][2], oRot[o2][0], oRot[o2][1], oRot[o2][2]);
  243. }
  244. if(AttachedPlayer[o] != INVALID_PLAYER_ID)
  245. {
  246. oOffset[o][0] = oOffset[o2][0], oOffset[o][1] = oOffset[o2][1], oOffset[o][2] = oOffset[o2][2];
  247. oRot[o][0] = oRot[o][0], oRot[o][1] = oRot[o2][1], oRot[o][2] = oRot[o2][2];
  248. AttachObjectToVehicle(o, AttachedPlayer[o], oOffset[o2][0], oOffset[o2][1], oOffset[o2][2], oRot[o2][0], oRot[o2][1], oRot[o2][2]);
  249. }
  250. format(string, sizeof(string), "Object ID %d copied. Object ID for the copied object is %d.", objectid, objid);
  251. SendClientMessage(playerid, COLOUR_INFO, string);
  252. }
  253. return 1;
  254. }
  255. else return 0;
  256. }
  257. dcmd_rotateobject(playerid, params[])
  258. {
  259. if(IsPlayerAdmin(playerid))
  260. {
  261. new objectid, Float:rX, Float:rY, Float:rZ, string[128];
  262. if(sscanf(params, "dF(0)F(0)F(0)", objectid, rX, rY, rZ)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /rotateobject (object id) (rotX) (rotY) (rotZ)");
  263. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  264. else
  265. {
  266. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  267. {
  268. new o = Objects[playerid][objectid];
  269. SetObjectRot(o, rX, rY, rZ);
  270. oRot[o][0] = rX, oRot[o][1] = rY, oRot[o][2] = rZ;
  271. format(string, sizeof(string), "Object ID %d rotated. New rotation: X: %0.2f | Y: %0.2f | Z: %0.2f.", objectid, rX, rY, rZ);
  272. SendClientMessage(playerid, COLOUR_INFO, string);
  273. }
  274. }
  275. return 1;
  276. }
  277. else return 0;
  278. }
  279. dcmd_attachpobject(playerid, params[])
  280. {
  281. if(IsPlayerAdmin(playerid))
  282. {
  283. new id, objectid, Float:ofsX, Float:ofsY, Float:ofsZ, Float:rX, Float:rY, Float:rZ, string[128];
  284. if(sscanf(params, "duF(0)F(0)F(0)F(0)F(0)F(0)", objectid, id, ofsX, ofsY, ofsZ, rX, rY, rZ)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /attachpobject (object id) (nick/id) (offset X) (offset Y) (offset Z) (rotation X) (rotation Y) (rotation Z)");
  285. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  286. if(AttachedVehicle[Objects[playerid][objectid]] != INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "You can not attach an object to a player wich is already attached to a vehicle!");
  287. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOUR_SYSTEM, "This player is not connected!");
  288. else
  289. {
  290. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  291. {
  292. new o = Objects[playerid][objectid];
  293. oOffset[o][0] = ofsX, oOffset[o][1] = ofsY, oOffset[o][2] = ofsZ;
  294. oRot[o][0] = rX, oRot[o][1] = rY, oRot[o][2] = rZ;
  295. AttachedPlayer[o] = id;
  296. AttachObjectToPlayer(o, id, ofsX, ofsY, ofsZ, rX, rY, rZ);
  297. format(string, sizeof(string), "Object ID %d attached to %s (%d). Offset: X: %0.2f | Y: %0.2f | Z: %0.2f | Rotation: X: %0.2f | Y: %0.2f | Z: %0.2f.", objectid, pNick(id), id, ofsX, ofsY, ofsZ, rX, rY, rZ);
  298. SendClientMessage(playerid, COLOUR_INFO, string);
  299. }
  300. }
  301. return 1;
  302. }
  303. else return 0;
  304. }
  305. dcmd_deattachpobject(playerid, params[])
  306. {
  307. if(IsPlayerAdmin(playerid))
  308. {
  309. new objectid, string[128], o, o2;
  310. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /deattachpobject (object id)");
  311. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  312. else
  313. {
  314. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  315. {
  316. DestroyObject(Objects[playerid][objectid]);
  317. ObjectCreator[Objects[playerid][objectid]] = INVALID_PLAYER_ID;
  318. o = Objects[playerid][objectid];
  319. Objects[playerid][objectid] = CreateObject(ModelID[o], (oPos[o][0] + oOffset[o][0]), (oPos[o][1] + oOffset[o][1]), (oPos[o][2] + oOffset[o][2]), oRot[o][0], oRot[o][1], oRot[o][2]);
  320. o2 = Objects[playerid][objectid];
  321. ModelID[o2] = ModelID[o], oPos[o2][0] = (oPos[o][0] + oOffset[o][0]), oPos[o2][1] = (oPos[o][1] + oOffset[o][1]), oPos[o2][2] = (oPos[o][2] + oOffset[o][2]), oRot[o2][0] = oRot[o][0], oRot[o2][1] = oRot[o][1], oRot[o2][2] = oRot[o][2];
  322. ObjectCreator[o2] = playerid;
  323. format(string, sizeof(string), "Object ID %d de-attached from %s (%d).", objectid, pNick(AttachedPlayer[o]), AttachedPlayer[o]);
  324. SendClientMessage(playerid, COLOUR_INFO, string);
  325. AttachedPlayer[o2] = INVALID_PLAYER_ID, AttachedPlayer[o] = INVALID_PLAYER_ID;
  326. }
  327. }
  328. return 1;
  329. }
  330. else return 0;
  331. }
  332. dcmd_attachvobject(playerid, params[])
  333. {
  334. if(IsPlayerAdmin(playerid))
  335. {
  336. new vehicleid, objectid, Float:ofsX, Float:ofsY, Float:ofsZ, Float:rX, Float:rY, Float:rZ, string[128];
  337. if(sscanf(params, "ddF(0)F(0)F(0)F(0)F(0)F(0)", objectid, vehicleid, ofsX, ofsY, ofsZ, rX, rY, rZ)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /attachpobject (object id) (vehicleid) (offset X) (offset Y) (offset Z) (rotation X) (rotation Y) (rotation Z)");
  338. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  339. if(AttachedPlayer[Objects[playerid][objectid]] != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "You can not attach an object to a vehicle wich is already attached to a player!");
  340. if(vehicleid == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid vehicle ID!");
  341. else
  342. {
  343. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  344. {
  345. new o = Objects[playerid][objectid];
  346. oOffset[o][0] = ofsX, oOffset[o][1] = ofsY, oOffset[o][2] = ofsZ;
  347. oRot[o][0] = rX, oRot[o][1] = rY, oRot[o][2] = rZ;
  348. AttachedVehicle[o] = vehicleid;
  349. AttachObjectToVehicle(o, vehicleid, ofsX, ofsY, ofsZ, rX, rY, rZ);
  350. format(string, sizeof(string), "Object ID %d attached to vehicle ID %d. Offset: X: %0.2f | Y: %0.2f | Z: %0.2f | Rotation: X: %0.2f | Y: %0.2f | Z: %0.2f.", objectid, vehicleid, ofsX, ofsY, ofsZ, rX, rY, rZ);
  351. SendClientMessage(playerid, COLOUR_INFO, string);
  352. }
  353. }
  354. return 1;
  355. }
  356. else return 0;
  357. }
  358. dcmd_deattachvobject(playerid, params[])
  359. {
  360. if(IsPlayerAdmin(playerid))
  361. {
  362. new objectid, string[128], o, o2;
  363. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /deattachpobject (object id)");
  364. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  365. else
  366. {
  367. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  368. {
  369. DestroyObject(Objects[playerid][objectid]);
  370. ObjectCreator[Objects[playerid][objectid]] = INVALID_PLAYER_ID;
  371. o = Objects[playerid][objectid];
  372. GetVehiclePos(AttachedVehicle[o], oPos[o][0], oPos[o][1], oPos[o][2]);
  373. Objects[playerid][objectid] = CreateObject(ModelID[o], (oPos[o][0] + oOffset[o][0]), (oPos[o][1] + oOffset[o][1]), (oPos[o][2] + oOffset[o][2]), oRot[o][0], oRot[o][1], oRot[o][2]);
  374. o2 = Objects[playerid][objectid];
  375. ObjectCreator[o2] = playerid;
  376. format(string, sizeof(string), "Object %d de-attached from vehicle ID %d.", objectid, AttachedVehicle[o]);
  377. SendClientMessage(playerid, COLOUR_INFO, string);
  378. ModelID[o2] = ModelID[o], oPos[o2][0] = (oPos[o][0] + oOffset[o][0]), oPos[o2][1] = (oPos[o][1] + oOffset[o][1]), oPos[o2][2] = (oPos[o][2] + oOffset[o][2]), oRot[o2][0] = oRot[o][0], oRot[o2][1] = oRot[o][1], oRot[o2][2] = oRot[o][2];
  379. AttachedVehicle[o2] = INVALID_VEHICLE_ID, AttachedVehicle[o] = INVALID_VEHICLE_ID;
  380. }
  381. }
  382. return 1;
  383. }
  384. else return 0;
  385. }
  386. dcmd_sethobj(playerid, params[])
  387. {
  388. if(IsPlayerAdmin(playerid))
  389. {
  390. new id, modelid, slot, Float:rX[3], Float:rY[3], Float:rZ[3], string[128], bodypart[36], bid;
  391. if(sscanf(params, "udds[36]F(0)F(0)F(0)F(0)F(0)F(0)F(1)F(1)F(1)", id, modelid, slot, bodypart, rX[0], rY[0], rZ[0], rX[1], rY[1], rZ[1], rX[2], rY[2], rZ[2])) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /sethobj (nick/id) (modelid) (slot: 0-4) (bodypart: name/id) (rotX) (rotY) (rotZ) (rotX) (rotY) (rotZ) (sizeX) (sizeY) (sizeZ)");
  392. if(strlen(bodypart) < 1 || bodypart[35] || GetBodypartIDFromName(bodypart) == -1) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid Bodypart Name/ID.");
  393. if(slot < 0 || slot > 4) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid slot ID. Valid slot IDs are between 0-4.");
  394. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOUR_SYSTEM, "This player is not connected!");
  395. else
  396. {
  397. if(IsPlayerAttachedObjectSlotUsed(id, slot))
  398. {
  399. RemovePlayerAttachedObject(id, slot);
  400. }
  401. bid = GetBodypartIDFromName(bodypart);
  402. SetPlayerAttachedObject(id, slot, modelid, bid, rX[0], rY[0], rZ[0], rX[1], rY[1], rZ[1], rX[2], rY[2], rZ[2]);
  403. format(string, sizeof(string), "Modelid %d has been attached to %s's (%d) Bodypart [%s].", modelid, pNick(id), id, GetBodypartName(bodypart));
  404. SendClientMessage(playerid, COLOUR_INFO, string);
  405. SetHOPVar(playerid, "HOIndex", slot, slot);
  406. SetHOPVar(playerid, "HOModel", modelid, slot);
  407. SetHOPVar(playerid, "HOBone", bid, slot);
  408. SetHOPFloat(playerid, "HOOX", rX[0], slot);
  409. SetHOPFloat(playerid, "HOOY", rY[0], slot);
  410. SetHOPFloat(playerid, "HOOZ", rZ[0], slot);
  411. SetHOPFloat(playerid, "HORX", rX[1], slot);
  412. SetHOPFloat(playerid, "HORY", rY[1], slot);
  413. SetHOPFloat(playerid, "HORZ", rZ[1], slot);
  414. SetHOPFloat(playerid, "HOSX", rX[2], slot);
  415. SetHOPFloat(playerid, "HOSY", rY[2], slot);
  416. SetHOPFloat(playerid, "HOSZ", rZ[2], slot);
  417. }
  418. return 1;
  419. }
  420. else return 0;
  421. }
  422. dcmd_stophobj(playerid, params[])
  423. {
  424. if(IsPlayerAdmin(playerid))
  425. {
  426. new id, string[128], slot;
  427. if(sscanf(params, "ud", id, slot)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /stophobj (nick/id) (slot: 0-4)");
  428. if(slot < 0 || slot > 4) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid slot ID. Valid slot IDs are between 0-4.");
  429. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOUR_SYSTEM, "This player is not connected!");
  430. else
  431. {
  432. RemovePlayerAttachedObject(id, slot);
  433. format(string, sizeof(string), "Attached object in slot ID %d removed from %s's (%d) bodypart.", slot, pNick(id), id);
  434. SendClientMessage(playerid, COLOUR_INFO, string);
  435. }
  436. return 1;
  437. }
  438. else return 0;
  439. }
  440. dcmd_stopallhobj(playerid, params[])
  441. {
  442. if(IsPlayerAdmin(playerid))
  443. {
  444. new id, string[128], count;
  445. if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /stopallhobj (nick/id)");
  446. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOUR_SYSTEM, "This player is not connected!");
  447. else
  448. {
  449. Loop(slot, 5)
  450. {
  451. if(IsPlayerAttachedObjectSlotUsed(id, slot))
  452. {
  453. count++;
  454. RemovePlayerAttachedObject(id, slot);
  455. }
  456. }
  457. format(string, sizeof(string), "All attached objects removed from %s's (%d) bodyparts (%d in total).", pNick(id), id, count);
  458. SendClientMessage(playerid, COLOUR_INFO, string);
  459. }
  460. return 1;
  461. }
  462. else return 0;
  463. }
  464. stock GetBodypartName(bodypart[])
  465. {
  466. new string[25];
  467. if(!strcmp(bodypart, "0", true)) format(string, sizeof(string), "-1");
  468. if(!strcmp(bodypart, "Spine", true) || !strcmp(bodypart, "1", true)) format(string, sizeof(string), "Spine - 1");
  469. if(!strcmp(bodypart, "Head", true) || !strcmp(bodypart, "2", true)) format(string, sizeof(string), "Head - 2");
  470. if(!strcmp(bodypart, "Left upper arm", true) || !strcmp(bodypart, "3", true)) format(string, sizeof(string), "Left upper arm - 3");
  471. if(!strcmp(bodypart, "Right upper arm", true) || !strcmp(bodypart, "4", true)) format(string, sizeof(string), "Right upper arm - 4");
  472. if(!strcmp(bodypart, "Left hand", true) || !strcmp(bodypart, "5", true)) format(string, sizeof(string), "Left hand - 5");
  473. if(!strcmp(bodypart, "Right hand", true) || !strcmp(bodypart, "6", true)) format(string, sizeof(string), "Right hand - 6");
  474. if(!strcmp(bodypart, "Left thigh ", true) || !strcmp(bodypart, "7", true)) format(string, sizeof(string), "Left thigh - 7");
  475. if(!strcmp(bodypart, "Right thigh ", true) || !strcmp(bodypart, "8", true)) format(string, sizeof(string), "Right thigh - 8");
  476. if(!strcmp(bodypart, "Left foot", true) || !strcmp(bodypart, "9", true)) format(string, sizeof(string), "Left foot - 9");
  477. if(!strcmp(bodypart, "Right foot", true) || !strcmp(bodypart, "10", true)) format(string, sizeof(string), "Right foot - 10");
  478. if(!strcmp(bodypart, "Left calf ", true) || !strcmp(bodypart, "11", true)) format(string, sizeof(string), "Left calf - 11");
  479. if(!strcmp(bodypart, "Right calf ", true) || !strcmp(bodypart, "12", true)) format(string, sizeof(string), "Right calf - 12");
  480. if(!strcmp(bodypart, "Left forearm", true) || !strcmp(bodypart, "13", true)) format(string, sizeof(string), "Left forearm - 13");
  481. if(!strcmp(bodypart, "Right forearm ", true) || !strcmp(bodypart, "14", true)) format(string, sizeof(string), "Right forearm - 14");
  482. if(!strcmp(bodypart, "Left clavicle ", true) || !strcmp(bodypart, "15", true)) format(string, sizeof(string), "Left clavicle - 15");
  483. if(!strcmp(bodypart, "Right clavicle ", true) || !strcmp(bodypart, "16", true)) format(string, sizeof(string), "Right clavicle - 16");
  484. if(!strcmp(bodypart, "Neck", true) || !strcmp(bodypart, "17", true)) format(string, sizeof(string), "Neck - 17");
  485. if(!strcmp(bodypart, "Jew", true) || !strcmp(bodypart, "18", true)) format(string, sizeof(string), "Jew - 18");
  486. return string;
  487. }
  488. stock GetBodypartIDFromName(bodypart[])
  489. {
  490. if(!strcmp(bodypart, "0", true)) return -1;
  491. if(!strcmp(bodypart, "Spine", true) || strval(bodypart) == 1) return 1;
  492. if(!strcmp(bodypart, "Head", true) || strval(bodypart) == 2) return 2;
  493. if(!strcmp(bodypart, "Left upper arm", true) || strval(bodypart) == 3) return 3;
  494. if(!strcmp(bodypart, "Right upper arm", true) || strval(bodypart) == 4) return 4;
  495. if(!strcmp(bodypart, "Left hand", true) || strval(bodypart) == 5) return 5;
  496. if(!strcmp(bodypart, "Right hand", true) || strval(bodypart) == 6) return 6;
  497. if(!strcmp(bodypart, "Left thigh ", true) || strval(bodypart) == 7) return 7;
  498. if(!strcmp(bodypart, "Right thigh ", true) || strval(bodypart) == 8) return 8;
  499. if(!strcmp(bodypart, "Left foot", true) || strval(bodypart) == 9) return 9;
  500. if(!strcmp(bodypart, "Right foot", true) || strval(bodypart) == 10) return 10;
  501. if(!strcmp(bodypart, "Left calf ", true) || strval(bodypart) == 11) return 11;
  502. if(!strcmp(bodypart, "Right calf ", true) || strval(bodypart) == 12) return 12;
  503. if(!strcmp(bodypart, "Left forearm", true) || strval(bodypart) == 13) return 13;
  504. if(!strcmp(bodypart, "Right forearm ", true) || strval(bodypart) == 14) return 14;
  505. if(!strcmp(bodypart, "Left clavicle ", true) || strval(bodypart) == 15) return 15;
  506. if(!strcmp(bodypart, "Right clavicle ", true) || strval(bodypart) == 16) return 16;
  507. if(!strcmp(bodypart, "Neck", true) || strval(bodypart) == 17) return 17;
  508. if(!strcmp(bodypart, "Jew", true) || strval(bodypart) == 18) return 18;
  509. else return -1;
  510. }
  511. dcmd_rotateallobject(playerid, params[])
  512. {
  513. if(IsPlayerAdmin(playerid))
  514. {
  515. new Float:rX, Float:rY, Float:rZ, string[128];
  516. if(sscanf(params, "F(0)F(0)F(0)", rX, rY, rZ)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /rotateallobject (rotX) (rotY) (rotZ)");
  517. else
  518. {
  519. Loop(o, MAX_OBJECTS)
  520. {
  521. if(ObjectCreator[o] == playerid)
  522. {
  523. SetObjectRot(o, rX, rY, rZ);
  524. oRot[o][0] = rX, oRot[o][1] = rY, oRot[o][2] = rZ;
  525. }
  526. }
  527. format(string, sizeof(string), "All of your objects have been rotated. New rotation: X: %0.2f | Y: %0.2f | Z: %0.2f.", rX, rY, rZ);
  528. SendClientMessage(playerid, COLOUR_INFO, string);
  529. }
  530. return 1;
  531. }
  532. else return 0;
  533. }
  534. dcmd_destroyobject(playerid, params[])
  535. {
  536. if(IsPlayerAdmin(playerid))
  537. {
  538. new objectid, string[128];
  539. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /destroyobject (object id)");
  540. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  541. else
  542. {
  543. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  544. {
  545. new o = Objects[playerid][objectid];
  546. if(ModelID[o] != -1)
  547. {
  548. DestroyObject(o);
  549. ModelID[o] = -1;
  550. }
  551. ObjectCreator[o] = INVALID_PLAYER_ID;
  552. oOffset[o][0] = -1, oOffset[o][1] = -1, oOffset[o][2] = -1;
  553. oPos[o][0] = -1, oPos[o][1] = -1, oPos[o][2] = -1;
  554. oRot[o][0] = -1, oRot[o][1] = -1, oRot[o][2] = -1;
  555. AttachedVehicle[o] = INVALID_VEHICLE_ID, AttachedPlayer[o] = INVALID_PLAYER_ID;
  556. format(string, sizeof(string), "Object ID %d destroyed.", objectid);
  557. SendClientMessage(playerid, COLOUR_INFO, string);
  558. Objects[playerid][objectid] = INVALID_OBJECT_ID;
  559. }
  560. }
  561. return 1;
  562. }
  563. else return 0;
  564. }
  565. dcmd_destroyallobject(playerid, params[])
  566. {
  567. #pragma unused params
  568. if(IsPlayerAdmin(playerid))
  569. {
  570. if(GetFreeObjectID(playerid) >= GOBJ_MAX_OBJECTS_CREATED-1) return SendClientMessage(playerid, COLOUR_SYSTEM, "You haven't created any objects.");
  571. else
  572. {
  573. Loop(o, MAX_OBJECTS)
  574. {
  575. if(ObjectCreator[o] == playerid)
  576. {
  577. if(ModelID[o] != -1)
  578. {
  579. DestroyObject(o);
  580. ModelID[o] = -1;
  581. }
  582. ObjectCreator[o] = INVALID_PLAYER_ID;
  583. oOffset[o][0] = -1, oOffset[o][1] = -1, oOffset[o][2] = -1;
  584. oPos[o][0] = -1, oPos[o][1] = -1, oPos[o][2] = -1;
  585. oRot[o][0] = -1, oRot[o][1] = -1, oRot[o][2] = -1;
  586. AttachedVehicle[o] = INVALID_VEHICLE_ID, AttachedPlayer[o] = INVALID_PLAYER_ID;
  587. }
  588. }
  589. Loop(o2, GOBJ_MAX_OBJECTS_CREATED)
  590. {
  591. Objects[playerid][o2] = INVALID_OBJECT_ID;
  592. }
  593. SendClientMessage(playerid, COLOUR_SYSTEM, "All of your objects have been destroyed.");
  594. return 1;
  595. }
  596. }
  597. else return 0;
  598. }
  599. dcmd_stopobject(playerid, params[])
  600. {
  601. if(IsPlayerAdmin(playerid))
  602. {
  603. new objectid, string[128];
  604. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /stopobject (object id)");
  605. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  606. else
  607. {
  608. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  609. {
  610. new o = Objects[playerid][objectid];
  611. StopObject(o);
  612. GetObjectPos(o, oPos[o][0], oPos[o][1], oPos[o][2]);
  613. format(string, sizeof(string), "You have stopped the movement of object ID %d.", objectid);
  614. SendClientMessage(playerid, COLOUR_INFO, string);
  615. }
  616. }
  617. return 1;
  618. }
  619. else return 0;
  620. }
  621. dcmd_stopallobject(playerid, params[])
  622. {
  623. #pragma unused params
  624. if(IsPlayerAdmin(playerid))
  625. {
  626. Loop(o, MAX_OBJECTS)
  627. {
  628. if(ObjectCreator[o] == playerid)
  629. {
  630. StopObject(o);
  631. GetObjectPos(o, oPos[o][0], oPos[o][1], oPos[o][2]);
  632. }
  633. }
  634. return 1;
  635. }
  636. else return 0;
  637. }
  638. dcmd_moveobject(playerid, params[])
  639. {
  640. if(IsPlayerAdmin(playerid))
  641. {
  642. new objectid, direction[6], Float:amount, Float:speed, string[128];
  643. if(sscanf(params, "ds[6]F(10)F(10)", objectid, direction, amount, speed)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /moveobject (object id) (direction) (amount) (speed) - Accepted directions are: north, south, east, west, up and down.");
  644. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  645. if(strlen(direction) < 2 || strlen(direction) > 5) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid direction. Accepted directions are: north, south, east, west, up and down.");
  646. if(strcmp(direction, "north", true) && strcmp(direction, "south", true) && strcmp(direction, "east", true) && strcmp(direction, "west", true) && strcmp(direction, "up", true) && strcmp(direction, "down", true)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid direction. Accepted directions are: north, south, east, west, up and down.");
  647. else
  648. {
  649. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  650. {
  651. new o = Objects[playerid][objectid];
  652. GetObjectPos(o, X, Y, Z);
  653. if(!strcmp(direction, "north", true)) MoveObject(o, X, Y+amount, Z, speed), oPos[o][1]+=amount;
  654. if(!strcmp(direction, "south", true)) MoveObject(o, X, Y-amount, Z, speed), oPos[o][1]-=amount;
  655. if(!strcmp(direction, "east", true)) MoveObject(o, X+amount, Y, Z, speed), oPos[o][0]+=amount;
  656. if(!strcmp(direction, "west", true)) MoveObject(o, X-amount, Y, Z, speed), oPos[o][0]-=amount;
  657. if(!strcmp(direction, "up", true)) MoveObject(o, X, Y, Z+amount, speed), oPos[o][2]+=amount;
  658. if(!strcmp(direction, "down", true)) MoveObject(o, X, Y, Z-amount, speed), oPos[o][2]-=amount;
  659. format(string, sizeof(string), "Object ID %d moved. Direction: %s (%d meters, %0.2f speed).", objectid, direction, speed);
  660. SendClientMessage(playerid, COLOUR_INFO, string);
  661. }
  662. }
  663. return 1;
  664. }
  665. else return 0;
  666. }
  667. dcmd_moveallobject(playerid, params[])
  668. {
  669. if(IsPlayerAdmin(playerid))
  670. {
  671. new direction[6], Float:amount, Float:speed, string[128], count;
  672. if(sscanf(params, "s[6]F(10)F(10)", direction, amount, speed)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /moveallobject (direction) (amount) (speed) - Accepted directions are: north, south, east, west, up and down.");
  673. if(strlen(direction) < 2 || strlen(direction) > 5) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid direction. Accepted directions are: north, south, east, west, up and down.");
  674. if(strcmp(direction, "north", true) && strcmp(direction, "south", true) && strcmp(direction, "east", true) && strcmp(direction, "west", true) && strcmp(direction, "up", true) && strcmp(direction, "down", true)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid direction. Accepted directions are: north, south, east, west, up and down.");
  675. else
  676. {
  677. Loop(o, MAX_OBJECTS)
  678. {
  679. if(ObjectCreator[o] == playerid)
  680. {
  681. GetObjectPos(o, X, Y, Z);
  682. if(!strcmp(direction, "north", true)) MoveObject(o, X, Y+amount, Z, speed), oPos[o][1]+=amount;
  683. if(!strcmp(direction, "south", true)) MoveObject(o, X, Y-amount, Z, speed), oPos[o][1]-=amount;
  684. if(!strcmp(direction, "east", true)) MoveObject(o, X+amount, Y, Z, speed), oPos[o][0]+=amount;
  685. if(!strcmp(direction, "west", true)) MoveObject(o, X-amount, Y, Z, speed), oPos[o][0]-=amount;
  686. if(!strcmp(direction, "up", true)) MoveObject(o, X, Y, Z+amount, speed), oPos[o][2]+=amount;
  687. if(!strcmp(direction, "down", true)) MoveObject(o, X, Y, Z-amount, speed), oPos[o][2]-=amount;
  688. count++;
  689. }
  690. }
  691. format(string, sizeof(string), "Moved %d objects. Direction: %s (%d meters, %0.2f speed).", count, direction, speed);
  692. SendClientMessage(playerid, COLOUR_INFO, string);
  693. }
  694. return 1;
  695. }
  696. else return 0;
  697. }
  698. dcmd_startobjectloop(playerid, params[])
  699. {
  700. if(IsPlayerAdmin(playerid))
  701. {
  702. new objectid, Float:Pos[6], Float:speed, string[128];
  703. if(sscanf(params, "dffffffF(10.0)", objectid, Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5], speed)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /startobjectloop (object id) (x1) (y1) (z1) (x2) (y2) (z2) (speed)");
  704. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  705. else
  706. {
  707. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  708. {
  709. new o = Objects[playerid][objectid];
  710. SetObjectPos(o, Pos[0], Pos[1], Pos[2]);
  711. oMoving[o] = 1, oLap[o] = 1, oMSpeed[o] = speed;
  712. oStart[o][0] = Pos[0], oStart[o][1] = Pos[1], oStart[o][2] = Pos[2];
  713. oEnd[o][0] = Pos[3], oEnd[o][1] = Pos[4], oEnd[o][2] = Pos[5];
  714. MoveObject(o, Pos[3], Pos[4], Pos[5], speed);
  715. format(string, sizeof(string), "Object loop for object ID %d started.", objectid);
  716. SendClientMessage(playerid, COLOUR_INFO, string);
  717. }
  718. }
  719. return 1;
  720. }
  721. else return 0;
  722. }
  723. dcmd_startallobjectloop(playerid, params[])
  724. {
  725. if(IsPlayerAdmin(playerid))
  726. {
  727. new Float:Pos[6], Float:speed, string[128], count;
  728. if(sscanf(params, "ffffffF(10.0)", Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5], speed)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /startallobjectloop (x1) (y1) (z1) (x2) (y2) (z2) (speed)");
  729. else
  730. {
  731. Loop(o, MAX_OBJECTS)
  732. {
  733. if(ObjectCreator[o] == playerid)
  734. {
  735. SetObjectPos(o, Pos[0], Pos[1], Pos[2]);
  736. oMoving[o] = 1, oLap[o] = 1, oMSpeed[o] = speed;
  737. oStart[o][0] = Pos[0], oStart[o][1] = Pos[1], oStart[o][2] = Pos[2];
  738. oEnd[o][0] = Pos[3], oEnd[o][1] = Pos[4], oEnd[o][2] = Pos[5];
  739. MoveObject(o, Pos[3], Pos[4], Pos[5], speed);
  740. count++;
  741. }
  742. }
  743. format(string, sizeof(string), "Object loop for %d objects started.", count);
  744. SendClientMessage(playerid, COLOUR_INFO, string);
  745. }
  746. return 1;
  747. }
  748. else return 0;
  749. }
  750. dcmd_stopobjectloop(playerid, params[])
  751. {
  752. if(IsPlayerAdmin(playerid))
  753. {
  754. new objectid, string[128];
  755. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /stopobjectloop (object id)");
  756. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  757. else
  758. {
  759. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  760. {
  761. oMoving[Objects[playerid][objectid]] = 0;
  762. StopObject(Objects[playerid][objectid]);
  763. format(string, sizeof(string), "Stopped the object loop for object ID %d.", objectid);
  764. SendClientMessage(playerid, COLOUR_INFO, string);
  765. }
  766. }
  767. return 1;
  768. }
  769. else return 0;
  770. }
  771. #if defined GO_DEBUG_CMDS
  772. dcmd_getmypos(playerid, params[])
  773. {
  774. if(IsPlayerAdmin(playerid))
  775. {
  776. new Float:Pos[3], string[128];
  777. switch(IsPlayerInAnyVehicle(playerid))
  778. {
  779. case 0:
  780. {
  781. GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  782. format(string, sizeof(string), "Position: X: %0.2f | Y: %0.2f | Z: %0.2f", Pos[0], Pos[1], Pos[2]);
  783. }
  784. case 1:
  785. {
  786. GetVehiclePos(GetPlayerVehicleID(playerid), Pos[0], Pos[1], Pos[2]);
  787. format(string, sizeof(string), "Position: X: %0.2f | Y: %0.2f | Z: %0.2f", Pos[0], Pos[1], Pos[2]);
  788. }
  789. }
  790. SendClientMessage(playerid, COLOUR_INFO, string);
  791. return 1;
  792. }
  793. }
  794. #endif
  795. dcmd_stopallobjectloop(playerid, params[])
  796. {
  797. #pragma unused params
  798. if(IsPlayerAdmin(playerid))
  799. {
  800. new string[128], count;
  801. Loop(o, MAX_OBJECTS)
  802. {
  803. if(ObjectCreator[o] == playerid)
  804. {
  805. oMoving[o] = 0;
  806. StopObject(o);
  807. count++;
  808. }
  809. }
  810. format(string, sizeof(string), "Stopped the object loop for %d objects.", count);
  811. SendClientMessage(playerid, COLOUR_INFO, string);
  812. return 1;
  813. }
  814. else return 0;
  815. }
  816. public OnObjectMoved(objectid)
  817. {
  818. if(oMoving[objectid] == 1)
  819. {
  820. switch(oLap[objectid])
  821. {
  822. case 0:
  823. {
  824. MoveObject(objectid, oEnd[objectid][0], oEnd[objectid][1], oEnd[objectid][2], oMSpeed[objectid]);
  825. oLap[objectid] = 1;
  826. }
  827. case 1:
  828. {
  829. MoveObject(objectid, oStart[objectid][0], oStart[objectid][1], oStart[objectid][2], oMSpeed[objectid]);
  830. oLap[objectid] = 0;
  831. }
  832. }
  833. }
  834. return 1;
  835. }
  836. dcmd_getobject(playerid, params[])
  837. {
  838. if(IsPlayerAdmin(playerid))
  839. {
  840. new objectid;
  841. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /getobject (object id)");
  842. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  843. else
  844. {
  845. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  846. {
  847. new o = Objects[playerid][objectid];
  848. GetPlayerPos(playerid, X, Y, Z);
  849. SetObjectPos(o, X, Y, Z);
  850. GetObjectPos(o, oPos[o][0], oPos[o][1], oPos[o][2]);
  851. }
  852. }
  853. return 1;
  854. }
  855. else return 0;
  856. }
  857. dcmd_getallobject(playerid, params[])
  858. {
  859. #pragma unused params
  860. if(IsPlayerAdmin(playerid))
  861. {
  862. GetPlayerPos(playerid, X, Y, Z);
  863. Loop(o, MAX_OBJECTS)
  864. {
  865. if(ObjectCreator[o] == playerid)
  866. {
  867. SetObjectPos(o, X, Y, Z);
  868. GetObjectPos(o, oPos[o][0], oPos[o][1], oPos[o][2]);
  869. }
  870. }
  871. return 1;
  872. }
  873. else return 0;
  874. }
  875. dcmd_objecttele(playerid, params[])
  876. {
  877. if(IsPlayerAdmin(playerid))
  878. {
  879. new objectid;
  880. if(sscanf(params, "d", objectid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "Usage: /objecttele (objectid)");
  881. if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT && !IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOUR_SYSTEM, "You need to spawn to be able to use this command.");
  882. if(objectid < 0 || objectid >= GOBJ_MAX_OBJECTS_CREATED-1 || Objects[playerid][objectid] == INVALID_OBJECT_ID) return SendClientMessage(playerid, COLOUR_SYSTEM, "Invalid object ID!");
  883. else
  884. {
  885. if(ObjectCreator[Objects[playerid][objectid]] == playerid)
  886. {
  887. GetObjectPos(Objects[playerid][objectid], X, Y, Z);
  888. SetPlayerPos(playerid, X, Y, Z+1);
  889. }
  890. }
  891. return 1;
  892. }
  893. else return 0;
  894. }
  895. dcmd_saveobject(playerid, params[])
  896. {
  897. #pragma unused params
  898. if(IsPlayerAdmin(playerid))
  899. {
  900. return ShowPlayerDialog(playerid, G_OBJ_DID, DIALOG_STYLE_INPUT, "{009900}GarObject - Object Saving", "{FF0000}Warning! {FFFFFF}You're about to save objects to a file.\nYou must include the .txt tag at the end of the filename.\nAll existing text in the file you're saving to will be overwritten.\n\nEnter the filename where you want to save the objects below:", "Save", "Cancel");
  901. }
  902. else return 0;
  903. }
  904. dcmd_loadobject(playerid, params[])
  905. {
  906. #pragma unused params
  907. if(IsPlayerAdmin(playerid))
  908. {
  909. return ShowPlayerDialog(playerid, (G_OBJ_DID+1), DIALOG_STYLE_INPUT, "{009900}GarObject - Object Loading", "{FF0000}Warning! {FFFFFF}You're about to load objects from a file.\nYou must include the .txt tag at the end of the filename.\n\nEnter the filename where you want to load the objects from below:", "Load", "Cancel");
  910. }
  911. else return 0;
  912. }
  913. dcmd_savehobject(playerid, params[])
  914. {
  915. #pragma unused params
  916. if(IsPlayerAdmin(playerid))
  917. {
  918. return ShowPlayerDialog(playerid, (G_OBJ_DID+2), DIALOG_STYLE_INPUT, "{009900}GarObject - Object Saving", "{FF0000}Warning! {FFFFFF}You're about to save objects to a file.\nYou must include the .txt tag at the end of the filename.\nAll existing text in the file you're saving to will be overwritten.\n\nEnter the filename where you want to save the objects below:", "Save", "Cancel");
  919. }
  920. else return 0;
  921. }
  922. dcmd_loadhobject(playerid, params[])
  923. {
  924. #pragma unused params
  925. if(IsPlayerAdmin(playerid))
  926. {
  927. return ShowPlayerDialog(playerid, (G_OBJ_DID+3), DIALOG_STYLE_INPUT, "{009900}GarObject - Object Loading", "{FF0000}Warning! {FFFFFF}You're about to load objects from a file.\nYou must include the .txt tag at the end of the filename.\n\nEnter the filename where you want to load the objects from below:", "Load", "Cancel");
  928. }
  929. else return 0;
  930. }
  931. dcmd_garobject(playerid, params[])
  932. {
  933. if(IsPlayerAdmin(playerid))
  934. {
  935. #pragma unused params
  936. #if !defined G_OBJ_USE_SHORTCUTS
  937. ShowPlayerDialog(playerid, (G_OBJ_DID+4), DIALOG_STYLE_MSGBOX, "{00BC00}GarObject {FF0000}v1.3 {00BC00}by {FF0000}[03]Garsino", "/createobject\n/destroy(all)object\n/rotate(all)object\n/stop(all)object\n/move(all)object\n/objecttele\n/(de)attachpobject\n/get(all)object\n/sethobj\n/(de)attachvobject\n/stop(all)hobj\n/copyobject\n/saveobject\n/loadobject\n/savehobject\n/loadhobject\n/start(all)objectloop\n/stop(all)objectloop\n\n{00BC00}Available at the {FF0000}SA:MP {00BC00}forum.", "Close", "");
  938. #endif
  939. #if defined G_OBJ_USE_SHORTCUTS
  940. new string[500];
  941. strcat(string, "/createobject\t\t/oc\n/destroy(all)object\t/od(all)\n/rotate(all)object\t/orot(all)\n/stop(all)object\t/os(all)\n/move(all)object\t/om(all)\n/objecttele\t\t/ot\n");
  942. strcat(string, "/(de)attachpobject\t/(de)apo\n/get(all)object\t\t/og(all)\n/sethobj\t\t/setho\n/(de)attachvobject\t/(de)avo\n/stop(all)hobj\t\t/stop(all)ho\n/copyobject\t\t/co\n/saveobject\t\t/so\n/loadobject\t\t/lo\n/savehobject\t\t/sho\n/loadhobject\t\t/lho\n/start(all)objectloop\t/s(all)ol\n/stop(all)objectloop\t/stop(all)ol\n\n{00BC00}Available at the {FF0000}SA:MP {00BC00}forum.");
  943. ShowPlayerDialog(playerid, (G_OBJ_DID+4), DIALOG_STYLE_MSGBOX, "{00BC00}GarObject {FF0000}v1.3 {00BC00}by {FF0000}[03]Garsino", string, "Close", "");
  944. #endif
  945. return 1;
  946. }
  947. else return 0;
  948. }
  949. #if defined G_OBJ_USE_SHORTCUTS
  950. dcmd_stopallol(playerid, params[]) return dcmd_stopallobjectloop(playerid, params);
  951. dcmd_stopol(playerid, params[]) return dcmd_stopobjectloop(playerid, params);
  952. dcmd_sallol(playerid, params[]) return dcmd_startallobjectloop(playerid, params);
  953. dcmd_sol(playerid, params[]) return dcmd_startobjectloop(playerid, params);
  954. dcmd_oc(playerid, params[]) return dcmd_createobject(playerid, params);
  955. dcmd_or(playerid, params[]) return dcmd_rotateobject(playerid, params);
  956. dcmd_apo(playerid, params[]) return dcmd_attachpobject(playerid, params);
  957. dcmd_deapo(playerid, params[]) return dcmd_deattachpobject(playerid, params);
  958. dcmd_avo(playerid, params[]) return dcmd_attachvobject(playerid, params);
  959. dcmd_deavo(playerid, params[]) return dcmd_deattachvobject(playerid, params);
  960. dcmd_orall(playerid, params[]) return dcmd_rotateallobject(playerid, params);
  961. dcmd_od(playerid, params[]) return dcmd_destroyobject(playerid, params);
  962. dcmd_odall(playerid, params[]) return dcmd_destroyallobject(playerid, params);
  963. dcmd_os(playerid, params[]) return dcmd_stopobject(playerid, params);
  964. dcmd_osall(playerid, params[]) return dcmd_stopallobject(playerid, params);
  965. dcmd_om(playerid, params[]) return dcmd_moveobject(playerid, params);
  966. dcmd_omall(playerid, params[]) return dcmd_moveallobject(playerid, params);
  967. dcmd_og(playerid, params[]) return dcmd_getobject(playerid, params);
  968. dcmd_ogall(playerid, params[]) return dcmd_getallobject(playerid, params);
  969. dcmd_ot(playerid, params[]) return dcmd_objecttele(playerid, params);
  970. dcmd_setho(playerid, params[]) return dcmd_sethobj(playerid, params);
  971. dcmd_stopho(playerid, params[]) return dcmd_stophobj(playerid, params);
  972. dcmd_stopallho(playerid, params[]) return dcmd_stopallhobj(playerid, params);
  973. dcmd_so(playerid, params[]) return dcmd_saveobject(playerid, params);
  974. dcmd_lo(playerid, params[]) return dcmd_loadobject(playerid, params);
  975. dcmd_sho(playerid, params[]) return dcmd_savehobject(playerid, params);
  976. dcmd_lho(playerid, params[]) return dcmd_loadhobject(playerid, params);
  977. dcmd_co(playerid, params[]) return dcmd_copyobject(playerid, params);
  978. dcmd_gobj(playerid, params[]) return dcmd_garobject(playerid, params);
  979. #endif
  980. stock GetFreeObjectID(playerid)
  981. {
  982. for(new a = 0; a < GOBJ_MAX_OBJECTS_CREATED; a++)
  983. {
  984. if(Objects[playerid][a] == INVALID_OBJECT_ID)
  985. {
  986. return a;
  987. }
  988. }
  989. return -1;
  990. }
  991. stock GetTotalNativeObjects()
  992. {
  993. new tmpcount = 0;
  994. Loop(o, MAX_OBJECTS)
  995. {
  996. if(IsValidObject(o))
  997. {
  998. tmpcount++;
  999. }
  1000. }
  1001. return tmpcount;
  1002. }
  1003. stock pNick(playerid)
  1004. {
  1005. new GFSnick[MAX_PLAYER_NAME];
  1006. GetPlayerName(playerid, GFSnick, MAX_PLAYER_NAME);
  1007. return GFSnick;
  1008. }
  1009. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  1010. {
  1011. if(dialogid == G_OBJ_DID && response)
  1012. {
  1013. return SaveObjectsToFile(playerid, inputtext);
  1014. }
  1015. if(dialogid == (G_OBJ_DID + 1) && response)
  1016. {
  1017. return LoadObjectsFromFile(playerid, inputtext);
  1018. }
  1019. if(dialogid == (G_OBJ_DID + 2) && response)
  1020. {
  1021. return SaveHObjectsToFile(playerid, inputtext);
  1022. }
  1023. if(dialogid == (G_OBJ_DID + 3) && response)
  1024. {
  1025. return LoadHObjectsFromFile(playerid, inputtext);
  1026. }
  1027. return 0;
  1028. }
  1029. stock SaveObjectsToFile(playerid, filename[], sendmsg = 1)
  1030. {
  1031. new File:gFile, string[158], count;
  1032. if(strlen(filename) < 4) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered is shorter than 4 characters. Minimum filename is 4 characters including the .txt extension.");
  1033. if(strfind(filename, ".txt", true) == -1) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
  1034. else
  1035. {
  1036. if(fexist(filename))
  1037. {
  1038. fremove(filename);
  1039. }
  1040. gFile = fopen(filename, io_write);
  1041. fclose(gFile);
  1042. gFile = fopen(filename, io_append);
  1043. Loop(o, MAX_OBJECTS)
  1044. {
  1045. if(ObjectCreator[o] == playerid && ModelID[o] != -1)
  1046. {
  1047. format(string, sizeof(string), "CreateObject(%d, %f, %f, %f, %f, %f, %f);\r\n", ModelID[o], oPos[o][0], oPos[o][1], oPos[o][2], oRot[o][0], oRot[o][1], oRot[o][2]);
  1048. fwrite(gFile, string);
  1049. DestroyObject(o);
  1050. ModelID[o] = -1;
  1051. count++;
  1052. }
  1053. }
  1054. fclose(gFile);
  1055. if(sendmsg == 1)
  1056. {
  1057. format(string, sizeof(string), "{009900}Save Successfull{FFFFFF}! Saved{009900} %d{FFFFFF} objects to {009900}%s{FFFFFF}.", count, filename);
  1058. SendClientMessage(playerid, COLOUR_INFO, string);
  1059. }
  1060. }
  1061. return 1;
  1062. }
  1063. stock LoadObjectsFromFile(playerid, filename[], sendmsg = 1)
  1064. {
  1065. new File:file_ptr, modelid, Float:pos[3], Float:rot[3], count, line[256];
  1066. if(strlen(filename) < 4) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered is shorter than 4 characters. Minimum filename is 4 characters including the .txt extension.");
  1067. if(strfind(filename, ".txt", true) == -1) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
  1068. if(!fexist(filename)) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}This file does not exist.");
  1069. else
  1070. {
  1071. file_ptr = fopen(filename, io_read);
  1072. while(fread(file_ptr, line) > 0)
  1073. {
  1074. if(GetTotalNativeObjects() >= (MAX_OBJECTS-1)) return SendClientMessage(playerid, COLOUR_SYSTEM, "The SA:MP object limit has been reached. You can not spawn any more objects.");
  1075. if(GetFreeObjectID(playerid) < 0) return SendClientMessage(playerid, COLOUR_SYSTEM, "You can not spawn any more objects. Please delete one of the current ones first.");
  1076. if(!sscanf(line, "p<,>'('ifffffp<)>f", modelid, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]))
  1077. {
  1078. new obj = GetFreeObjectID(playerid);
  1079. Objects[playerid][obj] = CreateObject(modelid, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
  1080. new o = Objects[playerid][obj];
  1081. ObjectCreator[o] = playerid, ModelID[o] = modelid, oPos[o][0] = pos[0], oPos[o][1] = pos[1], oPos[o][2] = pos[2], oRot[o][0] = rot[0], oRot[o][1] = rot[1], oRot[o][2] = rot[2], AttachedVehicle[o] = INVALID_VEHICLE_ID, AttachedPlayer[o] = INVALID_PLAYER_ID;
  1082. count++;
  1083. }
  1084. }
  1085. fclose(file_ptr);
  1086. if(sendmsg == 1)
  1087. {
  1088. format(line, sizeof(line), "{009900}Load Successfull{FFFFFF}! Loaded{009900} %d{FFFFFF} objects from {009900}%s{FFFFFF}.", count, filename);
  1089. SendClientMessage(playerid, COLOUR_INFO, line);
  1090. }
  1091. }
  1092. return 1;
  1093. }
  1094. stock SetHOPVar(playerid, varname[], int_value, slot)
  1095. {
  1096. new string[128];
  1097. format(string, sizeof(string), "%s%d", varname, slot);
  1098. return SetPVarInt(playerid, string, int_value);
  1099. }
  1100. stock GetHOPVar(playerid, varname[], slot)
  1101. {
  1102. new string[128];
  1103. format(string, sizeof(string), "%s%d", varname, slot);
  1104. return GetPVarInt(playerid, string);
  1105. }
  1106. stock SetHOPFloat(playerid, varname[], Float:int_value, slot)
  1107. {
  1108. new string[128];
  1109. format(string, sizeof(string), "%s%d", varname, slot);
  1110. return SetPVarFloat(playerid, string, int_value);
  1111. }
  1112. stock Float:GetHOPFloat(playerid, varname[], slot)
  1113. {
  1114. new string[128];
  1115. format(string, sizeof(string), "%s%d", varname, slot);
  1116. return GetPVarFloat(playerid, string);
  1117. }
  1118. stock CountTotalHoldingObjects(playerid)
  1119. {
  1120. new count;
  1121. Loop(o, 5)
  1122. {
  1123. if(IsPlayerAttachedObjectSlotUsed(playerid, o))
  1124. {
  1125. count++;
  1126. }
  1127. }
  1128. return count;
  1129. }
  1130. stock SaveHObjectsToFile(pid, filename[], sendmsg = 1)
  1131. {
  1132. new File:gFile, string[158], count;
  1133. if(strlen(filename) < 4) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered is shorter than 4 characters. Minimum filename is 4 characters including the .txt extension.");
  1134. if(strfind(filename, ".txt", true) == -1) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
  1135. if(CountTotalHoldingObjects(pid) == 0) return SendClientMessage(pid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}You do not have any objects to save.");
  1136. else
  1137. {
  1138. if(fexist(filename))
  1139. {
  1140. fremove(filename);
  1141. }
  1142. gFile = fopen(filename, io_write);
  1143. fclose(gFile);
  1144. gFile = fopen(filename, io_append);
  1145. Loop(o, 5)
  1146. {
  1147. if(IsPlayerAttachedObjectSlotUsed(pid, o))
  1148. {
  1149. format(string, sizeof(string), "SetPlayerAttachedObject(playerid, %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f);\r\n", GetHOPVar(pid, "HOIndex", o), GetHOPVar(pid, "HOModel", o), GetHOPVar(pid, "HOBone", o), GetHOPFloat(pid, "HOOX", o), GetHOPFloat(pid, "HOOY", o), GetHOPFloat(pid, "HOOZ", o), GetHOPFloat(pid, "HORX", o), GetHOPFloat(pid, "HORY", o), GetHOPFloat(pid, "HORZ", o), GetHOPFloat(pid, "HOSX", o), GetHOPFloat(pid, "HOSY", o), GetHOPFloat(pid, "HOSZ", o));
  1150. print(string);
  1151. fwrite(gFile, string);
  1152. RemovePlayerAttachedObject(pid, o);
  1153. count++;
  1154. }
  1155. }
  1156. fclose(gFile);
  1157. if(sendmsg == 1)
  1158. {
  1159. format(string, sizeof(string), "{009900}Save Successfull{FFFFFF}! Saved{009900} %d{FFFFFF} objects to {009900}%s{FFFFFF}.", count, filename);
  1160. SendClientMessage(pid, COLOUR_INFO, string);
  1161. }
  1162. }
  1163. return 1;
  1164. }
  1165. stock LoadHObjectsFromFile(playerid, filename[], sendmsg = 1)
  1166. {
  1167. new File:file_ptr, modelid, bone, index, Float:o[3], Float:r[3], Float:s[3], count, line[256];
  1168. if(strlen(filename) < 4) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered is shorter than 4 characters. Minimum filename is 4 characters including the .txt extension.");
  1169. if(strfind(filename, ".txt", true) == -1) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}The filename you entered didn't have the .txt extension at the end. Please add it and continue.");
  1170. if(!fexist(filename)) return SendClientMessage(playerid, COLOUR_SYSTEM, "{FF0000}Error! {FFFFFF}This file does not exist.");
  1171. else
  1172. {
  1173. file_ptr = fopen(filename, io_read);
  1174. while(fread(file_ptr, line) > 0)
  1175. {
  1176. if(!sscanf(line, "p<,>'(playerid'dddffffffffp<)>f", index, modelid, bone, o[0], o[1], o[2], r[0], r[1], r[2], s[0], s[1], s[2]))
  1177. {
  1178. print(line);
  1179. SetPlayerAttachedObject(playerid, count, modelid, bone, o[0], o[1], o[2], r[0], r[1], r[2], s[0], s[1], s[2]);
  1180. SetHOPVar(playerid, "HOIndex", count, count);
  1181. SetHOPVar(playerid, "HOModel", modelid, count);
  1182. SetHOPVar(playerid, "HOBone", bone, count);
  1183. SetHOPFloat(playerid, "HOOX", o[0], count);
  1184. SetHOPFloat(playerid, "HOOY", o[1], count);
  1185. SetHOPFloat(playerid, "HOOZ", o[2], count);
  1186. SetHOPFloat(playerid, "HORX", r[0], count);
  1187. SetHOPFloat(playerid, "HORY", r[1], count);
  1188. SetHOPFloat(playerid, "HORZ", r[2], count);
  1189. SetHOPFloat(playerid, "HOSX", s[0], count);
  1190. SetHOPFloat(playerid, "HOSY", s[1], count);
  1191. SetHOPFloat(playerid, "HOSZ", s[2], count);
  1192. count++;
  1193. }
  1194. }
  1195. fclose(file_ptr);
  1196. if(sendmsg == 1)
  1197. {
  1198. format(line, sizeof(line), "{009900}Load Successfull{FFFFFF}! Loaded{009900} %d{FFFFFF} objects from {009900}%s{FFFFFF}.", count, filename);
  1199. SendClientMessage(playerid, COLOUR_INFO, line);
  1200. }
  1201. }
  1202. return 1;
  1203. }
  1204. stock sscanf(string[], format[], {Float,_}:...)
  1205. {
  1206. new
  1207. formatPos = 0,
  1208. stringPos = 0,
  1209. paramPos = 2,
  1210. paramCount = numargs();
  1211. while (paramPos < paramCount && string[stringPos])
  1212. {
  1213. switch (format[formatPos++])
  1214. {
  1215. case '\0':
  1216. {
  1217. return 0;
  1218. }
  1219. case 'i', 'd':
  1220. {
  1221. new
  1222. neg = 1,
  1223. num = 0,
  1224. ch = string[stringPos];
  1225. if (ch == '-')
  1226. {
  1227. neg = -1;
  1228. ch = string[++stringPos];
  1229. }
  1230. do
  1231. {
  1232. stringPos++;
  1233. if (ch >= '0' && ch <= '9')
  1234. {
  1235. num = (num * 10) + (ch - '0');
  1236. }
  1237. else
  1238. {
  1239. return 1;
  1240. }
  1241. }
  1242. while ((ch = string[stringPos]) && ch != ' ');
  1243. setarg(paramPos, 0, num * neg);
  1244. }
  1245. case 'h', 'x':
  1246. {
  1247. new
  1248. ch,
  1249. num = 0;
  1250. while ((ch = string[stringPos++]))
  1251. {
  1252. switch (ch)
  1253. {
  1254. case 'x', 'X':
  1255. {
  1256. num = 0;
  1257. continue;
  1258. }
  1259. case '0' .. '9':
  1260. {
  1261. num = (num << 4) | (ch - '0');
  1262. }
  1263. case 'a' .. 'f':
  1264. {
  1265. num = (num << 4) | (ch - ('a' - 10));
  1266. }
  1267. case 'A' .. 'F':
  1268. {
  1269. num = (num << 4) | (ch - ('A' - 10));
  1270. }
  1271. case ' ':
  1272. {
  1273. break;
  1274. }
  1275. default:
  1276. {
  1277. return 1;
  1278. }
  1279. }
  1280. }
  1281. setarg(paramPos, 0, num);
  1282. }
  1283. case 'c':
  1284. {
  1285. setarg(paramPos, 0, string[stringPos++]);
  1286. }
  1287. case 'f':
  1288. {
  1289. new tmp[25];
  1290. strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
  1291. setarg(paramPos, 0, _:floatstr(tmp));
  1292. }
  1293. case 's', 'z':
  1294. {
  1295. new
  1296. i = 0,
  1297. ch;
  1298. if (format[formatPos])
  1299. {
  1300. while ((ch = string[stringPos++]) && ch != ' ')
  1301. {
  1302. setarg(paramPos, i++, ch);
  1303. }
  1304. if (!i) return 1;
  1305. }
  1306. else
  1307. {
  1308. while ((ch = string[stringPos++]))
  1309. {
  1310. setarg(paramPos, i++, ch);
  1311. }
  1312. }
  1313. stringPos--;
  1314. setarg(paramPos, i, '\0');
  1315. }
  1316. default:
  1317. {
  1318. continue;
  1319. }
  1320. }
  1321. while (string[stringPos] && string[stringPos] != ' ')
  1322. {
  1323. stringPos++;
  1324. }
  1325. while (string[stringPos] == ' ')
  1326. {
  1327. stringPos++;
  1328. }
  1329. paramPos++;
  1330. }
  1331. while (format[formatPos] == 'z') formatPos++;
  1332. return format[formatPos];
  1333. }