Guest User

faction Server side

a guest
Apr 5th, 2012
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.00 KB | None | 0 0
  1. mysql = exports.mysql
  2.  
  3. local unemployedPay = 150
  4. local result = mysql:query_fetch_assoc( "SELECT value FROM settings WHERE name = 'welfare'" )
  5. if result then
  6. if not result.value then
  7. mysql:query_free( "INSERT INTO settings (name, value) VALUES ('welfare', " .. unemployedPay .. ")" )
  8. else
  9. unemployedPay = tonumber( result.value ) or 150
  10. end
  11. end
  12. result = nil
  13.  
  14. -- EVENTS
  15. addEvent("onPlayerJoinFaction", false)
  16. addEventHandler("onPlayerJoinFaction", getRootElement(),
  17. function(theTeam)
  18. local id = getElementData(theTeam, "id")
  19. if id == 1 then
  20. exports.global:givePlayerAchievement(source, 2)
  21. elseif id == 2 then
  22. exports.global:givePlayerAchievement(source, 5)
  23. elseif id == 3 then
  24. exports.global:givePlayerAchievement(source, 6)
  25. end
  26. end
  27. )
  28.  
  29. function loadAllFactions(res)
  30. -- work out how many minutes it is until the next hour
  31. local mins = getRealTime().minute
  32. local minutes = 60 - mins
  33. setTimer(payAllWages, 60000*minutes, 1, true)
  34.  
  35. local result = mysql:query("SELECT * FROM factions ORDER BY id ASC")
  36. local counter = 0
  37.  
  38. if result then
  39. while true do
  40. local row = mysql:fetch_assoc(result)
  41. if not row then break end
  42.  
  43. local id = tonumber(row.id)
  44. local name = row.name
  45. local money = tonumber(row.bankbalance)
  46. local factionType = tonumber(row.type)
  47.  
  48. local theTeam = createTeam(tostring(name))
  49. exports.pool:allocateElement(theTeam, id)
  50. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "type", factionType)
  51. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "money", money)
  52. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "id", id)
  53.  
  54. local factionRanks = {}
  55. local factionWages = {}
  56. for i = 1, 15 do
  57. factionRanks[i] = row['rank_'..i]
  58. factionWages[i] = tonumber(row['wage_'..i])
  59. end
  60. local motd = row.motd
  61. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "ranks", factionRanks, false)
  62. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "wages", factionWages, false)
  63. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "motd", motd, false)
  64.  
  65. counter = counter + 1
  66. end
  67. mysql:free_result(result)
  68.  
  69. local citteam = createTeam("Citizen", 255, 255, 255)
  70. exports.pool:allocateElement(citteam, -1)
  71.  
  72. -- set all players into their appropriate faction
  73. local players = exports.pool:getPoolElementsByType("player")
  74. for k, thePlayer in ipairs(players) do
  75. local username = getPlayerName(thePlayer)
  76. local safeusername = mysql:escape_string(username)
  77.  
  78. local result = mysql:query_fetch_assoc("SELECT faction_id, faction_rank, faction_leader FROM characters WHERE charactername='" .. safeusername .. "' LIMIT 1")
  79. if result then
  80. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionMenu", 0)
  81. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "faction", tonumber(result.faction_id))
  82. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionrank", tonumber(result.faction_rank))
  83. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionleader", tonumber(result.faction_leader), false)
  84.  
  85. setPlayerTeam(thePlayer, exports.pool:getElement("team", result.faction_id) or citteam)
  86. end
  87. end
  88. end
  89. end
  90. addEventHandler("onResourceStart", getResourceRootElement(), loadAllFactions)
  91.  
  92. -- Bind Keys required
  93. function bindKeys()
  94. local players = exports.pool:getPoolElementsByType("player")
  95. for k, arrayPlayer in ipairs(players) do
  96. if not(isKeyBound(arrayPlayer, "F3", "down", showFactionMenu)) then
  97. bindKey(arrayPlayer, "F3", "down", showFactionMenu)
  98. end
  99. end
  100. end
  101.  
  102. function bindKeysOnJoin()
  103. bindKey(source, "F3", "down", showFactionMenu)
  104. end
  105. addEventHandler("onResourceStart", getResourceRootElement(), bindKeys)
  106. addEventHandler("onPlayerJoin", getRootElement(), bindKeysOnJoin)
  107.  
  108. function showFactionMenu(source)
  109. local logged = getElementData(source, "loggedin")
  110.  
  111. if (logged==1) then
  112. local menuVisible = getElementData(source, "factionMenu")
  113.  
  114. if (menuVisible==0) then
  115. local factionID = getElementData(source, "faction")
  116.  
  117. if (factionID~=-1) then
  118. local theTeam = getPlayerTeam(source)
  119. local query = mysql:query("SELECT charactername, faction_rank, faction_leader, DATEDIFF(NOW(), lastlogin) AS lastlogin FROM characters WHERE faction_ID='" .. factionID .. "' ORDER BY faction_rank DESC, charactername ASC")
  120. if query then
  121.  
  122. local memberUsernames = {}
  123. local memberRanks = {}
  124. local memberLeaders = {}
  125. local memberOnline = {}
  126. local memberLastLogin = {}
  127. local memberLocation = {}
  128. local factionRanks = getElementData(theTeam, "ranks")
  129. local factionWages = getElementData(theTeam, "wages")
  130. local motd = getElementData(theTeam, "motd")
  131.  
  132. if (motd == "") then motd = nil end
  133.  
  134. local i = 1
  135. while true do
  136. local row = mysql:fetch_assoc(query)
  137. if not row then break end
  138.  
  139. local playerName = row.charactername
  140. memberUsernames[i] = playerName
  141. memberRanks[i] = row.faction_rank
  142.  
  143. if (tonumber(row.faction_leader)==1) then
  144. memberLeaders[i] = true
  145. else
  146. memberLeaders[i] = false
  147. end
  148.  
  149. local login = ""
  150.  
  151. memberLastLogin[i] = tonumber(row.lastlogin)
  152.  
  153.  
  154. local targetPlayer = getPlayerFromName(tostring(playerName))
  155. if (targetPlayer) then
  156. memberOnline[i] = true
  157. if getElementData(targetPlayer, "hideF3Location") then
  158. memberLocation[i] = "N/A"
  159. elseif getElementData(targetPlayer, "loggedin") == 1 then
  160. local zone, city = exports.global:getElementZoneName(targetPlayer)
  161.  
  162. if(zone~=city) and (city~=nil) then
  163. memberLocation[i] = zone .. ", " .. city
  164. else
  165. memberLocation[i] = zone
  166. end
  167. else
  168. memberLocation[i] = "Not logged in"
  169. end
  170. else
  171. memberOnline[i] = false
  172. memberLocation[i] = "N/A"
  173. end
  174. i = i + 1
  175. end
  176. exports['anticheat-system']:changeProtectedElementDataEx(source, "factionMenu", 1)
  177. mysql:free_result(query)
  178.  
  179. local theTeam = getPlayerTeam(source)
  180. triggerClientEvent(source, "showFactionMenu", getRootElement(), motd, memberUsernames, memberRanks, memberLeaders, memberOnline, memberLastLogin, memberLocation, factionRanks, factionWages, theTeam)
  181. end
  182. else
  183. outputChatBox("You are not in a faction.", source)
  184. end
  185. else
  186. triggerClientEvent(source, "hideFactionMenu", getRootElement())
  187. end
  188. end
  189. end
  190.  
  191. -- // CALL BACKS FROM CLIENT GUI
  192. function callbackUpdateRanks(ranks, wages)
  193. local theTeam = getPlayerTeam(client)
  194. local factionID = getElementData(theTeam, "id")
  195.  
  196. for key, value in ipairs(ranks) do
  197. ranks[key] = mysql:escape_string(ranks[key])
  198. end
  199.  
  200. if (wages) then
  201. for key, value in ipairs(wages) do
  202. wages[key] = tonumber(wages[key]) or 0
  203. if wages[key]> 1500 then
  204. outputChatBox("Wage should not be more than 1500",source,255,5,5)
  205. return
  206. end
  207. end
  208.  
  209. mysql:query_free("UPDATE factions SET wage_1='" .. wages[1] .. "', wage_2='" .. wages[2] .. "', wage_3='" .. wages[3] .. "', wage_4='" .. wages[4] .. "', wage_5='" .. wages[5] .. "', wage_6='" .. wages[6] .. "', wage_7='" .. wages[7] .. "', wage_8='" .. wages[8] .. "', wage_9='" .. wages[9] .. "', wage_10='" .. wages[10] .. "', wage_11='" .. wages[11] .. "', wage_12='" .. wages[12] .. "', wage_13='" .. wages[13] .. "', wage_14='" .. wages[14] .. "', wage_15='" .. wages[15] .. "' WHERE id='" .. factionID .. "'")
  210. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "wages", wages, false)
  211. end
  212.  
  213. mysql:query_free("UPDATE factions SET rank_1='" .. ranks[1] .. "', rank_2='" .. ranks[2] .. "', rank_3='" .. ranks[3] .. "', rank_4='" .. ranks[4] .. "', rank_5='" .. ranks[5] .. "', rank_6='" .. ranks[6] .. "', rank_7='" .. ranks[7] .. "', rank_8='" .. ranks[8] .. "', rank_9='" .. ranks[9] .. "', rank_10='" .. ranks[10] .. "', rank_11='" .. ranks[11] .. "', rank_12='" .. ranks[12] .. "', rank_13='" .. ranks[13] .. "', rank_14='" .. ranks[14] .. "', rank_15='" .. ranks[15] .. "' WHERE id='" .. factionID .. "'")
  214. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "ranks", ranks, false)
  215.  
  216. outputChatBox("Faction information updated successfully.", source, 0, 255, 0)
  217. showFactionMenu(source)
  218. end
  219. addEvent("cguiUpdateRanks", true )
  220. addEventHandler("cguiUpdateRanks", getRootElement(), callbackUpdateRanks)
  221.  
  222.  
  223. function callbackRespawnVehicles()
  224. local theTeam = getPlayerTeam(source)
  225.  
  226. local factionCooldown = getElementData(theTeam, "cooldown")
  227.  
  228. if not (factionCooldown) then
  229. local factionID = getElementData(theTeam, "id")
  230.  
  231. for key, value in ipairs(exports.pool:getPoolElementsByType("vehicle")) do
  232. local faction = getElementData(value, "faction")
  233. if (faction == factionID and not getVehicleOccupant(value, 0) and not getVehicleOccupant(value, 1) and not getVehicleOccupant(value, 2) and not getVehicleOccupant(value, 3) and not getVehicleTowingVehicle(value)) then
  234. respawnVehicle(value)
  235. end
  236. end
  237.  
  238. -- Send message to everyone in the faction
  239. local teamPlayers = getPlayersInTeam(theTeam)
  240. local username = getPlayerName(source)
  241. for k, v in ipairs(teamPlayers) do
  242. outputChatBox(username .. " respawned all unoccupied faction vehicles.", v)
  243. end
  244.  
  245. setTimer(resetFactionCooldown, 600000, 1, theTeam)
  246. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "cooldown", true, false)
  247. else
  248. outputChatBox("You currently cannot respawn your factions vehicles, Please wait a while.", source, 255, 0, 0)
  249. end
  250. end
  251. addEvent("cguiRespawnVehicles", true )
  252. addEventHandler("cguiRespawnVehicles", getRootElement(), callbackRespawnVehicles)
  253.  
  254. function resetFactionCooldown(theTeam)
  255. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "cooldown")
  256. end
  257.  
  258. function callbackUpdateMOTD(motd)
  259. local faction = tonumber(getElementData(source, "faction"))
  260. local theTeam = getPlayerTeam(source)
  261.  
  262. if (faction~=-1) then
  263. if mysql:query_free("UPDATE factions SET motd='" .. tostring(mysql:escape_string(motd)) .. "' WHERE id='" .. faction .. "'") then
  264. outputChatBox("You changed your faction's MOTD to '" .. motd .. "'", source, 0, 255, 0)
  265. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "motd", motd, false)
  266. else
  267. outputChatBox("Error 300000 - Report on Mantis.", source, 255, 0, 0)
  268. end
  269. end
  270. end
  271. addEvent("cguiUpdateMOTD", true )
  272. addEventHandler("cguiUpdateMOTD", getRootElement(), callbackUpdateMOTD)
  273.  
  274. function callbackRemovePlayer(removedPlayerName)
  275. if mysql:query_free("UPDATE characters SET faction_id='-1', faction_leader='0', faction_rank='1', dutyskin = 0, duty = 0 WHERE charactername='" .. mysql:escape_string(removedPlayerName) .. "'") then
  276. local theTeam = getPlayerTeam(source)
  277. local theTeamName = "None"
  278. if (theTeam) then
  279. theTeamName = getTeamName(theTeam)
  280. end
  281.  
  282. local username = getPlayerName(source)
  283.  
  284.  
  285. local removedPlayer = getPlayerFromName(removedPlayerName)
  286. if (removedPlayer) then -- Player is online
  287. if (getElementData(source, "factionMenu")==1) then
  288. triggerClientEvent(removedPlayer, "hideFactionMenu", getRootElement())
  289. end
  290. outputChatBox(username .. " removed you from the faction '" .. tostring(theTeamName) .. "'", removedPlayer)
  291. setPlayerTeam(removedPlayer, getTeamFromName("Citizen"))
  292. exports['anticheat-system']:changeProtectedElementDataEx(removedPlayer, "faction", -1)
  293. exports['anticheat-system']:changeProtectedElementDataEx(removedPlayer, "dutyskin", -1, false)
  294. exports['anticheat-system']:changeProtectedElementDataEx(removedPlayer, "factionleader", 0, false)
  295. if getElementData(removedPlayer, "duty") and getElementData(removedPlayer, "duty") > 0 then
  296. exports.global:takeAllWeapons(removedPlayer)
  297. exports['anticheat-system']:changeProtectedElementDataEx(removedPlayer, "duty", 0, false)
  298. end
  299. end
  300.  
  301. -- Send message to everyone in the faction
  302. local teamPlayers = getPlayersInTeam(theTeam)
  303. for k, v in ipairs(teamPlayers) do
  304. if (v~=removedPlayer) then
  305. outputChatBox(username .. " kicked " .. removedPlayerName .. " from faction '" .. tostring(theTeamName) .. "'.", v)
  306. end
  307. end
  308. else
  309. outputChatBox("Failed to remove " .. removedPlayerName .. " from the faction, Contact an admin.", source, 255, 0, 0)
  310. end
  311. end
  312. addEvent("cguiKickPlayer", true )
  313. addEventHandler("cguiKickPlayer", getRootElement(), callbackRemovePlayer)
  314.  
  315. function callbackToggleLeader(playerName, isLeader)
  316.  
  317. if (isLeader) then -- Make player a leader
  318. local username = getPlayerName(source)
  319. if mysql:query_free("UPDATE characters SET faction_leader='1' WHERE charactername='" .. mysql:escape_string(playerName) .. "'") then
  320.  
  321. -- Send message to everyone in the faction
  322. local theTeam = getPlayerTeam(source)
  323. local teamPlayers = getPlayersInTeam(theTeam)
  324. for k, v in ipairs(teamPlayers) do
  325. outputChatBox(username .. " promoted " .. playerName .. " to leader.", v)
  326. end
  327.  
  328. local thePlayer = getPlayerFromName(playerName)
  329. if(thePlayer) then -- Player is online, tell them
  330. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionleader", 1, true)
  331. end
  332. else
  333. outputChatBox("Failed to promote " .. removedPlayerName .. " to faction leader, Contact an admin.", source, 255, 0, 0)
  334. end
  335. else
  336. local username = getPlayerName(source)
  337. if mysql:query_free("UPDATE characters SET faction_leader='0' WHERE charactername='" .. mysql:escape_string(playerName) .. "'") then
  338.  
  339. local thePlayer = getPlayerFromName(playerName)
  340. if(thePlayer) then -- Player is online, tell them
  341. if (getElementData(source, "factionMenu")==1) then
  342. triggerClientEvent(thePlayer, "hideFactionMenu", getRootElement())
  343. end
  344. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionleader", 0, true)
  345. end
  346.  
  347. -- Send message to everyone in the faction
  348. local theTeam = getPlayerTeam(source)
  349. local teamPlayers = getPlayersInTeam(theTeam)
  350. for k, v in ipairs(teamPlayers) do
  351. outputChatBox(username .. " demoted " .. playerName .. " to member.", v)
  352. end
  353. else
  354. outputChatBox("Failed to demote " .. removedPlayerName .. " from faction leader, Contact an admin.", source, 255, 0, 0)
  355. end
  356. end
  357. end
  358. addEvent("cguiToggleLeader", true )
  359. addEventHandler("cguiToggleLeader", getRootElement(), callbackToggleLeader)
  360.  
  361. function callbackPromotePlayer(playerName, rankNum, oldRank, newRank)
  362. local username = getPlayerName(source)
  363. if mysql:query_free("UPDATE characters SET faction_rank='" .. rankNum .. "' WHERE charactername='" .. mysql:escape_string(playerName) .. "'") then
  364. local thePlayer = getPlayerFromName(playerName)
  365. if(thePlayer) then -- Player is online, set his rank
  366. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionrank", rankNum)
  367. end
  368.  
  369. -- Send message to everyone in the faction
  370. local theTeam = getPlayerTeam(source)
  371. if (theTeam) then
  372. local teamPlayers = getPlayersInTeam(theTeam)
  373. for k, v in ipairs(teamPlayers) do
  374. outputChatBox(username .. " promoted " .. playerName .. " from '" .. oldRank .. "' to '" .. newRank .. "'.", v)
  375. end
  376. end
  377. else
  378. outputChatBox("Failed to promote " .. removedPlayerName .. " in the faction, Contact an admin.", source, 255, 0, 0)
  379. end
  380. end
  381. addEvent("cguiPromotePlayer", true )
  382. addEventHandler("cguiPromotePlayer", getRootElement(), callbackPromotePlayer)
  383.  
  384. function callbackDemotePlayer(playerName, rankNum, oldRank, newRank)
  385. local username = getPlayerName(source)
  386. local safename = mysql:escape_string(playerName)
  387.  
  388. if mysql:query_free("UPDATE characters SET faction_rank='" .. rankNum .. "' WHERE charactername='" .. safename .. "'") then
  389. local thePlayer = getPlayerFromName(playerName)
  390. if(thePlayer) then -- Player is online, tell them
  391. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "factionrank", rankNum)
  392. end
  393.  
  394. -- Send message to everyone in the faction
  395. local theTeam = getPlayerTeam(source)
  396. if (theTeam) then
  397. local teamPlayers = getPlayersInTeam(theTeam)
  398. for k, v in ipairs(teamPlayers) do
  399. outputChatBox(username .. " demoted " .. playerName .. " from '" .. oldRank .. "' to '" .. newRank .. "'.", v)
  400. end
  401. end
  402. else
  403. outputChatBox("Failed to demote " .. removedPlayerName .. " in the faction, Contact an admin.", source, 255, 0, 0)
  404. end
  405. end
  406. addEvent("cguiDemotePlayer", true )
  407. addEventHandler("cguiDemotePlayer", getRootElement(), callbackDemotePlayer)
  408.  
  409. function callbackQuitFaction()
  410. local username = getPlayerName(source)
  411. local safename = mysql:escape_string(username)
  412. local theTeam = getPlayerTeam(source)
  413. local theTeamName = getTeamName(theTeam)
  414. local factionID = getElementData(source, "faction")
  415. if factionID ==1 or factionID ==2 then
  416. if exports.global:hasItem(source,63+factionID) then
  417. exports.global:takeItem(source,63+factionID)
  418. else
  419. outputChatBox("Return your badge if you want to leave faction.",source,244,244,244)
  420. return
  421. end
  422. end
  423. if mysql:query_free("UPDATE characters SET faction_id='-1', faction_leader='0', dutyskin = -1, duty = 0 WHERE charactername='" .. safename .. "'") then
  424. outputChatBox("You quit the faction '" .. theTeamName .. "'.", source)
  425.  
  426. local newTeam = getTeamFromName("Citizen")
  427. setPlayerTeam(source, newTeam)
  428. exports['anticheat-system']:changeProtectedElementDataEx(source, "faction", -1, false)
  429. exports['anticheat-system']:changeProtectedElementDataEx(source, "dutyskin", -1, false)
  430. if getElementData(source, "duty") and getElementData(source, "duty") > 0 then
  431. exports.global:takeAllWeapons(source)
  432. exports['anticheat-system']:changeProtectedElementDataEx(source, "duty", 0, false)
  433. end
  434.  
  435. -- Send message to everyone in the faction
  436. if theTeam ~= newTeam then
  437. local teamPlayers = getPlayersInTeam(theTeam)
  438. for k, v in ipairs(teamPlayers) do
  439. if (v~=thePlayer) then
  440. outputChatBox(username .. " has quit the faction '" .. theTeamName .. "'.", v)
  441. end
  442. end
  443. end
  444. else
  445. outputChatBox("Failed to quit the faction, Contact an admin.", source, 255, 0, 0)
  446. end
  447. end
  448. addEvent("cguiQuitFaction", true )
  449. addEventHandler("cguiQuitFaction", getRootElement(), callbackQuitFaction)
  450.  
  451. function callbackInvitePlayer(invitedPlayer)
  452. local faction = tonumber(getElementData(source, "faction"))
  453.  
  454. local invitedPlayerNick = getPlayerName(invitedPlayer)
  455. local safename = mysql:escape_string(invitedPlayerNick)
  456.  
  457. if mysql:query_free("UPDATE characters SET faction_leader = 0, faction_id = " .. faction .. ", faction_rank = 1, dutyskin = -1 WHERE charactername='" .. safename .. "'") then
  458. local theTeam = getPlayerTeam(source)
  459. local theTeamName = getTeamName(theTeam)
  460.  
  461. local targetTeam = getPlayerTeam(invitedPlayer)
  462. if (targetTeam~=nil) and (getTeamName(targetTeam)~="Citizen") then
  463. outputChatBox("Player is already in a faction.", source, 255, 0, 0)
  464. else
  465. setPlayerTeam(invitedPlayer, theTeam)
  466. exports['anticheat-system']:changeProtectedElementDataEx(invitedPlayer, "faction", faction)
  467. outputChatBox("Player " .. invitedPlayerNick .. " is now a member of faction '" .. tostring(theTeamName) .. "'.", source, 0, 255, 0)
  468.  
  469. if (invitedPlayer) then
  470. triggerEvent("onPlayerJoinFaction", invitedPlayer, theTeam)
  471. exports['anticheat-system']:changeProtectedElementDataEx(invitedPlayer, "factionrank", 1)
  472. exports['anticheat-system']:changeProtectedElementDataEx(invitedPlayer, "dutyskin", -1, false)
  473. outputChatBox("You were set to Faction '" .. tostring(theTeamName) .. ".", invitedPlayer, 255, 194, 14)
  474. end
  475. end
  476. else
  477. outputChatBox("Player is already in a faction.", source, 255, 0, 0)
  478. end
  479. end
  480. addEvent("cguiInvitePlayer", true )
  481. addEventHandler("cguiInvitePlayer", getRootElement(), callbackInvitePlayer)
  482.  
  483. -- // ADMIN COMMANDS
  484. function createFaction(thePlayer, commandName, factionType, ...)
  485. if (exports.global:isPlayerLeadAdmin(thePlayer)) then
  486. if not (...) then
  487. outputChatBox("SYNTAX: /" .. commandName .. " [Faction Type 0=GANG, 1=MAFIA, 2=LAW, 3=GOV, 4=MED, 5=OTHER, 6=NEWS][Faction Name]", thePlayer, 255, 194, 14)
  488. else
  489. factionName = table.concat({...}, " ")
  490. factionType = tonumber(factionType)
  491.  
  492. local theTeam = createTeam(tostring(factionName))
  493. if theTeam then
  494. if mysql:query_free("INSERT INTO factions SET name='" .. mysql:escape_string(factionName) .. "', bankbalance='0', type='" .. mysql:escape_string(factionType) .. "'") then
  495. local id = mysql:insert_id()
  496. exports.pool:allocateElement(theTeam, id)
  497.  
  498. mysql:query_free("UPDATE factions SET rank_1='Dynamic Rank #1', rank_2='Dynamic Rank #2', rank_3='Dynamic Rank #3', rank_4='Dynamic Rank #4', rank_5='Dynamic Rank #5', rank_6='Dynamic Rank #6', rank_7='Dynamic Rank #7', rank_8='Dynamic Rank #8', rank_9='Dynamic Rank #9', rank_10='Dynamic Rank #10', rank_11='Dynamic Rank #11', rank_12='Dynamic Rank #12', rank_13='Dynamic Rank #13', rank_14='Dynamic Rank #14', rank_15='Dynamic Rank #15', motd='Welcome to the faction.' WHERE id='" .. id .. "'")
  499. outputChatBox("Faction " .. factionName .. " created with ID #" .. id .. ".", thePlayer, 0, 255, 0)
  500. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "type", tonumber(factionType))
  501. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "id", tonumber(id))
  502. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "money", 0)
  503.  
  504. local factionRanks = {}
  505. local factionWages = {}
  506. for i = 1, 15 do
  507. factionRanks[i] = "Dynamic Rank #" .. i
  508. factionWages[i] = 100
  509. end
  510. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "ranks", factionRanks, false)
  511. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "wages", factionWages, false)
  512. exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "motd", "Welcome to the faction.", false)
  513. else
  514. destroyElement(theTeam)
  515. outputChatBox("Error creating faction.", thePlayer, 255, 0, 0)
  516. end
  517. else
  518. outputChatBox("Faction '" .. tostring(factionName) .. "' already exists.", thePlayer, 255, 0, 0)
  519. end
  520. end
  521. end
  522. end
  523. addCommandHandler("makefaction", createFaction, false, false)
  524.  
  525. function adminRenameFaction(thePlayer, commandName, factionID, ...)
  526. if (exports.global:isPlayerAdmin(thePlayer)) then
  527. if not (factionID) or not (...) then
  528. outputChatBox("SYNTAX: /" .. commandName .. " [Faction ID] [Faction Name]", thePlayer, 255, 194, 14)
  529. else
  530. factionID = tonumber(factionID)
  531. if factionID and factionID > 0 then
  532. local theTeam = exports.pool:getElement("team", factionID)
  533. if (theTeam) then
  534. local factionName = table.concat({...}, " ")
  535. mysql:query_free("UPDATE factions SET name='" .. mysql:escape_string(factionName) .. "' WHERE id='" .. factionID .. "'")
  536.  
  537. setTeamName(theTeam, factionName)
  538.  
  539. outputChatBox("Faction #" .. factionID .. " was renamed to " .. factionName .. ".", thePlayer, 0, 255, 0)
  540. else
  541. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  542. end
  543. else
  544. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  545. end
  546. end
  547. end
  548. end
  549. addCommandHandler("renamefaction", adminRenameFaction, false, false)
  550.  
  551. function adminSetPlayerFaction(thePlayer, commandName, partialNick, factionID)
  552. if (exports.global:isPlayerAdmin(thePlayer)) then
  553. factionID = tonumber(factionID)
  554. if not (partialNick) or not (factionID) then
  555. outputChatBox("SYNTAX: /" .. commandName .. " [Player Partial Name/ID] [Faction ID (-1 for none)]", thePlayer, 255, 194, 14)
  556. else
  557. local targetPlayer, targetPlayerNick = exports.global:findPlayerByPartialNick(thePlayer, partialNick)
  558.  
  559. if targetPlayer then
  560. local theTeam = exports.pool:getElement("team", factionID)
  561. if not theTeam then
  562. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  563. return
  564. end
  565.  
  566. if mysql:query_free("UPDATE characters SET faction_leader = 0, faction_id = " .. factionID .. ", faction_rank = 1, duty = 0, dutyskin = -1 WHERE id=" .. getElementData(targetPlayer, "dbid")) then
  567. setPlayerTeam(targetPlayer, theTeam)
  568. if factionID > 0 then
  569. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "faction", factionID)
  570. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "factionrank", 1)
  571. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "dutyskin", -1, false)
  572. if getElementData(targetPlayer, "duty") and getElementData(targetPlayer, "duty") > 0 then
  573. exports.global:takeAllWeapons(targetPlayer)
  574. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "duty", 0, false)
  575. end
  576.  
  577. outputChatBox("Player " .. targetPlayerNick .. " is now a member of faction '" .. getTeamName(theTeam) .. "' (#" .. factionID .. ").", thePlayer, 0, 255, 0)
  578.  
  579. triggerEvent("onPlayerJoinFaction", targetPlayer, theTeam)
  580. outputChatBox("You were set to Faction '" .. getTeamName(theTeam) .. ".", targetPlayer, 255, 194, 14)
  581.  
  582. exports.logs:logMessage("[FACTION] " .. getPlayerName( thePlayer ) .. " set " .. getPlayerName( targetPlayer ) .. " to faction " .. getTeamName(theTeam) .. " (#" .. factionID .. ")", 15)
  583. else
  584. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "faction", -1)
  585. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "factionrank", 1)
  586. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "dutyskin", -1, false)
  587. if getElementData(targetPlayer, "duty") and getElementData(targetPlayer, "duty") > 0 then
  588. exports.global:takeAllWeapons(targetPlayer)
  589. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "duty", 0, false)
  590. end
  591.  
  592. outputChatBox("Player " .. targetPlayerNick .. " was set to no faction.", thePlayer, 0, 255, 0)
  593. outputChatBox("You were removed from your faction.", targetPlayer, 255, 0, 0)
  594.  
  595. exports.logs:logMessage("[FACTION] " .. getPlayerName( thePlayer ) .. " set " .. getPlayerName( targetPlayer ) .. " to no faction", 15)
  596. end
  597. end
  598. end
  599. end
  600. end
  601. end
  602. addCommandHandler("setfaction", adminSetPlayerFaction, false, false)
  603.  
  604. function adminSetFactionLeader(thePlayer, commandName, partialNick, factionID)
  605. if (exports.global:isPlayerLeadAdmin(thePlayer)) then
  606. factionID = tonumber(factionID)
  607. if not (partialNick) or not (factionID) then
  608. outputChatBox("SYNTAX: /" .. commandName .. " [Player Partial Name] [Faction ID]", thePlayer, 255, 194, 14)
  609. elseif factionID > 0 then
  610. local targetPlayer, targetPlayerNick = exports.global:findPlayerByPartialNick(thePlayer, partialNick)
  611.  
  612. if targetPlayer then
  613. local theTeam = exports.pool:getElement("team", factionID)
  614. if not theTeam then
  615. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  616. return
  617. end
  618.  
  619. if mysql:query_free("UPDATE characters SET faction_leader = 1, faction_id = " .. tonumber(factionID) .. ", faction_rank = 1, dutyskin = -1, duty = 0 WHERE id = " .. getElementData(targetPlayer, "dbid")) then
  620. setPlayerTeam(targetPlayer, theTeam)
  621. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "faction", factionID, false)
  622. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "factionrank", 1)
  623. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "dutyskin", -1, false)
  624. if getElementData(targetPlayer, "duty") and getElementData(targetPlayer, "duty") > 0 then
  625. exports.global:takeAllWeapons(targetPlayer)
  626. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "duty", 0, false)
  627. end
  628.  
  629. outputChatBox("Player " .. targetPlayerNick .. " is now a leader of faction '" .. getTeamName(theTeam) .. "' (#" .. factionID .. ").", thePlayer, 0, 255, 0)
  630.  
  631. triggerEvent("onPlayerJoinFaction", targetPlayer, theTeam)
  632. outputChatBox("You were set to the leader of Faction '" .. getTeamName(theTeam) .. ".", targetPlayer, 255, 194, 14)
  633.  
  634. exports.logs:logMessage("[FACTIONLEADER] " .. getPlayerName( thePlayer ) .. " set " .. getPlayerName( targetPlayer ) .. " to factionleader of " .. getTeamName(theTeam) .. " (#" .. factionID .. ")", 15)
  635. else
  636. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  637. end
  638. end
  639. end
  640. end
  641. end
  642. addCommandHandler("setfactionleader", adminSetFactionLeader, false, false)
  643.  
  644. function adminSetFactionRank(thePlayer, commandName, partialNick, factionRank)
  645. if (exports.global:isPlayerLeadAdmin(thePlayer)) then
  646. factionRank = math.ceil(tonumber(factionRank) or -1)
  647. if not (partialNick) or not (factionRank) then
  648. outputChatBox("SYNTAX: /" .. commandName .. " [Player Partial Name] [Faction Rank, 1-15]", thePlayer, 255, 194, 14)
  649. elseif factionRank >= 1 and factionRank <= 15 then
  650. local targetPlayer, targetPlayerNick = exports.global:findPlayerByPartialNick(thePlayer, partialNick)
  651.  
  652. if targetPlayer then
  653. local theTeam = getPlayerTeam(targetPlayer)
  654. if not theTeam or getTeamName( theTeam ) == "Citizen" then
  655. outputChatBox("Player is not in a faction.", thePlayer, 255, 0, 0)
  656. return
  657. end
  658.  
  659. if mysql:query_free("UPDATE characters SET faction_rank = " .. factionRank .. " WHERE id = " .. getElementData(targetPlayer, "dbid")) then
  660. exports['anticheat-system']:changeProtectedElementDataEx(targetPlayer, "factionrank", factionRank)
  661.  
  662. outputChatBox("Player " .. targetPlayerNick .. " is now on rank " .. factionRank .. ".", thePlayer, 0, 255, 0)
  663.  
  664. exports.logs:logMessage("[FACTIONRANK] " .. getPlayerName( thePlayer ) .. " set " .. getPlayerName( targetPlayer ) .. " to rank " .. factionRank, 15)
  665. else
  666. outputChatBox("Error #125151 - Report on Mantis.", thePlayer, 255, 0, 0)
  667. end
  668. end
  669. else
  670. outputChatBox( "Invalid Rank - valid ones are 1 to 15", thePlayer, 255, 0, 0 )
  671. end
  672. end
  673. end
  674. addCommandHandler("setfactionrank", adminSetFactionRank, false, false)
  675.  
  676. function adminDeleteFaction(thePlayer, commandName, factionID)
  677. if (exports.global:isPlayerHeadAdmin(thePlayer)) then
  678. if not (factionID) then
  679. outputChatBox("SYNTAX: /" .. commandName .. " [Faction ID]", thePlayer, 255, 194, 14)
  680. else
  681. factionID = tonumber(factionID)
  682. if factionID and factionID > 0 then
  683. local theTeam = exports.pool:getElement("team", factionID)
  684.  
  685. if (theTeam) then
  686. if factionID == 57 then
  687. outputChatBox("So you did it! HA! Logged. Now stop deleting factions needed for the script. -Mount", thePlayer, 255, 0, 0)
  688. exports.logs:logMessage("[BANKFACTION] " .. getPlayerName( thePlayer ) .. " tried to delete faction " .. getTeamName(theTeam) .. " (#" .. factionID .. ")", 15)
  689. else
  690. mysql:query_free("DELETE FROM factions WHERE id='" .. factionID .. "'")
  691.  
  692. outputChatBox("Faction #" .. factionID .. " was deleted.", thePlayer, 0, 255, 0)
  693. exports.logs:logMessage("[FACTION] " .. getPlayerName( thePlayer ) .. " deleted faction " .. getTeamName(theTeam) .. " (#" .. factionID .. ")", 15)
  694. local civTeam = getTeamFromName("Citizen")
  695. for key, value in pairs( getPlayersInTeam( theTeam ) ) do
  696. setPlayerTeam( value, civTeam )
  697. exports['anticheat-system']:changeProtectedElementDataEx( value, "faction", -1 )
  698. end
  699. destroyElement( theTeam )
  700. end
  701. else
  702. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  703. end
  704. else
  705. outputChatBox("Invalid Faction ID.", thePlayer, 255, 0, 0)
  706. end
  707. end
  708. end
  709. end
  710. addCommandHandler("delfaction", adminDeleteFaction, false, false)
  711.  
  712.  
  713. joboppur = createMarker (1469.392578125, -1768.2529296875, 17.795755386353, "cylinder", 1.8, 255, 0, 250, 250)
  714. function adminShowFactions(thePlayer)
  715. --if (exports.global:isPlayerAdmin(thePlayer)) then
  716. local result = mysql:query("SELECT id, name, type, (SELECT COUNT(*) FROM characters c WHERE c.faction_id = f.id) AS members FROM factions f ORDER BY id ASC")
  717.  
  718.  
  719.  
  720. if result then
  721. local factions = { }
  722.  
  723. while true do
  724. local row = mysql:fetch_assoc(result)
  725. if not row then break end
  726.  
  727. table.insert( factions, { row.id, row.name, row.type, ( getTeamFromName( row.name ) and #getPlayersInTeam( getTeamFromName( row.name ) ) or "?" ) .. " / " .. row.members } )
  728. end
  729.  
  730. mysql:free_result(result)
  731. triggerClientEvent(thePlayer, "showFactionList", getRootElement(), factions)
  732. showCursor(thePlayer,true)
  733. outputChatBox("San Andreas Job Opportunity.", thePlayer, 255, 255, 0)
  734. else
  735. outputChatBox("Error 300001 - Report on forums.", thePlayer, 255, 0, 0)
  736. end
  737. --end
  738. end
  739. addCommandHandler("showfactions", adminShowFactions, false, false)
  740. addEventHandler( "onMarkerHit",joboppur,adminShowFactions)
  741.  
  742.  
  743. function setFactionMoney(thePlayer, commandName, factionID, amount)
  744. if (exports.global:isPlayerHeadAdmin(thePlayer)) then
  745. if not (factionID) or not (amount) then
  746. outputChatBox("SYNTAX: /" .. commandName .. " [Faction ID] [Money]", thePlayer, 255, 194, 14)
  747. else
  748. factionID = tonumber(factionID)
  749. if factionID and factionID > 0 then
  750. local theTeam = exports.pool:getElement("team", factionID)
  751. amount = tonumber(amount)
  752.  
  753. if (theTeam) then
  754. exports.global:setMoney(theTeam, amount)
  755. outputChatBox("Set faction '" .. getTeamName(theTeam) .. "'s money to " .. amount .. " $.", thePlayer, 255, 194, 14)
  756. else
  757. outputChatBox("Invalid faction ID.", thePlayer, 255, 194, 14)
  758. end
  759. else
  760. outputChatBox("Invalid faction ID.", thePlayer, 255, 194, 14)
  761. end
  762. end
  763. end
  764. end
  765. addCommandHandler("setfactionmoney", setFactionMoney, false, false)
  766.  
  767. function setFactionBudget(thePlayer, commandName, factionID, amount)
  768. if getPlayerTeam(thePlayer) == getTeamFromName("Government of Los Santos") and getElementData(thePlayer, "factionrank") >= 10 then
  769. local amount = tonumber( amount )
  770. if not factionID or not amount or amount < 0 then
  771. outputChatBox("SYNTAX: /" .. commandName .. " [Faction ID] [Money]", thePlayer, 255, 194, 14)
  772. else
  773. factionID = tonumber(factionID)
  774. if factionID and factionID > 0 then
  775. local theTeam = exports.pool:getElement("team", factionID)
  776. amount = tonumber(amount)
  777.  
  778. if (theTeam) then
  779. if getElementData(theTeam, "type") >= 2 and getElementData(theTeam, "type") <= 6 then
  780. if exports.global:takeMoney(getPlayerTeam(thePlayer), amount) then
  781. exports.global:giveMoney(theTeam, amount)
  782. outputChatBox("You added $" .. amount .. " to the budget of '" .. getTeamName(theTeam) .. "' (Total: " .. exports.global:getMoney(theTeam) .. ").", thePlayer, 255, 194, 14)
  783. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. -getElementData(getPlayerTeam(thePlayer), "id") .. ", " .. -getElementData(theTeam, "id") .. ", " .. amount .. ", '', 8)" )
  784. else
  785. outputChatBox("You can't afford this.", thePlayer, 255, 194, 14)
  786. end
  787. else
  788. outputChatBox("You can't set a budget for that faction.", thePlayer, 255, 194, 14)
  789. end
  790. else
  791. outputChatBox("Invalid faction ID.", thePlayer, 255, 194, 14)
  792. end
  793. else
  794. outputChatBox("Invalid faction ID.", thePlayer, 255, 194, 14)
  795. end
  796. end
  797. end
  798. end
  799. addCommandHandler("setbudget", setFactionBudget, false, false)
  800.  
  801. function setTax(thePlayer, commandName, amount)
  802. if getPlayerTeam(thePlayer) == getTeamFromName("Government of Los Santos") and getElementData(thePlayer, "factionrank") >= 10 then
  803. local amount = tonumber( amount )
  804. if not amount or amount < 0 or amount > 30 then
  805. outputChatBox("SYNTAX: /" .. commandName .. " [0-30%]", thePlayer, 255, 194, 14)
  806. else
  807. exports.global:setTaxAmount(amount)
  808. outputChatBox("New Tax is " .. amount .. "%", thePlayer, 0, 255, 0)
  809. end
  810. end
  811. end
  812. addCommandHandler("settax", setTax, false, false)
  813.  
  814. function setIncomeTax(thePlayer, commandName, amount)
  815. if getPlayerTeam(thePlayer) == getTeamFromName("Government of Los Santos") and getElementData(thePlayer, "factionrank") >= 10 then
  816. local amount = tonumber( amount )
  817. if not amount or amount < 0 or amount > 25 then
  818. outputChatBox("SYNTAX: /" .. commandName .. " [0-25%]", thePlayer, 255, 194, 14)
  819. else
  820. exports.global:setIncomeTaxAmount(amount)
  821. outputChatBox("New Income Tax is " .. amount .. "%", thePlayer, 0, 255, 0)
  822. end
  823. end
  824. end
  825. addCommandHandler("setincometax", setIncomeTax, false, false)
  826.  
  827. function setWelfare(thePlayer, commandName, amount)
  828. if getPlayerTeam(thePlayer) == getTeamFromName("Government of Los Santos") and getElementData(thePlayer, "factionrank") >= 10 then
  829. local amount = tonumber( amount )
  830. if not amount or amount <= 0 then
  831. outputChatBox("SYNTAX: /" .. commandName .. " [Money]", thePlayer, 255, 194, 14)
  832. elseif mysql:query_free( "UPDATE settings SET value = " .. unemployedPay .. " WHERE name = 'welfare'" ) then
  833. unemployedPay = amount
  834. outputChatBox("New Welfare is $" .. unemployedPay .. "/payday", thePlayer, 0, 255, 0)
  835. else
  836. outputChatBox("Error 129314 - Report on Mantis.", thePlayer, 255, 0, 0)
  837. end
  838. end
  839. end
  840. addCommandHandler("setwelfare", setWelfare, false, false)
  841.  
  842. function getTax(thePlayer)
  843. outputChatBox( "Welfare: $" .. unemployedPay, thePlayer, 255, 194, 14 )
  844. outputChatBox( "Tax: " .. ( exports.global:getTaxAmount(thePlayer) * 100 ) .. "%", thePlayer, 255, 194, 14 )
  845. outputChatBox( "Income Tax: " .. ( exports.global:getIncomeTaxAmount(thePlayer) * 100 ) .. "%", thePlayer, 255, 194, 14 )
  846. end
  847. addCommandHandler("gettax", getTax, false, false)
  848.  
  849. -- /////////////// WAGES
  850. local governmentIncome = 0
  851.  
  852. local rentVehicles = {}
  853. local taxVehicles = {}
  854. local vehicleCount = {}
  855. local taxHouses = {}
  856.  
  857. local rc = 10
  858. local bike = 15
  859. local low = 25
  860. local offroad = 35
  861. local sport = 100
  862. local van = 50
  863. local bus = 75
  864. local truck = 200
  865. local boat = 300 -- except dinghy
  866. local heli = 500
  867. local plane = 750
  868. local race = 75
  869. local vehicleTaxes = {
  870. offroad, low, sport, truck, low, low, 1000, truck, truck, 200, -- dumper, stretch
  871. low, sport, low, van, van, sport, truck, heli, van, low,
  872. low, low, low, van, low, 1000, low, truck, van, sport, -- hunter
  873. boat, bus, 1000, truck, offroad, van, low, bus, low, low, -- rhino
  874. van, rc, low, truck, 500, low, boat, heli, bike, 0, -- monster, tram
  875. van, sport, boat, boat, boat, truck, van, 10, low, van, -- caddie
  876. plane, bike, bike, bike, rc, rc, low, low, bike, heli,
  877. van, bike, boat, 20, low, low, plane, sport, low, low, -- dinghy
  878. sport, bike, van, van, boat, 10, 75, heli, heli, offroad, -- baggage, dozer
  879. offroad, low, low, boat, low, offroad, low, heli, van, van,
  880. low, rc, low, low, low, offroad, sport, low, van, bike,
  881. bike, plane, plane, plane, truck, truck, low, low, low, plane,
  882. plane * 10, bike, bike, bike, truck, van, low, low, truck, low, -- hydra
  883. 10, 20, offroad, low, low, low, low, 0, 0, offroad, -- forklift, tractor, 2x train
  884. low, sport, low, van, truck, low, low, low, rc, low,
  885. low, low, van, plane, van, low, 500, 500, race, race, -- 2x monster
  886. race, low, race, heli, rc, low, low, low, offroad, 0, -- train trailer
  887. 0, 10, 10, offroad, 15, low, low, 3*plane, truck, low,-- train trailer, kart, mower, sweeper, at400
  888. low, bike, van, low, van, low, bike, race, van, low,
  889. 0, van, 2*plane, plane, rc, boat, low, low, low, offroad, -- train trailer, andromeda
  890. low, truck, race, sport, low, low, low, low, low, van,
  891. low, low
  892. }
  893. function payWage(player, pay, faction, tax)
  894. local governmentIncome = 0
  895. local bankmoney = getElementData(player, "bankmoney")
  896. local interestrate = 0.004
  897. local noWage = pay == 0
  898.  
  899. -- DONATOR PERKS
  900. local donator = getElementData(player, "donatorlevel")
  901. local donatormoney = 0
  902. if (donator==1) then
  903. donatormoney = donatormoney + 25
  904. interestrate = interestrate + 0.001
  905. elseif (donator==2) then
  906. donatormoney = donatormoney + 50
  907. interestrate = interestrate + 0.002
  908. elseif (donator==3) then
  909. donatormoney = donatormoney + 75
  910. interestrate = interestrate + 0.003
  911. elseif (donator==4) then
  912. donatormoney = donatormoney + 100
  913. interestrate = interestrate + 0.004
  914. elseif (donator==5) then
  915. donatormoney = donatormoney + 125
  916. interestrate = interestrate + 0.005
  917. elseif (donator==6) then
  918. donatormoney = donatormoney + 150
  919. interestrate = interestrate + 0.006
  920. elseif (donator==7) then
  921. donatormoney = donatormoney + 250
  922. interestrate = interestrate + 0.006
  923. end
  924.  
  925. local interest = math.ceil(interestrate * bankmoney)
  926. local capped = false
  927. if (interest > 99999) then
  928. capped = true
  929. interest = 100000
  930. end
  931.  
  932. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (-57, " .. getElementData(player, "dbid") .. ", " .. interest .. ", 'BANKINTEREST', 6)" )
  933.  
  934. local incomeTax = exports.global:getIncomeTaxAmount()
  935.  
  936. -- business money
  937. local profit = getElementData(player, "businessprofit")
  938. exports['anticheat-system']:changeProtectedElementDataEx(player, "businessprofit", 0, false)
  939. bankmoney = bankmoney + math.max( 0, pay ) + interest + profit + donatormoney
  940.  
  941.  
  942. -- rentable houses
  943. local rent = 0
  944. local rented = nil -- store id in here
  945. local dbid = tonumber(getElementData(player, "dbid"))
  946. for key, value in ipairs(getElementsByType("pickup", getResourceRootElement(getResourceFromName("interior-system")))) do
  947. local owner = tonumber(getElementData(value, "owner"))
  948. if (owner) and (owner == dbid) and (getElementData(value, "name")) and (tonumber(getElementData(value, "inttype")) == 3) and (tonumber(getElementData(value, "cost")) > 0) then
  949. rent = rent + tonumber(getElementData(value, "cost"))
  950. rented = tonumber(getElementData(value, "dbid"))
  951. end
  952. end
  953.  
  954. if not faction then
  955. if pay >= 0 then
  956. governmentIncome = governmentIncome - pay
  957. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (-3, " .. getElementData(player, "dbid") .. ", " .. pay .. ", 'STATEBENEFITS', 6)" )
  958. else
  959. pay = 0
  960. end
  961. else
  962. if pay >= 0 then
  963. local teamid = getElementData(player, "faction")
  964. if teamid <= 0 then
  965. teamid = 0
  966. else
  967. teamid = -teamid
  968. end
  969. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. teamid .. ", " .. getElementData(player, "dbid") .. ", " .. pay .. ", 'WAGE', 6)" )
  970. else
  971. pay = 0
  972. end
  973. end
  974.  
  975. if tax > 0 then
  976. pay = pay - tax
  977. bankmoney = bankmoney - tax
  978. governmentIncome = governmentIncome + tax
  979. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. getElementData(player, "dbid") .. ", -3, " .. tax .. ", 'INCOMETAX', 6)" )
  980. end
  981.  
  982. local vtax = taxVehicles[ getElementData(player, "dbid") ] or 0
  983. if vtax > 0 then
  984. vtax = math.min( vtax, bankmoney )
  985. bankmoney = bankmoney - vtax
  986.  
  987. if vtax > pay+profit+interest+donatormoney then
  988. exports.global:givePlayerAchievement(player, 19)
  989. end
  990.  
  991. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. getElementData(player, "dbid") .. ", -3, " .. vtax .. ", 'VEHICLETAX', 6)" )
  992.  
  993.  
  994. governmentIncome = governmentIncome + vtax
  995. end
  996.  
  997. local renttax = rentVehicles[ getElementData(player, "dbid") ] or 0
  998. if renttax > 0 then
  999. renttax = math.min( renttax, bankmoney )
  1000. bankmoney = bankmoney - renttax
  1001.  
  1002. if renttax > pay+profit+interest+donatormoney then
  1003. exports.global:givePlayerAchievement(player, 19)
  1004. end
  1005.  
  1006. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. getElementData(player, "dbid") .. ", -3, " .. renttax .. ", 'VEHICLERENT', 6)" )
  1007.  
  1008.  
  1009. governmentIncome = governmentIncome + renttax
  1010. end
  1011. local ptax = taxHouses[ getElementData(player, "dbid") ] or 0
  1012. if ptax > 0 then
  1013. ptax = math.floor( ptax * 0.6 )
  1014. ptax = math.min( ptax, bankmoney )
  1015. bankmoney = bankmoney - ptax
  1016. governmentIncome = governmentIncome + ptax
  1017. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. getElementData(player, "dbid") .. ", -3, " .. ptax .. ", 'PROPERTYTAX', 6)" )
  1018. end
  1019.  
  1020. if (rent > 0) then
  1021. if (rent > bankmoney) then
  1022. rent = -1
  1023. call( getResourceFromName( "interior-system" ), "publicSellProperty", player, rented, false, true )
  1024. else
  1025. exports.global:givePlayerAchievement(player, 11)
  1026. bankmoney = bankmoney - rent
  1027.  
  1028. -- gov shouldnt get anything of this
  1029. --governmentIncome = governmentIncome + rent
  1030. mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. getElementData(player, "dbid") .. ", 0, " .. rent .. ", 'HOUSERENT', 6)" )
  1031. end
  1032. end
  1033.  
  1034. -- save the bankmoney
  1035. exports['anticheat-system']:changeProtectedElementDataEx(player, "bankmoney", bankmoney)
  1036.  
  1037. local grossincome = pay+profit+interest+donatormoney-rent-vtax-ptax-renttax
  1038.  
  1039. -- let the client tell them the (bad) news
  1040. triggerClientEvent(player, "cPayDay", player, faction, noWage and -1 or pay, profit, interest, donatormoney, tax, incomeTax, vtax, ptax, rent, grossincome,renttax)
  1041. return governmentIncome
  1042. end
  1043.  
  1044. function payAllWages(timer)
  1045. if timer then
  1046. local mins = getRealTime().minute
  1047. local minutes = 60 - mins
  1048. if (minutes < 15) then
  1049. minutes = minutes + 60
  1050. end
  1051. setTimer(payAllWages, 60000*minutes, 1, true)
  1052. end
  1053.  
  1054. -- collect all vehicle info
  1055. taxVehicles = {}
  1056. rentVehicles = {}
  1057. vehicleCount = {}
  1058. for _, veh in pairs(getElementsByType("vehicle")) do
  1059. if isElement(veh) then
  1060. local owner, faction = tonumber(getElementData(veh, "owner")) or 0, tonumber(getElementData(veh, "faction")) or 0
  1061. local rent, rentcost = tonumber(getElementData(veh, "rent")) or 0, tonumber(getElementData(veh, "rentcost")) or 0
  1062. if rent==1 then
  1063. rentVehicles[owner] = ( rentVehicles[owner] or 0 ) + rentcost
  1064. elseif faction < 0 and owner > 0 then -- non-faction vehicles
  1065. taxVehicles[owner] = ( taxVehicles[owner] or 0 ) + ( vehicleTaxes[getElementModel(veh)-399] or 25 )
  1066. vehicleCount[owner] = ( vehicleCount[owner] or 0 ) + 1
  1067. if vehicleCount[owner] > 3 then -- $50 for having too much vehicles, per vehicle more than 3
  1068. taxVehicles[owner] = taxVehicles[owner] + 50
  1069. end
  1070. end
  1071. end
  1072. end
  1073.  
  1074. -- count all player props
  1075. taxHouses = { }
  1076. for _, property in pairs( getElementsByType( "pickup", getResourceRootElement( getResourceFromName( "interior-system" ) ) ) ) do
  1077. if getElementData( property, "cost" ) and getElementData( property, "owner" ) > 0 and getElementData( property, "inttype" ) < 2 then -- owned, not rented houses
  1078. taxHouses[ getElementData( property, "owner" ) ] = ( taxHouses[ getElementData( property, "owner" ) ] or 0 ) + 0.005 * getElementData( property, "cost" )
  1079. end
  1080. end
  1081.  
  1082. local players = exports.pool:getPoolElementsByType("player")
  1083.  
  1084. local govAmount = exports.global:getMoney(getTeamFromName("Government of Los Santos"))
  1085.  
  1086. for key, value in ipairs(players) do
  1087. local logged = getElementData(value, "loggedin")
  1088. local timeinserver = getElementData(value, "timeinserver")
  1089.  
  1090. -- Pay Check tooltip
  1091. if(getResourceFromName("tooltips-system"))then
  1092. triggerClientEvent(value,"tooltips:showHelp", getRootElement(),12)
  1093. end
  1094.  
  1095. if (logged==1) and (timeinserver>=60) then
  1096. mysql:query_free( "UPDATE characters SET jobcontract = jobcontract - 1 WHERE id = " .. getElementData( value, "dbid" ) .. " AND jobcontract > 0" )
  1097. if getElementData(value, "license.car") and getElementData(value, "license.car") < 0 then
  1098. exports['anticheat-system']:changeProtectedElementDataEx(value, "license.car", getElementData(value, "license.car") + 1)
  1099. mysql:query_free( "UPDATE characters SET car_license = car_license + 1 WHERE id = " .. getElementData( value, "dbid" ) )
  1100. end
  1101. if getElementData(value, "license.gun") and getElementData(value, "license.gun") < 0 then
  1102. exports['anticheat-system']:changeProtectedElementDataEx(value, "license.gun", getElementData(value, "license.gun") + 1)
  1103. mysql:query_free( "UPDATE characters SET gun_license = gun_license + 1 WHERE id = " .. getElementData( value, "dbid" ) )
  1104. end
  1105. local playerFaction = getElementData(value, "faction")
  1106. if (playerFaction~=-1) then -- In a faction
  1107. local theTeam = getPlayerTeam(value)
  1108. local factionType = getElementData(theTeam, "type")
  1109.  
  1110. if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then -- Factions with wages
  1111. local username = getPlayerName(value)
  1112.  
  1113. local factionRank = getElementData(value, "factionrank")
  1114. local rankWageresult = mysql:query_fetch_assoc("SELECT wage_" .. factionRank .. " FROM factions WHERE id='" .. playerFaction .. "'")
  1115. local rankWage = tonumber( rankWageresult['wage_' .. factionRank] )
  1116.  
  1117. local taxes = 0
  1118. if not exports.global:takeMoney(theTeam, rankWage) then
  1119. rankWage = -1
  1120. else
  1121. local incomeTax = exports.global:getIncomeTaxAmount()
  1122. taxes = math.ceil( incomeTax * rankWage )
  1123. end
  1124.  
  1125. govAmount = govAmount + payWage( value, rankWage, true, taxes )
  1126. else
  1127. if unemployedPay >= govAmount then
  1128. unemployedPay = -1
  1129. end
  1130.  
  1131. govAmount = govAmount + payWage( value, unemployedPay, false, 0 )
  1132. end
  1133. else
  1134. if unemployedPay >= govAmount then
  1135. unemployedPay = -1
  1136. end
  1137.  
  1138. govAmount = govAmount + payWage( value, unemployedPay, false, 0 )
  1139. end
  1140.  
  1141. exports['anticheat-system']:changeProtectedElementDataEx(value, "timeinserver", timeinserver-60, false)
  1142.  
  1143. local hoursplayed = getElementData(value, "hoursplayed") or 0
  1144. exports['anticheat-system']:changeProtectedElementDataEx(value, "hoursplayed", hoursplayed+1, false)
  1145. mysql:query_free( "UPDATE characters SET hoursplayed = hoursplayed + 1, bankmoney = " .. getElementData( value, "bankmoney" ) .. " WHERE id = " .. getElementData( value, "dbid" ) )
  1146. elseif (logged==1) and (timeinserver) and (timeinserver<60) then
  1147. outputChatBox("You have not played long enough to recieve a payday. (You require another " .. 60-timeinserver .. " Minutes of play.)", value, 255, 0, 0)
  1148. end
  1149. end
  1150.  
  1151. -- Store the government money
  1152. exports.global:setMoney(getTeamFromName("Government of Los Santos"), govAmount)
  1153. end
  1154.  
  1155.  
  1156. function adminDoPayday(thePlayer)
  1157. local logged = getElementData(thePlayer, "loggedin")
  1158.  
  1159. if (logged==1) then
  1160. if (exports.global:isPlayerLeadAdmin(thePlayer)) then
  1161. payAllWages(false)
  1162. end
  1163. end
  1164. end
  1165. addCommandHandler("dopayday", adminDoPayday)
  1166.  
  1167. function timeSaved(thePlayer)
  1168. local logged = getElementData(thePlayer, "loggedin")
  1169.  
  1170. if (logged==1) then
  1171. local timeinserver = getElementData(thePlayer, "timeinserver")
  1172.  
  1173. if (timeinserver>60) then
  1174. timeinserver = 60
  1175. end
  1176.  
  1177. outputChatBox("You currently have " .. timeinserver .. " Minutes played.", thePlayer, 255, 195, 14)
  1178. outputChatBox("You require another " .. 60-timeinserver .. " Minutes to obtain a payday.", thePlayer, 255, 195, 14)
  1179. end
  1180. end
  1181. addCommandHandler("timesaved", timeSaved)
  1182.  
  1183. function hideFactionMenu()
  1184. exports['anticheat-system']:changeProtectedElementDataEx(source, "factionMenu", 0, true)
  1185. end
  1186. addEvent("factionmenu:hide", true)
  1187. addEventHandler("factionmenu:hide", getRootElement(), hideFactionMenu)
Advertisement
Add Comment
Please, Sign In to add comment