Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2011
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.25 KB | None | 0 0
  1. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  2. {
  3. static bool:PressingUse[MAXPLAYERS + 1];
  4. static bool:DuckBuffer[MAXPLAYERS + 1];
  5.  
  6. if (buttons & IN_USE)
  7. {
  8. if (!PressingUse[client])
  9. {
  10. if (GetEntPropEnt(client, Prop_Send, "m_hVehicle") != -1)
  11. {
  12. LeaveVehicle(client);
  13. buttons &= ~IN_USE;
  14. PressingUse[client] = true;
  15. return Plugin_Handled;
  16. }
  17. else
  18. {
  19. decl Ent;
  20. Ent = GetClientAimTarget(client, false);
  21. if (IsValidEdict(Ent))
  22. {
  23. decl String:ClassName[255];
  24. GetEdictClassname(Ent, ClassName, 255);
  25.  
  26. //Valid:
  27. if (StrEqual(ClassName, "prop_vehicle_driveable", false))
  28. {
  29. new Float:origin[3];
  30. new Float:car_origin[3];
  31. new Float:distance;
  32.  
  33. GetClientAbsOrigin(client, origin);
  34. GetEntPropVector(Ent, Prop_Send, "m_vecOrigin", car_origin);
  35. distance = GetVectorDistance(origin, car_origin, false);
  36. if ((distance <= 72.00) && (!GetEntProp(Ent, Prop_Data, "m_bLocked")))
  37.  
  38. // It is a car. See if it is locked or not, and if it is in range.
  39. if ((!GetEntProp(Ent, Prop_Data, "m_bLocked")) && (distance <= 64.00))
  40. {
  41. // Car in range, unlocked.
  42. new Driver = GetEntPropEnt(Ent, Prop_Send, "m_hPlayer");
  43. if (Driver == -1)
  44. {
  45. // AcceptEntityInput(Ent, "use", client);
  46. // buttons &= ~IN_USE;
  47. PressingUse[client] = true;
  48. return Plugin_Handled;
  49. }
  50. else if (cars_seats[Ent] > 0)
  51. {
  52. // Car has multiple seats, someone already driving
  53. new Passenger = -1;
  54. for ( new ic = 1; ic < cars_seats[Ent] + 1; ic++ )
  55. {
  56. // Is there a passenger in one of the seats?
  57. Passenger = GetEntPropEnt(cars_seat_entities[Ent][ic], Prop_Send, "m_hPlayer");
  58. if (Passenger == -1)
  59. {
  60. new chair = cars_seat_entities[Ent][ic];
  61. if (IsValidEntity(chair))
  62. {
  63. new t = cars_type[Ent];
  64. SetVariantString("");
  65. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  66. AcceptEntityInput(chair, "use", client);
  67.  
  68. new String:car_name2[128];
  69. GetTargetName(Ent,car_name2,sizeof(car_name2));
  70.  
  71. SetVariantString(car_name2);
  72. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  73. SetVariantString(car_passenger_attachment[t][ic]);
  74. AcceptEntityInput(chair, "SetParentAttachment", chair, chair, 0);
  75.  
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
  82. else
  83. {
  84. EmitSoundToAll("doors/default_locked.wav", Ent, SNDCHAN_AUTO, SNDLEVEL_NORMAL);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. PressingUse[client] = true;
  91. }
  92. else
  93. {
  94. PressingUse[client] = false;
  95. }
  96. if (buttons & IN_DUCK)
  97. {
  98. if (!DuckBuffer[client])
  99. {
  100. new car = GetEntPropEnt(client, Prop_Send, "m_hVehicle");
  101. if (car != -1)
  102. {
  103. ViewToggle(car, client);
  104. }
  105. }
  106. DuckBuffer[client] = true;
  107. }
  108. else
  109. {
  110. DuckBuffer[client] = false;
  111. }
  112. return Plugin_Continue;
  113. }
  114.  
  115.  
  116.  
  117.  
  118. public OnThink(entity)
  119. {
  120. new Driver = GetEntPropEnt(entity, Prop_Send, "m_hPlayer");
  121. decl Float:ang[3];
  122. /* GetEntPropVector(entity, Prop_Data, "m_angRotation", ang);
  123.  
  124. new Float:roll = ang[2];
  125.  
  126. if(roll > 100.0 || roll < -100.0)
  127. {
  128. if (Driver > 0)
  129. {
  130. if(IsClientInGame(Driver) && IsPlayerAlive(Driver))
  131. {
  132. LeaveVehicle(Driver);
  133. FakeClientCommand(Driver, "kill");
  134. }
  135. }
  136. } */
  137. if (IsValidEntity(ViewEnt[entity]))
  138. {
  139. if (Driver > 0)
  140. {
  141. if(IsClientInGame(Driver) && IsPlayerAlive(Driver))
  142. {
  143. SetEntProp(entity, Prop_Data, "m_nNextThinkTick", 1);
  144. SetEntPropFloat(entity, Prop_Data, "m_flTurnOffKeepUpright", 1.0);
  145.  
  146. SetClientViewEntity(Driver, ViewEnt[entity]);
  147. Driving[Driver] = true;
  148.  
  149. new t = cars_type[entity];
  150. if (car_driver_view[t] == 1)
  151. {
  152. if (Cars_Driver_Prop[entity] == -1)
  153. {
  154. new prop = CreateEntityByName("prop_physics_override");
  155. if(IsValidEntity(prop))
  156. {
  157. new String:model[128];
  158. GetClientModel(Driver, model, sizeof(model));
  159. DispatchKeyValue(prop, "model", model);
  160. DispatchKeyValue(prop, "skin","0");
  161. ActivateEntity(prop);
  162. DispatchSpawn(prop);
  163.  
  164. new enteffects = GetEntProp(prop, Prop_Send, "m_fEffects");
  165. enteffects |= 1;
  166. enteffects |= 128;
  167. enteffects |= 512;
  168. SetEntProp(prop, Prop_Send, "m_fEffects", enteffects);
  169.  
  170. new String:car_ent_name[128];
  171. GetTargetName(entity,car_ent_name,sizeof(car_ent_name));
  172.  
  173. SetVariantString(car_ent_name);
  174. AcceptEntityInput(prop, "SetParent", prop, prop, 0);
  175. SetVariantString("vehicle_driver_eyes");
  176. AcceptEntityInput(prop, "SetParentAttachment", prop, prop, 0);
  177. Cars_Driver_Prop[entity] = prop;
  178. }
  179. }
  180. }
  181. else Cars_Driver_Prop[entity] = -1;
  182. }
  183. }
  184. }
  185. if (GetEntProp(entity, Prop_Send, "m_bEnterAnimOn") == 1)
  186. {
  187. for (new client = 1; client <= MaxClients; client++)
  188. {
  189. if (IsClientInGame(client) && IsPlayerAlive(client))
  190. {
  191. if (client != Driver)
  192. {
  193. TeleportEntity(client, NULL_VECTOR, CurrentEyeAngle[client], NULL_VECTOR);
  194. }
  195. }
  196. }
  197.  
  198. SetEntProp(entity, Prop_Send, "m_nSequence", 0);
  199.  
  200. CarHorn[Driver] = false;
  201. armour[Driver] = GetEntProp(Driver, Prop_Send, "m_ArmorValue");
  202. SetEntProp(entity, Prop_Send, "m_bEnterAnimOn", 0);
  203. SetEntProp(entity, Prop_Send, "m_nSequence", 0);
  204. if (is_chair[entity] <= 1)
  205. {
  206. if (GetConVarInt(g_Cvar_GasUse))
  207. {
  208. if (car_fuel[entity] > 0.0)
  209. {
  210. AcceptEntityInput(entity, "TurnOn");
  211. }
  212. else PrintToChat(Driver, "\x04[Car] %T", "No_Gas", Driver);
  213. }
  214. else
  215. {
  216. AcceptEntityInput(entity, "TurnOn");
  217. CarOn[entity] = true;
  218. }
  219. }
  220. else if (is_chair[entity] == 2)
  221. {
  222. AcceptEntityInput(entity, "TurnOff");
  223. CarOn[entity] = false;
  224. }
  225.  
  226. decl String:targetName[100];
  227.  
  228. decl Float:sprite_rgb[3];
  229. sprite_rgb[0] = 0.0;
  230. sprite_rgb[1] = 0.0;
  231. sprite_rgb[2] = 0.0;
  232.  
  233. GetTargetName(entity, targetName, sizeof(targetName));
  234.  
  235. new sprite = CreateEntityByName("env_sprite");
  236.  
  237. DispatchKeyValue(sprite, "model", "materials/sprites/dot.vmt");
  238. DispatchKeyValue(sprite, "renderamt", "0");
  239. DispatchKeyValue(sprite, "renderamt", "0");
  240. DispatchKeyValueVector(sprite, "rendercolor", sprite_rgb);
  241.  
  242. DispatchSpawn(sprite);
  243.  
  244. new Float:vec[3];
  245.  
  246. GetClientAbsOrigin(Driver, vec);
  247. GetClientAbsAngles(Driver, ang);
  248.  
  249. TeleportEntity(sprite, vec, ang, NULL_VECTOR);
  250.  
  251. SetClientViewEntity(Driver, sprite);
  252.  
  253. SetVariantString("!activator");
  254. AcceptEntityInput(sprite, "SetParent", Driver);
  255.  
  256. SetVariantString(targetName);
  257. AcceptEntityInput(Driver, "SetParent");
  258.  
  259. SetVariantString("vehicle_driver_eyes");
  260. AcceptEntityInput(Driver, "SetParentAttachment");
  261.  
  262. // SetEntProp(entity, Prop_Send, "m_nSolidType", 2);
  263.  
  264. ViewEnt[entity] = sprite;
  265. }
  266. if (Driver > 0)
  267. {
  268. drivers_car[Driver] = entity;
  269. Driving[Driver] = true;
  270. buttons2 = GetClientButtons(Driver);
  271. // Brake Lights on or Off
  272.  
  273. if (buttons2 & IN_ATTACK)
  274. {
  275. if (!CarHorn[Driver])
  276. {
  277. if (is_chair[entity] <= 1)
  278. {
  279. EmitSoundToAll("vehicles/mustang_horn.mp3", entity, SNDCHAN_AUTO, SNDLEVEL_AIRCRAFT);
  280. CarHorn[Driver] = true;
  281. new Float:delay = GetConVarFloat(g_Cvar_DelayH);
  282. h_horn = CreateTimer(delay, Horn_Time, Driver);
  283. }
  284. }
  285. }
  286. new car_index = g_CarIndex[entity];
  287. new max = g_CarLightQuantity[car_index];
  288. if (max > 0)
  289. {
  290. decl light;
  291. if (CarOn[entity])
  292. {
  293. light = g_CarLights[car_index][2];
  294. if (IsValidEntity(light))
  295. {
  296. AcceptEntityInput(light, "ShowSprite");
  297. }
  298. light = g_CarLights[car_index][3];
  299. if (IsValidEntity(light))
  300. {
  301. AcceptEntityInput(light, "ShowSprite");
  302. }
  303.  
  304. /* AcceptEntityInput(g_CarLights[car_index][6], "LightOn");
  305. AcceptEntityInput(g_CarLights[car_index][7], "LightOn"); */
  306. }
  307. if (buttons2 & IN_JUMP)
  308. {
  309. light = g_CarLights[car_index][0];
  310. if (IsValidEntity(light))
  311. {
  312. AcceptEntityInput(light, "ShowSprite");
  313. }
  314. light = g_CarLights[car_index][1];
  315. if (IsValidEntity(light))
  316. {
  317. AcceptEntityInput(light, "ShowSprite");
  318. }
  319. }
  320. else
  321. {
  322. light = g_CarLights[car_index][0];
  323. if (IsValidEntity(light))
  324. {
  325. AcceptEntityInput(light, "HideSprite");
  326. }
  327. light = g_CarLights[car_index][1];
  328. if (IsValidEntity(light))
  329. {
  330. AcceptEntityInput(light, "HideSprite");
  331. }
  332. }
  333. }
  334. if (GetConVarInt(g_Cvar_GasUse))
  335. {
  336. // Car is on so they're burning gas
  337. // How fast they burn it depends on forewards or reverse or idle
  338. if (buttons2 & IN_FORWARD)
  339. {
  340. car_fuel[entity] -= (0.001 / mpg[entity]);
  341. }
  342. else if (buttons2 & IN_BACK)
  343. {
  344. car_fuel[entity] -= (0.0005 / mpg[entity]);
  345. }
  346. else car_fuel[entity] -= (0.0001 / mpg[entity]);
  347.  
  348. if (car_fuel[entity] <= 0.0)
  349. {
  350. car_fuel[entity] = 0.0;
  351. AcceptEntityInput(entity, "TurnOff");
  352. }
  353. fuel_display[entity] = RoundToCeil(car_fuel[entity]);
  354. SetEntData(Driver, m_ArmorValue,fuel_display[entity],4,true);
  355. }
  356. if (is_chair[entity] == 0)
  357. {
  358. new speed = GetEntProp(entity, Prop_Data, "m_nSpeed");
  359. PrintHintText(Driver, "%T", "Speed", Driver, speed);
  360. }
  361. }
  362. }
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373. public Action:Event_player_hurt(Handle:event, const String:name[], bool:dontBroadcast)
  374. {
  375. new victimId = GetEventInt(event, "userid");
  376. if (victimId != 0)
  377. {
  378. new victim = GetClientOfUserId(victimId);
  379. new car = GetEntPropEnt(victim, Prop_Send, "m_hVehicle");
  380. if (car != -1)
  381. {
  382. new plyr_hp = GetClientHealth(victim);
  383. new damage = GetEventInt(event, "dmg_health");
  384. plyr_hp -= damage;
  385.  
  386. if (plyr_hp <= 0)
  387. {
  388. LeaveVehicle(victim);
  389. FakeClientCommand(victim, "kill");
  390. }
  391. else
  392. {
  393. SetEntityHealth(victim, plyr_hp);
  394. }
  395. if ((cars_seats[car] > 0) && (is_chair[car] == 0))
  396. {
  397. new Passenger = -1;
  398. for ( new ic = 1; ic < cars_seats[car] + 1; ic++ )
  399. {
  400. Passenger = GetEntPropEnt(cars_seat_entities[car][ic], Prop_Send, "m_hPlayer");
  401. if (Passenger > 0)
  402. {
  403. plyr_hp = GetClientHealth(Passenger);
  404. plyr_hp -= damage;
  405.  
  406. if (plyr_hp <= 0)
  407. {
  408. LeaveVehicle(Passenger);
  409. FakeClientCommand(Passenger, "kill");
  410. }
  411. else
  412. {
  413. SetEntityHealth(Passenger, plyr_hp);
  414. }
  415. }
  416. }
  417. }
  418. return Plugin_Continue;
  419. }
  420. }
  421. return Plugin_Continue;
  422. }
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431. public Action:Car_Seat(client, args)
  432. {
  433. if (GetConVarInt(g_Cvar_Enable))
  434. {
  435. if (IsPlayerAlive(client))
  436. {
  437. new car = GetEntPropEnt(client, Prop_Send, "m_hVehicle");
  438. if(car != -1)
  439. {
  440. if (is_chair[car] == 1)
  441. {
  442. new seat = car;
  443. car = chairs_car[seat];
  444.  
  445. new done = 0;
  446. new Passenger = -1;
  447. for ( new ic = 1; ic < cars_seats[car] + 1; ic++ )
  448. {
  449. Passenger = GetEntPropEnt(cars_seat_entities[car][ic], Prop_Send, "m_hPlayer");
  450. if (Passenger == -1)
  451. {
  452. new chair = cars_seat_entities[car][ic];
  453. if (IsValidEntity(chair))
  454. {
  455. LeaveVehicle(client);
  456. new t = cars_type[car];
  457. SetVariantString("");
  458. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  459. AcceptEntityInput(chair, "use", client);
  460.  
  461. new String:car_name2[128];
  462. GetTargetName(car,car_name2,sizeof(car_name2));
  463.  
  464. SetVariantString(car_name2);
  465. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  466. SetVariantString(car_passenger_attachment[t][ic]);
  467. AcceptEntityInput(chair, "SetParentAttachment", chair, chair, 0);
  468. done = 1;
  469. break;
  470. }
  471. }
  472. }
  473. new driver = GetEntPropEnt(car, Prop_Send, "m_hPlayer");
  474. if ((done == 0) && (driver == -1))
  475. {
  476. LeaveVehicle(client);
  477. AcceptEntityInput(car, "use", client);
  478. done = 1;
  479. }
  480. }
  481. else if (cars_seats[car] > 0)
  482. {
  483. new done = 0;
  484. new Passenger = -1;
  485. for ( new ic = 1; ic < cars_seats[car] + 1; ic++ )
  486. {
  487. if (IsValidEntity(cars_seat_entities[car][ic]))
  488. {
  489. Passenger = GetEntPropEnt(cars_seat_entities[car][ic], Prop_Send, "m_hPlayer");
  490. if (Passenger == -1)
  491. {
  492. new chair = cars_seat_entities[car][ic];
  493. if (IsValidEntity(chair))
  494. {
  495. LeaveVehicle(client);
  496. new t = cars_type[car];
  497. SetVariantString("");
  498. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  499. AcceptEntityInput(chair, "use", client);
  500.  
  501. new String:car_name2[128];
  502. GetTargetName(car,car_name2,sizeof(car_name2));
  503.  
  504. SetVariantString(car_name2);
  505. AcceptEntityInput(chair, "SetParent", chair, chair, 0);
  506. SetVariantString(car_passenger_attachment[t][ic]);
  507. AcceptEntityInput(chair, "SetParentAttachment", chair, chair, 0);
  508. done = 1;
  509. break;
  510. }
  511. }
  512. }
  513. }
  514. new driver = GetEntPropEnt(car, Prop_Send, "m_hPlayer");
  515. if ((done == 0) && (driver == -1))
  516. {
  517. AcceptEntityInput(car, "use", client);
  518. done = 1;
  519. }
  520. }
  521. }
  522. else PrintToChat(client, "\x04[Car] %T", "Get_Inside", client);
  523. return Plugin_Handled;
  524. }
  525. else PrintToChat(client, "\x04[Car] %T", "Youre_Dead", client);
  526. return Plugin_Handled;
  527. }
  528. else PrintToChat(client, "\x04[Car] %T", "Disabled", client);
  529. return Plugin_Handled;
  530. }
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537. // This spawns the car. At the end is seat information.
  538.  
  539. if (StrEqual(info,"1"))
  540. {
  541. if (!IsPlayerAlive(param1))
  542. {
  543. PrintToChat(param1, "\x04[Car] %T", "Youre_Dead", param1);
  544. Reset_Car_Selection(param1);
  545. return;
  546. }
  547. if (selected_car[param1] == -1)
  548. {
  549. Reset_Car_Selection(param1);
  550. return;
  551. }
  552. if (selected_car_stowed[param1] == 0)
  553. {
  554. Reset_Car_Selection(param1);
  555. return;
  556. }
  557. new i = selected_car_type[param1];
  558. if (i == 0)
  559. {
  560. Reset_Car_Selection(param1);
  561. return;
  562. }
  563.  
  564. if (StrEqual(car_model[i],"FUCK_YOU"))
  565. {
  566. PrintToServer("[Car DEBUG] Error in cars.ini for vehicle: %s (Model not found.)", car_name[i]);
  567. PrintToChat(param1, "\x04[Car DEBUG] %T", "Error_V", param1, car_name[i]);
  568. PrintToChat(param1, "\x04[Car DEBUG] %T", "Error_No_Spawn", param1);
  569. Reset_Car_Selection(param1);
  570. return;
  571. }
  572. if (StrEqual(car_script[i],"FUCK_YOU"))
  573. {
  574. PrintToServer("[Car DEBUG] Error in cars.ini for vehicle: %s (Script not found.)", car_name[i]);
  575. PrintToChat(param1, "\x04[Car DEBUG] %T", "Error_V", param1, car_name[i]);
  576. PrintToChat(param1, "\x04[Car DEBUG] %T", "Error_No_Spawn", param1);
  577. Reset_Car_Selection(param1);
  578. return;
  579. }
  580.  
  581. selected_car_stowed[param1] = 0;
  582.  
  583. // Get the location for the car.
  584. new Float:EyeAng[3];
  585. GetClientEyeAngles(param1, EyeAng);
  586. new Float:ForwardVec[3];
  587. GetAngleVectors(EyeAng, ForwardVec, NULL_VECTOR, NULL_VECTOR);
  588. ScaleVector(ForwardVec, 100.0);
  589. ForwardVec[2] = 0.0;
  590. new Float:EyePos[3];
  591. GetClientEyePosition(param1, EyePos);
  592. new Float:AbsAngle[3];
  593. GetClientAbsAngles(param1, AbsAngle);
  594.  
  595. new Float:SpawnAngles[3];
  596. SpawnAngles[1] = EyeAng[1];
  597. new Float:SpawnOrigin[3];
  598. AddVectors(EyePos, ForwardVec, SpawnOrigin);
  599.  
  600. new ent = CreateEntityByName("prop_vehicle_driveable");
  601. if(IsValidEntity(ent))
  602. {
  603. Cars_Driver_Prop[ent] = -1;
  604. ActivateEntity(ent);
  605. decl String:skin[4];
  606. Format(skin, sizeof(skin), "%i", selected_car_skin[param1]);
  607.  
  608. new String:ent_name[16], String:light_index[16];
  609. Format(ent_name, 16, "%i", ent);
  610. Format(light_index, 16, "%iLgt", ent);
  611.  
  612. g_SpawnedCars[param1] += 1;
  613. new String:Car_Name[64];
  614. Format(Car_Name, sizeof(Car_Name), "%s_%i", authid[param1], g_SpawnedCars[param1]);
  615.  
  616. DispatchKeyValue(ent, "vehiclescript", car_script[i]);
  617. DispatchKeyValue(ent, "model", car_model[i]);
  618. DispatchKeyValueFloat (ent, "MaxPitch", 360.00);
  619. DispatchKeyValueFloat (ent, "MinPitch", -360.00);
  620. DispatchKeyValueFloat (ent, "MaxYaw", 90.00);
  621. DispatchKeyValue(ent, "targetname", Car_Name);
  622. DispatchKeyValue(ent, "solid","6");
  623. DispatchKeyValue(ent, "actionScale","1");
  624. DispatchKeyValue(ent, "EnableGun","0");
  625. DispatchKeyValue(ent, "ignorenormals","0");
  626. DispatchKeyValue(ent, "fadescale","1");
  627. DispatchKeyValue(ent, "fademindist","-1");
  628. DispatchKeyValue(ent, "VehicleLocked","0");
  629. DispatchKeyValue(ent, "screenspacefade","0");
  630. DispatchKeyValue(ent, "spawnflags", "256" );
  631. DispatchKeyValue(ent, "skin", skin);
  632. DispatchKeyValue(ent, "setbodygroup", "511" );
  633. TeleportEntity(ent, SpawnOrigin, SpawnAngles, NULL_VECTOR);
  634.  
  635.  
  636. PrintToServer("[Car] %s spawned a %s.", authid[param1], car_name[i]);
  637. PrintToChat(param1, "\x04[Car] %T", "Spawn", param1, car_name[i]);
  638.  
  639. DispatchSpawn(ent);
  640.  
  641. // Thanks to blodia for this
  642.  
  643. SetEntProp(ent, Prop_Data, "m_nNextThinkTick", -1);
  644. SDKHook(ent, SDKHook_Think, OnThink);
  645.  
  646. ViewEnt[ent] = -1;
  647.  
  648. SetCarOwnership(param1, ent, 1);
  649. car_owner[ent] = param1;
  650.  
  651. new c = selected_car[param1];
  652. Car_Entity[param1][c] = ent;
  653.  
  654. g_CarQty += 1;
  655. g_CarIndex[ent] = g_CarQty;
  656. new car_index2 = g_CarIndex[ent];
  657. g_CarLightQuantity[car_index2] = 0;
  658.  
  659. // Set the gas in the tank.
  660. car_fuel[ent] = selected_car_fuel[param1];
  661. mpg[ent] = car_mpg[i];
  662. cars_type[ent] = i;
  663. CarOn[ent] = true;
  664. cars_index[ent] = selected_car_index[param1];
  665. is_chair[ent] = 0;
  666. chairs_car[ent] = -1;
  667.  
  668.  
  669. // Car is spawned and all neccessary arrays are taken care of.
  670. // Now we move on to lights.
  671.  
  672.  
  673.  
  674.  
  675.  
  676. if (car_lights[i] == 1)
  677. {
  678. // First declare some angles and colours.
  679. decl Float:brake_rgb[3], Float:brake_angles[3], Float:white_rgb[3], Float:blue_rgb[3];
  680. brake_rgb[0] = 255.0;
  681. brake_rgb[1] = 0.0;
  682. brake_rgb[2] = 0.0;
  683.  
  684. blue_rgb[0] = 0.0;
  685. blue_rgb[1] = 0.0;
  686. blue_rgb[2] = 255.0;
  687.  
  688. white_rgb[0] = 255.0;
  689. white_rgb[1] = 255.0;
  690. white_rgb[2] = 255.0;
  691.  
  692. brake_angles[0] = 0.0;
  693. brake_angles[1] = 0.0;
  694. brake_angles[2] = 0.0;
  695.  
  696. // Then we create the brake lights. Siren lights will come later if applicable.
  697.  
  698. new brake_l = CreateEntityByName("env_sprite");
  699.  
  700.  
  701. DispatchKeyValue(brake_l, "parentname", ent_name);
  702. DispatchKeyValue(brake_l, "targetname", light_index);
  703. DispatchKeyValueFloat(brake_l, "HDRColorScale", 1.0);
  704. DispatchKeyValue(brake_l, "renderamt", "155");
  705. DispatchKeyValueVector(brake_l, "rendercolor", brake_rgb);
  706. DispatchKeyValueVector(brake_l, "angles", brake_angles);
  707. DispatchKeyValue(brake_l, "spawnflags", "3");
  708. DispatchKeyValue(brake_l, "rendermode", "5");
  709. DispatchKeyValue(brake_l, "model", "sprites/light_glow02.spr");
  710. DispatchKeyValueFloat(brake_l, "scale", 0.2);
  711. DispatchSpawn(brake_l);
  712. TeleportEntity(brake_l, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  713. SetVariantString(Car_Name);
  714. AcceptEntityInput(brake_l, "SetParent", brake_l, brake_l, 0);
  715. SetVariantString("light_rl")
  716. AcceptEntityInput(brake_l, "SetParentAttachment", brake_l, brake_l, 0);
  717.  
  718. g_CarLightQuantity[car_index2] += 1;
  719. g_CarLights[car_index2][0] = brake_l;
  720.  
  721.  
  722. new brake_r = CreateEntityByName("env_sprite");
  723.  
  724.  
  725. DispatchKeyValue(brake_l, "parentname", ent_name);
  726. DispatchKeyValue(brake_l, "targetname", light_index);
  727. DispatchKeyValueFloat(brake_r, "HDRColorScale", 1.0);
  728. DispatchKeyValue(brake_r, "renderamt", "155");
  729. DispatchKeyValueVector(brake_r, "rendercolor", brake_rgb);
  730. DispatchKeyValueVector(brake_r, "angles", brake_angles);
  731. DispatchKeyValue(brake_r, "spawnflags", "3");
  732. DispatchKeyValue(brake_r, "rendermode", "5");
  733. DispatchKeyValue(brake_r, "model", "sprites/light_glow02.spr");
  734. DispatchKeyValueFloat(brake_r, "scale", 0.2);
  735. DispatchSpawn(brake_r);
  736. TeleportEntity(brake_r, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  737. SetVariantString(Car_Name);
  738. AcceptEntityInput(brake_r, "SetParent", brake_r, brake_r, 0);
  739. SetVariantString("light_rr")
  740. AcceptEntityInput(brake_r, "SetParentAttachment", brake_r, brake_r, 0);
  741.  
  742. g_CarLightQuantity[car_index2] += 1;
  743. g_CarLights[car_index2][1] = brake_r;
  744.  
  745.  
  746. new brake_l2 = CreateEntityByName("env_sprite");
  747.  
  748. DispatchKeyValue(brake_l2, "parentname", ent_name);
  749. DispatchKeyValue(brake_l2, "targetname", light_index);
  750. DispatchKeyValueFloat(brake_l2, "HDRColorScale", 1.0);
  751. DispatchKeyValue(brake_l2, "renderamt", "100");
  752. DispatchKeyValueVector(brake_l2, "rendercolor", brake_rgb);
  753. DispatchKeyValueVector(brake_l2, "angles", brake_angles);
  754. DispatchKeyValue(brake_l2, "spawnflags", "3");
  755. DispatchKeyValue(brake_l2, "rendermode", "5");
  756. DispatchKeyValue(brake_l2, "model", "sprites/light_glow02.spr");
  757. DispatchKeyValueFloat(brake_l2, "scale", 0.2);
  758. DispatchSpawn(brake_l2);
  759. TeleportEntity(brake_l2, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  760. SetVariantString(Car_Name);
  761. AcceptEntityInput(brake_l2, "SetParent", brake_l, brake_l, 0);
  762. SetVariantString("light_rl")
  763. AcceptEntityInput(brake_l2, "SetParentAttachment", brake_l, brake_l, 0);
  764.  
  765. g_CarLightQuantity[car_index2] += 1;
  766. g_CarLights[car_index2][2] = brake_l2;
  767.  
  768.  
  769. new brake_r2 = CreateEntityByName("env_sprite");
  770.  
  771.  
  772. DispatchKeyValue(brake_r2, "parentname", ent_name);
  773. DispatchKeyValue(brake_r2, "targetname", light_index);
  774. DispatchKeyValueFloat(brake_r2, "HDRColorScale", 1.0);
  775. DispatchKeyValue(brake_r2, "renderamt", "100");
  776. DispatchKeyValueVector(brake_r2, "rendercolor", brake_rgb);
  777. DispatchKeyValueVector(brake_r2, "angles", brake_angles);
  778. DispatchKeyValue(brake_r2, "spawnflags", "3");
  779. DispatchKeyValue(brake_r2, "rendermode", "5");
  780. DispatchKeyValue(brake_r2, "model", "sprites/light_glow02.spr");
  781. DispatchKeyValueFloat(brake_r2, "scale", 0.2);
  782. DispatchSpawn(brake_r2);
  783. TeleportEntity(brake_r2, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  784. SetVariantString(Car_Name);
  785. AcceptEntityInput(brake_r2, "SetParent", brake_r, brake_r, 0);
  786. SetVariantString("light_rr")
  787. AcceptEntityInput(brake_r2, "SetParentAttachment", brake_r, brake_r, 0);
  788.  
  789. g_CarLightQuantity[car_index2] += 1;
  790. g_CarLights[car_index2][3] = brake_r2;
  791.  
  792.  
  793.  
  794. /* new headlight_l = CreateEntityByName("point_spotlight");
  795. DispatchKeyValue(headlight_l, "parentname", ent_name);
  796. DispatchKeyValue(headlight_l, "targetname", light_index);
  797. DispatchKeyValueVector(headlight_l, "rendercolor", white_rgb);
  798. DispatchKeyValue(headlight_l, "inner_cone", "10");
  799. DispatchKeyValue(headlight_l, "cone", "20");
  800. DispatchKeyValueFloat(headlight_l, "spotlight_radius", 40.0);
  801. DispatchKeyValueFloat(headlight_l, "distance", 400.0);
  802. DispatchKeyValue(headlight_l, "brightness", "1");
  803. DispatchKeyValue(headlight_l, "rendercolor", "255 255 255");
  804. DispatchKeyValue(headlight_l, "_light", "255 255 255 255");
  805. DispatchKeyValue(headlight_l, "style", "0");
  806. DispatchKeyValue(headlight_l, "pitch", "90");
  807. DispatchKeyValue(headlight_l, "renderamt", "200");
  808. DispatchSpawn(headlight_l);
  809. TeleportEntity(headlight_l, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  810. SetVariantString(Car_Name);
  811. AcceptEntityInput(headlight_l, "SetParent", headlight_l, headlight_l, 0);
  812. SetVariantString("light_fl")
  813. AcceptEntityInput(headlight_l, "SetParentAttachment", headlight_l, headlight_l, 0);
  814. AcceptEntityInput(headlight_l, "LightOn");
  815.  
  816. g_CarLights[car_index2][6] = headlight_l;
  817.  
  818.  
  819. new headlight_r = CreateEntityByName("point_spotlight");
  820. DispatchKeyValue(headlight_r, "parentname", ent_name);
  821. DispatchKeyValue(headlight_r, "targetname", light_index);
  822. DispatchKeyValueVector(headlight_r, "rendercolor", white_rgb);
  823. DispatchKeyValue(headlight_r, "inner_cone", "10");
  824. DispatchKeyValue(headlight_r, "cone", "20");
  825. DispatchKeyValueFloat(headlight_r, "spotlight_radius", 40.0);
  826. DispatchKeyValueFloat(headlight_r, "distance", 400.0);
  827. DispatchKeyValue(headlight_r, "brightness", "1");
  828. DispatchKeyValue(headlight_r, "rendercolor", "255 255 255");
  829. DispatchKeyValue(headlight_r, "_light", "255 255 255 255");
  830. DispatchKeyValue(headlight_r, "style", "0");
  831. DispatchKeyValue(headlight_r, "pitch", "90");
  832. DispatchKeyValue(headlight_r, "renderamt", "200");
  833. DispatchSpawn(headlight_r);
  834. TeleportEntity(headlight_r, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  835. SetVariantString(Car_Name);
  836. AcceptEntityInput(headlight_r, "SetParent", headlight_r, headlight_r, 0);
  837. SetVariantString("light_fr")
  838. AcceptEntityInput(headlight_r, "SetParentAttachment", headlight_r, headlight_r, 0);
  839. AcceptEntityInput(headlight_r, "LightOn");
  840.  
  841. g_CarLights[car_index2][7] = headlight_r; */
  842.  
  843.  
  844. if (car_police_lights[i] == 1)
  845. {
  846. new blue_1 = CreateEntityByName("env_sprite");
  847.  
  848. DispatchKeyValue(blue_1, "parentname", ent_name);
  849. DispatchKeyValue(blue_1, "targetname", light_index);
  850. DispatchKeyValueFloat(blue_1, "HDRColorScale", 1.0);
  851. DispatchKeyValue(blue_1, "renderamt", "255");
  852. DispatchKeyValueVector(blue_1, "rendercolor", blue_rgb);
  853. DispatchKeyValueVector(blue_1, "angles", brake_angles);
  854. DispatchKeyValue(blue_1, "spawnflags", "3");
  855. DispatchKeyValue(blue_1, "rendermode", "5");
  856. DispatchKeyValue(blue_1, "model", "sprites/light_glow02.spr");
  857. /* DispatchKeyValue(blue_1, "spotlightwidth", "40");
  858. DispatchKeyValue(blue_1, "spotlightlength", "10"); */
  859. DispatchSpawn(blue_1);
  860. TeleportEntity(blue_1, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  861. SetVariantString(Car_Name)
  862. AcceptEntityInput(blue_1, "SetParent", blue_1, blue_1, 0);
  863. SetVariantString("light_bar1")
  864. AcceptEntityInput(blue_1, "SetParentAttachment", blue_1, blue_1, 0);
  865. AcceptEntityInput(blue_1, "HideSprite");
  866.  
  867. g_CarLightQuantity[car_index2] += 1;
  868. g_CarLights[car_index2][4] = blue_1;
  869.  
  870. new blue_2 = CreateEntityByName("env_sprite");
  871.  
  872. DispatchKeyValue(blue_2, "parentname", ent_name);
  873. DispatchKeyValue(blue_2, "targetname", light_index);
  874. DispatchKeyValueFloat(blue_2, "HDRColorScale", 1.0);
  875. DispatchKeyValue(blue_2, "renderamt", "255");
  876. DispatchKeyValueVector(blue_2, "rendercolor", blue_rgb);
  877. DispatchKeyValueVector(blue_2, "angles", brake_angles);
  878. DispatchKeyValue(blue_2, "spawnflags", "3");
  879. DispatchKeyValue(blue_2, "rendermode", "5");
  880. DispatchKeyValue(blue_2, "model", "sprites/light_glow02.spr");
  881. /* DispatchKeyValue(blue_2, "spotlightwidth", "40");
  882. DispatchKeyValue(blue_2, "spotlightlength", "10"); */
  883. DispatchSpawn(blue_2);
  884. TeleportEntity(blue_2, SpawnOrigin, NULL_VECTOR, NULL_VECTOR);
  885. SetVariantString(Car_Name)
  886. AcceptEntityInput(blue_2, "SetParent", blue_2, blue_2, 0);
  887. SetVariantString("light_bar2")
  888. AcceptEntityInput(blue_2, "SetParentAttachment", blue_2, blue_2, 0);
  889. AcceptEntityInput(blue_2, "HideSprite");
  890.  
  891. g_CarLightQuantity[car_index2] += 1;
  892. g_CarLights[car_index2][5] = blue_2;
  893.  
  894. CarSiren[ent] = false;
  895. }
  896. }
  897.  
  898. // That was the bit for car lights. Now for seats. :)
  899. cars_seats[ent] = 0;
  900. if (car_passengers[i] > 0)
  901. {
  902. for ( new ic = 1; ic < car_passengers[i] + 1; ic++ )
  903. {
  904. new seat = CreateEntityByName("prop_vehicle_driveable");
  905. if(IsValidEntity(seat))
  906. {
  907. cars_seat_entities[ent][ic] = seat;
  908. Cars_Driver_Prop[seat] = -1;
  909.  
  910. new String:Seat_Name[64];
  911. Format(Seat_Name, sizeof(Seat_Name), "%i_chair", seat);
  912.  
  913. DispatchKeyValue(seat, "vehiclescript", "scripts/vehicles/chair.txt");
  914. DispatchKeyValue(seat, "model", car_passenger_seat[i][ic]);
  915. DispatchKeyValueFloat (seat, "MaxPitch", 360.00);
  916. DispatchKeyValueFloat (seat, "MinPitch", -360.00);
  917. DispatchKeyValueFloat (seat, "MaxYaw", 90.00);
  918. DispatchKeyValue(seat, "targetname", Seat_Name);
  919. DispatchKeyValue(seat, "solid","6");
  920. DispatchKeyValue(seat, "actionScale","1");
  921. DispatchKeyValue(seat, "EnableGun","0");
  922. DispatchKeyValue(seat, "ignorenormals","0");
  923. DispatchKeyValue(seat, "fadescale","1");
  924. DispatchKeyValue(seat, "fademindist","-1");
  925. DispatchKeyValue(seat, "VehicleLocked","0");
  926. DispatchKeyValue(seat, "screenspacefade","0");
  927. DispatchKeyValue(seat, "spawnflags", "256" );
  928. DispatchKeyValue(seat, "skin", "0");
  929. DispatchKeyValue(seat, "setbodygroup", "511" );
  930. TeleportEntity(seat, SpawnOrigin, SpawnAngles, NULL_VECTOR);
  931.  
  932. DispatchSpawn(seat);
  933. ActivateEntity(seat);
  934.  
  935. SetEntProp(seat, Prop_Data, "m_nNextThinkTick", -1);
  936. SDKHook(seat, SDKHook_Think, OnThink);
  937. AcceptEntityInput(seat, "TurnOff");
  938.  
  939. ViewEnt[seat] = -1;
  940.  
  941. car_fuel[seat] = 10.0;
  942. mpg[seat] = 10;
  943. cars_type[seat] = 100;
  944.  
  945. SetVariantString(Car_Name)
  946. AcceptEntityInput(seat, "SetParent", seat, seat, 0);
  947. SetVariantString(car_passenger_attachment[i][ic]);
  948. AcceptEntityInput(seat, "SetParentAttachment", seat, seat, 0);
  949. cars_seats[ent] += 1;
  950. is_chair[seat] = 1;
  951. chairs_car[seat] = ent;
  952. }
  953. }
  954. }
  955. }
  956. }
  957.  
  958.  
  959. // Put these in OnPluginStart()
  960. RegConsoleCmd("sm_seat", Car_Seat, " -- Switch seats in a car if applicable.");
  961. ReadCarFile();
  962.  
  963.  
  964. // You probably need most of these at the start of the plugin
  965. // Car Buy Menu Load Arrays
  966.  
  967. new car_quantity = 0;
  968. new car_quantity_vip = 0;
  969. new car_quantity_disabled = 0;
  970. new car_vip[MAX_CARS];
  971. new String:car_name[MAX_CARS][32];
  972. new String:car_model[MAX_CARS][256];
  973. new String:car_script[MAX_CARS][256];
  974. new car_skins[MAX_CARS];
  975. new car_price[MAX_CARS];
  976. new car_mpg[MAX_CARS];
  977. new car_lights[MAX_CARS];
  978. new car_police_lights[MAX_CARS];
  979. new car_view_enabled[MAX_CARS];
  980. new car_siren_enabled[MAX_CARS];
  981. new car_driver_view[MAX_CARS];
  982. new Float:car_gas[MAX_CARS];
  983. new car_passengers[MAX_CARS];
  984. new String:car_passenger_seat[MAX_CARS][11][128];
  985. new String:car_passenger_attachment[MAX_CARS][11][32];
  986.  
  987. // Temporary Car Menu Arrays
  988. new selected_car[MAXPLAYERS+1];
  989. new selected_car_stowed[MAXPLAYERS+1];
  990. new selected_car_skin[MAXPLAYERS+1];
  991. new selected_car_type[MAXPLAYERS+1];
  992. new selected_car_index[MAXPLAYERS+1];
  993. new Float:selected_car_fuel[MAXPLAYERS+1];
  994. new String:selected_car_name[MAXPLAYERS+1][32];
  995.  
  996. new m_ArmorValue;
  997. new MoneyOffset;
  998.  
  999. // Individual Car Arrays
  1000. new cars_type[MAX_ENTITIES];
  1001. new cars_index[MAX_ENTITIES];
  1002. new drivers_car[MAXPLAYERS+1];
  1003. new Car_Entity[MAXPLAYERS+1][10];
  1004. new Car_Type[MAXPLAYERS+1][10];
  1005. new Car_Skin[MAXPLAYERS+1][10];
  1006. new Float:Car_Gas[MAXPLAYERS+1][10];
  1007. new Cars_Driver_Prop[MAX_ENTITIES];
  1008. new cars_seats[MAX_ENTITIES];
  1009. new cars_seat_entities[MAX_ENTITIES][11];
  1010. new is_chair[MAX_ENTITIES];
  1011. new chairs_car[MAX_ENTITIES];
  1012. new car_owner[MAX_ENTITIES];
  1013.  
  1014.  
  1015. public ReadCarFile()
  1016. {
  1017. carbuykv = CreateKeyValues("Commands")
  1018. new String:file[256]
  1019. BuildPath(Path_SM, file, 255, "configs/cars.ini")
  1020. FileToKeyValues(carbuykv, file)
  1021.  
  1022. KvRewind(carbuykv);
  1023.  
  1024. if (!KvGotoFirstSubKey(carbuykv))
  1025. {
  1026. PrintToServer("[RP DEBUG] There are no cars listed in cars.ini, or there is an error with the file.");
  1027. return;
  1028. }
  1029. new t = 1;
  1030. do
  1031. {
  1032. KvGetSectionName(carbuykv, car_name[t], sizeof(car_name[]));
  1033. car_price[t] = KvGetNum(carbuykv, "Price", 2000);
  1034. car_vip[t] = KvGetNum(carbuykv, "VIP", 0);
  1035. car_skins[t] = KvGetNum(carbuykv, "val_1", 0);
  1036. KvGetString(carbuykv, "model", car_model[t], 255, "FUCK_YOU");
  1037. PrecacheModel(car_model[t]);
  1038. KvGetString(carbuykv, "script", car_script[t], 255, "FUCK_YOU");
  1039. car_mpg[t] = KvGetNum(carbuykv, "mpg", 20);
  1040. car_gas[t] = KvGetFloat(carbuykv, "gas_tank", 16.00);
  1041. car_lights[t] = KvGetNum(carbuykv, "lights", 0);
  1042. car_police_lights[t] = KvGetNum(carbuykv, "police_lights", 0);
  1043. car_view_enabled[t] = KvGetNum(carbuykv, "view", 0);
  1044. car_siren_enabled[t] = KvGetNum(carbuykv, "siren", 0);
  1045. car_driver_view[t] = KvGetNum(carbuykv, "driver", 0);
  1046. car_passengers[t] = KvGetNum(carbuykv, "passengers", 0);
  1047.  
  1048. if (car_passengers[t] > 0)
  1049. {
  1050. new String:buffer_m[32];
  1051. new String:buffer_a[32];
  1052. for ( new ic = 1; ic < car_passengers[t] + 1; ic++ )
  1053. {
  1054. Format(buffer_m, sizeof(buffer_m), "p%i_model", ic);
  1055. KvGetString(carbuykv, buffer_m, car_passenger_seat[t][ic], sizeof(car_passenger_seat), "UNKNOWN");
  1056. if (StrEqual(car_passenger_seat[t][ic], "UNKNOWN", false))
  1057. {
  1058. car_passengers[t] = 0;
  1059. PrintToServer("[Car] Car %s has an error for passenger seat model %i.", car_name[t], ic);
  1060. break;
  1061. }
  1062. Format(buffer_a, sizeof(buffer_a), "p%i_attachment", ic);
  1063. KvGetString(carbuykv, buffer_a, car_passenger_attachment[t][ic], sizeof(car_passenger_attachment), "UNKNOWN");
  1064. if (StrEqual(car_passenger_attachment[t][ic], "UNKNOWN", false))
  1065. {
  1066. car_passengers[t] = 0;
  1067. PrintToServer("[Car] Car %s has an error for passenger seat attachment %i.", car_name[t], ic);
  1068. break;
  1069. }
  1070. }
  1071. PrintToServer("[Car] Car %s has %i seat(s).", car_name[t], car_passengers[t]);
  1072. }
  1073.  
  1074.  
  1075. if (car_vip[t] == 1)
  1076. {
  1077. car_quantity_vip += 1;
  1078. }
  1079. else if (car_vip[t] == -1)
  1080. {
  1081. car_quantity_disabled += 1;
  1082. }
  1083. car_quantity += 1;
  1084. t += 1;
  1085.  
  1086. } while (KvGotoNextKey(carbuykv));
  1087.  
  1088. KvRewind(carbuykv);
  1089.  
  1090. car_view_enabled[100] = 1;
  1091. car_driver_view[100] = 1;
  1092.  
  1093. PrintToServer("[Car] Cars Loaded");
  1094. PrintToServer("[Car] %i Cars were detected.", car_quantity - car_quantity_vip - car_quantity_disabled);
  1095. PrintToServer("[Car] %i VIP Cars were detected.", car_quantity_vip);
  1096. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement