Advertisement
Guest User

Object Creator

a guest
Sep 15th, 2015
1,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. //////////////////////////////////////////
  2. // //
  3. // Script Created By DarkLored //
  4. // //
  5. //////////////////////////////////////////
  6.  
  7. #include <a_samp>
  8. #include <zcmd>
  9. #include <sscanf2>
  10. #include <streamer>
  11.  
  12. #define FILTERSCRIPT
  13.  
  14. new DB:Loot;
  15.  
  16. enum LootInfo
  17. {
  18. ObjectID,
  19. ObjectModelID,
  20. Float:ObjectX,
  21. Float:ObjectY,
  22. Float:ObjectZ,
  23. Float:ObjectRX,
  24. Float:ObjectRY,
  25. Float:ObjectRZ,
  26. ObjectVW,
  27. ObjectINT
  28. };
  29. new lInfo[MAX_OBJECTS][LootInfo];
  30.  
  31.  
  32. public OnFilterScriptInit()
  33. {
  34. LoadLoot();
  35. print("Dynamic Object Creator/Delete/Editor loaded! By DarkLored");
  36. return 1;
  37. }
  38.  
  39. public OnFilterScriptExit()
  40. {
  41. db_close(Loot);
  42. print("Filterscript Unloaded!");
  43. return 1;
  44. }
  45.  
  46. CMD:createobject(playerid, params[])
  47. {
  48. new objectmodelid, objectvw, objectint, Float:x, Float:y, Float:z, Query[500];
  49. if(sscanf(params, "ddd", objectmodelid, objectvw, objectint))
  50. {
  51. SendClientMessage(playerid, -1, "[USAGE]/createobject (modelid) (virtual world) (interior)");
  52. return 1;
  53. }
  54. GetPlayerPos(playerid, x, y, z);
  55. format(Query, sizeof(Query), "INSERT INTO loot (objmodelid, objx, objy, objz, objvw, objint) VALUES (%d, %f, %f, %f, %d, %d)", objectmodelid, x, y, z, objectvw, objectint);
  56. db_query(Loot, Query);
  57. print(Query);
  58. return 1;
  59. }
  60.  
  61. CMD:editobject(playerid, params[])
  62. {
  63. new objectid;
  64. if(sscanf(params, "d", objectid))
  65. {
  66. SendClientMessage(playerid, -1, "[USAGE]/editobject (objid)");
  67. return 1;
  68. }
  69. EditDynamicObject(playerid, objectid);
  70. return 1;
  71. }
  72.  
  73. CMD:spawnobject(playerid, params[])
  74. {
  75. new objectid, Query[500], DBResult:Result;
  76. if(sscanf(params, "d", objectid))
  77. {
  78. SendClientMessage(playerid, -1, "[USAGE]/spawnobject (objid)");
  79. return 1;
  80. }
  81. format(Query, sizeof(Query), "SELECT * FROM loot WHERE objid = %d", objectid);
  82. Result = db_query(Loot, Query);
  83. if(db_num_rows(Result))
  84. {
  85. db_get_field_assoc(Result, "objmodelid", Query, 7);
  86. lInfo[objectid][ObjectModelID] = strval(Query);
  87.  
  88. db_get_field_assoc(Result, "objx", Query, 60);
  89. lInfo[objectid][ObjectX] = floatstr(Query);
  90.  
  91. db_get_field_assoc(Result, "objy", Query, 60);
  92. lInfo[objectid][ObjectY] = floatstr(Query);
  93.  
  94. db_get_field_assoc(Result, "objz", Query, 60);
  95. lInfo[objectid][ObjectZ] = floatstr(Query);
  96.  
  97. db_get_field_assoc(Result, "objrx", Query, 60);
  98. lInfo[objectid][ObjectRX] = floatstr(Query);
  99.  
  100. db_get_field_assoc(Result, "objry", Query, 60);
  101. lInfo[objectid][ObjectRY] = floatstr(Query);
  102.  
  103. db_get_field_assoc(Result, "objrz", Query, 60);
  104. lInfo[objectid][ObjectRZ] = floatstr(Query);
  105.  
  106. db_get_field_assoc(Result, "objvw", Query, 7);
  107. lInfo[objectid][ObjectVW] = strval(Query);
  108.  
  109. db_get_field_assoc(Result, "objint", Query, 7);
  110. lInfo[objectid][ObjectINT] = strval(Query);
  111.  
  112. objectid = CreateDynamicObject(lInfo[objectid][ObjectModelID], lInfo[objectid][ObjectX], lInfo[objectid][ObjectY], lInfo[objectid][ObjectZ], lInfo[objectid][ObjectRX], lInfo[objectid][ObjectRY], lInfo[objectid][ObjectRZ], lInfo[objectid][ObjectVW], lInfo[objectid][ObjectINT], -1, 200.0);
  113.  
  114. db_free_result(Result);
  115. }
  116. else
  117. {
  118. SendClientMessage(playerid, -1, "Object does not exist.");
  119. db_free_result(Result);
  120. }
  121. return 1;
  122. }
  123.  
  124. CMD:destroyobject(playerid, params[])
  125. {
  126. new objectid, Query[500], DBResult:Result;
  127. if(sscanf(params, "d", objectid))
  128. {
  129. SendClientMessage(playerid, -1, "[USAGE]/destroyobject (objectid).");
  130. return 1;
  131. }
  132. if(IsValidDynamicObject(objectid))
  133. {
  134. format(Query, sizeof(Query), "DELETE FROM loot WHERE objid = %d", objectid);
  135. db_query(Loot, Query);
  136. print("Existing object destroyed");
  137.  
  138. DestroyDynamicObject(objectid);
  139. return 1;
  140. }
  141. else if(!IsValidDynamicObject(objectid))
  142. {
  143. format(Query, sizeof(Query), "SELECT * from loot WHERE objid = %d", objectid);
  144. Result = db_query(Loot, Query);
  145.  
  146. if(db_num_rows(Result))
  147. {
  148. format(Query, sizeof(Query), "DELETE FROM loot WHERE objid = %d", objectid);
  149. db_query(Loot, Query);
  150. print("None existing object deleted");
  151. }
  152. else
  153. {
  154. SendClientMessage(playerid, -1, "Object does not exist!");
  155. }
  156. db_free_result(Result);
  157. return 1;
  158. }
  159. return 1;
  160. }
  161.  
  162.  
  163. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  164. {
  165. new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ, Query[800];
  166. GetObjectPos(objectid, oldX, oldY, oldZ);
  167. GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
  168. if(!playerobject)
  169. {
  170. if(!IsValidObject(objectid)) return 1;
  171. SetObjectPos(objectid, fX, fY, fZ);
  172. SetObjectRot(objectid, fRotX, fRotY, fRotZ);
  173. }
  174. if(response == EDIT_RESPONSE_UPDATE)
  175. {
  176. GetObjectPos(objectid, fX, fY, fZ);
  177. GetObjectRot(objectid, fRotX, fRotY, fRotZ);
  178. }
  179. if(response == EDIT_RESPONSE_FINAL)
  180. {
  181. GetObjectPos(objectid, fX, fY, fZ);
  182. GetObjectRot(objectid, fRotX, fRotY, fRotZ);
  183.  
  184. format(Query, sizeof(Query), "UPDATE loot SET objx = %f, objy = %f, objz = %f, objrx = %f, objry = %f, objrz = %f WHERE objid = %d",
  185. fX, fY, fZ, fRotX, fRotY, fRotZ, objectid);
  186. db_query(Loot, Query);
  187. print(Query);
  188. }
  189.  
  190. if(response == EDIT_RESPONSE_CANCEL)
  191. {
  192. if(!playerobject)
  193. {
  194. SetObjectPos(objectid, oldX, oldY, oldZ);
  195. SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
  196. }
  197. else
  198. {
  199. SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
  200. SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
  201. }
  202. }
  203. return 1;
  204. }
  205.  
  206. LoadLoot()
  207. {
  208. new Query[800];
  209. Loot = db_open("loot.db");
  210. strcat(Query, "CREATE TABLE IF NOT EXISTS loot (objid INTEGER PRIMARY KEY AUTOINCREMENT, objmodelid INTEGER DEFAULT 0 NOT NULL, objx FLOAT DEFAULT 0.0 NOT NULL, objy FLOAT DEFAULT 0.0 NOT NULL,", sizeof(Query));
  211. strcat(Query, "objz FLOAT DEFAULT 0.0 NOT NULL, objrx FLOAT DEFAULT 0.0 NOT NULL, objry FLOAT DEFAULT 0.0 NOT NULL, objrz FLOAT DEFAULT 0.0 NOT NULL, objvw INTEGER DEFAULT 0 NOT NULL, objint INTEGER DEFAULT 0 NOT NULL )", sizeof(Query));
  212. db_query(Loot, Query);
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement