Guest User

Untitled

a guest
Jan 12th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.54 KB | None | 0 0
  1. local mysql = exports.mysql
  2.  
  3. factionsThatPayForFuel = { [1]=false, [2]=false, [3]=false, [4]=true, [47]=true, [59]=true, [50]=true, [190]=false }
  4.  
  5. function startTalkToPed ()
  6.  
  7. thePed = source
  8. thePlayer = client
  9.  
  10.  
  11. if not (thePlayer and isElement(thePlayer)) then
  12. return
  13. end
  14.  
  15. local posX, posY, posZ = getElementPosition(thePlayer)
  16. local pedX, pedY, pedZ = getElementPosition(thePed)
  17. if not (getDistanceBetweenPoints3D(posX, posY, posZ, pedX, pedY, pedZ)<=7) then
  18. return
  19. end
  20.  
  21. if not (isPedInVehicle(thePlayer)) or (isPedInVehicle(thePlayer) and getVehicleType(getPedOccupiedVehicle(thePlayer)) == "BMX") then
  22. processMessage(thePed, "Sveiki, kā varu jums palīdzēt?")
  23. setConvoState(thePlayer, 3)
  24. local responseArray = { "Vai varat uzpildīt manu kanniņu?", "Ehh...nekā.", "Vai jums neatradīsies kāda cigarete priekš manis?", "Man patīk tavs kombinzons" }
  25. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  26. else
  27. local theVehicle = getPedOccupiedVehicle(thePlayer)
  28. if (exports['vehicle-system']:isVehicleWindowUp(theVehicle)) then
  29. outputChatBox("You might want to lower your window first, before talking to anyone outside the vehicle", thePlayer, 255,0,0)
  30. return
  31. end
  32. -- processMeMessage(thePed, "noelicas pie " .. getPlayerName(thePlayer):gsub("_"," ") .. " transportlīdzekļa", thePlayer )
  33. triggerEvent('sendAme', thePed, "noelicas pie " .. getPlayerName(thePlayer):gsub("_"," ") .. " transportlīdzekļa")
  34. processMessage(thePed, "Sveiki, kā varu jums palīdzēt?")
  35. setConvoState(thePlayer, 1)
  36. local responseArray = { "Ehm, es vēlētos uzpildīties.", "Nē, paldies.", "Vai jums neatradīsies kāda cigarete priekš manis?", "Varbūt beigsiet stutēties pie mana auto?" }
  37. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  38. end
  39. end
  40. addEvent( "fuel:startConvo", true )
  41. addEventHandler( "fuel:startConvo", getRootElement(), startTalkToPed )
  42.  
  43. function talkToPed(answer, answerStr)
  44. thePed = source
  45. thePlayer = client
  46.  
  47. if not (thePlayer and isElement(thePlayer)) then
  48. return
  49. end
  50.  
  51. local posX, posY, posZ = getElementPosition(thePlayer)
  52. local pedX, pedY, pedZ = getElementPosition(thePed)
  53. if not (getDistanceBetweenPoints3D(posX, posY, posZ, pedX, pedY, pedZ) <= 7) then
  54. return
  55. end
  56.  
  57. local convState = getElementData(thePlayer, "ped:convoState")
  58. local currSlot = getElementData(thePlayer, "languages.current")
  59. local currLang = getElementData(thePlayer, "languages.lang" .. currSlot)
  60. processMessage(thePlayer, answerStr, currLang)
  61. if (convState == 1) then -- "Sveiki, kā varu jums palīdzēt?"
  62. local languageSkill = exports['language-system']:getSkillFromLanguage(thePlayer, 1)
  63. if (languageSkill < 60) or (currLang ~= 1) then
  64. processMessage(thePed, "Vecīt, es ne sūd' nesaprotu *nosmiedams*")
  65. setConvoState(thePlayer, 0)
  66. return
  67. end
  68.  
  69. if (answer == 1) then -- "Ehm, fill my tank up, please."
  70. if not (isPedInVehicle(thePlayer)) then
  71. processMessage(thePed, "Ehm...")
  72. setConvoState(thePlayer, 0)
  73. return
  74. end
  75. local theVehicle = getPedOccupiedVehicle(thePlayer)
  76. if (getElementData(theVehicle, "engine") == 1) then
  77. processMessage(thePed, "Izklausās, ka dzinējs ir ieslēgts. Vai varat lūdzu to izslēgt?")
  78. local responseArray = { "Protams", "Tiešām? To nedrīkst darīt ar ieslēgtu dzinēju?", "Kā lūdzu?" }
  79. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  80. setConvoState(thePlayer, 2)
  81. return
  82. elseif getElementData(theVehicle, 'fuel') > (getMaxFuel(getElementModel(theVehicle))-1) then
  83. processMessage(thePed, "Man šķiet, ka tā jau ir pilns....")
  84. else
  85. processMessage(thePed, "Tātad. Kādā veidā jūs taisateis maksāt?")
  86. if getATMCardFromATMMachine(thePlayer) then
  87. local responseArray = { "Skaidrā!", "Izmantojot savu ATM karti!", "Kā lūdzu?" }
  88. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  89. else
  90. local responseArray = { "Skaidrā!", false, "Kā lūdzu?" }
  91. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  92. end
  93. setConvoState(thePlayer, 4)
  94. --processMessage(thePed, "Sure... we could arrange that.")
  95. --pedWillFillVehicle(thePlayer, thePed)
  96. end
  97. elseif (answer == 2) then -- "Nē, paldies."
  98. processMessage(thePed, "Labs ir, gaidīsim jūs, kad jums būs nepieciešama degviela!")
  99. setConvoState(thePlayer, 0)
  100. elseif (answer == 3) then -- "Do you have a sigarette for me?"
  101. processMessage(thePed, "Ughm, nē. Tās jūs varat iegādāties 24/7 veikalā!")
  102. setConvoState(thePlayer, 0)
  103. elseif (answer == 4) then -- stop leaning against my car
  104. processMessage(thePed, "Labi, labi..Mierīgāk, vecīt'.")
  105. --processMeMessage(thePed, "ar abu roku palīdzību atspiežas no auto.", thePlayer )
  106. triggerEvent('sendAme', thePed, "ar abu roku palīdzību atspiežas no auto.")
  107. processMessage(thePed, "Tātad, pildīsim iekšā vai nē?.")
  108. local responseArray = { "Protams!", "Vairs jau nē...." }
  109. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  110. setConvoState(thePlayer, 1)
  111. end
  112. elseif (convState == 2) then -- "Izklausās, ka dzinējs ir ieslēgts. Vai varat lūdzu to izslēgt?"
  113. if (answer == 1) then -- "Protams" / "Protams!"
  114. if not (isPedInVehicle(thePlayer)) then
  115. processMessage(thePed, "Ehm...")
  116. setConvoState(thePlayer, 0)
  117. return
  118. end
  119. local theVehicle = getPedOccupiedVehicle(thePlayer)
  120. -- processMeMessage(thePlayer, "izslēdz dzinēju.",thePlayer )
  121. triggerEvent('sendAme', thePlayer, "izslēdz dzinēju.")
  122. setElementData(theVehicle, "engine", 0)
  123. setVehicleEngineState(theVehicle, false)
  124.  
  125. processMessage(thePed, "Tātad. Kādā veidā jūs taisateis maksāt?")
  126. if getATMCardFromATMMachine(thePlayer) then
  127. local responseArray = { "Skaidrā!", "Izmantojot savu ATM karti!", "Kā lūdzu?" }
  128. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  129. else
  130. local responseArray = { "Skaidrā!", false, "Kā lūdzu?" }
  131. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  132. end
  133. setConvoState(thePlayer, 4)
  134. elseif (answer == 2) then -- "Tiešām? To nedrīkst darīt ar ieslēgtu dzinēju?"
  135. --processMeMessage(thePed, "nopūšas.",thePlayer )
  136. triggerEvent('sendAme', thePed, "nopūšas.")
  137. processMessage(thePed, "Ehm... nē? Es nevēlos uzsprāgt.....Slēgsim vai nē?")
  138. local responseArray = { "Protams!", false, false, "Ugh, tad lasies!" }
  139. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  140. setConvoState(thePlayer, 2)
  141. elseif (answer == 3) then -- "Kā lūdzu?"
  142. processMessage(thePed, "Es jums pajautāju: Vai jūs varat izslēgt dzinēju?")
  143. local responseArray = { "Protams!", false,false, "Ugh, nē." }
  144. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  145. setConvoState(thePlayer, 2)
  146. elseif answer == 4 then -- "Ugh, tad lasies!" / "Ugh, nē."
  147. processMessage(thePed, "Labi, labi...Nomierinies.")
  148. setConvoState(thePlayer, 0)
  149. end
  150. elseif (convState == 3) then
  151. if answer == 1 then -- Could you fill my fuelcan?
  152. if (exports.global:hasItem(thePlayer, 57)) then
  153. processMessage(thePed, "Protams!")
  154. --processMeMessage(thePed, "saķerdams šļūteni, atver kanniņu, pēc kā tuvinādams šļūteni kannas vākam .",thePlayer )
  155. --processMeMessage(thePed, "rūpīgi liedams degvielu iekšā, seko līdzi tam, lai tā neizlīst.",thePlayer )
  156. triggerEvent('sendAme', thePed, "saķerdams šļūteni, atver kanniņu, pēc kā tuvinādams šļūteni kannas vākam .")
  157. triggerEvent('sendAme', thePed, "rūpīgi liedams degvielu iekšā, seko līdzi tam, lai tā neizlīst.")
  158. setTimer(pedWillFillFuelCan, 3500, 1, thePlayer, thePed)
  159. else
  160. processMessage(thePed, "Aghm...Jums būs nepieciešama degvielas kanna. To var iegādāties 24/7 veikalā!")
  161. setConvoState(thePlayer, 0)
  162. end
  163. elseif answer == 2 then -- No thanks
  164. processMessage(thePed, "Labs ir! Visu labu, jauku dienu.")
  165. setConvoState(thePlayer, 0)
  166. elseif answer == 3 then -- do you have a cigarette for me?
  167. processMessage(thePed, "Ughm, nē. Tās jūs varat iegādāties 24/7 veikalā!")
  168. setConvoState(thePlayer, 0)
  169. elseif answer == 4 then -- I like your suit
  170. processMessage(thePed, "Huh *nopūšoties* Liels paldies *nosarkstot*")
  171. setConvoState(thePlayer, 0)
  172. end
  173. elseif (convState == 4) then -- How would you like to pay?
  174. if answer == 1 or answer == 2 then -- Bank = 2 Cash = 1
  175. if answer == 2 and answerStr ~= "accepted" then
  176. triggerClientEvent(thePlayer, "fuel:requestATMInterfacePIN", thePed, thePlayer, exports.global:getElementZoneName(thePlayer))
  177. setConvoState(thePlayer, 4)
  178. return
  179. end
  180. processMessage(thePed, "Labs ir, uz cik lejam?")
  181. local responseArray = { "$40", "$60", "$100", "Pildi tik iekšā!" }
  182. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  183. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:Type", answer, false)
  184. setConvoState(thePlayer, 5)
  185. elseif answer == 3 then
  186. processMessage(thePed, "Es prasīju: Kādā veidā jūs taisaties maksāt?")
  187. if getATMCardFromATMMachine(thePlayer) then
  188. local responseArray = { "Skaidrā!", "Izmantojot savu ATM karti!", "Kā lūdzu?", "Labs ir, nevajag.." }
  189. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  190. else
  191. local responseArray = { "Skaidrā!", false, "Kā lūdzu?", "Labs ir, nevajag.." }
  192. triggerClientEvent(thePlayer, "fuel:convo", thePed, responseArray)
  193. end
  194. setConvoState(thePlayer, 4)
  195. elseif answer == 4 then
  196. processMessage(thePed, "Nu ja nē, tad nē. Visu labu")
  197. setConvoState(thePlayer, 0)
  198. end
  199. elseif (convState == 5) then
  200. if answer == 1 then
  201. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:amount", 40, false)
  202. elseif answer == 2 then
  203. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:amount", 80, false)
  204. elseif answer == 3 then
  205. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:amount", 100, false)
  206. elseif answer == 4 then
  207. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:amount", 0, false)
  208. end
  209. if not (isPedInVehicle(thePlayer)) then
  210. processMessage(thePed, "Ehm...")
  211. setConvoState(thePlayer, 0)
  212. return
  213. end
  214.  
  215. local theVehicle = getPedOccupiedVehicle(thePlayer)
  216. if getElementData(theVehicle, 'fuel') > (getMaxFuel(getElementModel(theVehicle))-1) then
  217. processMessage(thePed, "Man šķiet, ka tā jau ir pilns....")
  218. else
  219. pedWillFillVehicle(thePlayer, thePed)
  220. end
  221. end
  222. end
  223. addEvent( "fuel:convo", true )
  224. addEventHandler( "fuel:convo", getRootElement(), talkToPed )
  225.  
  226. function pedWillFillFuelCan(thePlayer, thePed)
  227. if not (thePlayer and isElement(thePlayer)) then
  228. return
  229. end
  230. local posX, posY, posZ = getElementPosition(thePlayer)
  231. local pedX, pedY, pedZ = getElementPosition(thePed)
  232. if not (getDistanceBetweenPoints3D(posX, posY, posZ, pedX, pedY, pedZ) <= 7) then
  233. exports['chat-system']:localShout(thePed, "do", "Labi, paliksi bez bendzīna!")
  234. return
  235. end
  236.  
  237. local hasItem, itemSlot, itemValue, itemUniqueID = exports.global:hasItem(thePlayer, 57)
  238. if not (hasItem) then
  239. processMessage(thePed, "Smieklīgi.......")
  240. --processMeMessage(thePed, "nopūšas.",thePlayer )
  241. triggerEvent('sendAme', thePed, "nopūšas.")
  242. return
  243. end
  244.  
  245. if itemValue >= 10 then
  246. processMessage(thePed, "Eh... Ir jau pilna.")
  247. return
  248. end
  249.  
  250. local theLitres = 10 - itemValue
  251.  
  252. local currentTax = exports.global:getTaxAmount()
  253. local fuelCost = math.floor(theLitres*(FUEL_PRICE + (currentTax*FUEL_PRICE)))
  254.  
  255. local money = exports.global:getMoney(thePlayer)
  256. if tonumber(money) == 0 then
  257. processMessage(thePed, "Tu domāji, ka pa brīvu kaut kas sanāks? Lasies!")
  258. return
  259. else
  260. if not exports.global:takeMoney(thePlayer, fuelCost) then
  261. processMessage(thePed, "Yeah, this costs like $" .. fuelCost .. ", derēs?")
  262. return
  263. end
  264. end
  265.  
  266. if not (exports['item-system']:updateItemValue(thePlayer, itemSlot, itemValue + theLitres)) then
  267. outputChatBox("Kaut kas nogājis greizi, lūdzu /report.", thePlayer)
  268. return
  269. end
  270.  
  271. local info = {
  272. {"Gas Station Receipt"},
  273. {""},
  274. {" " .. math.ceil(theLitres) .. " Litres of petrol - " .. fuelCost .. "$"},
  275. }
  276. triggerClientEvent(thePlayer, "hudOverlay:drawOverlayTopRight", thePlayer, info )
  277. end
  278.  
  279. function pedWillFillVehicle(thePlayer, thePed)
  280. if not (thePlayer and isElement(thePlayer)) then
  281. return
  282. end
  283. local amount = getElementData(thePlayer, "ped:amount")
  284. local moneyType = getElementData(thePlayer, "ped:Type")
  285.  
  286. setTimer(pedWillFuelTheVehicle, 5000, 1, thePlayer, thePed, amount, moneyType)
  287. end
  288.  
  289. function pedWillFuelTheVehicle(thePlayer, thePed, amount, moneyType)
  290. if not (thePlayer and isElement(thePlayer)) then
  291. return
  292. end
  293. local posX, posY, posZ = getElementPosition(thePlayer)
  294. local pedX, pedY, pedZ = getElementPosition(thePed)
  295. if not (getDistanceBetweenPoints3D(posX, posY, posZ, pedX, pedY, pedZ) <= 7) then
  296. exports['chat-system']:localShout(thePed, "do", "IDIOT! VĒLIES NOMIRT? PAKAĻA")
  297. return
  298. end
  299.  
  300. local theVehicle = getPedOccupiedVehicle(thePlayer)
  301.  
  302. if (getVehicleEngineState(theVehicle) == true) then
  303. exports['chat-system']:localShout(thePed, "do", "IDIOT! VĒLIES NOMIRT? PAKAĻA")
  304. --processDoMessage(thePlayer, "The vehicle explodes", thePlayer)
  305. --blowVehicle (theVehicle, false )
  306. return
  307. end
  308.  
  309. if not (isPedInVehicle(thePlayer) == true) then
  310. processMessage(thePed, "Ehm...")
  311. setConvoState(thePlayer, 0)
  312. return
  313. end
  314.  
  315.  
  316.  
  317. local theLitres = calculateFuelPrice(thePlayer, thePed, amount, moneyType)
  318. local fuelCost = math.ceil(theLitres*(1 + exports.global:getTaxAmount())*FUEL_PRICE)
  319.  
  320. if moneyType == 1 then
  321. money = exports.global:getMoney(thePlayer)
  322. else
  323. money = getElementData(thePlayer, "bankmoney")
  324. end
  325. local factionPlayer = getElementData(thePlayer, "faction")
  326. local factionVehicle = getElementData(theVehicle, "faction")
  327.  
  328. local factionPaid = false
  329. if factionPlayer == factionVehicle and factionsThatPayForFuel[factionPlayer] and factionsThatPayForFuel[factionVehicle] then
  330. local theTeam = getPlayerTeam(thePlayer)
  331. if exports.global:takeMoney(theTeam, fuelCost, true) then
  332. processMessage(thePed, "I'll send the receipt to your employer.")
  333. mysql:query_free("INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. mysql:escape_string(( -getElementData( theTeam, "id" ) )) .. ", " .. mysql:escape_string(getElementData(thePlayer, "dbid")) .. ", " .. mysql:escape_string(fuelCost) .. ", '"..mysql:escape_string(theLitres).."', 9)" )
  334.  
  335. factionPaid = true
  336. end
  337. end
  338.  
  339. if not factionPaid then
  340. if (fuelCost > 0 and money > 0) then
  341. if not exports.donators:hasPlayerPerk(thePlayer, 7) then
  342. if moneyType == 1 then
  343. if exports.global:takeMoney(thePlayer, fuelCost) then
  344. processMessage(thePed, "Te būs jūsu čeks!.")
  345. else
  346. processMessage(thePed, "Tu domāji, ka pa brīvu kaut kas sanāks? Lasies!")
  347. return
  348. end
  349. else
  350. if exports.bank:updateBankMoney(thePlayer, getElementData(thePlayer, "dbid"), fuelCost, "minus") then
  351. processMessage(thePed, "Te būs jūsu čeks!.")
  352. else
  353. processMessage(thePed, "Jūsu karte netiek pieņemta")
  354. return
  355. end
  356. end
  357. else
  358. processMessage(thePed, "Te būs jūsu čeks!.")
  359. end
  360. else
  361. processMessage(thePed, "Tu domāji, ka pa brīvu kaut kas sanāks? Lasies!")
  362. return
  363. end
  364. end
  365.  
  366. local loldFuel = getElementData(theVehicle, "fuel")
  367. local newFuel = loldFuel+theLitres
  368. exports.anticheat:changeProtectedElementDataEx(theVehicle, "fuel", newFuel, false)
  369. triggerClientEvent(thePlayer, "syncFuel", theVehicle, newFuel)
  370.  
  371. local info = {
  372. {"Gas Station Receipt"},
  373. {""},
  374. }
  375.  
  376. if exports.donators:hasPlayerPerk(thePlayer, 7) and not factionPaid then
  377. table.insert(info, {" " .. math.ceil(theLitres) .. " litres of petrol - (( Free Fuel ))"})
  378. else
  379. table.insert(info, {" " .. math.ceil(theLitres) .. " litres of petrol - " .. fuelCost .. "$"})
  380. if factionPaid then
  381. table.insert(info, {" Paid by employer "..tostring(exports.factions:getFactionName(factionPlayer))})
  382. end
  383. end
  384. table.insert(info, {" "..exports.global:getVehicleName(theVehicle).." - "..exports.global:round(newFuel, 2).."/"..exports.global:round(getMaxFuel(theVehicle), 2).." litres"})
  385. triggerClientEvent(thePlayer, "hudOverlay:drawOverlayTopRight", thePlayer, info )
  386.  
  387. -- give shop owner a portion of fuel price
  388. local shopLink = tonumber( getElementData( thePed, 'shop_link') )
  389. outputDebugString( 'Shop Link: ' .. shopLink )
  390. if shopLink > 0 then
  391. local money = math.floor( tonumber( fuelCost ) * 0.4 ) -- give 40% to shop owner
  392. outputDebugString( 'Money: ' .. money )
  393. local findShop = exports.mysql:query('SELECT `id`, `sIncome` FROM `shops` WHERE `shoptype` = 15 AND `dimension` = ' .. getElementData( thePed, 'shop_link') .. ' LIMIT 1')
  394.  
  395. local row = exports.mysql:fetch_assoc( findShop )
  396. if row then
  397. for index, shopPed in pairs( getElementsByType( 'ped')) do
  398. if tonumber( getElementData( shopPed, "dbid") ) == tonumber( row.id ) and getElementData( shopPed, "ped:type" ) == 'shop' then
  399. outputDebugString( 'Shop ID: ' .. row.id )
  400. exports.anticheat:changeProtectedElementDataEx( shopPed, "sIncome", tonumber( row.sIncome ) + money )
  401. end
  402. end
  403. exports.mysql:query_free( "UPDATE `shops` SET `sIncome` = `sIncome` + " .. money .. " WHERE `id` = " .. row.id )
  404. end
  405. mysql:free_result( findShop )
  406. end
  407.  
  408. end
  409.  
  410. function setConvoState(thePlayer, state)
  411. exports.anticheat:changeProtectedElementDataEx(thePlayer, "ped:convoState", state, false)
  412. end
  413.  
  414. function processMessage(thePed, message, language)
  415. if not (language) then
  416. language = 1
  417. end
  418. exports['chat-system']:localIC(thePed, message, language)
  419. end
  420.  
  421. function processMeMessage(thePed, message, source)
  422. local name = getElementData(thePed, "name") or getPlayerName(thePed)
  423. exports['global']:sendLocalText(source, " *" .. string.gsub(name, "_", " ").. ( message:sub( 1, 1 ) == "'" and "" or " " ) .. message, 255, 51, 102)
  424. end
  425.  
  426. function processDoMessage(thePed, message, source)
  427. local name = getElementData(thePed, "name") or getPlayerName(thePed)
  428. exports['global']:sendLocalText(source, " * " .. message .. " * ((" .. name:gsub("_", " ") .. "))", 255, 51, 102)
  429. end
  430.  
  431. function calculateFuelPrice(thePlayer, thePed, amount, moneyType)
  432. local theVehicle = getPedOccupiedVehicle(thePlayer)
  433. local litresAffordable = getMaxFuel(getElementModel(theVehicle))
  434. local MAX_FUEL = getMaxFuel(getElementModel(theVehicle))
  435. local currFuel = tonumber(getElementData(theVehicle, "fuel"))
  436.  
  437. if not (exports.donators:hasPlayerPerk(thePlayer, 7)) then
  438. if moneyType == 2 then
  439. local money = getElementData(thePlayer, "bankmoney")
  440.  
  441. local tax = exports.global:getTaxAmount()
  442. local cost = FUEL_PRICE + (tax*FUEL_PRICE)
  443. if amount ~= 0 then
  444. litresAffordable = (amount/cost)
  445. else
  446. litresAffordable = math.floor(money/cost)
  447. end
  448.  
  449. if (litresAffordable>MAX_FUEL) then
  450. litresAffordable=MAX_FUEL
  451. end
  452. else
  453. local money = exports.global:getMoney(thePlayer)
  454.  
  455. local tax = exports.global:getTaxAmount()
  456. local cost = FUEL_PRICE + (tax*FUEL_PRICE)
  457. if amount ~= 0 then
  458. litresAffordable = (amount/cost)
  459. else
  460. litresAffordable = math.floor(money/cost)
  461. end
  462.  
  463. if (litresAffordable>MAX_FUEL) then
  464. litresAffordable=MAX_FUEL
  465. end
  466. end
  467. else
  468. -- free fuel
  469. end
  470.  
  471. if (litresAffordable+currFuel>MAX_FUEL) then
  472. litresAffordable = MAX_FUEL - currFuel
  473. end
  474. return litresAffordable
  475. end
  476.  
  477. function createFuelPed(skin, posX, posY, posZ, rotZ, name, int, dim, id, shop_link)
  478. theNewPed = createPed (skin, posX, posY, posZ)
  479. exports.pool:allocateElement(theNewPed)
  480. setPedRotation (theNewPed, rotZ)
  481. setElementFrozen(theNewPed, true)
  482. --setPedAnimation(theNewPed, "FOOD", "FF_Sit_Loop", -1, true, false, true)
  483. exports.anticheat:changeProtectedElementDataEx(theNewPed, "talk",1, true)
  484. exports.anticheat:changeProtectedElementDataEx(theNewPed, "name", name:gsub("_", " "), true)
  485. exports.anticheat:changeProtectedElementDataEx(theNewPed, "ped:type", "fuel", true)
  486. exports.anticheat:changeProtectedElementDataEx(theNewPed, "ped:fuelped",true, true)
  487. exports.anticheat:changeProtectedElementDataEx(theNewPed, "shop_link", shop_link, true)
  488.  
  489. -- For the language system
  490. exports.anticheat:changeProtectedElementDataEx(theNewPed, "languages.lang1" , 1, false)
  491. exports.anticheat:changeProtectedElementDataEx(theNewPed, "languages.lang1skill", 100, false)
  492. exports.anticheat:changeProtectedElementDataEx(theNewPed, "languages.lang2" , 2, false)
  493. exports.anticheat:changeProtectedElementDataEx(theNewPed, "languages.lang2skill", 100, false)
  494. exports.anticheat:changeProtectedElementDataEx(theNewPed, "languages.current", 1, false)
  495. setElementInterior(theNewPed, int)
  496. setElementDimension(theNewPed, dim)
  497. exports.anticheat:changeProtectedElementDataEx(theNewPed, "dbid",id, true)
  498. createBlip(posX, posY, posZ, 55, 2, 255, 0, 0, 255, 0, 300)
  499. return theNewPed
  500. end
  501.  
  502. function makeFuelPed(thePlayer, commandName, skin, ...)
  503. if (exports.integration:isPlayerTrialAdmin(thePlayer)) then
  504. outputChatBox("SYNTAX: /" .. commandName .. " [skin, default = 50, -1 = random] [Firstname Lastname, -1 = random]", thePlayer, 255, 194, 14)
  505.  
  506. local skin = tonumber(skin)
  507.  
  508. if not skin or skin == -1 then --Random
  509. skin = exports.global:getRandomSkin()
  510. end
  511.  
  512. if skin then
  513. local ped = createPed(skin, 0, 0, 3)
  514. if not ped then
  515. outputChatBox("Invalid Skin.", thePlayer, 255, 0, 0)
  516. return
  517. else
  518. destroyElement(ped)
  519. end
  520. else
  521. skin = -1
  522. end
  523.  
  524. local x, y, z = getElementPosition(thePlayer)
  525. local dimension = getElementDimension(thePlayer)
  526. local interior = getElementInterior(thePlayer)
  527. local rotation = getPedRotation(thePlayer)
  528.  
  529. local pedName = table.concat({...}, "_") or false
  530.  
  531. if not pedName or pedName== "" or (tonumber(pedName) and tonumber(pedName) == -1) then
  532. pedName = exports.global:createRandomMaleName()
  533. pedName = string.gsub(pedName, " ", "_")
  534. end
  535.  
  536. local id = false
  537. id = mysql:query_insert_free("INSERT INTO `fuelpeds` SET `name`='"..exports.global:toSQL(pedName).."', `posX`='" .. mysql:escape_string(x) .. "', `posY`='" .. mysql:escape_string(y) .. "', `posZ`='" .. mysql:escape_string(z) .. "', dimension='" .. mysql:escape_string(dimension) .. "', interior='" .. mysql:escape_string(interior) .. "', `rotZ`='" .. mysql:escape_string(rotation) .. "', `skin`='".. mysql:escape_string(skin).."' ")
  538.  
  539. if (id) then
  540. createFuelPed(skin ~= -1 and skin or 50, x,y,z,rotation,pedName,interior,dimension,id, 0)
  541. exports.logs:logMessage("[/"..commandName.."] " .. getElementData(thePlayer, "account:username") .. "/".. getPlayerName(thePlayer) .." did make fuel ped id " .. id .. ".", 4)
  542. else
  543. outputChatBox("Error creating fuel ped.", thePlayer, 255, 0, 0)
  544. end
  545. end
  546. end
  547. addCommandHandler("makefuelped", makeFuelPed, false, false)
  548. addCommandHandler("makefuel", makeFuelPed, false, false)
  549. addCommandHandler("makefuelnpc", makeFuelPed, false, false)
  550.  
  551. function onServerStart()
  552. local sqlHandler = mysql:query("SELECT * FROM fuelpeds WHERE `deletedBy` = 0 ")
  553. if (sqlHandler) then
  554. while true do
  555. local row = mysql:fetch_assoc( sqlHandler )
  556. if not row then break end
  557. local thePed = createFuelPed(tonumber(row["skin"]),tonumber(row["posX"]),tonumber(row["posY"]),tonumber(row["posZ"]), tonumber(row["rotZ"]), row["name"], tonumber(row["interior"]), tonumber(row["dimension"]), tonumber(row["id"]), tonumber( row["shop_link"]))
  558. end
  559. end
  560. mysql:free_result(sqlHandler)
  561. end
  562. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onServerStart)
  563.  
  564.  
  565. function getNearByFuelPeds(thePlayer, commandName) --maxime
  566. if (exports.integration:isPlayerTrialAdmin(thePlayer) or exports.integration:isPlayerSupporter(thePlayer)) then
  567. local posX, posY, posZ = getElementPosition(thePlayer)
  568. outputChatBox("Nearby Fuel NPC(s):", thePlayer, 255, 126, 0)
  569. local count = 0
  570.  
  571. local dimension = getElementDimension(thePlayer)
  572.  
  573. for k, thePed in ipairs(getElementsByType("ped", resourceRoot)) do
  574. local pedType = getElementData(thePed, "ped:type")
  575. if (pedType) then
  576. if (pedType=="fuel") then
  577. local x, y = getElementPosition(thePed)
  578. local distance = getDistanceBetweenPoints2D(posX, posY, x, y)
  579. local cdimension = getElementDimension(thePed)
  580. if (distance<=10) and (dimension==cdimension) then
  581. local dbid = getElementData(thePed, "dbid")
  582. local pedName = getElementData(thePed, "name")
  583. local shopLink = tonumber( getElementData(thePed, "shop_link") )
  584. outputChatBox(" Fuel NPC ID #" .. dbid .. ", name: "..tostring(pedName):gsub("_", " ") .. ( shopLink > 0 and ' shop link: ' .. shopLink or ''), thePlayer, 255, 126, 0)
  585. count = count + 1
  586. end
  587. end
  588. end
  589. end
  590.  
  591. if (count==0) then
  592. outputChatBox(" None.", thePlayer, 255, 126, 0)
  593. end
  594. end
  595. end
  596. addCommandHandler("nearbyfuels", getNearByFuelPeds, false, false)
  597. addCommandHandler("nearbynpcs", getNearByFuelPeds, false, false)
  598.  
  599. function gotoFuelPed(thePlayer, commandName, shopID) --maxime
  600. if (exports.integration:isPlayerTrialAdmin(thePlayer) or exports.integration:isPlayerSupporter(thePlayer)) then
  601. if not tonumber(shopID) then
  602. outputChatBox("SYNTAX: /" .. commandName .. " [Shop ID]", thePlayer, 255, 194, 14)
  603. else
  604. local possibleShops = getElementsByType("ped", resourceRoot)
  605. local foundShop = false
  606. for _, shop in ipairs(possibleShops) do
  607. if getElementData(shop,"ped:type") == "fuel" and (tonumber(getElementData(shop, "dbid")) == tonumber(shopID)) then
  608. foundShop = shop
  609. break
  610. end
  611. end
  612.  
  613. if not foundShop then
  614. outputChatBox("No shop founded with ID #"..shopID, thePlayer, 255, 0, 0)
  615. return false
  616. end
  617.  
  618. local x, y, z = getElementPosition(foundShop)
  619. local dim = getElementDimension(foundShop)
  620. local int = getElementInterior(foundShop)
  621. local rot = getElementRotation(foundShop)
  622. startGoingToShop(thePlayer, x,y,z,rot,int,dim,shopID)
  623. end
  624. end
  625. end
  626. addCommandHandler("gotofuel", gotoFuelPed, false, false)
  627. addCommandHandler("gotofuelped", gotoFuelPed, false, false)
  628. addCommandHandler("gotofuelnpc", gotoFuelPed, false, false)
  629.  
  630. function startGoingToShop(thePlayer, x,y,z,r,interior,dimension,shopID) --maxime
  631. -- Maths calculations to stop the player being stuck in the target
  632. x = x + ( ( math.cos ( math.rad ( r ) ) ) * 2 )
  633. y = y + ( ( math.sin ( math.rad ( r ) ) ) * 2 )
  634.  
  635. setCameraInterior(thePlayer, interior)
  636.  
  637. if (isPedInVehicle(thePlayer)) then
  638. local veh = getPedOccupiedVehicle(thePlayer)
  639. setVehicleTurnVelocity(veh, 0, 0, 0)
  640. setElementInterior(thePlayer, interior)
  641. setElementDimension(thePlayer, dimension)
  642. setElementInterior(veh, interior)
  643. setElementDimension(veh, dimension)
  644. setElementPosition(veh, x, y, z + 1)
  645. warpPedIntoVehicle ( thePlayer, veh )
  646. setTimer(setVehicleTurnVelocity, 50, 20, veh, 0, 0, 0)
  647. else
  648. setElementPosition(thePlayer, x, y, z)
  649. setElementInterior(thePlayer, interior)
  650. setElementDimension(thePlayer, dimension)
  651. end
  652. outputChatBox(" You have teleported to Fuel NPC ID#"..shopID, thePlayer)
  653. end
  654.  
  655. function deleteFuelPed(thePlayer, commandName, id) -- maxime
  656. if (exports.integration:isPlayerTrialAdmin(thePlayer)) then
  657. if not (id) then
  658. outputChatBox("SYNTAX: /" .. commandName .. " [ID]", thePlayer, 255, 194, 14)
  659. else
  660. local counter = 0
  661. for k, thePed in ipairs(getElementsByType("ped", resourceRoot)) do
  662. local pedType = getElementData(thePed, "ped:type")
  663. if (pedType) then
  664. if (pedType=="fuel") then
  665. local dbid = getElementData(thePed, "dbid")
  666. if (tonumber(id)==dbid) then
  667. destroyElement(thePed)
  668. local adminID = getElementData(thePlayer,"account:id")
  669. mysql:query_free("UPDATE `fuelpeds` SET `deletedBy` = '"..tostring(adminID).."' WHERE id='" .. mysql:escape_string(dbid) .. "' LIMIT 1")
  670. outputChatBox(" Deleted fuel npc with ID #" .. id .. ".", thePlayer, 0, 255, 0)
  671. counter = counter + 1
  672. setElementData(thePlayer, "fuel:mostRecentDeleteFuelPed",dbid )
  673. end
  674. end
  675. end
  676. end
  677.  
  678. if (counter==0) then
  679. outputChatBox("No fuel ped with such an ID exists.", thePlayer, 255, 0, 0)
  680. return false
  681. end
  682. return true
  683. end
  684. end
  685. end
  686. addCommandHandler("delfuel", deleteFuelPed, false, false)
  687. addCommandHandler("deletefuel", deleteFuelPed, false, false)
  688. addCommandHandler("delfuelped", deleteFuelPed, false, false)
  689. addCommandHandler("deletefuelped", deleteFuelPed, false, false)
  690.  
  691.  
  692.  
  693. addCommandHandler( 'setfuelpedlink',
  694. function ( player, command, fuelped, shopID )
  695. if exports.integration:isPlayerAdmin( player ) then
  696. -- make sure the player actually filled in the data
  697. if tonumber( fuelped ) and tonumber( shopID ) then
  698. -- determine if the fuel ped exists.
  699. local findFuelPed = exports.mysql:query('SELECT `name` FROM `fuelpeds` WHERE `id` = ' .. exports.mysql:escape_string( fuelped ))
  700. if exports.mysql:num_rows( findFuelPed ) > 0 then
  701. -- determine if shop exists.
  702. local findShop = exports.mysql:query( 'SELECT `name` FROM `interiors` WHERE `id` = ' .. exports.mysql:escape_string( shopID ))
  703. if exports.mysql:num_rows( findShop ) > 0 then
  704. local findShopPed = exports.mysql:query( 'SELECT `id` FROM `shops` WHERE `shoptype` = 15 AND `dimension` = ' .. exports.mysql:escape_string( shopID ) )
  705. if exports.mysql:num_rows( findShopPed ) > 0 then
  706. exports.mysql:update( 'fuelpeds', { shop_link = shopID }, { id = fuelped } )
  707.  
  708. for i, ped in pairs( getElementsByType('ped')) do
  709. if getElementData(ped, "ped:type" ) == "fuel" and getElementData( ped, "dbid") == tonumber( fuelped ) then
  710. exports.anticheat:changeProtectedElementDataEx( ped, "shop_link", tonumber( shopID ), true )
  711. end
  712. end
  713.  
  714. outputChatBox( 'That interior has been linked to the fuel ped.', player, 155, 255, 155 )
  715. else
  716. outputChatBox( 'That interior does not have a shop type 15.', player, 255, 155, 155 )
  717. end
  718. exports.mysql:free_result( findShopPed )
  719. else
  720. outputChatBox( 'No such interior found.', player, 255, 155, 155 )
  721. end
  722. mysql:free_result( findShop )
  723. else
  724. outputChatBox( 'No such fuel ped found.', player, 255, 155, 155 )
  725. end
  726. mysql:free_result( findFuelPed )
  727. else
  728. outputChatBox( "SYNTAX: /" .. command .. " [fuel ped ID] [shop interior ID]", player, 255, 255, 255 )
  729. end
  730. end
  731. end
  732. )
Advertisement
Add Comment
Please, Sign In to add comment