So i have insurance script, if u are customer every payday u need to pay about insurance, insurance works fine, but it doesnt take money from player when its payday.
Insurance:
local function formatVehIds(table)
local ids = ""
for i, vehid in pairs(table) do
ids = ids..ids..", "
end
return string.sub(ids, 1, string.len(ids)) -- remove 2 last characters from string ", "
end
function analyzeInsurance(data, playerId) -- edit in payday resource to pass playerId here too
local totalFee = 0
local totalFeePerVehicles = {}
local totalFeePerFactions = {}
if data then
for vehid, insurance in pairs(data) do
for iFaction, fee in pairs(insurance) do
if not totalFeePerVehicles[vehid] then totalFeePerVehicles[vehid] = {} end
if not totalFeePerVehicles[vehid]['ifaction'] then totalFeePerVehicles[vehid]['ifaction'] = iFaction end
if not totalFeePerVehicles[vehid]['fee'] then totalFeePerVehicles[vehid]['fee'] = 0 end
totalFeePerVehicles[vehid]['fee'] = totalFeePerVehicles[vehid]['fee'] + fee
if not datatable[vehid]['cashout'] then
datatable[vehid]['cashout'] = 0
end
datatable[vehid]['cashout'] = datatable[vehid]['cashout'] + fee
if not totalFeePerFactions[iFaction] then totalFeePerFactions[iFaction] = {} end
if not totalFeePerFactions[iFaction]['fee'] then totalFeePerFactions[iFaction]['fee'] = 0 end
if not totalFeePerFactions[iFaction]['vehs'] then totalFeePerFactions[iFaction]['vehs'] = {} end
totalFeePerFactions[iFaction]['fee'] = totalFeePerFactions[iFaction]['fee'] + fee
table.insert(totalFeePerFactions[iFaction]['vehs'], vehid)
totalFee = totalFee + fee
end
end
end
for factionId, data in pairs(totalFeePerFactions) do
local theInsurer = exports.pool:getElement("team", factionId)
if exports.bank:giveBankMoney(theInsurer, data.fee) then
exports.bank:addBankTransactionLog(playerId, -getElementData(theInsurer, "id") , data.fee, 2, "Insurance fee for vehicles with VINS: "..formatVehIds(data.vehs) )
end
end
return totalFee, totalFeePerVehicles, totalFeePerFactions
end
Payday:
local mysql = exports.mysql local incomeTax = 0 local taxVehicles = {} local insuranceVehicles = {} local vehicleCount = {} local taxHouses = {} local threads = { } local threadTimer = nil local govAmount = 10000000 local unemployedPay = 200 function payWage(player, pay, faction, tax) local dbid = tonumber(getElementData(player, "dbid")) local governmentIncome = 0 local bankmoney = getElementData(player, "bankmoney") local noWage = pay == 0 local donatormoney = 0 local startmoney = bankmoney if (exports.donators:hasPlayerPerk(player, 4)) then donatormoney = donatormoney + 25 end if (exports.donators:hasPlayerPerk(player, 5)) then donatormoney = donatormoney + 75 end local interest = 0 local cP = 0 if bankmoney > 0 then interest = math.min(5000, math.floor(3 * math.sqrt(bankmoney))) cP = interest / bankmoney * 100 end if interest ~= 0 then mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (-57, " .. dbid .. ", " .. interest .. ", 'BANKINTEREST', 6)" ) end -- business money local profit = getElementData(player, "businessprofit") exports.anticheat:changeProtectedElementDataEx(player, "businessprofit", 0, false) bankmoney = bankmoney + math.max( 0, pay ) + interest + profit + donatormoney -- rentable houses local rent = 0 local rented = nil -- store id in here for key, value in ipairs(getElementsByType("interior")) do -- Who the hell made this bullsit lol / MAXIME local interiorStatus = getElementData(value, "status") local owner = tonumber( interiorStatus[4] ) if (owner) and (owner == dbid) and (getElementData(value, "status")) and (tonumber(interiorStatus[1]) == 3) and (tonumber(interiorStatus[5]) > 0) then rent = rent + tonumber(interiorStatus[5]) rented = tonumber(getElementData(value, "dbid")) end end if not faction then if bankmoney > 25000 then noWage = true pay = 0 elseif pay > 0 then governmentIncome = governmentIncome - pay mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (-3, " .. dbid .. ", " .. pay .. ", 'STATEBENEFITS', 6)" ) else pay = 0 end else if pay > 0 then local teamid = getElementData(player, "faction") if teamid <= 0 then teamid = 0 else teamid = -teamid end mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. teamid .. ", " .. dbid .. ", " .. pay .. ", 'WAGE', 6)" ) else pay = 0 end end if tax > 0 then pay = pay - tax bankmoney = bankmoney - tax governmentIncome = governmentIncome + tax mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. dbid .. ", -3, " .. tax .. ", 'INCOMETAX', 6)" ) end local vtax = taxVehicles[ dbid ] or 0 if vtax > 0 then vtax = math.min( vtax, bankmoney ) bankmoney = bankmoney - vtax governmentIncome = governmentIncome + vtax mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. dbid .. ", -3, " .. vtax .. ", 'VEHICLETAX', 6)" ) end --vehicle insurance local totalInsFee, totalInsFeePerVehicles, totalInsFeePerFactions = 0, {}, {} if exports.global:isResourceRunning("insurance") and exports.global:isResourceRunning("factions") then --outputDebugString("Payday insurance running") totalInsFee, totalInsFeePerVehicles, totalInsFeePerFactions = exports.insurance:analyzeInsurance(insuranceVehicles[ dbid ], getElementData(player, "dbid")) if totalInsFee > 0 then if bankmoney >= totalInsFee then bankmoney = bankmoney - totalInsFee for factionId, data in pairs(totalInsFeePerFactions) do if data.fee > 0 then local theFaction = exports.factions:getTeamFromFactionID(factionId) if exports.bank:giveBankMoney(theFaction, data.fee) then exports.bank:addBankTransactionLog(dbid, -factionId, data.fee, 2, "Insurance fees for "..(#(data.vehs)).." vehicles.") end end end else if exports.global:isResourceRunning("announcement") then local customerName = getPlayerName(player):gsub("_", " ") for factionId, data in pairs(totalInsFeePerFactions) do local details = 'List of insuranced vehicles from customer '..customerName..":\n\n" for i, vehid in pairs(data.vehs) do details = details..'Vehicle VIN #'..vehid.."\n" end details = details.."\nTotal: $"..exports.global:formatMoney(data.fee) exports.factions:sendNotiToAllFactionMembers(factionId, customerName.." has failed to pay his total insurance fees of $"..exports.global:formatMoney(data.fee).." over his "..(#(data.vehs)).." vehicles.", details) end end end end end local ptax = taxHouses[ dbid ] or 0 if ptax > 0 then ptax = math.floor( ptax ) ptax = math.min( ptax, bankmoney ) bankmoney = bankmoney - ptax governmentIncome = governmentIncome + ptax mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. dbid .. ", -3, " .. ptax .. ", 'PROPERTYTAX', 6)" ) end if (rent > 0) then if (rent > bankmoney) then rent = -1 call( getResourceFromName( "interior-system" ), "publicSellProperty", player, rented, false, true ) else bankmoney = bankmoney - rent mysql:query_free( "INSERT INTO wiretransfers (`from`, `to`, `amount`, `reason`, `type`) VALUES (" .. dbid .. ", 0, " .. rent .. ", 'HOUSERENT', 6)" ) end end -- save the bankmoney exports.anticheat:changeProtectedElementDataEx(player, "bankmoney", bankmoney, true) -- let the client tell them the (bad) news local grossincome = pay+profit+interest+donatormoney-rent-vtax-ptax triggerClientEvent(player, "cPayDay", player, faction, noWage and -1 or pay, profit, interest, donatormoney, tax, incomeTax, vtax, ptax, rent, grossincome, cP) return governmentIncome end function payAllWages(isForcePayday) if not isForcePayday then local mins = getRealTime().minute local minutes = 60 - mins if (minutes < 15) then minutes = minutes + 60 end setTimer(payAllWages, 60000*minutes, 1, false) end loadWelfare( ) threads = { } taxVehicles = {} vehicleCount = {} insuranceVehicles = {} for _, veh in pairs(getElementsByType("vehicle")) do if isElement(veh) then local owner, faction, registered = tonumber(getElementData(veh, "owner")) or 0, tonumber(getElementData(veh, "faction")) or 0, tonumber(getElementData(veh, "registered")) or 0 local vehid = getElementData(veh, "dbid") or 0 if vehid >0 and faction <= 0 and owner > 0 then -- Vehicle inactivity scanner / MAXIME / 2015.1.11 local deletedByScanner = nil local active, reason = exports['vehicle-system']:isActive(veh) if not active and not exports['vehicle-system']:isProtected(veh) then local name = exports.global:getVehicleName(veh) if exports['vehicle-manager']:systemDeleteVehicle(vehid, "Deleted by Inactivity Scanner. Reason: "..reason) then local account = exports.cache:getAccountFromCharacterId(owner) or {id = 0, username="No-one"} local characterName = exports.cache:getCharacterNameFromID(owner) or "No-one" if owner > 0 and account then exports.announcement:makePlayerNotification(account.id, "Vehicle ID #"..vehid.." ("..name..") was taken away from "..characterName.."'s possession by the vehicle inactivity scanner.", "Reason: "..reason..". Your vehicle was marked as inactive because your character hasn't been logged in game for longer than 30 days or no body has ever started its engine for longer than 14 days while parking outdoor. \n\nAn inactive vehicle is a waste of resources and thus far the vehicle's ownership was removed or stripped from your possession to give other players opportunities to buy and use it more efficiently.\n\nThis vehicle wasn't unprotected. To prevent this to happen again to other vehicles of yours, you may want to spend your GC(s) to protect it from the inactive vehicle scanner on UCP.") end exports.global:sendMessageToAdmins("[VEHICLE] Vehicle ID #"..vehid.." ("..name..", owner: "..characterName.." - "..account.username..") has been deleted by the vehicle inactivity scanner. "..reason) deletedByScanner = true end end if registered == 1 and not deletedByScanner then --Taxes local tax = tonumber(getElementData(veh, "carshop:taxcost")) or 25 if tax > 0 then taxVehicles[owner] = ( taxVehicles[owner] or 0 ) + ( tax * 1 ) --[[vehicleCount[owner] = ( vehicleCount[owner] or 0 ) + 1 if vehicleCount[owner] > 3 then -- $75 for having too much vehicles, per vehicle more than 3 taxVehicles[owner] = taxVehicles[owner] + 50 end]] end --Insurance if exports.global:isResourceRunning("insurance") then local insuranceFee = getElementData(veh, "insurance:fee") or 0 insurancefee = tonumber(insurancefee) local insuranceFaction = getElementData(veh, "insurance:faction") or 0 insuranceFaction = tonumber(insuranceFaction) if insuranceFee > 0 and insuranceFaction > 0 then if not insuranceVehicles[owner] then insuranceVehicles[owner] = {} end if not insuranceVehicles[owner][vehid] then insuranceVehicles[owner][vehid] = {} end if not insuranceVehicles[owner][vehid][insuranceFaction] then insuranceVehicles[owner][vehid][insuranceFaction] = 0 end insuranceVehicles[owner][vehid][insuranceFaction] = insuranceVehicles[owner][vehid][insuranceFaction] + insuranceFee end end end end end end -- count all player props taxHouses = { } for _, property in pairs( getElementsByType( "interior" ) ) do local interiorStatus = getElementData(property, "status") local cost = tonumber(interiorStatus[5]) or 0 local owner = tonumber(interiorStatus[4]) or 0 local type = tonumber(interiorStatus[1]) local intid = getElementData(property, "dbid") local name = getElementData(property, "name") if cost > 0 and owner > 0 and type < 2 then -- MAXIME local propertyTax = getPropertyTaxRate(interiorStatus[1]) taxHouses[ interiorStatus[4] ] = ( taxHouses[ interiorStatus[4] ] or 0 ) + propertyTax * interiorStatus[5] end -- Interior inactivity scanner / MAXIME / 2015.1.11 local active, reason = exports['interior-system']:isActive(property) if not active and not exports['interior-system']:isProtected(property) then if exports['interior-system']:unownProperty(intid, "Forcesold by Inactivity Scanner. Reason: "..reason) then local account = exports.cache:getAccountFromCharacterId(owner) or {id = 0, username="No-one"} local characterName = exports.cache:getCharacterNameFromID(owner) or "No-one" if owner > 0 and account then exports.announcement:makePlayerNotification(account.id, "Interior ID #"..intid.." ("..name..") was taken away from "..characterName.."'s possession by the interior inactivity scanner.", "Reason: "..reason..". Your interior was marked as inactive because no body has ever entered it for the last 14 days or your character(who owns it) hasn't been logged in game for 30 days.\n\nAn inactive interior is a waste of resources and thus far the interior's ownership was stripped from your possession to give other players opportunities to buy and use it more efficiently.\n\nThis interior wasn't unprotected. To prevent this to happen again to other interiors of yours, you may want to spend your GC(s) to protect it from the inactive interior scanner on UCP.") end exports.