SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

425 lines
17 KiB

5 years ago
  1. /* SA-MP Functions
  2. *
  3. * (c) Copyright 2005-2015, SA-MP Team
  4. *
  5. */
  6. #if defined _samp_included
  7. #endinput
  8. #endif
  9. #define _samp_included
  10. #pragma library samp
  11. #pragma tabsize 4
  12. // Ignores warning 217 for properly indented PAWNO code
  13. // It's tab size is 4 and often uses 4 spaces instead, PAWNCC's is 8
  14. #include <core>
  15. #include <float>
  16. #include <string>
  17. #include <file>
  18. #include <time>
  19. #include <datagram>
  20. #include <a_players>
  21. #include <a_vehicles>
  22. #include <a_objects>
  23. #include <a_actor>
  24. #include <a_sampdb>
  25. // Limits and internal constants
  26. #define MAX_PLAYER_NAME (24)
  27. #define MAX_PLAYERS (1000)
  28. #define MAX_VEHICLES (2000)
  29. #define MAX_ACTORS (1000)
  30. #define INVALID_PLAYER_ID (0xFFFF)
  31. #define INVALID_VEHICLE_ID (0xFFFF)
  32. #define INVALID_ACTOR_ID (0xFFFF)
  33. #define NO_TEAM (255)
  34. #define MAX_OBJECTS (1000)
  35. #define INVALID_OBJECT_ID (0xFFFF)
  36. #define MAX_GANG_ZONES (1024)
  37. #define MAX_TEXT_DRAWS (2048)
  38. #define MAX_PLAYER_TEXT_DRAWS (256)
  39. #define MAX_MENUS (128)
  40. #define MAX_3DTEXT_GLOBAL (1024)
  41. #define MAX_3DTEXT_PLAYER (1024)
  42. #define MAX_PICKUPS (4096)
  43. #define INVALID_MENU (0xFF)
  44. #define INVALID_TEXT_DRAW (0xFFFF)
  45. #define INVALID_GANG_ZONE (-1)
  46. #define INVALID_3DTEXT_ID (0xFFFF)
  47. // --------------------------------------------------
  48. // Natives
  49. // --------------------------------------------------
  50. // Util
  51. native print(const string[]);
  52. native printf(const format[], {Float,_}:...);
  53. native format(output[], len, const format[], {Float,_}:...);
  54. native SendClientMessage(playerid, color, const message[]);
  55. native SendClientMessageToAll(color, const message[]);
  56. native SendPlayerMessageToPlayer(playerid, senderid, const message[]);
  57. native SendPlayerMessageToAll(senderid, const message[]);
  58. native SendDeathMessage(killer, killee, weapon);
  59. native SendDeathMessageToPlayer(playerid, killer, killee, weapon);
  60. native GameTextForAll(const string[],time,style);
  61. native GameTextForPlayer(playerid,const string[],time,style);
  62. native SetTimer(funcname[], interval, repeating);
  63. native SetTimerEx(funcname[], interval, repeating, const format[], {Float,_}:...);
  64. native KillTimer(timerid);
  65. native GetTickCount();
  66. native GetMaxPlayers();
  67. native CallRemoteFunction(const function[], const format[], {Float,_}:...);
  68. native CallLocalFunction(const function[], const format[], {Float,_}:...);
  69. native Float:VectorSize(Float:x, Float:y, Float:z);
  70. native Float:asin(Float:value);
  71. native Float:acos(Float:value);
  72. native Float:atan(Float:value);
  73. native Float:atan2(Float:x, Float:y);
  74. native GetPlayerPoolSize();
  75. native GetVehiclePoolSize();
  76. native GetActorPoolSize();
  77. // Hash
  78. native SHA256_PassHash(password[], salt[], ret_hash[], ret_hash_len); // SHA256 for password hashing
  79. // Server wide persistent variable system (SVars)
  80. native SetSVarInt(varname[], int_value);
  81. native GetSVarInt(varname[]);
  82. native SetSVarString(varname[], string_value[]);
  83. native GetSVarString(varname[], string_return[], len);
  84. native SetSVarFloat(varname[], Float:float_value);
  85. native Float:GetSVarFloat(varname[]);
  86. native DeleteSVar(varname[]);
  87. // SVar enumeration
  88. #define SERVER_VARTYPE_NONE 0
  89. #define SERVER_VARTYPE_INT 1
  90. #define SERVER_VARTYPE_STRING 2
  91. #define SERVER_VARTYPE_FLOAT 3
  92. native GetSVarsUpperIndex();
  93. native GetSVarNameAtIndex(index, ret_varname[], ret_len);
  94. native GetSVarType(varname[]);
  95. // Game
  96. native SetGameModeText(const string[]);
  97. native SetTeamCount(count);
  98. native AddPlayerClass(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  99. native AddPlayerClassEx(teamid, modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  100. native AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2);
  101. native AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, addsiren=0);
  102. native AddStaticPickup(model, type, Float:X, Float:Y, Float:Z, virtualworld = 0);
  103. native CreatePickup(model, type, Float:X, Float:Y, Float:Z, virtualworld = 0);
  104. native DestroyPickup(pickup);
  105. native ShowNameTags(show);
  106. native ShowPlayerMarkers(mode);
  107. native GameModeExit();
  108. native SetWorldTime(hour);
  109. native GetWeaponName(weaponid, const weapon[], len);
  110. native EnableTirePopping(enable); // deprecated function
  111. native EnableVehicleFriendlyFire();
  112. native AllowInteriorWeapons(allow);
  113. native SetWeather(weatherid);
  114. native SetGravity(Float:gravity);
  115. native AllowAdminTeleport(allow);
  116. native SetDeathDropAmount(amount);
  117. native CreateExplosion(Float:X, Float:Y, Float:Z, type, Float:Radius);
  118. native EnableZoneNames(enable);
  119. native UsePlayerPedAnims(); // Will cause the players to use CJ running/walking animations
  120. native DisableInteriorEnterExits(); // will disable all interior enter/exits in the game.
  121. native SetNameTagDrawDistance(Float:distance); // Distance at which nametags will start rendering on the client.
  122. native DisableNameTagLOS(); // Disables the nametag Line-Of-Sight checking
  123. native LimitGlobalChatRadius(Float:chat_radius);
  124. native LimitPlayerMarkerRadius(Float:marker_radius);
  125. // Npc
  126. native ConnectNPC(name[], script[]);
  127. native IsPlayerNPC(playerid);
  128. // Admin
  129. native IsPlayerAdmin(playerid);
  130. native Kick(playerid);
  131. native Ban(playerid);
  132. native BanEx(playerid, const reason[]);
  133. native SendRconCommand(command[]);
  134. native GetPlayerNetworkStats(playerid, retstr[], retstr_size);
  135. native GetNetworkStats(retstr[], retstr_size);
  136. native GetPlayerVersion(playerid, const version[], len); // Returns the SA-MP client revision as reported by the player
  137. native BlockIpAddress(ip_address[], timems);
  138. native UnBlockIpAddress(ip_address[]);
  139. // Deprecated:
  140. native GetServerVarAsString(const varname[], buffer[], len);
  141. native GetServerVarAsInt(const varname[]);
  142. native GetServerVarAsBool(const varname[]);
  143. // These are the same 3 functions as above although they avoid the name ambiguity/conflict with the SVar system.
  144. native GetConsoleVarAsString(const varname[], buffer[], len);
  145. native GetConsoleVarAsInt(const varname[]);
  146. native GetConsoleVarAsBool(const varname[]);
  147. // Extended admin network stats
  148. native GetServerTickRate();
  149. native NetStats_GetConnectedTime(playerid);
  150. native NetStats_MessagesReceived(playerid);
  151. native NetStats_BytesReceived(playerid);
  152. native NetStats_MessagesSent(playerid);
  153. native NetStats_BytesSent(playerid);
  154. native NetStats_MessagesRecvPerSecond(playerid);
  155. native Float:NetStats_PacketLossPercent(playerid);
  156. native NetStats_ConnectionStatus(playerid);
  157. native NetStats_GetIpPort(playerid, ip_port[], ip_port_len);
  158. // Menu
  159. native Menu:CreateMenu(const title[], columns, Float:x, Float:y, Float:col1width, Float:col2width = 0.0);
  160. native DestroyMenu(Menu:menuid);
  161. native AddMenuItem(Menu:menuid, column, const menutext[]);
  162. native SetMenuColumnHeader(Menu:menuid, column, const columnheader[]);
  163. native ShowMenuForPlayer(Menu:menuid, playerid);
  164. native HideMenuForPlayer(Menu:menuid, playerid);
  165. native IsValidMenu(Menu:menuid);
  166. native DisableMenu(Menu:menuid);
  167. native DisableMenuRow(Menu:menuid, row);
  168. native Menu:GetPlayerMenu(playerid);
  169. // Text Draw
  170. #define TEXT_DRAW_FONT_SPRITE_DRAW 4
  171. #define TEXT_DRAW_FONT_MODEL_PREVIEW 5
  172. native Text:TextDrawCreate(Float:x, Float:y, text[]);
  173. native TextDrawDestroy(Text:text);
  174. native TextDrawLetterSize(Text:text, Float:x, Float:y);
  175. native TextDrawTextSize(Text:text, Float:x, Float:y);
  176. native TextDrawAlignment(Text:text, alignment);
  177. native TextDrawColor(Text:text, color);
  178. native TextDrawUseBox(Text:text, use);
  179. native TextDrawBoxColor(Text:text, color);
  180. native TextDrawSetShadow(Text:text, size);
  181. native TextDrawSetOutline(Text:text, size);
  182. native TextDrawBackgroundColor(Text:text, color);
  183. native TextDrawFont(Text:text, font);
  184. native TextDrawSetProportional(Text:text, set);
  185. native TextDrawSetSelectable(Text:text, set);
  186. native TextDrawShowForPlayer(playerid, Text:text);
  187. native TextDrawHideForPlayer(playerid, Text:text);
  188. native TextDrawShowForAll(Text:text);
  189. native TextDrawHideForAll(Text:text);
  190. native TextDrawSetString(Text:text, string[]);
  191. native TextDrawSetPreviewModel(Text:text, modelindex);
  192. native TextDrawSetPreviewRot(Text:text, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fZoom = 1.0);
  193. native TextDrawSetPreviewVehCol(Text:text, color1, color2);
  194. // Gang Zones
  195. native GangZoneCreate(Float:minx, Float:miny, Float:maxx, Float:maxy);
  196. native GangZoneDestroy(zone);
  197. native GangZoneShowForPlayer(playerid, zone, color);
  198. native GangZoneShowForAll(zone, color);
  199. native GangZoneHideForPlayer(playerid, zone);
  200. native GangZoneHideForAll(zone);
  201. native GangZoneFlashForPlayer(playerid, zone, flashcolor);
  202. native GangZoneFlashForAll(zone, flashcolor);
  203. native GangZoneStopFlashForPlayer(playerid, zone);
  204. native GangZoneStopFlashForAll(zone);
  205. // Global 3D Text Labels
  206. native Text3D:Create3DTextLabel(text[], color, Float:X, Float:Y, Float:Z, Float:DrawDistance, virtualworld, testLOS=0);
  207. native Delete3DTextLabel(Text3D:id);
  208. native Attach3DTextLabelToPlayer(Text3D:id, playerid, Float:OffsetX, Float:OffsetY, Float:OffsetZ);
  209. native Attach3DTextLabelToVehicle(Text3D:id, vehicleid, Float:OffsetX, Float:OffsetY, Float:OffsetZ);
  210. native Update3DTextLabelText(Text3D:id, color, text[]);
  211. // Per-player 3D Text Labels
  212. native PlayerText3D:CreatePlayer3DTextLabel(playerid, text[], color, Float:X, Float:Y, Float:Z, Float:DrawDistance, attachedplayer=INVALID_PLAYER_ID, attachedvehicle=INVALID_VEHICLE_ID, testLOS=0);
  213. native DeletePlayer3DTextLabel(playerid, PlayerText3D:id);
  214. native UpdatePlayer3DTextLabelText(playerid, PlayerText3D:id, color, text[]);
  215. // Player GUI Dialog
  216. #define DIALOG_STYLE_MSGBOX 0
  217. #define DIALOG_STYLE_INPUT 1
  218. #define DIALOG_STYLE_LIST 2
  219. #define DIALOG_STYLE_PASSWORD 3
  220. #define DIALOG_STYLE_TABLIST 4
  221. #define DIALOG_STYLE_TABLIST_HEADERS 5
  222. native ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[]);
  223. // --------------------------------------------------
  224. // Defines
  225. // --------------------------------------------------
  226. // States
  227. #define PLAYER_STATE_NONE (0)
  228. #define PLAYER_STATE_ONFOOT (1)
  229. #define PLAYER_STATE_DRIVER (2)
  230. #define PLAYER_STATE_PASSENGER (3)
  231. #define PLAYER_STATE_EXIT_VEHICLE (4) // (used internally)
  232. #define PLAYER_STATE_ENTER_VEHICLE_DRIVER (5) // (used internally)
  233. #define PLAYER_STATE_ENTER_VEHICLE_PASSENGER (6) // (used internally)
  234. #define PLAYER_STATE_WASTED (7)
  235. #define PLAYER_STATE_SPAWNED (8)
  236. #define PLAYER_STATE_SPECTATING (9)
  237. // Marker modes used by ShowPlayerMarkers()
  238. #define PLAYER_MARKERS_MODE_OFF (0)
  239. #define PLAYER_MARKERS_MODE_GLOBAL (1)
  240. #define PLAYER_MARKERS_MODE_STREAMED (2)
  241. // Weapons
  242. #define WEAPON_BRASSKNUCKLE (1)
  243. #define WEAPON_GOLFCLUB (2)
  244. #define WEAPON_NITESTICK (3)
  245. #define WEAPON_KNIFE (4)
  246. #define WEAPON_BAT (5)
  247. #define WEAPON_SHOVEL (6)
  248. #define WEAPON_POOLSTICK (7)
  249. #define WEAPON_KATANA (8)
  250. #define WEAPON_CHAINSAW (9)
  251. #define WEAPON_DILDO (10)
  252. #define WEAPON_DILDO2 (11)
  253. #define WEAPON_VIBRATOR (12)
  254. #define WEAPON_VIBRATOR2 (13)
  255. #define WEAPON_FLOWER (14)
  256. #define WEAPON_CANE (15)
  257. #define WEAPON_GRENADE (16)
  258. #define WEAPON_TEARGAS (17)
  259. #define WEAPON_MOLTOV (18)
  260. #define WEAPON_COLT45 (22)
  261. #define WEAPON_SILENCED (23)
  262. #define WEAPON_DEAGLE (24)
  263. #define WEAPON_SHOTGUN (25)
  264. #define WEAPON_SAWEDOFF (26)
  265. #define WEAPON_SHOTGSPA (27)
  266. #define WEAPON_UZI (28)
  267. #define WEAPON_MP5 (29)
  268. #define WEAPON_AK47 (30)
  269. #define WEAPON_M4 (31)
  270. #define WEAPON_TEC9 (32)
  271. #define WEAPON_RIFLE (33)
  272. #define WEAPON_SNIPER (34)
  273. #define WEAPON_ROCKETLAUNCHER (35)
  274. #define WEAPON_HEATSEEKER (36)
  275. #define WEAPON_FLAMETHROWER (37)
  276. #define WEAPON_MINIGUN (38)
  277. #define WEAPON_SATCHEL (39)
  278. #define WEAPON_BOMB (40)
  279. #define WEAPON_SPRAYCAN (41)
  280. #define WEAPON_FIREEXTINGUISHER (42)
  281. #define WEAPON_CAMERA (43)
  282. #define WEAPON_PARACHUTE (46)
  283. #define WEAPON_VEHICLE (49)
  284. #define WEAPON_DROWN (53)
  285. #define WEAPON_COLLISION (54)
  286. // Keys
  287. #define KEY_ACTION (1)
  288. #define KEY_CROUCH (2)
  289. #define KEY_FIRE (4)
  290. #define KEY_SPRINT (8)
  291. #define KEY_SECONDARY_ATTACK (16)
  292. #define KEY_JUMP (32)
  293. #define KEY_LOOK_RIGHT (64)
  294. #define KEY_HANDBRAKE (128)
  295. #define KEY_LOOK_LEFT (256)
  296. #define KEY_SUBMISSION (512)
  297. #define KEY_LOOK_BEHIND (512)
  298. #define KEY_WALK (1024)
  299. #define KEY_ANALOG_UP (2048)
  300. #define KEY_ANALOG_DOWN (4096)
  301. #define KEY_ANALOG_LEFT (8192)
  302. #define KEY_ANALOG_RIGHT (16384)
  303. #define KEY_YES (65536)
  304. #define KEY_NO (131072)
  305. #define KEY_CTRL_BACK (262144)
  306. #define KEY_UP (-128)
  307. #define KEY_DOWN (128)
  308. #define KEY_LEFT (-128)
  309. #define KEY_RIGHT (128)
  310. // --------------------------------------------------
  311. // Forwards (Callback declarations)
  312. // --------------------------------------------------
  313. forward OnGameModeInit();
  314. forward OnGameModeExit();
  315. forward OnFilterScriptInit();
  316. forward OnFilterScriptExit();
  317. forward OnPlayerConnect(playerid);
  318. forward OnPlayerDisconnect(playerid, reason);
  319. forward OnPlayerSpawn(playerid);
  320. forward OnPlayerDeath(playerid, killerid, reason);
  321. forward OnVehicleSpawn(vehicleid);
  322. forward OnVehicleDeath(vehicleid, killerid);
  323. forward OnPlayerText(playerid, text[]);
  324. forward OnPlayerCommandText(playerid, cmdtext[]);
  325. forward OnPlayerRequestClass(playerid, classid);
  326. forward OnPlayerEnterVehicle(playerid, vehicleid, ispassenger);
  327. forward OnPlayerExitVehicle(playerid, vehicleid);
  328. forward OnPlayerStateChange(playerid, newstate, oldstate);
  329. forward OnPlayerEnterCheckpoint(playerid);
  330. forward OnPlayerLeaveCheckpoint(playerid);
  331. forward OnPlayerEnterRaceCheckpoint(playerid);
  332. forward OnPlayerLeaveRaceCheckpoint(playerid);
  333. forward OnRconCommand(cmd[]);
  334. forward OnPlayerRequestSpawn(playerid);
  335. forward OnObjectMoved(objectid);
  336. forward OnPlayerObjectMoved(playerid, objectid);
  337. forward OnPlayerPickUpPickup(playerid, pickupid);
  338. forward OnVehicleMod(playerid, vehicleid, componentid);
  339. forward OnEnterExitModShop(playerid, enterexit, interiorid);
  340. forward OnVehiclePaintjob(playerid, vehicleid, paintjobid);
  341. forward OnVehicleRespray(playerid, vehicleid, color1, color2);
  342. forward OnVehicleDamageStatusUpdate(vehicleid, playerid);
  343. forward OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z);
  344. forward OnPlayerSelectedMenuRow(playerid, row);
  345. forward OnPlayerExitedMenu(playerid);
  346. forward OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid);
  347. forward OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  348. forward OnRconLoginAttempt( ip[], password[], success );
  349. forward OnPlayerUpdate(playerid);
  350. forward OnPlayerStreamIn(playerid, forplayerid);
  351. forward OnPlayerStreamOut(playerid, forplayerid);
  352. forward OnVehicleStreamIn(vehicleid, forplayerid);
  353. forward OnVehicleStreamOut(vehicleid, forplayerid);
  354. forward OnActorStreamIn(actorid, forplayerid);
  355. forward OnActorStreamOut(actorid, forplayerid);
  356. forward OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  357. forward OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart);
  358. forward OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart);
  359. forward OnPlayerGiveDamageActor(playerid, damaged_actorid, Float:amount, weaponid, bodypart);
  360. forward OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ);
  361. forward OnPlayerClickTextDraw(playerid, Text:clickedid);
  362. forward OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid);
  363. forward OnIncomingConnection(playerid, ip_address[], port);
  364. forward OnTrailerUpdate(playerid, vehicleid);
  365. forward OnVehicleSirenStateChange(playerid, vehicleid, newstate);
  366. #define CLICK_SOURCE_SCOREBOARD 0
  367. forward OnPlayerClickPlayer(playerid, clickedplayerid, source);
  368. #define EDIT_RESPONSE_CANCEL 0
  369. #define EDIT_RESPONSE_FINAL 1
  370. #define EDIT_RESPONSE_UPDATE 2
  371. forward OnPlayerEditObject( playerid, playerobject, objectid, response,
  372. Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ );
  373. forward OnPlayerEditAttachedObject( playerid, response, index, modelid, boneid,
  374. Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ,
  375. Float:fRotX, Float:fRotY, Float:fRotZ,
  376. Float:fScaleX, Float:fScaleY, Float:fScaleZ );
  377. #define SELECT_OBJECT_GLOBAL_OBJECT 1
  378. #define SELECT_OBJECT_PLAYER_OBJECT 2
  379. forward OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ);
  380. #define BULLET_HIT_TYPE_NONE 0
  381. #define BULLET_HIT_TYPE_PLAYER 1
  382. #define BULLET_HIT_TYPE_VEHICLE 2
  383. #define BULLET_HIT_TYPE_OBJECT 3
  384. #define BULLET_HIT_TYPE_PLAYER_OBJECT 4
  385. forward OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  386. // --------------------------------------------------