Advertisement
Guest User

[FS] /sendweapon

a guest
Dec 23rd, 2010
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.74 KB | None | 0 0
  1. /*======================================================================================================*
  2. * This /sendweapon Filterscript is made by Jeffry! *
  3. * *
  4. * *
  5. * Made in April 2010. *
  6. * *
  7. * Your Rights: *
  8. * *
  9. * -You are allowed to modify this Filterscript, aslong as you DO NOT remove credits or re-upload it. *
  10. * *
  11. * -You are NOT allowed to re-upload this Filterscript. *
  12. * -You are NOT allowed to claim this as your own. *
  13. * -You are NOT allowed to remove any credits. *
  14. * *
  15. * Thank you. *
  16. * Have fun. I would be happy if you give me /credits. :D *
  17. * *
  18. *=======================================================================================================*/
  19.  
  20. //========================================================================================================================
  21. //-------------------------Definitions that you may change----------------------------------------------------------------
  22. //------------------------------------------------------------------------------------------------------------------------
  23. #define WEAPON_TAX_BILL 10000 //Thats the amount you have to pay, when you send a weapon.
  24. #define MAX_REFUSE_TIME 30 // Thats the time in seconds, which allows the receiver to do /weaponsback.
  25. #define WAIT_TIME 30 // Thats the time in seconds the sender needs to wait to send another weapon.
  26. new ForbiddenWeapons[]= { 44, 45, 38 }; // Here you add the weapon IDs that you do not want to be sent.
  27. //------------------------------------------------------------------------------------------------------------------------
  28. //-------------------------End of the Definitions-------------------------------------------------------------------------
  29. //========================================================================================================================
  30. #include <a_samp>
  31.  
  32. //DCMD: Credits to DracoBlue.
  33. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  34. // The colors.
  35. #define red 0xFF0000AA
  36. #define green 0x33FF33AA
  37. #define dgreen 0x009000FF
  38.  
  39. new savedweapon[MAX_PLAYERS][13];
  40. new savedammo[MAX_PLAYERS][13];
  41. new Receiver[MAX_PLAYERS];
  42. new Sender[MAX_PLAYERS];
  43. new ReceivedWeapon[MAX_PLAYERS][2];
  44. new Sended[MAX_PLAYERS];
  45.  
  46. public OnFilterScriptInit()
  47. {
  48. print("\n--------------------------------------");
  49. print(" [FS] /sendweapon FilterScript by Jeffry");
  50. print("--------------------------------------\n");
  51. return 1;
  52. }
  53.  
  54. public OnPlayerConnect(playerid)
  55. {
  56. Receiver[playerid]=0;
  57. Sender[playerid]=-1;
  58. ReceivedWeapon[playerid][0]=0;
  59. ReceivedWeapon[playerid][1]=0;
  60. Sended[playerid]=0;
  61. return 1;
  62. }
  63.  
  64. public OnPlayerDisconnect(playerid, reason)
  65. {
  66. if(Receiver[playerid]!=0) KillTimer(Receiver[playerid]);
  67. for(new i=0; i<MAX_PLAYERS; i++) if(Sender[i]==playerid) Sender[i]=-1;
  68. return 1;
  69. }
  70.  
  71. public OnPlayerCommandText(playerid, cmdtext[])
  72. {
  73. dcmd(sendweapon, 10, cmdtext);
  74. dcmd(weaponsback, 11, cmdtext);
  75. return 0;
  76. }
  77.  
  78. dcmd_sendweapon(playerid,params[])
  79. {
  80. if(GetPlayerMoney(playerid) < WEAPON_TAX_BILL)
  81. {
  82. new msg[128];
  83. format(msg, 128, "ERROR: You need $%d to send a weapon!", WEAPON_TAX_BILL);
  84. return SendClientMessage(playerid, red, msg);
  85. }
  86. if(Sended[playerid] != 0)
  87. {
  88. new msg[128];
  89. format(msg, 128, "ERROR: You can only send a weapon every %d seconds!", WAIT_TIME);
  90. return SendClientMessage(playerid, red, msg);
  91. }
  92. new string[156], tmp[256], tmp2[256], weaponname[50], Index; tmp = strtok(params,Index); tmp2 = strtok(params,Index);
  93. if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid,red,"USAGE: /sendweapon [PlayerID] [Ammo]");
  94. new player1, ammo, weapon, weapon1, slot; player1=strval(tmp); ammo=strval(tmp2);
  95. if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"ERROR: This player is not connected!");
  96. if(playerid==player1) return SendClientMessage(playerid,red,"ERROR: You can't give yourself a weapon!");
  97. if(ammo<1) return SendClientMessage(playerid,red,"ERROR: Invalid ammo amount!");
  98. weapon=GetPlayerWeapon(playerid); weapon1=GetPlayerWeapon(player1);
  99. if(weapon==0) return SendClientMessage(playerid,red,"ERROR: You don't have a weapon!");
  100. for(new i=0; i<sizeof(ForbiddenWeapons); i++) if(weapon==ForbiddenWeapons[i]) return SendClientMessage(playerid,red,"ERROR: You are not allowed to send this weapon!");
  101. SaveWeapons(playerid); SaveWeapons(player1);
  102. slot=GetWeaponSlot(weapon);
  103. if(savedammo[playerid][slot]<ammo) return SendClientMessage(playerid,red,"ERROR: You don't have this amount of ammo!");
  104. savedammo[playerid][slot]-=ammo;
  105. ResetPlayerWeapons(playerid); ResetPlayerWeapons(player1);
  106. GetWeaponName(weapon, weaponname, 50);
  107. format(string, 156, "[Weapon] %s (ID:%d) has sent you a %s (ID:%d) with %d ammo. Type /weaponsback if you don't want it.", pName(playerid), playerid, weaponname, weapon, ammo);
  108. SendClientMessage(player1, green, string);
  109. format(string, 156, "[Weapon] You have sent %s (ID:%d) a %s (ID:%d) with %d ammo.", pName(player1), player1, weaponname, weapon, ammo);
  110. SendClientMessage(playerid, green, string);
  111. GivePlayerMoney(playerid, -WEAPON_TAX_BILL);
  112. GiveWeapons(playerid); GiveWeapons(player1);
  113. GivePlayerWeapon(player1, weapon, ammo);
  114. GivePlayerWeapon(player1, weapon1, 0);
  115. GivePlayerWeapon(playerid, weapon, 0);
  116. Sender[player1]=playerid; ReceivedWeapon[player1][0]=weapon; ReceivedWeapon[player1][1]=ammo;
  117. if(Receiver[playerid]!=0) KillTimer(Receiver[playerid]);
  118. Receiver[player1]=SetTimerEx("OldWeaponsBack", MAX_REFUSE_TIME*1000, 0, "d", player1);
  119. new time=WAIT_TIME;
  120. if(time!=0) Sended[playerid]=SetTimerEx("CanSendAgain", time*1000, 0, "d", playerid);
  121. return 1;
  122. }
  123.  
  124. dcmd_weaponsback(playerid,params[])
  125. {
  126. #pragma unused params
  127. if(Receiver[playerid]!=0)
  128. {
  129. new weapon;
  130. weapon=GetPlayerWeapon(playerid);
  131. ResetPlayerWeapons(playerid);
  132. GiveWeapons(playerid);
  133. GivePlayerWeapon(playerid, weapon, 0);
  134. if(Sender[playerid]!=-1)
  135. {
  136. new weap, wname[50], string[128]; weap=GetPlayerWeapon(Sender[playerid]);
  137. GetWeaponName(ReceivedWeapon[playerid][0], wname, 50);
  138. ResetPlayerWeapons(Sender[playerid]);
  139. GiveWeapons(Sender[playerid]);
  140. GivePlayerWeapon(Sender[playerid], ReceivedWeapon[playerid][0], ReceivedWeapon[playerid][1]);
  141. GivePlayerWeapon(Sender[playerid], weap, 0);
  142. format(string, 128, "[Weapon] %s (ID:%d) has refused your weapon and you got it back (%s (ID:%d) with %d ammo) .", pName(playerid), playerid, wname, ReceivedWeapon[playerid][0], ReceivedWeapon[playerid][1]);
  143. SendClientMessage(Sender[playerid], dgreen, string);
  144. }
  145. Receiver[playerid]=0; KillTimer(Receiver[playerid]);
  146. SendClientMessage(playerid, dgreen, "[Weapon] You have you old weapons back!");
  147. }
  148. else
  149. {
  150. new string[128];
  151. format(string, 128, "ERROR: You don't have received any weapons in the last %d seconds!", MAX_REFUSE_TIME);
  152. SendClientMessage(playerid,red,string);
  153. }
  154. return 1;
  155. }
  156.  
  157. forward SaveWeapons(playerid);
  158. public SaveWeapons(playerid)
  159. {
  160. for(new i=0; i<13; i++)
  161. {
  162. savedweapon[playerid][i]=0; savedammo[playerid][i]=0;
  163. }
  164. for(new i=0; i<13; i++) GetPlayerWeaponData(playerid, i, savedweapon[playerid][i], savedammo[playerid][i]);
  165. return 1;
  166. }
  167.  
  168. forward GiveWeapons(playerid);
  169. public GiveWeapons(playerid)
  170. {
  171. for(new i=0; i<13; i++) GivePlayerWeapon(playerid, savedweapon[playerid][i], savedammo[playerid][i]);
  172. return 1;
  173. }
  174.  
  175. forward OldWeaponsBack(playerid);
  176. public OldWeaponsBack(playerid)
  177. {
  178. Receiver[playerid]=0;
  179. return 1;
  180. }
  181.  
  182. forward CanSendAgain(playerid);
  183. public CanSendAgain(playerid)
  184. {
  185. Sended[playerid]=0;
  186. return 1;
  187. }
  188.  
  189. stock pName(playerid)
  190. {
  191. new name[MAX_PLAYER_NAME];
  192. GetPlayerName(playerid, name, sizeof(name));
  193. return name;
  194. }
  195.  
  196. stock GetWeaponSlot(weapon)
  197. {
  198. switch(weapon)
  199. {
  200. case 0,1: return 0;
  201. case 2..9: return 1;
  202. case 22..24: return 2;
  203. case 25..27: return 3;
  204. case 28,29,32: return 4;
  205. case 30,31: return 5;
  206. case 33,34: return 6;
  207. case 35..38: return 7;
  208. case 16..18,39: return 8;
  209. case 41..43: return 9;
  210. case 10..15: return 10;
  211. case 44..46: return 11;
  212. case 40: return 12;
  213. default: return -1;
  214. }
  215. return -1;
  216. }
  217.  
  218. //strtok
  219. strtok(const string[], &index)
  220. {
  221. new length = strlen(string);
  222. while ((index < length) && (string[index] <= ' '))
  223. {
  224. index++;
  225. }
  226.  
  227. new offset = index;
  228. new result[20];
  229. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  230. {
  231. result[index - offset] = string[index];
  232. index++;
  233. }
  234. result[index - offset] = EOS;
  235. return result;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement