Guest User

[SA-MP] Teleport Maker [YINI] Save/Load [0.3x]

a guest
Mar 13th, 2013
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.38 KB | None | 0 0
  1. /*
  2.  
  3. Teleport Maker [Checkpoints] - Save/Load [YINI]
  4.  
  5. Credits to
  6.  
  7. Romel, Y_Less
  8.  
  9. Gagi for the GetCloset function.
  10.  
  11. Commands:
  12.  
  13. /createtele [id] [Name]
  14.  
  15. Then you will go to place where you want the player to be teleported. Then type
  16.  
  17. /finishtele [interior] [world]. Then done
  18.  
  19. to end the teleport creating/cancel it. Do /canceltele.
  20.  
  21. /deletemode - Enables Delete Mod/Disables Delete Mod
  22.  
  23. /removetele - Remove the closset Teleport Checkpoints (You need to enable the Delete Mod First)
  24.  
  25. /gototele [id] - Goto the Teleport ID
  26.  
  27. /instruction
  28.  
  29. /tcmds
  30.  
  31. Note: Delete Mod allows you to walk through teleport checkpoints
  32. so that you will not be teleported!
  33.  
  34. */
  35.  
  36. #include <a_samp>
  37. #include <sscanf2>
  38. #include <YSI\y_ini>
  39. #include <YSI\y_commands>
  40. #include <streamer>
  41.  
  42. #define FILTERSCRIPT
  43.  
  44. #define DISTANCE_PER_TELE 20.0
  45. #define MAPICON_PER_TELE 35
  46. #define CPSIZE_PER_TELE 2.0
  47.  
  48. #define TeleportFile "telefile/%i.ini" //Change the path if needed
  49.  
  50. #define COLOR_RED 0xFF0000FF
  51. #define COLOR_RED2 0xE01B4CFF
  52.  
  53. #define SCM SendClientMessage
  54.  
  55. #define COL_YELLOW "{F5E618}"
  56. #define COL_GREEN "{2EAD15}"
  57.  
  58. #define MAX_TELEPORTS 500 //More value, More AMX Size
  59.  
  60. enum E_TELEPORT_DATA
  61. {
  62. Text3D:Label[128],
  63. Name[128],
  64. CP,
  65. Icon,
  66. World,
  67. Interior,
  68. Float:cX,
  69. Float:cY,
  70. Float:cZ,
  71. Float:pX,
  72. Float:pY,
  73. Float:pZ,
  74. Float:pA,
  75. pInterior,
  76. pWorld
  77. };
  78. new TeleData[MAX_TELEPORTS][E_TELEPORT_DATA];
  79. new tFile[256],
  80. Float:myPos[3],
  81. myWor,
  82. myInt,
  83. paname[128],
  84. paid,
  85. Process[MAX_PLAYERS],
  86. DeleteMod[MAX_PLAYERS],
  87. CurCP,
  88. CountT = 0,
  89. CurIcon;
  90.  
  91. //==============================================================================
  92.  
  93. #if defined FILTERSCRIPT
  94.  
  95. public OnFilterScriptInit()
  96. {
  97. print("\n");
  98. print("[0.3x] Teleport Maker w/ Checkpoints - Save/Load [YINI]");
  99. print("Provides Label, Very Cool Teleport Maker Designer!");
  100. print("Loaded, with the includes of: Y_INI, Y_COMMAND, A_SAMP, SSCANF2, STREAMER");
  101. print("\n");
  102. for(new i = 0; i <= MAX_TELEPORTS; i++)
  103. {
  104. format(tFile, sizeof tFile, TeleportFile, i);
  105. if(fexist(tFile))
  106. {
  107. INI_ParseFile(tFile, "LoadTeleport", .bExtra = true, .extra = i);
  108. ReadTeleport(i);
  109. CountT += 1;
  110. }
  111. }
  112. printf("Total Teleports: %i", CountT);
  113. return 1;
  114. }
  115.  
  116. public OnFilterScriptExit()
  117. {
  118. print("\n");
  119. print("[0.3x] Teleport Maker w/ Checkpoints - Save/Load [YINI]");
  120. print("Provides Label, Very Cool Teleport Maker Designer!");
  121. print("Unloaded, with the includes of: Y_INI, Y_COMMAND, A_SAMP, SSCANF2, STREAMER");
  122. print("\n");
  123. for(new i = 0; i < MAX_TELEPORTS; i++)
  124. {
  125. format(tFile, sizeof tFile, TeleportFile, i);
  126. if(fexist(tFile))
  127. {
  128. INI_ParseFile(tFile, "LoadTeleport", .bExtra = true, .extra = i);
  129. UnloadTeleport(i);
  130. }
  131. }
  132. return 1;
  133. }
  134.  
  135. #endif
  136.  
  137. public OnPlayerConnect(playerid)
  138. {
  139. Process[playerid] = 0;
  140. DeleteMod[playerid] = 0;
  141. return 1;
  142. }
  143.  
  144. public OnPlayerDisconnect(playerid, reason)
  145. {
  146. Process[playerid] = 0;
  147. DeleteMod[playerid] = 0;
  148. return 1;
  149. }
  150.  
  151. public OnPlayerDeath(playerid, killerid, reason)
  152. {
  153. if(DeleteMod[playerid] == 1) DeleteMod[playerid] = 0;
  154. if(Process[playerid] == 1)
  155. {
  156. DestroyDynamicCP(CurCP);
  157. DestroyDynamicMapIcon(CurIcon);
  158. Process[playerid] = 0;
  159. }
  160. return 1;
  161. }
  162.  
  163. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  164. {
  165. for(new i = 0; i < MAX_TELEPORTS; i++)
  166. {
  167. if(checkpointid == TeleData[i][CP])
  168. {
  169. if(DeleteMod[playerid] == 1)
  170. {
  171. SCM(playerid, -1, "/removetele, To remove this teleport checkpoint!");
  172. SCM(playerid, -1, "If you don't want to remove this, Skip this checkpoint");
  173. return 1;
  174. }
  175. if(!IsPlayerInAnyVehicle(playerid))
  176. {
  177. SetCameraBehindPlayer(playerid);
  178. SetPlayerInterior(playerid, TeleData[i][pInterior]);
  179. SetPlayerVirtualWorld(playerid, TeleData[i][pWorld]);
  180. SetPlayerPos(playerid, TeleData[i][pX], TeleData[i][pY], TeleData[i][pZ]);
  181. SetPlayerFacingAngle(playerid, TeleData[i][pA]);
  182. }
  183. }
  184. }
  185. if(checkpointid == CurCP) return 1;
  186. SCM(playerid, -1, "Teleported Successfully!");
  187. return 1;
  188. }
  189.  
  190. forward LoadTeleport(id, name[], value[]);
  191. public LoadTeleport(id, name[], value[])
  192. {
  193. INI_String("TeleName", TeleData[id][Name], 128);
  194. INI_Int("TeleWorld", TeleData[id][World]);
  195. INI_Int("TeleInterior", TeleData[id][Interior]);
  196. INI_Float("TeleX", TeleData[id][cX]);
  197. INI_Float("TeleY", TeleData[id][cY]);
  198. INI_Float("TeleZ", TeleData[id][cZ]);
  199. INI_Float("PlayerX", TeleData[id][pX]);
  200. INI_Float("PlayerY", TeleData[id][pY]);
  201. INI_Float("PlayerZ", TeleData[id][pZ]);
  202. INI_Float("PlayerA", TeleData[id][pA]);
  203. INI_Int("PlayerWorld", TeleData[id][pWorld]);
  204. INI_Int("PlayerInterior", TeleData[id][pInterior]);
  205. return 1;
  206. }
  207.  
  208. //==============================================================================
  209.  
  210. YCMD:instructions(playerid, params[], help)
  211. {
  212. #pragma unused help
  213. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be RCON admin");
  214. SCM(playerid, -1, "Teleport Maker [YINI] - Save/Load by Romel Instruction (v1.0):");
  215. SCM(playerid, COLOR_RED2, "To create teleports, /createtele, Make sure you're rcon login!");
  216. SCM(playerid, COLOR_RED2, "After typing the command, It will send a USAGE message ''USAGE: /createtele [ID] [Name]''");
  217. SCM(playerid, COLOR_RED2, "The ID will be the Teleport ID, and the Name will be the teleports name, example ''/createtele 0 My Teleport''");
  218. SCM(playerid, COLOR_RED2, "After doing that step, The create system, will ask you, to go to the position where player will be teleported when entered the checkpoint");
  219. SCM(playerid, COLOR_RED2, "If you're already in the position, Just do /finishtele, Oopppss the command usage is wrong. It must be ''/finishtele [interior] [world]''");
  220. SCM(playerid, COLOR_RED2, "Just do /finishtele 0 0 (Interior 0: Whole SAN ANDREAS INTERIOR) | (World 0: Main Virtual World), Now you can start your own one!");
  221. SCM(playerid, COLOR_RED2, "if you want to remove the previous teleport, Do /deletemode, Then go to the checkpoint position, Then type, /removetele");
  222. SCM(playerid, COLOR_RED2, "To go to the teleport checkpoint, do /gototele [ID], to cancel the teleport making, Just do /canceltele");
  223. return 1;
  224. }
  225.  
  226. YCMD:tcmds(playerid, params[], help)
  227. {
  228. #pragma unused help
  229. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be RCON admin");
  230. SCM(playerid, -1, "Teleport Maker [YINI] - Save/Load by Romel Commands (v1.0):");
  231. SCM(playerid, COLOR_RED2, "/createtele, /removetele, /gototele, /deletemode, /finishtele /canceltele");
  232. return 1;
  233. }
  234.  
  235. YCMD:gototele(playerid, params[], help)
  236. {
  237. #pragma unused help
  238. new id;
  239. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be RCON admin");
  240. if(sscanf(params, "i", id)) return SCM(playerid, COLOR_RED, "USAGE: /gototele [ID]");
  241. format(tFile, sizeof tFile, TeleportFile, id);
  242. if(!fexist(tFile)) return SCM(playerid, COLOR_RED, "ERROR: There is no Teleport on that id.");
  243. SetPlayerPos(playerid, TeleData[id][cX]+2, TeleData[id][cY], TeleData[id][cZ]);
  244. return 1;
  245. }
  246.  
  247. YCMD:removetele(playerid, params[], help)
  248. {
  249. #pragma unused help
  250. #pragma unused params
  251. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be RCON admin");
  252. new t = GetClosetTeleID(playerid);
  253. if(DeleteMod[playerid] == 0) return SCM(playerid, COLOR_RED, "ERROR: You must enable Delete Mod first before removing teleports!");
  254. if(t == -1) return SCM(playerid, COLOR_RED, "ERROR: There is no teleport checkpoint");
  255. format(tFile, sizeof tFile, TeleportFile, t);
  256. if(fexist(tFile))
  257. {
  258. fremove(tFile);
  259. DestroyDynamicCP(TeleData[t][CP]);
  260. DestroyDynamic3DTextLabel(TeleData[t][Label]);
  261. DestroyDynamicMapIcon(TeleData[t][Icon]);
  262. }
  263. return 1;
  264. }
  265.  
  266. YCMD:deletemode(playerid, params[], help)
  267. {
  268. #pragma unused help
  269. if(DeleteMod[playerid] == 0)
  270. {
  271. DeleteMod[playerid] = 1;
  272. SCM(playerid, -1, "Delete Mod Enable!");
  273. SCM(playerid, -1, "You're now able to delete teleports with /removetele");
  274. SCM(playerid, -1, "Go to the Teleport Checkpoint then type /removetele");
  275. }
  276. else if(DeleteMod[playerid] == 1)
  277. {
  278. DeleteMod[playerid] = 0;
  279. SCM(playerid, COLOR_RED2, "Delete Mod Disable!");
  280. SCM(playerid, -1, "Removing Teleports has been cancelled, Due to Delete Mod Disabled!");
  281. }
  282. return 1;
  283. }
  284.  
  285. YCMD:canceltele(playerid, params[], help)
  286. {
  287. #pragma unused help
  288. if(Process[playerid] == 1)
  289. {
  290. paid = -1;
  291. format(paname, sizeof paname, "None");
  292. DestroyDynamicCP(CurCP);
  293. DestroyDynamicMapIcon(CurIcon);
  294. Process[playerid] = 0;
  295. SCM(playerid, COLOR_RED2, "Cancelled Teleport Making Design");
  296. }
  297. else return SCM(playerid, COLOR_RED, "ERROR: You aren't creating Teleport!");
  298. return 1;
  299. }
  300.  
  301. YCMD:createtele(playerid, params[], help)
  302. {
  303. #pragma unused help
  304. myInt = GetPlayerInterior(playerid),
  305. myWor = GetPlayerVirtualWorld(playerid);
  306. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be RCON admin");
  307. if(sscanf(params, "is[128]", paid, paname)) return SCM(playerid, COLOR_RED, "USAGE: /createtele [ID] [Name]");
  308. if(paid >= MAX_TELEPORTS) return SCM(playerid, COLOR_RED, "ERROR: You have typed the wrong teleport id.");
  309. format(tFile, sizeof tFile, TeleportFile, paid);
  310. if(fexist(tFile)) return SCM(playerid, COLOR_RED, "ERROR: Teleport File on that id already exists!");
  311. GetPlayerPos(playerid, myPos[0], myPos[1], myPos[2]);
  312. Process[playerid] = 1;
  313. CurCP = CreateDynamicCP(myPos[0], myPos[1], myPos[2], CPSIZE_PER_TELE, myWor, myInt, -1, DISTANCE_PER_TELE);
  314. CurIcon = CreateDynamicMapIcon(myPos[0], myPos[1], myPos[2], MAPICON_PER_TELE, -1, myWor, myInt, -1, DISTANCE_PER_TELE);
  315. SCM(playerid, -1, "Next go to the place, Where player will be teleported when the checkpoint is entered");
  316. SCM(playerid, -1, "After you go to position, Type /finishtele");
  317. SCM(playerid, -1, "Or if you want to cancel this teleport designing then /canceltele");
  318. return 1;
  319. }
  320.  
  321. YCMD:finishtele(playerid, params[], help)
  322. {
  323. #pragma unused help
  324. new
  325. Float:pMyPos[4],
  326. world,
  327. interior;
  328. if(Process[playerid] == 0) return SCM(playerid, COLOR_RED, "ERROR: You aren't designing any Teleports!");
  329. if(sscanf(params, "ii", interior, world)) return SCM(playerid, COLOR_RED, "USAGE: /finishtele [interior] [world]");
  330. format(tFile, sizeof tFile, TeleportFile, paid);
  331. GetPlayerPos(playerid, pMyPos[0], pMyPos[1], pMyPos[2]);
  332. GetPlayerFacingAngle(playerid, pMyPos[3]);
  333. new INI:file = INI_Open(tFile);
  334. INI_WriteString(file, "TeleName", paname);
  335. INI_WriteInt(file, "TeleWorld", myWor);
  336. INI_WriteInt(file, "TeleInterior", myInt);
  337. INI_WriteFloat(file, "TeleX", myPos[0]);
  338. INI_WriteFloat(file, "TeleY", myPos[1]);
  339. INI_WriteFloat(file, "TeleZ", myPos[2]);
  340. INI_WriteFloat(file, "PlayerX", pMyPos[0]);
  341. INI_WriteFloat(file, "PlayerY", pMyPos[1]);
  342. INI_WriteFloat(file, "PlayerZ", pMyPos[2]);
  343. INI_WriteFloat(file, "PlayerA", pMyPos[3]);
  344. INI_WriteInt(file, "PlayerWorld", world);
  345. INI_WriteInt(file, "PlayerInterior", interior);
  346. INI_Close(file);
  347. DestroyDynamicCP(CurCP); DestroyDynamicMapIcon(CurIcon);
  348. Process[playerid] = 0;
  349. SCM(playerid, -1, "Successfully created, Now going to reload all teleports!");
  350. for(new i = 0; i < MAX_TELEPORTS; i++)
  351. {
  352. format(tFile, sizeof tFile, TeleportFile, i);
  353. if(fexist(tFile))
  354. {
  355. INI_ParseFile(tFile, "LoadTeleport", .bExtra = true, .extra = i);
  356. ReadTeleport(i);
  357. }
  358. }
  359. return 1;
  360. }
  361.  
  362. //==============================================================================
  363.  
  364. forward GetClosetTeleID(playerid);
  365. public GetClosetTeleID(playerid)
  366. {
  367. new Float:Distance;
  368. for(new t; t<MAX_TELEPORTS; t++)
  369. {
  370. Distance = GetDistanceToTele(playerid, t);
  371. if(Distance < 2.0)
  372. {
  373. return t;
  374. }
  375. }
  376. return -1;
  377. }
  378. forward Float:GetDistanceToTele(playerid, t);
  379. public Float:GetDistanceToTele(playerid, t)
  380. {
  381. new Float:x1,
  382. Float:y1,
  383. Float:z1,
  384. Float:x2,
  385. Float:y2,
  386. Float:z2;
  387. GetPlayerPos(playerid, x1, y1, z1);
  388. x2 = TeleData[t][cX];
  389. y2 = TeleData[t][cY];
  390. z2 = TeleData[t][cZ];
  391. return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  392. }
  393.  
  394. stock ReadTeleport(i)
  395. {
  396. new string[500];
  397. format(string, sizeof(string), ""COL_YELLOW"Teleport to: {FFFFFF}%s\n"COL_GREEN"Set Interior to: {FFFFFF}%i\n"COL_GREEN"Set Virtual World to: {FFFFFF}%i\nCreated by Teleport Maker by Romel\n"COL_YELLOW"Step in to teleport!", TeleData[i][Name], TeleData[i][pInterior], TeleData[i][pWorld]);
  398. TeleData[i][Label] = CreateDynamic3DTextLabel(string, -1, TeleData[i][cX], TeleData[i][cY], TeleData[i][cZ], 50.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, TeleData[i][World], TeleData[i][Interior], -1, DISTANCE_PER_TELE);
  399. TeleData[i][CP] = CreateDynamicCP(TeleData[i][cX], TeleData[i][cY], TeleData[i][cZ], CPSIZE_PER_TELE, TeleData[i][World], TeleData[i][Interior], -1, DISTANCE_PER_TELE);
  400. TeleData[i][Icon] = CreateDynamicMapIcon(TeleData[i][cX], TeleData[i][cY], TeleData[i][cZ], MAPICON_PER_TELE, -1, TeleData[i][World], TeleData[i][Interior], -1, DISTANCE_PER_TELE);
  401. return 1;
  402. }
  403.  
  404. stock UnloadTeleport(i)
  405. {
  406. DestroyDynamic3DTextLabel(TeleData[i][Label]);
  407. DestroyDynamicCP(TeleData[i][CP]);
  408. DestroyDynamicMapIcon(TeleData[i][Icon]);
  409. return 1;
  410. }
Advertisement
Add Comment
Please, Sign In to add comment