Sign in to follow this  
easyrider

Turf System (Turf Money)(take turf without car)

Recommended Posts

The player only earns moneys when player take turf.but ı want a group to make money every 20 minutes.and ı dont want to make turf with the car.

Would you help me with this? its important for us.Thank you.

 

 

 

 

 


 

local turfPos = {
{ 2709.5104980469, -1593.6439208984, 0, 197.5, 92, 90 },
{ 2440.403320315, -1722.5418701172, 0,  245, 133, 30 },
{ 2625.7390136719, -2024.4792480469, 0,  245, 133, 30 },
{2422.5437011719, -1829.01171875, 0, 197.5, 92, 90 },
{ 2641.6721191406, -1449.9906005899, 0,  245, 133, 30 },
{ 2635.8344726563, -1289.7164306641, 0,  245, 133, 30 },
{ 2650.5544433594, -1141.5219726563, 0, 197.5, 92, 90 },
{ 2443.5759277344, -2247.7583007813, 0,  255, 140, 30 },
{ 2292.3610839844, -2062.405761788, 0,  255, 140, 30 },
{ 2175.6198730469, -1858.5258789063, 0, 197.5, 92, 90 },
{ 2129.63110351556, -1746.5291748047, 0,  245, 150, 30 },
{ 2372.3046875, -1549.7535400391, 0,  245, 225, 30 },
{ 2372.6462402344, -1300.7740478516, 0, 245, 260, 30 },
{ 2103.0454101563, -1568.2351074219, 0, 242, 400, 30 },
{ 2056.5090332031, -1129.5450439453, 0,  245, 133, 30 },
{ 2376.6982421875, -2787.8405761719, 0,  460, 420, 220 },
{ 1279.3182373047, -2644.47245625, 0,  600, 600, 400 },
{ -2364.412109375, -181.12747192383, 0,  150, 200, 90 }}

local turfElement = {}
local turfTimer = {}
local checkComplete = false

local messages = {
    [1] = "Turf System By VitoScaletta Was Started Correctly!",
    [2] = "This Territory Already Belongs To %s",
    [3] = "You Enter Into De %s's Turf Zone.Wait 2 Minutes To Capture The Turf And Win +1K!",
    [4] = "This Turf Doesn't Belong To Anyone.Wait 2 Minutes To Capture The Turf And Win +1K!",
    [5] = "Congratulations.You Capture The Turf. +1K!",
    [6] = "If You Don't Come Back Within 20 Second, You Won't Capture The Turf",
    [7] = "You Couldn't Capture The Turf Because Of Absence"
 }
 
--     Nadie = None | Just a translation

addEventHandler("onResourceStart", resourceRoot,
function()
    executeSQLQuery("CREATE TABLE IF NOT EXISTS Turf_System ( Turfs TEXT, GangOwner TEXT, r INT, g INT, b INT)")
    --
    local check = executeSQLQuery("SELECT * FROM Turf_System" )
    if #check == 0 then
        for i=1,#turfPos do
            executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0)
        end
    elseif #check > 1 then
        for i = #check, #turfPos do
            executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0)
        end
    end
    
    for i,v in ipairs(turfPos) do
        local sqlData = executeSQLQuery("SELECT * FROM Turf_System WHERE Turfs=?", "Turf["..tostring(i).."]")
        local turfCol = createColCuboid(unpack(v))
        setElementData(turfCol, "getTurfGang", sqlData[1].GangOwner)
        local turfArea = createRadarArea(v[1], v[2], v[4], v[5], sqlData[1].r, sqlData[1].g, sqlData[1].b, 175)
        turfElement[turfCol] = {turfCol, turfArea, i}
        turfTimer[turfCol] = {}
    end
    
    outputDebugString( messages[1] )
end )

addEventHandler ( "onColShapeHit", root,
    function ( player )
        if turfElement[source] and source == turfElement[source][1] then
            local turf,area,id = unpack( turfElement[source] )
            local playerGang = getElementData ( player, "gang" )
            local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(id).."]" )
            if ( turfGang[1].GangOwner == playerGang ) then
                outputChatBox( messages[2]:format( turfGang[1].GangOwner or "None" ), player, 0, 255, 0, false )
            else
                local playerGang = getElementData ( player, "gang" )
                setElementData( source, "warTurf", playerGang )
                if ( isTimer ( turfTimer[source][1] ) ) then
                    if isTimer( turfTimer[source][2] ) then killTimer( turfTimer[source][2] ) end 
                    return 
                end
                if ( playerGang ) then
                    local r, g, b = unpack ( getGangColor ( playerGang ) )
                    -- local r, g, b = 255, 255, 255
                    setRadarAreaFlashing ( area, true )
                    if turfGang[1].GangOwner ~= "Nadie" then
                        outputChatBox( messages[3]:format( turfGang[1].GangOwner ), player, 0, 255, 0, false )
                    else
                        outputChatBox( messages[4], player, 0, 255, 0, false )
                    end
                    
                    turfTimer[source][1] = setTimer (
                        function ( )
                            local players = getGangPlayersInTurf ( turf, playerGang )
                            setRadarAreaColor ( area, tonumber(r), tonumber(g), tonumber(b), 175 )
                            for _, player in ipairs ( players ) do
                                outputChatBox( messages[5], player, 0, 255, 0, false )
                                triggerClientEvent(player, "onTakeTurf", player)
                                givePlayerMoney ( player, 1000 )
                                executeSQLQuery("UPDATE Turf_System SET GangOwner=?,r=?,g=?,b=? WHERE Turfs=?", playerGang, tonumber(r), tonumber(g), tonumber(b), "Turf["..tostring(id).."]" )
                                -- setElementData ( turf, "getTurfGang", playerGang )
                            end
                            setRadarAreaFlashing ( area, false )
                        end
                    ,120000, 1)
                end
            end
        end
    end
)

addEventHandler ( "onColShapeLeave", root, 
    function( player )
        if turfElement[source] and source == turfElement[source][1] then
            if isTimer( turfTimer[source][1] ) then
                local aGang = getElementData( source, "warTurf" )
                local ps = getGangPlayersInTurf( source, aGang )
                if ps == 0 then
                    outputChatBox( messages[6], player, 255, 0, 0 )
                    turfTimer[source][2] = setTimer(
                        function(source, aGang)
                            if isTimer(turfTimer[source][1]) then killTimer(turfTimer[source][1]) end
                            setRadarAreaFlashing(turfElement[source][2], false)
                            for _, v in ipairs( getElementsByType("player") ) do
                                if getElementData(v, "gang") == aGang then
                                    outputChatBox(messages[7], v, 255, 0, 0)
                                end
                            end
                        end
                    , 20000, 1, source, aGang)
                end
            end
        end
    end
)

function getGangPlayersInTurf( turf, gang ) -- element, string
    if turf and gang then
        local players = getElementsWithinColShape ( turf, "player" )
        local gPla = {}
        for _, v in ipairs(    players ) do        
            if getElementData(v, "gang") == gang then
                table.insert(gPla, v)
            end
        end
        return gPla
    end
end

function getGangColor(gangName)
    return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

 

Edited by Dutchman101
Added code tags

Share this post


Link to post

I can answer the not taking in car part....  Just simply use isPedOnGround.  Here is a small code (I admiteddly had a lot of help with) that will only set a players team ONLY if he is on foot.

local jobTeam = createTeam("Test Team", 20, 100, 150) --Create the team
local jobMarker = createMarker(7002.419921875, -4831.384765625, 9.60000038147, "cylinder", 2.0, 20, 100, 150, 255) --And marker for team

VehiclesTable = {}
local myBlip = createBlipAttachedTo ( jobMarker, 55 ) --Random blip, I just thought why not?




function takeJob(hitElement, matchingDimension) --define what hitElement is
	if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then --If it's a player and the player is in the same dimension then do something.
		if getTeamFromName("Test Team") then
			local team = getTeamFromName("Test Team") --This defines team
			if team then --This checks team
				if isPedOnGround ( hitElement ) then --If the player is on foot
				setPlayerTeam(hitElement, team) --Then do something here, this will set the team...
				elseif not isPedOnGround ( hitElement ) then --If player is not on foot
				outputChatBox("You must be on foot!", hitElement, 255, 0, 0) --Output a message saying he needs to be on foot
				end	
			end
		end
	end
end
addEventHandler("onMarkerHit", jobMarker, takeJob) --When player hits marker the function is triggered 

Honestly too lazy to edit it right now, but I hope this helps you with isPedOnGround! :D

Share this post


Link to post

" - The Scripting section is not meant for those unwilling to learn, whose only intent is to try get others to finish the scripts they need, line by line. We see this happening way too often -  someone with seemingly zero scripting skills does not react on-topic to the set of functions they can use that other users provide them, and does not seem to take any pushes in the right direction forward; they are just waiting for a collective effort from other scripters to develop what they want. This is what we do not want to see."

This is exactly a post which is asking someone to write the whole script for them. I think you should start learning this language, and then if you are stuck somewhere we'll help ya.

Share this post


Link to post

as nexus said scripting section is for people willing to learn if you want someone to make/edit a script for you, you should post at "Looking for staff" section

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.