-- MySQL Housesystem created & released by Noneatme(MuLTi), Do not remove credits! -- -- All Rights go to Noneatme -- --[[ Total time token: - 3 hour - 1.5 hour ________ 4.5 hours ]] ------------------------ -- CONNECTION HANDLER -- ------------------------ -- Here you can change some settings -- -- FIRST CONNECTION -- local mysqlhost1 = "localhost" local mysqluser1 = "root" local mysqlpassword1 = "" local mysqldatabase1 = "dbs_housesystem2" -- SECOND CONNECTION, OPTIONAL IF CONNECTION 1 DON'T WORK local mysqlhost2 = "localhost" local mysqluser2 = "root" local mysqlpassword2 = "" local mysqldatabase2 = "dbs_housesystem" local dbpTime = 500 -- How many Miliseconds will use the dbPoll function for waiting for a result local max_player_houses = 2 -- Define the buyable houses per player local sellhouse_value = 80 -- The ammount in percent that you get back if you sell a house local open_key = "F5" -- Define the key for the infomenue and the housepanel -- I don't know whats the right time for that -- ----------------------------------------------------------------- -- IF YOU CAN'T WRITE IN LUA, DO NOT EDIT ANYTHING ABOVE HERE! -- ----------------------------------------------------------------- -- EVENTS -- addEvent("onHouseSystemHouseCreate", true) addEvent("onHouseSystemHouseLock", true) addEvent("onHouseSystemHouseDeposit", true) addEvent("onHouseSystemHouseWithdraw", true) addEvent("onHouseSystemWeaponDeposit", true) addEvent("onHouseSystemWeaponWithdraw", true) addEvent("onHouseSystemRentableSwitch", true) addEvent("onHouseSystemRentalprice", true) addEvent("onHouseSystemTenandRemove", true) addEvent("onHouseSystemInfoBuy", true) addEvent("onHouseSystemInfoRent", true) addEvent("onHouseSystemInfoEnter", true) local handler -- local only, we don't need a global handler local saveableValues = { ["MONEY"] = "MONEY", ["WEAP1"] = "WEAP1", ["WEAP2"] = "WEAP2", ["WEAP3"] = "WEAP3", ["LOCKED"] = "LOCKED", ["OWNER"] = "OWNER", ["RENTABLE"] = "RENTABLE", ["RENTALPRICE"] = "RENTALPRICE", ["RENT1"] = "RENT1", ["RENT2"] = "RENT2", ["RENT3"] = "RENT3", ["RENT4"] = "RENT4", ["RENT5"] = "RENT5", } local created = false -- DONT EDIT local houseid = 0 -- Define the Houseid, local house = {} -- The House array local houseData = {} -- The House Data arry local houseInt = {} -- The House Interior array local houseIntData = {} -- The House Interior Data Array local buildStartTick local buildEndTick local rentTimer -- STARTUP EVENT HANDLER -- addEventHandler("onResourceStart", getResourceRootElement(), function() handler = dbConnect("sqlite", ".sql files/FOR EXISTING DATABASES/execute_this.sql") -- If the Handler 1 dont work if not(handler) then outputServerLog("[HOUSESYSTEM]MySQL handler 2 not accepted! Shutting down...") cancelEvent() else dbExec ( handler, "CREATE TABLE IF NOT EXISTS `houses` (`X`, `Y`, `Z`, `INTERIOR`, `INTX`, `INTY`, `INTZ`, `PRICE`)") outputServerLog("[HOUSESYSTEM]MySQL handler 1 accepted!") housesys_startup() end end) -- SHUTDOWN EVENT HANDLER -- addEventHandler("onResourceStop", getResourceRootElement(), function() -- Free the arrays -- for index, houses in pairs(house) do houses = nil end for index, houseDatas in pairs(houseData) do houseDatas = nil end for index, houseInts in pairs(houseInt) do houseInts = nil end for index, houseIntDatas in pairs(houseIntData) do houseIntDatas = nil end houseid = 0 created = false end) -------------- -- COMMANDS -- -------------- -- /unrent -- addCommandHandler("unrent", function(thePlayer) if(getElementData(thePlayer, "house:lastvisit")) and (getElementData(thePlayer, "house:lastvisit") ~= false) then local id = tonumber(getElementData(thePlayer, "house:lastvisit")) if(isPlayerRentedHouse(thePlayer, id) == false) then outputChatBox("You are not tenad of this house!", thePlayer, 255, 0, 0) return end local sucess = removeHouseTenand(id, thePlayer) if(sucess == true) then outputChatBox("You have sucessfull terminate the tenancy!", thePlayer, 0, 255, 0) else outputChatBox("An error occurred!", thePlayer, 255, 0, 0) end end end) -- /rent -- addCommandHandler("rent", function(thePlayer) if(getElementData(thePlayer, "house:lastvisit")) and (getElementData(thePlayer, "house:lastvisit") ~= false) then local id = tonumber(getElementData(thePlayer, "house:lastvisit")) if(houseData[id]["OWNER"] == getPlayerName(thePlayer)) then outputChatBox("You can't rent here! It's your house!", thePlayer, 255, 0, 0) return end if(tonumber(houseData[id]["RENTABLE"]) ~= 1) then outputChatBox("This house is not rentable!", thePlayer, 255, 0, 0) return end if(getPlayerRentedHouse(thePlayer) ~= false) then outputChatBox("You are allready a tenand in a house! Use /unrent first.", thePlayer, 255, 0, 0) return end local sucess = addHouseTenand(thePlayer, id) if(sucess == true) then outputChatBox("You are now tenand this house!", thePlayer, 0, 255, 0) else outputChatBox("You can't rent this house!", thePlayer, 255, 0, 0) end end end) -- /createhouse -- addCommandHandler("createhouse", function(thePlayer) if(hasObjectPermissionTo ( thePlayer, "function.kickPlayer", false ) ) then if(getElementInterior(thePlayer) ~= 0) then outputChatBox("You are not outside!", thePlayer, 255, 0, 0) return end if(isPedInVehicle(thePlayer) == true) then outputChatBox("Please exit your vehicle.", thePlayer, 255, 0, 0) return end -- INSERT SECURITY OPTIONS LIKE ADMINLEVEL HERE( if(adminlevel > :~) then ...) triggerClientEvent(thePlayer, "onClientHouseSystemGUIStart", thePlayer) else outputChatBox("You are not an admin!", thePlayer, 255, 0, 0) end end) -- /in -- addCommandHandler("in", function(thePlayer) if(getElementData(thePlayer, "house:lastvisit")) and (getElementData(thePlayer, "house:lastvisit") ~= false) then local house = getElementData(thePlayer, "house:lastvisit") if(house) then local id = tonumber(house) if(tonumber(houseData[id]["LOCKED"]) == 0) or (houseData[id]["OWNER"] == getPlayerName(thePlayer)) or (isPlayerRentedHouse(thePlayer, id) == true) then local int, intx, inty, intz, dim = houseIntData[id]["INT"], houseIntData[id]["X"], houseIntData[id]["Y"], houseIntData[id]["Z"], id setElementData(thePlayer, "house:in", true) setInPosition(thePlayer, intx, inty, intz, int, false, dim) unbindKey(thePlayer, open_key, "down", togglePlayerInfomenue, id) setElementData(thePlayer, "house:lastvisitINT", id) if(houseData[id]["OWNER"] == getPlayerName(thePlayer)) or (isPlayerRentedHouse(thePlayer, id) == true) then bindKey(thePlayer, open_key, "down", togglePlayerHousemenue, id) end else outputChatBox("You don't have the housekey for this House!", thePlayer, 255, 0, 0) end end end end) -- /out -- addCommandHandler("out", function(thePlayer) if(getElementData(thePlayer, "house:lastvisitINT")) and (getElementData(thePlayer, "house:lastvisitINT") ~= false) then local house = getElementData(thePlayer, "house:lastvisitINT") if(house) then local id = tonumber(house) local x, y, z = houseData[id]["X"], houseData[id]["Y"], houseData[id]["Z"] setElementData(thePlayer, "house:in", false) setInPosition(thePlayer, x, y, z, 0, false, 0) end end end) -- /buyhouse -- addCommandHandler("buyhouse", function(thePlayer) if(getElementData(thePlayer, "house:lastvisit")) and (getElementData(thePlayer, "house:lastvisit") ~= false) then local house = getElementData(thePlayer, "house:lastvisit") if(house) then local id = house local owner = houseData[id]["OWNER"] if(owner ~= "no-one") then outputChatBox("You can't buy this house!", thePlayer, 255, 0, 0) else local houses = 0 for index, col in pairs(getElementsByType("colshape")) do if(getElementData(col, "house") == true) and (houseData[getElementData(col, "ID")]["OWNER"] == getPlayerName(thePlayer)) then houses = houses+1 if(houses == max_player_houses) then outputChatBox("You have allready "..max_player_houses.." houses! Sell a house to buy this one.", thePlayer, 255, 0, 0) return end end end local money = getPlayerMoney(thePlayer)