Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.27 KB | None | 0 0
  1.  
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define PARACHUTE_VERSION "2.5.1"
  7.  
  8. //Parachute Model
  9. #define PARACHUTE_MODEL "parachute_carbon"
  10.  
  11. //Parachute Textures
  12. #define PARACHUTE_PACK "pack_carbon"
  13. #define PARACHUTE_TEXTURE "parachute_carbon"
  14.  
  15. new g_iVelocity = -1;
  16. new g_iMoney = -1;
  17. new g_maxplayers = -1;
  18.  
  19. new String:g_game[30];
  20. new String:path_model[256];
  21. new String:path_pack[256];
  22. new String:path_texture[256];
  23.  
  24. new Handle:g_fallspeed = INVALID_HANDLE;
  25. new Handle:g_enabled = INVALID_HANDLE;
  26. new Handle:g_linear = INVALID_HANDLE;
  27. new Handle:g_msgtype = INVALID_HANDLE;
  28. new Handle:g_cost = INVALID_HANDLE;
  29. new Handle:g_payback = INVALID_HANDLE;
  30. new Handle:g_welcome = INVALID_HANDLE;
  31. new Handle:g_roundmsg = INVALID_HANDLE;
  32. new Handle:g_version = INVALID_HANDLE;
  33. new Handle:g_model = INVALID_HANDLE;
  34. new Handle:g_decrease = INVALID_HANDLE;
  35. new Handle:g_button = INVALID_HANDLE;
  36.  
  37. new x;
  38. new cl_flags;
  39. new cl_buttons;
  40. new Float:speed[3];
  41. new bool:isfallspeed;
  42.  
  43. new USE_BUTTON;
  44. new String:ButtonText[265];
  45.  
  46. new bool:inUse[MAXPLAYERS+1];
  47. new bool:hasPara[MAXPLAYERS+1];
  48. new bool:hasModel[MAXPLAYERS+1];
  49. new bool:hasAccess[MAXPLAYERS+1];
  50. new Parachute_Ent[MAXPLAYERS+1];
  51.  
  52. public Plugin:myinfo =
  53. {
  54. name = "SM Parachute",
  55. author = "SWAT_88 edited by pTu",
  56. description = "To use your parachute press and hold your E(+use) button while falling.",
  57. version = PARACHUTE_VERSION,
  58. url = "http://www.sourcemod.net/"
  59. };
  60.  
  61. public OnPluginStart()
  62. {
  63. LoadTranslations ("sm_parachute.phrases");
  64.  
  65. g_enabled = CreateConVar("sm_parachute_enabled","1");
  66. g_fallspeed = CreateConVar("sm_parachute_fallspeed","100");
  67. g_linear = CreateConVar("sm_parachute_linear","1");
  68. g_msgtype = CreateConVar("sm_parachute_msgtype","1");
  69. g_cost = CreateConVar("sm_parachute_cost","0");
  70. g_payback = CreateConVar("sm_parachute_payback","75");
  71. g_welcome = CreateConVar("sm_parachute_welcome","1");
  72. g_roundmsg = CreateConVar("sm_parachute_roundmsg","1");
  73. g_version = CreateConVar("sm_parachute_version", PARACHUTE_VERSION, "SM Parachute Version", FCVAR_NOTIFY);
  74. g_model = CreateConVar("sm_parachute_model","1");
  75. g_decrease = CreateConVar("sm_parachute_decrease","50");
  76. g_button = CreateConVar("sm_parachute_button","1");
  77. g_iVelocity = FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]");
  78. g_iMoney = FindSendPropOffs("CCSPlayer", "m_iAccount");
  79. g_maxplayers = GetMaxClients();
  80. SetConVarString(g_version, PARACHUTE_VERSION);
  81.  
  82. InitModel();
  83. InitGameMode();
  84.  
  85. RegConsoleCmd("say",HandleSay,"",FCVAR_GAMEDLL);
  86. RegConsoleCmd("say_team",HandleSay,"",FCVAR_GAMEDLL);
  87. HookEvent("player_death",PlayerDeath);
  88. HookEvent("player_spawn",PlayerSpawn);
  89. HookConVarChange(g_enabled, CvarChange_Enabled);
  90. HookConVarChange(g_linear, CvarChange_Linear);
  91. HookConVarChange(g_cost, CvarChange_Cost);
  92. HookConVarChange(g_model, CvarChange_Model);
  93. HookConVarChange(g_button, CvarChange_Button);
  94.  
  95. //CreateTimer(5.0, Timer_Copy, _, TIMER_REPEAT);
  96. }
  97.  
  98. public Action:Timer_Copy(Handle:timer)
  99. {
  100. PrintToChatAll("\x01[\x04DEMO\x01]\x04 PLUGIN DEMO PLUGIN DEMOPLUGIN DEMOPLUGIN DEMO");
  101. }
  102.  
  103. public OnPluginEnd(){
  104. CloseHandle(g_fallspeed);
  105. CloseHandle(g_enabled);
  106. CloseHandle(g_linear);
  107. CloseHandle(g_msgtype);
  108. CloseHandle(g_cost);
  109. CloseHandle(g_payback);
  110. CloseHandle(g_welcome);
  111. CloseHandle(g_roundmsg);
  112. CloseHandle(g_version);
  113. CloseHandle(g_model);
  114. CloseHandle(g_decrease);
  115. }
  116.  
  117. public InitModel(){
  118. Format(path_model,255,"models/parachute/%s",PARACHUTE_MODEL);
  119. Format(path_pack,255,"materials/models/parachute/%s",PARACHUTE_PACK);
  120. Format(path_texture,255,"materials/models/parachute/%s",PARACHUTE_TEXTURE);
  121. }
  122.  
  123. public InitGameMode(){
  124. GetGameFolderName(g_game, 29);
  125. if(StrEqual(g_game,"tf",false)){
  126. SetConVarInt(g_button,2);
  127. SetButton(2);
  128. }
  129. else{
  130. SetButton(1);
  131. }
  132. }
  133.  
  134. public OnMapStart(){
  135. new String:path[256];
  136.  
  137. strcopy(path,255,path_model);
  138. StrCat(path,255,".mdl")
  139. PrecacheModel(path,true);
  140.  
  141. strcopy(path,255,path_model);
  142. StrCat(path,255,".dx80.vtx")
  143. AddFileToDownloadsTable(path);
  144.  
  145. strcopy(path,255,path_model);
  146. StrCat(path,255,".dx90.vtx")
  147. AddFileToDownloadsTable(path);
  148.  
  149. strcopy(path,255,path_model);
  150. StrCat(path,255,".mdl")
  151. AddFileToDownloadsTable(path);
  152.  
  153. strcopy(path,255,path_model);
  154. StrCat(path,255,".sw.vtx")
  155. AddFileToDownloadsTable(path);
  156.  
  157. strcopy(path,255,path_model);
  158. StrCat(path,255,".vvd")
  159. AddFileToDownloadsTable(path);
  160.  
  161. strcopy(path,255,path_model);
  162. StrCat(path,255,".xbox.vtx")
  163. AddFileToDownloadsTable(path);
  164.  
  165. strcopy(path,255,path_pack);
  166. StrCat(path,255,".vmt")
  167. AddFileToDownloadsTable(path);
  168.  
  169. strcopy(path,255,path_pack);
  170. StrCat(path,255,".vtf")
  171. AddFileToDownloadsTable(path);
  172.  
  173. strcopy(path,255,path_texture);
  174. StrCat(path,255,".vmt")
  175. AddFileToDownloadsTable(path);
  176.  
  177. strcopy(path,255,path_texture);
  178. StrCat(path,255,".vtf")
  179. AddFileToDownloadsTable(path);
  180. }
  181.  
  182. public OnEventShutdown()
  183. {
  184. UnhookEvent("player_death",PlayerDeath);
  185. UnhookEvent("player_spawn",PlayerSpawn);
  186. }
  187.  
  188. public OnClientPutInServer(client)
  189. {
  190. inUse[client] = false;
  191. hasPara[client] = false;
  192. hasModel[client] = false;
  193. hasAccess[client] = false;
  194. g_maxplayers = GetMaxClients();
  195. CreateTimer (20.0, WelcomeMsg, client);
  196. }
  197.  
  198. public OnClientPostAdminCheck(client)
  199. {
  200. hasAccess[client] = IsPlayerGenericAdmin(client);
  201. }
  202.  
  203. public OnClientDisconnect(client){
  204. g_maxplayers = GetMaxClients();
  205. CloseParachute(client);
  206. }
  207.  
  208. public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast){
  209. new client;
  210. client = GetClientOfUserId(GetEventInt(event, "userid"));
  211. if (GetConVarInt(g_cost) == 0){
  212. CreateTimer (1.0, RoundMsg, client);
  213. }
  214. return Plugin_Continue;
  215. }
  216.  
  217. public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){
  218. new client;
  219. client = GetClientOfUserId(GetEventInt(event, "userid"));
  220. hasPara[client] = false;
  221. EndPara(client);
  222. return Plugin_Continue;
  223. }
  224.  
  225. public Action:RoundMsg(Handle:timer, any:client){
  226. if(GetConVarInt(g_roundmsg) == 1){
  227. if(IsClientConnected (client) && IsClientInGame(client))
  228. PrintMsg(client,"Have Got Free Parachute");
  229. }
  230. return Plugin_Continue;
  231. }
  232.  
  233. public StartPara(client,bool:open)
  234. {
  235. decl Float:velocity[3];
  236. decl Float:fallspeed;
  237. if (g_iVelocity == -1) return;
  238. if((GetConVarInt(g_enabled)== 1 && hasPara[client]) || (GetConVarInt(g_enabled) == 1 && GetConVarInt(g_cost) == 0)){
  239. fallspeed = GetConVarFloat(g_fallspeed)*(-1.0);
  240. GetEntDataVector(client, g_iVelocity, velocity);
  241. if(velocity[2] >= fallspeed){
  242. isfallspeed = true;
  243. }
  244. if(velocity[2] < 0.0) {
  245. if(isfallspeed && GetConVarInt(g_linear) == 0){
  246. }
  247. else if((isfallspeed && GetConVarInt(g_linear) == 1) || GetConVarFloat(g_decrease) == 0.0){
  248. velocity[2] = fallspeed;
  249. }
  250. else{
  251. velocity[2] = velocity[2] + GetConVarFloat(g_decrease);
  252. }
  253. TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, velocity);
  254. SetEntDataVector(client, g_iVelocity, velocity);
  255. SetEntityGravity(client,0.1);
  256. if(open) OpenParachute(client);
  257. }
  258. }
  259. }
  260.  
  261. public EndPara(client)
  262. {
  263. if(GetConVarInt(g_enabled)== 1 ){
  264. SetEntityGravity(client,1.0);
  265. inUse[client]=false;
  266. CloseParachute(client);
  267. }
  268. }
  269.  
  270. public OpenParachute(client){
  271. decl String:path[256];
  272. strcopy(path,255,path_model);
  273. StrCat(path,255,".mdl")
  274.  
  275. if(GetConVarInt(g_model) == 1){
  276. Parachute_Ent[client] = CreateEntityByName("prop_dynamic_override");
  277. DispatchKeyValue(Parachute_Ent[client],"model",path);
  278. SetEntityMoveType(Parachute_Ent[client], MOVETYPE_NOCLIP);
  279. DispatchSpawn(Parachute_Ent[client]);
  280.  
  281. hasModel[client]=true;
  282. TeleportParachute(client);
  283. }
  284. }
  285.  
  286. public TeleportParachute(client){
  287. if(hasModel[client] && IsValidEntity(Parachute_Ent[client])){
  288. decl Float:Client_Origin[3];
  289. decl Float:Client_Angles[3];
  290. decl Float:Parachute_Angles[3] = {0.0, 0.0, 0.0};
  291. GetClientAbsOrigin(client,Client_Origin);
  292. GetClientAbsAngles(client,Client_Angles);
  293. Parachute_Angles[1] = Client_Angles[1];
  294. TeleportEntity(Parachute_Ent[client], Client_Origin, Parachute_Angles, NULL_VECTOR);
  295. }
  296. }
  297.  
  298. public CloseParachute(client){
  299. if(hasModel[client] && IsValidEntity(Parachute_Ent[client])){
  300. RemoveEdict(Parachute_Ent[client]);
  301. hasModel[client]=false;
  302. }
  303. }
  304.  
  305. public Check(client){
  306. if(GetConVarInt(g_enabled)== 1 ){
  307. GetEntDataVector(client,g_iVelocity,speed);
  308. cl_flags = GetEntityFlags(client);
  309. if(speed[2] >= 0 || (cl_flags & FL_ONGROUND)) EndPara(client);
  310. }
  311. }
  312.  
  313. public OnGameFrame()
  314. {
  315. if(GetConVarInt(g_enabled) == 0) return;
  316. for (x = 1; x <= g_maxplayers; x++)
  317. {
  318. if (IsClientInGame(x) && IsPlayerAlive(x) && hasAccess[x])
  319. {
  320. cl_buttons = GetClientButtons(x);
  321. if (cl_buttons & USE_BUTTON)
  322. {
  323. if (!inUse[x])
  324. {
  325. inUse[x] = true;
  326. isfallspeed = false;
  327. StartPara(x,true);
  328. }
  329. StartPara(x,false);
  330. TeleportParachute(x);
  331. }
  332. else
  333. {
  334. if (inUse[x])
  335. {
  336. inUse[x] = false;
  337. EndPara(x);
  338. }
  339. }
  340. Check(x);
  341. }
  342. }
  343. }
  344.  
  345. stock GetNextSpaceCount(String:text[],CurIndex){
  346. new Count=0;
  347. new len = strlen(text);
  348. for(new i=CurIndex;i<len;i++){
  349. if(text[i] == ' ') return Count;
  350. else Count++;
  351. }
  352. return Count;
  353. }
  354.  
  355. stock SendHintText(client, String:text[], any:...){
  356. new String:message[192];
  357.  
  358. VFormat(message,191,text, 2);
  359. new len = strlen(message);
  360. if(len > 30){
  361. new LastAdded=0;
  362.  
  363. for(new i=0;i<len;i++){
  364. if((message[i]==' ' && LastAdded > 30 && (len-i) > 10) || ((GetNextSpaceCount(text,i+1) + LastAdded) > 34)){
  365. message[i] = '\n';
  366. LastAdded = 0;
  367. }
  368. else LastAdded++;
  369. }
  370. }
  371. new Handle:HintMessage = StartMessageOne("HintText",client);
  372. if (GetUserMessageType() == UM_Protobuf)
  373. PbSetString(HintMessage, "text", message);
  374. else
  375. {
  376. BfWriteByte(HintMessage,-1);
  377. BfWriteString(HintMessage,message);
  378. }
  379. EndMessage();
  380. }
  381.  
  382. public PrintMsg(client,String:msg[]){
  383. new String:translation[256];
  384. if(GetConVarInt(g_enabled) == 0) return;
  385. Format(translation, 255, "%T", msg, LANG_SERVER, ButtonText);
  386. if(GetConVarInt(g_msgtype) == 1){
  387. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %s", translation);
  388. }
  389. else if(GetConVarInt(g_msgtype) == 2) {
  390. new Handle:panel = CreatePanel();
  391. DrawPanelText(panel,translation);
  392. SendPanelToClient(panel,client,PanelHandle,5);
  393. }
  394. else if(GetConVarInt(g_msgtype) == 3){
  395. SendHintText(client,translation);
  396. }
  397. }
  398.  
  399. public PanelHandle(Handle:menu, MenuAction:action, param1, param2){
  400. }
  401.  
  402. public BuyParachute(client){
  403. new money;
  404. new cost;
  405. if (g_iMoney == -1) return;
  406. if (hasPara[client] == false){
  407. money = GetEntData(client,g_iMoney);
  408. cost = GetConVarInt(g_cost);
  409. if (cost == 0){
  410. PrintMsg(client,"Have Free Parachute");
  411. }
  412. else{
  413. if((money - cost)<0){
  414. PrintMsg(client,"No Money");
  415. }
  416. else{
  417. hasPara[client] = true;
  418. SetEntData(client,g_iMoney,money-cost);
  419. PrintMsg(client,"Have Bought Parachute");
  420. }
  421. }
  422. }
  423. else{
  424. PrintMsg(client,"Have Parachute");
  425. }
  426.  
  427. }
  428.  
  429. public SellParachute(client){
  430. new money;
  431. new Float:payback;
  432. new String:pb[10];
  433. if (g_iMoney == -1) return;
  434. if (hasPara[client] == true){
  435. money = GetEntData(client,g_iMoney);
  436. payback = GetConVarInt(g_cost)*(GetConVarFloat(g_payback)/100);
  437. if ((money + payback) > 16000){
  438. SetEntData(client,g_iMoney,16000);
  439. }
  440. else{
  441. FloatToString(payback,pb,9);
  442. SetEntData(client,g_iMoney,money+StringToInt(pb));
  443. }
  444. hasPara[client] = false;
  445. PrintMsg(client,"Sold Parachute");
  446. }
  447. else{
  448. if (GetConVarInt(g_cost)==0){
  449. PrintMsg(client,"Sell Free Parachute");
  450. }
  451. else{
  452. PrintMsg(client,"No Parachute");
  453. }
  454. }
  455. }
  456.  
  457. public Action:HandleSay(client, args){
  458. new String:line[30];
  459. if(GetConVarInt(g_enabled) == 0) return Plugin_Continue;
  460. if (args > 0){
  461. GetCmdArg(1,line,sizeof(line));
  462. if (strcmp(g_game,"cstrike",false)==0){
  463. if (StrEqual(line, "!bp", false) || StrEqual(line, "!buy_parachute", false)) BuyParachute(client);
  464. else if(StrEqual(line, "!sp", false) || StrEqual(line, "!sell_parachute", false)) SellParachute(client);
  465. }
  466. else{
  467. SetConVarInt(g_cost,0);
  468. if (StrEqual(line, "!bp", false) || StrEqual(line, "!buy_parachute", false)) PrintMsg(client,"Have Free Parachute");
  469. else if(StrEqual(line, "!sp", false) || StrEqual(line, "!sell_parachute", false)) PrintMsg(client,"Sell Free Parachute");
  470. }
  471. }
  472. return Plugin_Continue;
  473. }
  474.  
  475.  
  476. public Action:WelcomeMsg (Handle:timer, any:client)
  477. {
  478. if(GetConVarInt(g_enabled) == 0) return Plugin_Continue;
  479.  
  480. if (GetConVarInt (g_welcome) == 1 && IsClientConnected (client) && IsClientInGame (client))
  481. {
  482. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Welcome", LANG_SERVER);
  483. if (GetConVarInt(g_cost)==0){
  484. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Parachute For Everyone", LANG_SERVER);
  485. }
  486. else{
  487. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Buy Help", LANG_SERVER);
  488. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Sell Help", LANG_SERVER);
  489. }
  490. }
  491. return Plugin_Continue;
  492. }
  493.  
  494.  
  495. public CvarChange_Enabled(Handle:cvar, const String:oldvalue[], const String:newvalue[]){
  496. if (StringToInt(newvalue) == 0){
  497. for (new client = 1; client <= g_maxplayers; client++){
  498. if (IsClientInGame(client) && IsPlayerAlive(client)){
  499. if (hasPara[client]){
  500. SetEntityGravity(client,1.0);
  501. SetEntityMoveType(client,MOVETYPE_WALK);
  502. SellParachuteOff(client,GetConVarInt(g_cost));
  503. }
  504. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Disabled", LANG_SERVER);
  505. }
  506. }
  507. }
  508. else{
  509. for (new client = 1; client <= g_maxplayers; client++){
  510. if (IsClientInGame(client) && IsPlayerAlive(client)){
  511. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Enabled", LANG_SERVER);
  512. if (GetConVarInt(g_cost)==0){
  513. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Parachute For Everyone", LANG_SERVER);
  514. }
  515. else{
  516. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Buy Help", LANG_SERVER);
  517. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Sell Help", LANG_SERVER);
  518. }
  519. }
  520. }
  521. }
  522. }
  523.  
  524. public CvarChange_Linear(Handle:cvar, const String:oldvalue[], const String:newvalue[]){
  525. if (StringToInt(newvalue) == 0){
  526. for (new client = 1; client <= g_maxplayers; client++){
  527. if (IsClientInGame(client) && IsPlayerAlive(client) && hasPara[client]){
  528. SetEntityMoveType(client,MOVETYPE_WALK);
  529. }
  530. }
  531. }
  532. }
  533.  
  534. public CvarChange_Cost(Handle:cvar, const String:oldvalue[], const String:newvalue[]){
  535. if (StringToInt(newvalue) == 0){
  536. for (new client = 1; client <= g_maxplayers; client++){
  537. if (IsClientInGame(client) && IsPlayerAlive(client)){
  538. if (hasPara[client]) SellParachuteOff(client,StringToInt(oldvalue));
  539. PrintToChat(client,"\x01\x04[SM Parachute]\x01 %T", "Parachute For Everyone", LANG_SERVER);
  540. }
  541. }
  542. }
  543. else{
  544. if (strcmp(g_game,"cstrike",false) != 0) SetConVarInt(g_cost,0);
  545. }
  546. }
  547.  
  548. public CvarChange_Button(Handle:cvar, const String:oldvalue[], const String:newvalue[]){
  549. if (StringToInt(newvalue) == 1){
  550. SetButton(1);
  551. }
  552. else if(StringToInt(newvalue) == 2){
  553. SetButton(2);
  554. }
  555. }
  556.  
  557. public CvarChange_Model(Handle:cvar, const String:oldvalue[], const String:newvalue[]){
  558. if (StringToInt(newvalue) == 0){
  559. for (new client = 1; client <= g_maxplayers; client++){
  560. if (IsClientInGame(client) && IsPlayerAlive(client)){
  561. CloseParachute(client);
  562. }
  563. }
  564. }
  565. }
  566.  
  567. public SellParachuteOff(client,cost){
  568. new money;
  569. new Float:payback;
  570. new String:pb[10];
  571. if (g_iMoney == -1) return;
  572. if (hasPara[client] == true){
  573. money = GetEntData(client,g_iMoney);
  574. payback = cost*(GetConVarFloat(g_payback)/100);
  575. if ((money + payback) > 16000){
  576. SetEntData(client,g_iMoney,16000);
  577. }
  578. else{
  579. FloatToString(payback,pb,9);
  580. SetEntData(client,g_iMoney,money+StringToInt(pb));
  581. }
  582. hasPara[client] = false;
  583. }
  584. }
  585.  
  586. public SetButton(button){
  587. if (button == 1){
  588. USE_BUTTON = IN_USE;
  589. ButtonText = "E";
  590. }
  591. else if(button == 2){
  592. USE_BUTTON = IN_JUMP;
  593. ButtonText = "Space";
  594. }
  595. }
  596.  
  597. /*
  598. @param client id
  599.  
  600. return bool
  601. */
  602. bool:IsPlayerGenericAdmin(client)
  603. {
  604. if (CheckCommandAccess(client, "generic_admin", ADMFLAG_RESERVATION, false))
  605. {
  606. return true;
  607. }
  608.  
  609. return false;
  610. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement