Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.99 KB | None | 0 0
  1. #include <ApolloRP_SQL>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <hamsandwich>
  5.  
  6. new Handle:g_hSQLTuple, g_iGas[32]
  7.  
  8. new TravTrie:g_hCar, TravTrie:g_hParkedCar[32], g_iCar[32], g_szModel[32][24], g_szSoundFile[32][24], Float:g_fpCarSpeed[32], TravTrie:g_hStereo
  9.  
  10. new bool:g_bDriveToggle[32], bool:g_bDrivingPoliceCar[32], bool:g_bSirenToggle[32], bool:g_bStereoToggle[32], bool:g_bHeadlightToggle[32]
  11. new bool:g_bAntiFloodRev[32], bool:g_bAntiFloodHonk[32], bool:g_bAntiFloodNote[32], bool:g_bAntiFloodOwner[32], bool:g_bAntiFloodCrash[32]
  12.  
  13. new g_iEngineTaskID[32], g_iSirenTaskID[32], g_iSirenLightsTaskID[32], g_iStereoTaskID[32], g_iGasTaskID[32], g_iAntiFloodRevTaskID[32], g_iAntiFloodHonkTaskID[32]
  14.  
  15. new g_pDaylight, g_pDamage, g_pImpact
  16.  
  17. new g_mStereoMenu[32]
  18.  
  19. public plugin_init()
  20. {
  21. register_forward(FM_Touch, "fnDrive")
  22.  
  23. RegisterHam(Ham_Spawn, "player", "fnSpawn", 1)
  24. RegisterHam(Ham_Killed, "player", "fnKilled", 0)
  25. }
  26.  
  27. public client_PreThink(id)
  28. {
  29. if (!is_user_alive(id))
  30. return
  31.  
  32. if (g_bDriveToggle[id - 1])
  33. {
  34. new iButton = entity_get_int(id, EV_INT_button)
  35.  
  36. iButton &= ~IN_ATTACK
  37. iButton &= ~IN_ATTACK2
  38.  
  39. entity_set_int(id, EV_INT_button, iButton)
  40. }
  41. }
  42.  
  43. public fnDrive(tid, id)
  44. {
  45. new szClassName[12]
  46. entity_get_string(tid, EV_SZ_classname, szClassName, 11)
  47.  
  48. new const iIndex = id - 1
  49.  
  50. if (!equal(szClassName, "func_car"))
  51. {
  52. if (!get_speed(id))
  53. return
  54.  
  55. if (is_user_alive(id) && g_bDriveToggle[iIndex] && !g_bAntiFloodCrash[iIndex] && is_user_alive(tid))
  56. {
  57. emit_sound(id, CHAN_AUTO, "spunky/carmod/crash.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  58.  
  59. new Float:fpVelocity[3]
  60. entity_get_vector(id, EV_VEC_velocity, fpVelocity)
  61.  
  62. for (new i; i < 3; i++)
  63. fpVelocity[i] *= get_pcvar_float(g_pImpact)
  64.  
  65. entity_set_vector(tid, EV_VEC_velocity, fpVelocity)
  66.  
  67. new const Float:fpDamage = get_pcvar_float(g_pDamage)
  68.  
  69. if (fpDamage < 1.0)
  70. fakedamage(tid, "car crash", 1.0, 0)
  71.  
  72. else if (fpDamage > 100.0)
  73. fakedamage(tid, "car crash", 100.0, 0)
  74.  
  75. else
  76. fakedamage(tid, "car crash", fpDamage, 0)
  77.  
  78. g_bAntiFloodCrash[iIndex] = true
  79.  
  80. new iData[1]
  81. iData[0] = id
  82.  
  83. set_task(5.0, "fnResetFloodCrash", _, iData, 1)
  84. }
  85.  
  86. return
  87. }
  88.  
  89. if (g_bDriveToggle[iIndex])
  90. {
  91. if (!g_bAntiFloodNote[iIndex])
  92. {
  93. client_print(id, print_chat, "[CM] You might want to leave a note to the owner of that car...")
  94.  
  95. g_bAntiFloodNote[iIndex] = true
  96.  
  97. new iData[1]
  98. iData[0] = id
  99.  
  100. set_task(10.0, "fnResetFloodNote", _, iData, 1)
  101. }
  102.  
  103. return
  104. }
  105.  
  106. new const iOwner = entity_get_edict(tid, EV_ENT_owner)
  107.  
  108. if (id != iOwner)
  109. {
  110. if (!g_bAntiFloodOwner[iIndex])
  111. {
  112. if (access(id, ADMIN_KICK))
  113. {
  114. new szOwnerName[32]
  115. get_user_name(iOwner, szOwnerName, 31)
  116.  
  117. client_print(id, print_chat, "[CM] ADMIN: This car belongs to %s.", szOwnerName)
  118. }
  119. else
  120. client_print(id, print_chat, "[CM] You are not the owner of this car.")
  121.  
  122. g_bAntiFloodOwner[iIndex] = true
  123.  
  124. new iData[1]
  125. iData[0] = id
  126.  
  127. set_task(10.0, "fnResetFloodOwner", _, iData, 1)
  128. }
  129.  
  130. return
  131. }
  132.  
  133. new szOutput[96], szCarName[32], szCarModel[32], szCarSpeed[12], szPoliceCar[8], szEnt[6], iSpeed, Float:fpSpeed, travTrieIter:hParkedCarIter = GetTravTrieIterator(g_hParkedCar[iIndex])
  134.  
  135. while (MoreTravTrie(hParkedCarIter))
  136. {
  137. ReadTravTrieKey(hParkedCarIter, szCarName, 31)
  138. ReadTravTrieString(hParkedCarIter, szOutput, 95)
  139.  
  140. parse(szOutput, szCarModel, 31, szCarSpeed, 11, szPoliceCar, 7, szEnt, 5)
  141.  
  142. if (tid == str_to_num(szEnt))
  143. {
  144. iSpeed = str_to_num(szCarSpeed)
  145. fpSpeed = float(iSpeed)
  146.  
  147. g_fpCarSpeed[iIndex] = fpSpeed
  148. get_user_info(id, "model", g_szModel[iIndex], 23)
  149. set_user_maxspeed(id, fpSpeed)
  150. client_cmd(id, "cl_forwardspeed %d; cl_sidespeed %d; cl_backspeed %d", iSpeed, iSpeed, iSpeed)
  151. set_user_info(id, "model", szCarModel)
  152. set_user_footsteps(id, 1)
  153. emit_sound(id, CHAN_AUTO, "spunky/carmod/enginestart.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  154.  
  155. new iData[1]
  156. iData[0] = id
  157.  
  158. g_iEngineTaskID[iIndex] = random(1337)
  159. set_task(5.0, "fnEngine", g_iEngineTaskID[iIndex], iData, 1)
  160.  
  161. remove_entity(tid)
  162.  
  163. client_print(id, print_chat, "[CM] You get back into your %s, then start the engine.", szCarName)
  164.  
  165. ARP_FindItemId(szCarName, szOutput, 95)
  166. g_iCar[iIndex] = szOutput[0]
  167.  
  168. g_bDriveToggle[iIndex] = true
  169.  
  170. TravTrieDeleteKey(g_hParkedCar[iIndex], szCarName)
  171.  
  172. if (equali(szPoliceCar, "yes"))
  173. g_bDrivingPoliceCar[iIndex] = true
  174.  
  175. new szID[24]
  176. get_user_authid(id, szID, 23)
  177.  
  178. new szQuery[64]
  179. formatex(szQuery, 63, "SELECT * FROM arp_carmod WHERE SteamID = '%s'", szID)
  180.  
  181. SQL_ThreadQuery(g_hSQLTuple, "fnLoadGas", szQuery, iData, 1)
  182.  
  183. break
  184. }
  185. }
  186.  
  187. DestroyTravTrieIterator(hParkedCarIter)
  188. }
  189.  
  190. public fnResetFloodNote(iData[])
  191. {
  192. new const iIndex = iData[0] - 1
  193.  
  194. g_bAntiFloodNote[iIndex] = false
  195. }
  196.  
  197. public fnResetFloodOwner(iData[])
  198. {
  199. new const iIndex = iData[0] - 1
  200.  
  201. g_bAntiFloodOwner[iIndex] = false
  202. }
  203.  
  204. public fnResetFloodCrash(iData[])
  205. {
  206. new const iIndex = iData[0] - 1
  207.  
  208. g_bAntiFloodCrash[iIndex] = false
  209. }
  210.  
  211. public fnSpawn(id)
  212. {
  213. client_cmd(id, "cl_forwardspeed 1300; cl_sidespeed 1300; cl_backspeed 1300")
  214.  
  215. return HAM_HANDLED
  216. }
  217.  
  218. public fnKilled(id, attacker_id)
  219. {
  220. new const iIndex = id - 1
  221.  
  222. if (g_bDriveToggle[iIndex])
  223. {
  224. emit_sound(id, CHAN_AUTO, "spunky/carmod/enginestart.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  225. emit_sound(id, CHAN_AUTO, "spunky/carmod/rev.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  226. emit_sound(id, CHAN_AUTO, "spunky/carmod/horn.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  227.  
  228. if (task_exists(g_iEngineTaskID[iIndex], 0))
  229. {
  230. remove_task(g_iEngineTaskID[iIndex], 0)
  231.  
  232. emit_sound(id, CHAN_AUTO, "spunky/carmod/engine.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  233. }
  234.  
  235. if (task_exists(g_iSirenTaskID[iIndex], 0))
  236. {
  237. remove_task(g_iSirenTaskID[iIndex], 0)
  238.  
  239. emit_sound(id, CHAN_AUTO, "spunky/carmod/fixedsiren.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  240.  
  241. g_bSirenToggle[iIndex] = false
  242. }
  243.  
  244. if (task_exists(g_iSirenLightsTaskID[iIndex], 0))
  245. remove_task(g_iSirenLightsTaskID[iIndex], 0)
  246.  
  247. if (task_exists(g_iStereoTaskID[iIndex], 0))
  248. {
  249. remove_task(g_iStereoTaskID[iIndex], 0)
  250.  
  251. new szInput[48]
  252. formatex(szInput, 47, "spunky/carmod/stereo/%s.wav", g_szSoundFile[iIndex])
  253. emit_sound(id, CHAN_AUTO, szInput, VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  254.  
  255. g_szSoundFile[iIndex] = ""
  256. g_bStereoToggle[iIndex] = false
  257. }
  258.  
  259. if (task_exists(g_iGasTaskID[iIndex], 0))
  260. remove_task(g_iGasTaskID[iIndex], 0)
  261.  
  262. if (task_exists(g_iAntiFloodRevTaskID[iIndex], 0))
  263. {
  264. remove_task(g_iAntiFloodRevTaskID[iIndex], 0)
  265.  
  266. g_bAntiFloodRev[iIndex] = false
  267. }
  268.  
  269. if (task_exists(g_iAntiFloodHonkTaskID[iIndex], 0))
  270. {
  271. remove_task(g_iAntiFloodHonkTaskID[iIndex], 0)
  272.  
  273. g_bAntiFloodHonk[iIndex] = false
  274. }
  275.  
  276. g_bAntiFloodCrash[iIndex] = false
  277.  
  278. if (g_bHeadlightToggle[iIndex])
  279. {
  280. entity_set_int(id, EV_INT_effects, 0)
  281.  
  282. g_bHeadlightToggle[iIndex] = false
  283. }
  284.  
  285. g_fpCarSpeed[iIndex] = 0.0
  286.  
  287. set_user_info(id, "model", g_szModel[iIndex])
  288. set_user_footsteps(id, 0)
  289.  
  290. g_bDriveToggle[iIndex] = false
  291. g_bDrivingPoliceCar[iIndex] = false
  292. }
  293.  
  294. if (is_user_alive(attacker_id))
  295. g_bAntiFloodCrash[attacker_id - 1] = false
  296.  
  297. return HAM_HANDLED
  298. }
  299.  
  300. public ARP_Init()
  301. {
  302. ARP_RegisterPlugin("Car Mod", "1.3.5", "Spunky", "Allows players to drive cars")
  303.  
  304. ARP_RegisterCmd("say /rev", "cmd_rev", "- revs the engine")
  305. ARP_RegisterCmd("say /honk", "cmd_honk", "- honks car horn")
  306. ARP_RegisterCmd("say /siren", "cmd_siren", "- turns siren on/off")
  307. ARP_RegisterCmd("say /headlight", "cmd_headlight", "- turns headlights on/off")
  308.  
  309. ARP_RegisterEvent("HUD_Render", "fnHUDRender")
  310.  
  311. g_pDaylight = register_cvar("arp_daylight", "1")
  312. g_pDamage = register_cvar("arp_crash_damage", "5")
  313. g_pImpact = register_cvar("arp_impact_multiplier", "2.0")
  314.  
  315. set_cvar_num("sv_maxspeed", 1500)
  316.  
  317. g_hSQLTuple = ARP_SqlHandle()
  318.  
  319. if (g_hSQLTuple == Empty_Handle)
  320. set_fail_state("[CM] Failed to retrieve SQL handle.")
  321.  
  322. new szDriver[8]
  323. SQL_GetAffinity(szDriver, 7)
  324.  
  325. new szQuery[128]
  326. formatex(szQuery, 127, "CREATE TABLE IF NOT EXISTS arp_carmod (SteamID VARCHAR(20), Gasoline INT(6), %s (SteamID))", equali(szDriver, "mysql") ? "UNIQUE KEY" : "UNIQUE")
  327.  
  328. SQL_ThreadQuery(g_hSQLTuple, "fnCreateTable", szQuery)
  329.  
  330. for (new i; i < 32; i++)
  331. g_hParkedCar[i] = TravTrieCreate()
  332. }
  333.  
  334. public plugin_natives()
  335. {
  336. register_library("arp_carmod")
  337.  
  338. register_native("is_user_driving", "arp_get_driving")
  339. register_native("get_user_gas", "arp_get_gas")
  340. }
  341.  
  342. public fnHUDRender(szName[], iData[], iLen)
  343. {
  344. new const id = iData[0], iIndex = id - 1
  345.  
  346. if (!is_user_alive(id) || iData[1] != HUD_PRIM)
  347. return
  348.  
  349. if (ARP_PlayerReady(id) && g_bDriveToggle[iIndex])
  350. ARP_AddHudItem(id, HUD_PRIM, 0, "Gasoline: %d%%", g_iGas[iIndex])
  351. }
  352.  
  353. public fnCreateTable(FailState, Handle:hQuery, szError[], iErrorCode)
  354. {
  355. if (FailState == TQUERY_CONNECT_FAILED)
  356. set_fail_state("[CM] Could not connect to SQL database!")
  357.  
  358. else if (FailState == TQUERY_QUERY_FAILED)
  359. set_fail_state("[CM] Query failed to execute!")
  360.  
  361. if (iErrorCode)
  362. set_fail_state(szError)
  363.  
  364. return PLUGIN_CONTINUE
  365. }
  366.  
  367. public ARP_RegisterItems()
  368. {
  369. g_hCar = TravTrieCreate()
  370. g_hStereo = TravTrieCreate()
  371.  
  372. new szConfigsDir[32]
  373. get_configsdir(szConfigsDir, 31)
  374.  
  375. new szFilePath[48]
  376. formatex(szFilePath, 47, "%s/arp/carmod.cfg", szConfigsDir)
  377.  
  378. new iFileSize = file_size(szFilePath, 1), szOutput[96], szInput[96]
  379.  
  380. if (iFileSize)
  381. {
  382. new szCarName[32], szCarDescription[48], TravTrie:hOldCar = TravTrieCreate(), travTrieIter:hCarIter, szOldCarModel[32], szCarModel[32], szCarSpeed[12], szPoliceCar[8], iCarNum, iLen
  383.  
  384. for (new i, bool:bRegisterItem = true; i < iFileSize; i++)
  385. {
  386. read_file(szFilePath, i, szOutput, 95, iLen)
  387. parse(szOutput, szCarName, 31, szCarModel, 31, szCarSpeed, 11, szPoliceCar, 7)
  388.  
  389. hCarIter = GetTravTrieIterator(hOldCar)
  390.  
  391. while (MoreTravTrie(hCarIter))
  392. {
  393. ReadTravTrieString(hCarIter, szOldCarModel, 31)
  394.  
  395. if (equal(szCarModel, szOldCarModel))
  396. {
  397. bRegisterItem = false
  398.  
  399. break
  400. }
  401. }
  402.  
  403. if (!bRegisterItem)
  404. {
  405. bRegisterItem = true
  406.  
  407. ARP_Log("Duplicate ^"%s^" found in ^"carmod.cfg^"! Skipped registration of item.", szCarName)
  408.  
  409. continue
  410. }
  411.  
  412. formatex(szInput, 95, "models/player/%s/%s.mdl", szCarModel, szCarModel)
  413. precache_model(szInput)
  414.  
  415. formatex(szInput, 95, "%s Key", szCarName)
  416. formatex(szCarDescription, 47, "A key to a %s.", szCarName)
  417. ARP_RegisterItem(szInput, "fnCarItem", szCarDescription, 0)
  418.  
  419. formatex(szInput, 95, "^"%s^" ^"%s^" ^"%s^"", szCarModel, szCarSpeed, szPoliceCar)
  420. TravTrieSetString(g_hCar, szCarName, szInput)
  421.  
  422. TravTrieSetString(hOldCar, szCarName, szCarModel)
  423.  
  424. iCarNum++
  425. }
  426.  
  427. ARP_Log("Loaded %d cars...", iCarNum)
  428.  
  429. DestroyTravTrieIterator(hCarIter)
  430. TravTrieDestroy(hOldCar)
  431. }
  432. else
  433. ARP_Log("Configuration file ^"carmod.cfg^" empty!")
  434.  
  435. precache_sound("spunky/carmod/enginestart.wav")
  436. precache_sound("spunky/carmod/rev.wav")
  437. precache_sound("spunky/carmod/engine.wav")
  438. precache_sound("spunky/carmod/crash.wav")
  439. precache_sound("spunky/carmod/horn.wav")
  440. precache_sound("spunky/carmod/fixedsiren.wav")
  441.  
  442. formatex(szFilePath, 47, "%s/arp/stereo.cfg", szConfigsDir)
  443.  
  444. iFileSize = file_size(szFilePath, 1)
  445.  
  446. if (iFileSize)
  447. {
  448. new szSongName[32], szArtistName[32], szSoundFile[24], szSongLength[8], szOldSongName[32], iSongNum, iLen, TravTrie:hOldSong = TravTrieCreate(), travTrieIter:hSongIter
  449.  
  450. for (new i, bool:bPrecacheSong = true; i < iFileSize; i++)
  451. {
  452. read_file(szFilePath, i, szOutput, 95, iLen)
  453.  
  454. if (!iLen)
  455. continue
  456.  
  457. parse(szOutput, szSongName, 31, szArtistName, 31, szSoundFile, 23, szSongLength, 7)
  458.  
  459. hSongIter = GetTravTrieIterator(hOldSong)
  460.  
  461. while (MoreTravTrie(hSongIter))
  462. {
  463. ReadTravTrieString(hSongIter, szOldSongName, 31)
  464.  
  465. if (equal(szSongName, szOldSongName))
  466. {
  467. bPrecacheSong = false
  468.  
  469. break
  470. }
  471. }
  472.  
  473. if (!bPrecacheSong)
  474. {
  475. bPrecacheSong = true
  476.  
  477. ARP_Log("Duplicate sound found in ^"radio.cfg^"! Skipped precache of sound ^"%s.wav^".", szSoundFile)
  478.  
  479. continue
  480. }
  481.  
  482. formatex(szInput, 95, "spunky/carmod/stereo/%s.wav", szSoundFile)
  483. precache_sound(szInput)
  484.  
  485. formatex(szInput, 95, "^"%s^" ^"%s^" ^"%s^"", szArtistName, szSoundFile, szSongLength)
  486. TravTrieSetString(g_hStereo, szSongName, szInput)
  487.  
  488. TravTrieSetString(hOldSong, szSongName, szSongName)
  489.  
  490. iSongNum++
  491. }
  492.  
  493. ARP_Log("Loaded %d songs...", iSongNum)
  494.  
  495. if (iSongNum)
  496. ARP_RegisterItem("Car Stereo System", "fnCarStereoSystemItem", "A car stereo system.", 0)
  497.  
  498. if (iLen)
  499. DestroyTravTrieIterator(hSongIter)
  500.  
  501. TravTrieDestroy(hOldSong)
  502. }
  503. else
  504. ARP_Log("Configuration file ^"radio.cfg^" empty!")
  505.  
  506. ARP_RegisterItem("Gasoline", "fnGasolineItem", "A canister of gasoline.", 1)
  507. }
  508.  
  509. public plugin_end()
  510. {
  511. TravTrieDestroy(g_hCar)
  512.  
  513. for (new i; i < 32; i++)
  514. TravTrieDestroy(g_hParkedCar[i])
  515.  
  516. TravTrieDestroy(g_hStereo)
  517. }
  518.  
  519. public client_disconnect(id)
  520. {
  521. new const iIndex = id - 1
  522.  
  523. g_iGas[iIndex] = 0
  524. g_iCar[iIndex] = 0
  525. g_bDriveToggle[iIndex] = false
  526. g_bDrivingPoliceCar[iIndex] = false
  527. g_bSirenToggle[iIndex] = false
  528. g_bStereoToggle[iIndex] = false
  529. g_bAntiFloodNote[iIndex] = false
  530. g_bAntiFloodOwner[iIndex] = false
  531. g_bAntiFloodCrash[iIndex] = false
  532. g_bHeadlightToggle[iIndex] = false
  533. g_szModel[iIndex] = ""
  534. g_szSoundFile[iIndex] = ""
  535. g_fpCarSpeed[iIndex] = 0.0
  536.  
  537. if (task_exists(g_iEngineTaskID[iIndex], 0))
  538. remove_task(g_iEngineTaskID[iIndex], 0)
  539.  
  540. if (task_exists(g_iSirenTaskID[iIndex], 0))
  541. remove_task(g_iSirenTaskID[iIndex], 0)
  542.  
  543. if (task_exists(g_iSirenLightsTaskID[iIndex], 0))
  544. remove_task(g_iSirenLightsTaskID[iIndex], 0)
  545.  
  546. if (task_exists(g_iStereoTaskID[iIndex], 0))
  547. remove_task(g_iStereoTaskID[iIndex], 0)
  548.  
  549. if (task_exists(g_iGasTaskID[iIndex], 0))
  550. remove_task(g_iGasTaskID[iIndex], 0)
  551.  
  552. if (task_exists(g_iAntiFloodRevTaskID[iIndex], 0))
  553. {
  554. remove_task(g_iAntiFloodRevTaskID[iIndex], 0)
  555.  
  556. g_bAntiFloodRev[iIndex] = false
  557. }
  558.  
  559. if (task_exists(g_iAntiFloodHonkTaskID[iIndex], 0))
  560. {
  561. remove_task(g_iAntiFloodHonkTaskID[iIndex], 0)
  562.  
  563. g_bAntiFloodHonk[iIndex] = false
  564. }
  565.  
  566. g_mStereoMenu[iIndex] = 0
  567.  
  568. new szOutput[96], szCarModel[32], szCarSpeed[12], szPoliceCar[8], szEnt[6]
  569.  
  570. new travTrieIter:hParkedCarIter = GetTravTrieIterator(g_hParkedCar[iIndex])
  571.  
  572. while (MoreTravTrie(hParkedCarIter))
  573. {
  574. ReadTravTrieString(hParkedCarIter, szOutput, 95)
  575. parse(szOutput, szCarModel, 31, szCarSpeed, 11, szPoliceCar, 7, szEnt, 5)
  576.  
  577. remove_entity(str_to_num(szEnt))
  578. }
  579.  
  580. DestroyTravTrieIterator(hParkedCarIter)
  581. TravTrieClear(g_hParkedCar[iIndex])
  582. }
  583.  
  584. public cmd_rev(id)
  585. {
  586. new const iIndex = id - 1
  587.  
  588. if (g_bDriveToggle[iIndex])
  589. {
  590. if (g_bAntiFloodRev[iIndex])
  591. return PLUGIN_HANDLED
  592.  
  593. emit_sound(id, CHAN_AUTO, "spunky/carmod/rev.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  594.  
  595. g_bAntiFloodRev[iIndex] = true
  596.  
  597. new iData[1]
  598. iData[0] = id
  599.  
  600. g_iAntiFloodRevTaskID[iIndex] = random(1337)
  601. set_task(10.0, "fnAntiFloodRevUpdate", g_iAntiFloodRevTaskID[iIndex], iData, 1)
  602. }
  603. else
  604. client_print(id, print_chat, "[CM] You are not driving a car.")
  605.  
  606. return PLUGIN_HANDLED
  607. }
  608.  
  609. public fnAntiFloodRevUpdate(iData[])
  610. {
  611. new const iIndex = iData[0] - 1
  612.  
  613. g_bAntiFloodRev[iIndex] = false
  614. }
  615.  
  616. public cmd_honk(id)
  617. {
  618. new const iIndex = id - 1
  619.  
  620. if (g_bDriveToggle[iIndex])
  621. {
  622. if (g_bAntiFloodHonk[iIndex])
  623. return PLUGIN_HANDLED
  624.  
  625. emit_sound(id, CHAN_AUTO, "spunky/carmod/horn.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  626.  
  627. g_bAntiFloodHonk[iIndex] = true
  628.  
  629. new iData[1]
  630. iData[0] = id
  631.  
  632. g_iAntiFloodHonkTaskID[iIndex] = random(1337)
  633. set_task(5.0, "fnAntiFloodHonkUpdate", g_iAntiFloodHonkTaskID[iIndex], iData, 1)
  634. }
  635. else
  636. client_print(id, print_chat, "[CM] You are not driving a car.")
  637.  
  638. return PLUGIN_HANDLED
  639. }
  640.  
  641. public fnAntiFloodHonkUpdate(iData[])
  642. {
  643. new const iIndex = iData[0] - 1
  644.  
  645. g_bAntiFloodHonk[iIndex] = false
  646. }
  647.  
  648. public cmd_siren(id)
  649. {
  650. new const iIndex = id - 1
  651.  
  652. if (g_bDriveToggle[iIndex])
  653. {
  654. if (g_bDrivingPoliceCar[iIndex])
  655. {
  656. if (g_bStereoToggle[iIndex])
  657. {
  658. client_print(id, print_chat, "[CM] You must turn your stereo system off to use your siren.")
  659.  
  660. return PLUGIN_HANDLED
  661. }
  662.  
  663. if (g_bSirenToggle[iIndex])
  664. {
  665. client_print(id, print_chat, "[CM] You have turned your siren off.")
  666.  
  667. if (task_exists(g_iSirenTaskID[iIndex], 0))
  668. remove_task(g_iSirenTaskID[iIndex], 0)
  669.  
  670. if (task_exists(g_iSirenLightsTaskID[iIndex], 0))
  671. remove_task(g_iSirenLightsTaskID[iIndex], 0)
  672.  
  673. emit_sound(id, CHAN_AUTO, "spunky/carmod/fixedsiren.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  674.  
  675. g_bSirenToggle[iIndex] = false
  676. }
  677. else
  678. {
  679. client_print(id, print_chat, "[CM] You have turned your siren on.")
  680.  
  681. emit_sound(id, CHAN_AUTO, "spunky/carmod/fixedsiren.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  682.  
  683. new iData[2]
  684. iData[0] = id
  685. iData[1] = 1
  686.  
  687. g_iSirenTaskID[iIndex] = random(1337)
  688. set_task(11.7, "fnSiren", g_iSirenTaskID[iIndex], iData, 1)
  689.  
  690. g_iSirenLightsTaskID[iIndex] = random(1337)
  691. set_task(0.1, "fnSirenLights", g_iSirenLightsTaskID[iIndex], iData, 2)
  692.  
  693. g_bSirenToggle[iIndex] = true
  694. }
  695. }
  696. else
  697. client_print(id, print_chat, "[CM] You are not driving a police car.")
  698. }
  699. else
  700. client_print(id, print_chat, "[CM] You are not driving a car.")
  701.  
  702. return PLUGIN_HANDLED
  703. }
  704.  
  705. public fnSiren(iData[])
  706. {
  707. new const id = iData[0], iIndex = id - 1
  708.  
  709. emit_sound(id, CHAN_AUTO, "spunky/carmod/fixedsiren.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  710.  
  711. set_task(11.7, "fnSiren", g_iSirenTaskID[iIndex], iData, 1)
  712. }
  713.  
  714. public fnSirenLights(iData[])
  715. {
  716. new const id = iData[0]
  717.  
  718. new iOrigin[3]
  719. get_user_origin(id, iOrigin)
  720.  
  721. message_begin(MSG_ALL, SVC_TEMPENTITY, {0, 0, 0}, id)
  722. write_byte(TE_DLIGHT)
  723. write_coord(iOrigin[0])
  724. write_coord(iOrigin[1])
  725. write_coord(iOrigin[2])
  726.  
  727. if (get_pcvar_num(g_pDaylight))
  728. write_byte(40)
  729. else
  730. write_byte(20)
  731.  
  732. if (iData[1])
  733. {
  734. if (get_pcvar_num(g_pDaylight))
  735. write_byte(175)
  736. else
  737. write_byte(50)
  738.  
  739. write_byte(0)
  740. write_byte(0)
  741.  
  742. iData[1] = 0
  743. }
  744. else
  745. {
  746. write_byte(0)
  747. write_byte(0)
  748.  
  749. if (get_pcvar_num(g_pDaylight))
  750. write_byte(175)
  751. else
  752. write_byte(50)
  753.  
  754. iData[1] = 1
  755. }
  756.  
  757. write_byte(75)
  758. write_byte(25)
  759. message_end()
  760.  
  761. set_task(0.25, "fnSirenLights", g_iSirenTaskID[id - 1], iData, 2)
  762. }
  763.  
  764. public cmd_headlight(id)
  765. {
  766. new const iIndex = id - 1
  767.  
  768. if (g_bDriveToggle[iIndex])
  769. {
  770. if (g_bHeadlightToggle[iIndex])
  771. {
  772. client_print(id, print_chat, "[CM] You have turned your headlights off.")
  773.  
  774. entity_set_int(id, EV_INT_effects, 0)
  775.  
  776. g_bHeadlightToggle[iIndex] = false
  777. }
  778. else
  779. {
  780. client_print(id, print_chat, "[CM] You have turned your headlights on.")
  781.  
  782. entity_set_int(id, EV_INT_effects, EF_DIMLIGHT)
  783.  
  784. g_bHeadlightToggle[iIndex] = true
  785. }
  786. }
  787. else
  788. client_print(id, print_chat, "[CM] You are not driving a car.")
  789.  
  790. return PLUGIN_HANDLED
  791. }
  792.  
  793. public fnCarItem(id, iid)
  794. {
  795. new const iIndex = id - 1
  796.  
  797. new szName[64], szID[24]
  798. new szOutput[96], szTempOutput[48], szInput[96], szCarName[32], szParkedCarName[32], szCarModel[32], szCarSpeed[12], iSpeed, szPoliceCar[8], iCar, travTrieIter:hCarIter = GetTravTrieIterator(g_hCar), travTrieIter:hParkedCarIter = GetTravTrieIterator(g_hParkedCar[iIndex])
  799. new bool:bParked = false
  800.  
  801. new Float:fpOrigin[3], Float:fpAngles[3]
  802.  
  803. while (MoreTravTrie(hCarIter))
  804. {
  805. ReadTravTrieKey(hCarIter, szCarName, 31)
  806.  
  807. ARP_FindItemId(szCarName, szOutput, 5)
  808. iCar = szOutput[0]
  809.  
  810. ReadTravTrieString(hCarIter, szOutput, 95)
  811.  
  812. if (iid == iCar)
  813. {
  814. if (g_bDriveToggle[iIndex])
  815. {
  816. if (g_iCar[iIndex] != iid)
  817. {
  818. client_print(id, print_chat, "[CM] You're already driving a different car.")
  819.  
  820. break
  821. }
  822.  
  823. emit_sound(id, CHAN_AUTO, "spunky/carmod/enginestart.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  824. emit_sound(id, CHAN_AUTO, "spunky/carmod/rev.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  825. emit_sound(id, CHAN_AUTO, "spunky/carmod/horn.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  826.  
  827. g_bAntiFloodRev[iIndex] = false
  828. g_bAntiFloodHonk[iIndex] = false
  829.  
  830. if (task_exists(g_iEngineTaskID[iIndex], 0))
  831. {
  832. remove_task(g_iEngineTaskID[iIndex], 0)
  833.  
  834. emit_sound(id, CHAN_AUTO, "spunky/carmod/engine.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  835. }
  836.  
  837. if (g_bSirenToggle[iIndex])
  838. {
  839. remove_task(g_iSirenTaskID[iIndex], 0)
  840.  
  841. emit_sound(id, CHAN_AUTO, "spunky/carmod/fixedsiren.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  842.  
  843. g_bSirenToggle[iIndex] = false
  844.  
  845. if (task_exists(g_iSirenLightsTaskID[iIndex], 0))
  846. remove_task(g_iSirenLightsTaskID[iIndex], 0)
  847. }
  848.  
  849. if (g_bStereoToggle[iIndex])
  850. {
  851. remove_task(g_iStereoTaskID[iIndex], 0)
  852.  
  853. formatex(szInput, 95, "spunky/carmod/stereo/%s.wav", g_szSoundFile[iIndex])
  854. emit_sound(id, CHAN_AUTO, szInput, VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  855.  
  856. g_bStereoToggle[iIndex] = false
  857. }
  858.  
  859. if (task_exists(g_iGasTaskID[iIndex], 0))
  860. remove_task(g_iGasTaskID[iIndex], 0)
  861.  
  862. if (g_bHeadlightToggle[iIndex])
  863. {
  864. entity_set_int(id, EV_INT_effects, 0)
  865.  
  866. g_bHeadlightToggle[iIndex] = false
  867. }
  868.  
  869. g_fpCarSpeed[iIndex] = 0.0
  870.  
  871. parse(szOutput, szCarModel, 31, szCarSpeed, 11, szPoliceCar, 7)
  872.  
  873. entity_get_vector(id, EV_VEC_origin, fpOrigin)
  874. entity_get_vector(id, EV_VEC_angles, fpAngles)
  875.  
  876. fpAngles[0] = 0.0
  877.  
  878. new iEnt = create_entity("info_target")
  879. entity_set_string(iEnt, EV_SZ_classname, "func_car")
  880. entity_set_vector(iEnt, EV_VEC_origin, fpOrigin)
  881. entity_set_vector(iEnt, EV_VEC_angles, fpAngles)
  882.  
  883. formatex(szInput, 95, "models/player/%s/%s.mdl", szCarModel, szCarModel)
  884. entity_set_model(iEnt, szInput)
  885.  
  886. get_user_name(id, szName, 63)
  887. get_user_authid(id, szID, 23)
  888.  
  889. ARP_Log("%s (%s) parked their car at coordinates (x: %d, y: %d, z: %d), at angle (pitch: %d, yaw: %d, roll: %d)...", szName, szID, floatround(fpOrigin[0]), floatround(fpOrigin[1]), floatround(fpOrigin[2]), floatround(fpAngles[0]), floatround(fpAngles[1]), floatround(fpAngles[2]))
  890.  
  891. formatex(szInput, 95, "^"%s^" ^"%s^" ^"%s^" %d", szCarModel, szCarSpeed, szPoliceCar, iEnt)
  892. TravTrieSetString(g_hParkedCar[iIndex], szCarName, szInput)
  893.  
  894. new iData[2]
  895. iData[0] = id
  896. iData[1] = iEnt
  897.  
  898. set_task(2.5, "fnSolidifyCar", _, iData, 2)
  899.  
  900. set_user_maxspeed(id, 320.0)
  901. client_cmd(id, "cl_forwardspeed 320; cl_sidespeed 320; cl_backspeed 320")
  902. set_user_info(id, "model", g_szModel[iIndex])
  903. set_user_footsteps(id, 0)
  904.  
  905. client_print(id, print_chat, "[CM] You turn off the engine, then get out of the %s.", szCarName)
  906.  
  907. g_iCar[iIndex] = 0
  908. g_bDriveToggle[iIndex] = false
  909. g_bDrivingPoliceCar[iIndex] = false
  910. }
  911. else
  912. {
  913. while (MoreTravTrie(hParkedCarIter))
  914. {
  915. ReadTravTrieKey(hParkedCarIter, szParkedCarName, 31)
  916. ReadTravTrieString(hParkedCarIter, szTempOutput, 47)
  917.  
  918. if (equali(szCarName, szParkedCarName))
  919. {
  920. bParked = true
  921.  
  922. break
  923. }
  924. }
  925.  
  926. DestroyTravTrieIterator(hParkedCarIter)
  927.  
  928. if (bParked)
  929. {
  930. client_print(id, print_chat, "[CM] Your %s is already parked elsewhere.", szCarName)
  931.  
  932. break
  933. }
  934.  
  935. parse(szOutput, szCarModel, 31, szCarSpeed, 11, szPoliceCar, 7)
  936.  
  937. iSpeed = str_to_num(szCarSpeed)
  938. g_fpCarSpeed[iIndex] = float(iSpeed)
  939.  
  940. get_user_info(id, "model", g_szModel[iIndex], 23)
  941. set_user_maxspeed(id, float(iSpeed))
  942. client_cmd(id, "cl_forwardspeed %d; cl_sidespeed %d; cl_backspeed %d", iSpeed, iSpeed, iSpeed)
  943. set_user_info(id, "model", szCarModel)
  944.  
  945. set_user_footsteps(id, 1)
  946.  
  947. emit_sound(id, CHAN_AUTO, "spunky/carmod/enginestart.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  948.  
  949. new iData[1]
  950. iData[0] = id
  951.  
  952. g_iEngineTaskID[iIndex] = random(1337)
  953. set_task(5.0, "fnEngine", g_iEngineTaskID[iIndex], iData, 1)
  954.  
  955. client_print(id, print_chat, "[CM] You get into your %s, then start the engine.", szCarName)
  956.  
  957. g_iCar[iIndex] = iid
  958.  
  959. g_bDriveToggle[iIndex] = true
  960.  
  961. if (equali(szPoliceCar, "yes"))
  962. g_bDrivingPoliceCar[iIndex] = true
  963.  
  964. get_user_authid(id, szID, 23)
  965.  
  966. new szQuery[64]
  967. formatex(szQuery, 63, "SELECT * FROM arp_carmod WHERE SteamID = '%s'", szID)
  968.  
  969. SQL_ThreadQuery(g_hSQLTuple, "fnLoadGas", szQuery, iData, 1)
  970. }
  971.  
  972. break
  973. }
  974. }
  975.  
  976. DestroyTravTrieIterator(hCarIter)
  977. }
  978.  
  979. public fnEngine(iData[])
  980. {
  981. new const id = iData[0]
  982.  
  983. emit_sound(id, CHAN_AUTO, "spunky/carmod/engine.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  984.  
  985. set_task(1.15, "fnEngine", g_iEngineTaskID[id - 1], iData, 1)
  986. }
  987.  
  988. public fnSolidifyCar(iData[])
  989. {
  990. new const id = iData[0], iEnt = iData[1]
  991.  
  992. if (is_user_connected(id))
  993. {
  994. entity_set_int(iEnt, EV_INT_solid, SOLID_TRIGGER)
  995. entity_set_size(iEnt, Float:{-16.0, -16.0, -250.0}, Float:{16.0, 16.0, 40.0})
  996. drop_to_floor(iEnt)
  997. entity_set_edict(iEnt, EV_ENT_owner, id)
  998.  
  999. client_print(id, print_chat, "[CM] You have successfully parked your car. Probably.")
  1000. }
  1001. }
  1002.  
  1003. public fnCreateNewUser(FailState, Handle:hQuery, szError[], iErrorCode, iData[], iDataSize)
  1004. {
  1005. if (FailState == TQUERY_CONNECT_FAILED)
  1006. set_fail_state("[CM] Could not connect to SQL database!")
  1007.  
  1008. else if (FailState == TQUERY_QUERY_FAILED)
  1009. set_fail_state("[CM] Query failed to execute!")
  1010.  
  1011. return PLUGIN_CONTINUE
  1012. }
  1013.  
  1014. public fnLoadGas(FailState, Handle:hQuery, szError[], iErrorCode, iData[], iDataSize)
  1015. {
  1016. if (FailState == TQUERY_CONNECT_FAILED)
  1017. set_fail_state("[CM] Could not connect to SQL database!")
  1018.  
  1019. else if (FailState == TQUERY_QUERY_FAILED)
  1020. set_fail_state("[CM] Query failed to execute!")
  1021.  
  1022. new const id = iData[0], iIndex = id - 1
  1023.  
  1024. if (SQL_NumResults(hQuery) > 0)
  1025. g_iGas[iIndex] = SQL_ReadResult(hQuery, 1)
  1026. else
  1027. {
  1028. g_iGas[iIndex] = 100
  1029.  
  1030. new szID[24]
  1031. get_user_authid(id, szID, 23)
  1032.  
  1033. new szQuery[64]
  1034. formatex(szQuery, 63, "INSERT INTO arp_carmod VALUES ('%s', 100)", szID)
  1035.  
  1036. SQL_ThreadQuery(g_hSQLTuple, "fnCreateNewUser", szQuery)
  1037.  
  1038. return PLUGIN_HANDLED
  1039. }
  1040.  
  1041. new iData[1]
  1042. iData[0] = id
  1043.  
  1044. g_iGasTaskID[iIndex] = random(1337)
  1045. set_task(60.0, "fnGasUpdate", g_iGasTaskID[iIndex], iData, 1, "b")
  1046.  
  1047. if (g_iGas[iIndex] <= 0)
  1048. {
  1049. client_print(id, print_chat, "[CM] Your car has no gas!")
  1050.  
  1051. set_user_maxspeed(id, 0.0)
  1052. client_cmd(id, "cl_forwardspeed 0; cl_sidespeed 0; cl_backspeed 0")
  1053. }
  1054.  
  1055. return PLUGIN_CONTINUE
  1056. }
  1057.  
  1058. public fnGasUpdate(iData[])
  1059. {
  1060. new const id = iData[0], iIndex = id - 1
  1061.  
  1062. g_iGas[iIndex]--
  1063.  
  1064. if (g_iGas[iIndex] < 0)
  1065. g_iGas[iIndex] = 0
  1066.  
  1067. new szID[24]
  1068. get_user_authid(id, szID, 23)
  1069.  
  1070. new szQuery[96]
  1071. formatex(szQuery, 95, "UPDATE arp_carmod SET Gasoline = %d WHERE SteamID = '%s'", g_iGas[iIndex], szID)
  1072.  
  1073. SQL_ThreadQuery(g_hSQLTuple, "fnUpdateGasoline", szQuery)
  1074.  
  1075. if (!g_iGas[iIndex])
  1076. {
  1077. client_print(id, print_chat, "[CM] Your vehicle has run out of gas!")
  1078.  
  1079. remove_task(g_iGasTaskID[iIndex], 0)
  1080.  
  1081. set_user_maxspeed(id, 0.0)
  1082. client_cmd(id, "cl_forwardspeed 0; cl_sidespeed 0; cl_backspeed 0")
  1083. }
  1084. }
  1085.  
  1086. public fnUpdateGasoline(FailState, Handle:hQuery, szError[], iErrorCode, iData[], iDataSize)
  1087. {
  1088. if (FailState == TQUERY_CONNECT_FAILED)
  1089. set_fail_state("[CM] Could not connect to SQL database!")
  1090.  
  1091. else if (FailState == TQUERY_QUERY_FAILED)
  1092. set_fail_state("[CM] Query failed to execute!")
  1093.  
  1094. return PLUGIN_CONTINUE
  1095. }
  1096.  
  1097. public fnCarStereoSystemItem(id, iid)
  1098. {
  1099. new const iIndex = id - 1
  1100.  
  1101. if (g_bDriveToggle[iIndex])
  1102. {
  1103. new szInput[64]
  1104.  
  1105. client_print(id, print_chat, g_bStereoToggle[iIndex] ? "[CM] You turn your stereo system off." : "[CM] You turn your stereo system on.")
  1106.  
  1107. if (g_bStereoToggle[iIndex])
  1108. {
  1109. if (task_exists(g_iStereoTaskID[iIndex], 0))
  1110. remove_task(g_iStereoTaskID[iIndex], 0)
  1111.  
  1112. formatex(szInput, 63, "spunky/carmod/stereo/%s.wav", g_szSoundFile[iIndex])
  1113. emit_sound(id, CHAN_AUTO, szInput, VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
  1114.  
  1115. g_bStereoToggle[iIndex] = false
  1116. }
  1117. else
  1118. {
  1119. if (g_bDrivingPoliceCar[iIndex])
  1120. {
  1121. client_print(id, print_chat, "[CM] You can't listen to the stereo in a police issue vehicle.")
  1122.  
  1123. return
  1124. }
  1125.  
  1126. new szOutput[96], szSongName[32], szArtistName[32], szSoundFile[24], szSongLength[8], travTrieIter:hStereoIter = GetTravTrieIterator(g_hStereo)
  1127.  
  1128. g_mStereoMenu[iIndex] = menu_create("Stereo Menu:", "fnStereoMenu")
  1129.  
  1130. while (MoreTravTrie(hStereoIter))
  1131. {
  1132. ReadTravTrieKey(hStereoIter, szSongName, 31)
  1133. ReadTravTrieString(hStereoIter, szOutput, 95)
  1134. parse(szOutput, szArtistName, 31, szSoundFile, 23, szSongLength, 7)
  1135.  
  1136. formatex(szInput, 63, "^"%s^" by %s", szSongName, szArtistName)
  1137. menu_additem(g_mStereoMenu[iIndex], szInput, szSoundFile)
  1138. }
  1139.  
  1140. DestroyTravTrieIterator(hStereoIter)
  1141.  
  1142. menu_setprop(g_mStereoMenu[iIndex], MPROP_TITLE, "Stereo Menu:")
  1143. menu_setprop(g_mStereoMenu[iIndex], MPROP_PERPAGE, 7)
  1144. menu_setprop(g_mStereoMenu[iIndex], MPROP_EXIT, MEXIT_ALL)
  1145.  
  1146. menu_display(id, g_mStereoMenu[iIndex], 0)
  1147. }
  1148. }
  1149. else
  1150. client_print(id, print_chat, "[CM] You are not driving a car.")
  1151. }
  1152.  
  1153. public fnStereoMenu(id, menu, item)
  1154. {
  1155. if (item == MENU_EXIT)
  1156. {
  1157. menu_destroy(menu)
  1158.  
  1159. return PLUGIN_HANDLED
  1160. }
  1161.  
  1162. new const iIndex = id - 1
  1163.  
  1164. new szData[24], access, callback
  1165. menu_item_getinfo(menu, item, access, szData, 23, _, _, callback)
  1166.  
  1167. new szOutput[64], szInput[64], szArtistName[32], szSoundFile[24], szSongLength[8]
  1168.  
  1169. new travTrieIter:hStereoIter = GetTravTrieIterator(g_hStereo)
  1170.  
  1171. while (MoreTravTrie(hStereoIter))
  1172. {
  1173. ReadTravTrieString(hStereoIter, szOutput, 63)
  1174. parse(szOutput, szArtistName, 31, szSoundFile, 23, szSongLength, 7)
  1175.  
  1176. if (equal(szData, szSoundFile))
  1177. {
  1178. formatex(szInput, 63, "spunky/carmod/stereo/%s.wav", szSoundFile)
  1179. emit_sound(id, CHAN_AUTO, szInput, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  1180.  
  1181. g_szSoundFile[iIndex] = szSoundFile
  1182. g_bStereoToggle[iIndex] = true
  1183.  
  1184. g_iStereoTaskID[iIndex] = id
  1185. set_task(str_to_float(szSongLength), "fnStereoLoop", id, _, _, "b")
  1186.  
  1187. break
  1188. }
  1189. }
  1190.  
  1191. DestroyTravTrieIterator(hStereoIter)
  1192.  
  1193. return PLUGIN_CONTINUE
  1194. }
  1195.  
  1196. public fnStereoLoop(id)
  1197. {
  1198. new const iIndex = id - 1
  1199.  
  1200. new szInput[64]
  1201. formatex(szInput, 63, "spunky/carmod/stereo/%s.wav", g_szSoundFile[iIndex])
  1202. emit_sound(id, CHAN_AUTO, szInput, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  1203. }
  1204.  
  1205. public fnGasolineItem(id, iid)
  1206. {
  1207. new const iIndex = id - 1
  1208.  
  1209. if (g_bDriveToggle[iIndex])
  1210. {
  1211. if (g_iGas[iIndex] >= 100)
  1212. {
  1213. client_print(id, print_chat, "[CM] Your car is already running on a full tank!")
  1214.  
  1215. ARP_SetUserItemNum(id, iid, ARP_GetUserItemNum(id, iid) + 1)
  1216. }
  1217. else
  1218. {
  1219. if (g_iGas[iIndex] + 50 >= 100)
  1220. g_iGas[iIndex] = 100
  1221. else
  1222. g_iGas[iIndex] += 50
  1223.  
  1224. new iSpeed = floatround(g_fpCarSpeed[iIndex])
  1225.  
  1226. set_user_maxspeed(id, g_fpCarSpeed[iIndex])
  1227. client_cmd(id, "cl_forwardspeed %d; cl_sidespeed %d; cl_backspeed %d", iSpeed, iSpeed, iSpeed)
  1228.  
  1229. new szID[24]
  1230. get_user_authid(id, szID, 23)
  1231.  
  1232. new szQuery[96]
  1233. formatex(szQuery, 95, "UPDATE arp_carmod SET Gasoline = %d WHERE SteamID = '%s'", g_iGas[iIndex], szID)
  1234.  
  1235. SQL_ThreadQuery(g_hSQLTuple, "fnUpdateGasoline", szQuery)
  1236.  
  1237. client_print(id, print_chat, "[CM] You used a tank of gasoline.")
  1238. }
  1239. }
  1240. else
  1241. {
  1242. ARP_SetUserItemNum(id, iid, ARP_GetUserItemNum(id, iid) + 1)
  1243.  
  1244. client_print(id, print_chat, "[CM] You are not driving a car.")
  1245. }
  1246. }
  1247.  
  1248. public arp_get_driving(iPlugin, iParams)
  1249. {
  1250. if (iParams != 1)
  1251. return PLUGIN_CONTINUE
  1252.  
  1253. new const id = get_param(1)
  1254.  
  1255. if (!id)
  1256. return PLUGIN_CONTINUE
  1257.  
  1258. return g_bDriveToggle[id - 1] ? 1 : 0
  1259. }
  1260.  
  1261. public arp_get_gas(iPlugin, iParams)
  1262. {
  1263. if (iParams != 1)
  1264. return PLUGIN_CONTINUE
  1265.  
  1266. new const id = get_param(1)
  1267.  
  1268. if (!id)
  1269. return PLUGIN_CONTINUE
  1270.  
  1271. return g_iGas[id - 1]
  1272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement