Glizzy. Posted April 18, 2014 Share Posted April 18, 2014 Hello Can anyone help me please? I've installed this turf system, with a groupsystem has /turfcolor R G B, When I choose a random color (ex: 255 0 0), I went to the turf after the turf has been taken it still white like all of the turfs (White turfs), When I restart the resourse of that script It became Black the turf I've took became black, Idk why, It's supposed to be when I take a turf automaticly became red because I've choose 255 0 0, without restarting the resource, thanks for reading. client: -- Time before a player capture the turf function showTimeLeft( ) if getElementData( localPlayer, "isInTurf" ) then local time = tonumber( getElementData( localPlayer, "captureTime" )) local sx, sy = guiGetScreenSize( ) if time and time > 0 then dxDrawText ( "Time before your gang capture the turf: "..tostring(time).." seconds", (sx/2)-250, sy-50, 0, 0, tocolor( 200, 200, 200, 255 ), 0.8, "bankgothic" ) end end end addEventHandler( "onClientRender", root, showTimeLeft ) server: capturing = { } cooldown = { } members_in_turf = {{ }} time_syncer = { } local db = dbConnect("sqlite", "/turfs.db") addEventHandler("onResourceStart", getResourceRootElement(), function() dbExec(db, "CREATE TABLE IF NOT EXISTS turfs (X NUMERIC, Y NUMERIC, Z NUMERIC, sizeX NUMERIC, sizeY NUMERIC, red NUMERIC, green NUMERIC, blue NUMERIC, owner TEXT)") dbQuery(loadTurfs, db, "SELECT * FROM turfs") end) -- Gets all members in team function getGroupMembers(player) local teamMembers = {} for w,gangmember in ipairs(getElementsByType("player")) do if getElementData(gangmember,"Group") == getElementData(player,"Group") then table.insert(teamMembers,gangmember) end end return teamMembers end function onTurfEnter(hitElement) if hitElement and isElement(hitElement) and getElementType(hitElement) == "player" and getElementData( hitElement, "Group" ) and getElementData( hitElement, "Group" ) ~= "None" then local owner = getElementData( source, "owner") if getPedOccupiedVehicle(hitElement) then exports["ac-message"]:outputTopBar( "TURFS: This turf belongs to: "..owner, hitElement, 255, 200, 0 ) return end local area = getElementData( source, "area" ) if ( getPlayerTeam(hitElement) == getTeamFromName("Criminals") or getPlayerTeam(hitElement) == getTeamFromName("Gangsters")) then setElementData(hitElement,"isInTurf",true) local group = getElementData( hitElement, "Group" ) if not members_in_turf[group] then members_in_turf[group] = { } end if not members_in_turf[group][area] then members_in_turf[group][area] = 0 end members_in_turf[group][area] = members_in_turf[group][area] + 1 local gangmems = getGroupMembers(hitElement) local px,py,pz = getElementPosition(hitElement) local currturf = getZoneName(px,py,pz) for w,mem in ipairs(gangmems) do if mem ~= hitElement and not getElementData(hitElement,"isInTurf") and members_in_turf[group][area] > 1 then exports["ac-message"]:outputTopBar( "TURFS: Your gang received backup at: "..currturf..", good luck! ("..tostring(members_in_turf[group][area]).." members)", mem, 0, 255, 0 ) end end local iR, iG, iB = exports["ac-groupsys"]:getGroupTurfColor(group) local rR, gG, bB = getRadarAreaColor( area ) local colCuboid = source local time_to_capture = math.random(180,300)*1000 if group == owner then exports["ac-message"]:outputTopBar( "TURFS: This turf belongs to: "..owner, hitElement, 0, 255, 0 ) else setRadarAreaFlashing( area, true ) exports["ac-message"]:outputTopBar( "TURFS: This turf belongs to: "..owner.." hold it for "..tostring(math.floor(time_to_capture/60000)+1).." minutes to capture it", hitElement, 0, 255, 0 ) for w,mem in ipairs(gangmems) do if mem ~= hitElement and not getElementData(hitElement,"isInTurf") and members_in_turf[group][area] > 1 then exports["ac-message"]:outputTopBar( "TURFS: Your gang is attacking a turf at: "..currturf..", go there and help them! ("..tostring(members_in_turf[group][area]).." members)", mem, 255, 200, 0 ) end end if not isTimer(capturing[source]) then -- Start a timer that calls the capturing function local player_turfer = hitElement capturing[source] = setTimer( function( ) setElementData( colCuboid, "owner", group ) setElementData( area, "owner", group ) for w,mem in ipairs(gangmems) do if getElementData(mem,"isInTurf") then givePlayerMoney( mem, math.random( 1000, 3000 )) end end setRadarAreaColor( area, iR, iG, iB, 130 ) setRadarAreaFlashing( area, false ) dbExec(db, "UPDATE turfs SET owner=?, red=?, green=?, blue=? WHERE X=? AND Y=?", group, iR, iG, iB, tonumber(getElementData(colCuboid,"posx")), tonumber(getElementData(colCuboid,"posy"))) end, time_to_capture, 1) end if not isTimer(time_syncer[hitElement]) and isTimer(capturing[source]) then -- Start a timer that shows the time left to capture local timer_to_check = capturing[source] local player_time_req = hitElement time_syncer[hitElement] = setTimer( function() local i1,i2,i3 = 0,0,0 if isTimer(timer_to_check) then i1,i2,i3 = getTimerDetails( timer_to_check ) end if isElement(player_time_req) and i1 then setElementData( player_time_req, "captureTime", math.floor( i1/1000 )) end end, 1000, (time_to_capture/1000)) end end elseif getElementData( hitElement, "Group" ) == "None" and getPlayerTeam(hitElement) == getTeamFromName("Criminals") then exports["ac-message"]:outputTopBar( "Only gang members can capture turfs, (see F6)", hitElement, 255, 0, 0 ) end end end function onTurfLeave(hitElement) if hitElement and isElement(hitElement) and getElementType(hitElement) == "player" and getElementData( hitElement, "Group" ) and getElementData( hitElement, "Group" ) ~= "None" and ( getPlayerTeam(hitElement) == getTeamFromName("Criminals") or getPlayerTeam(hitElement) == getTeamFromName("Gangsters")) then -- Leave a turf local owner = getElementData(source, "owner") local area = getElementData( source, "area" ) local group = getElementData( hitElement, "Group" ) if not members_in_turf[group] then members_in_turf[group] = {} end if not members_in_turf[group][area] then members_in_turf[group][area] = 0 end members_in_turf[group][area] = members_in_turf[group][area] - 1 if members_in_turf[group][area] > 0 then exports["ac-message"]:outputTopBar( "TURFS: Go back and help your gang members! ("..tostring(members_in_turf[group][area]).." members left)", hitElement, 255, 0, 0 ) else local gangmems = getGroupMembers(hitElement) local px,py,pz = getElementPosition(hitElement) local currturf = getZoneName(px,py,pz) for w,mem in ipairs(gangmems) do if getElementData(source,"owner") ~= group then exports["ac-message"]:outputTopBar( "TURFS: Gang war was interrupted at: "..currturf..", due to lack of members!", mem, 255, 0, 0 ) end end end setElementData(hitElement,"isInTurf",false) if members_in_turf[group][area] == 0 then setRadarAreaFlashing( area, false ) if isTimer(capturing[source]) then killTimer(capturing[source]) end end if isTimer(time_syncer[hitElement]) then killTimer(time_syncer[hitElement]) end end end function changeTurfColor(plr, cmd, r, g, b) local r, g, b = r or 255, g or 255, b or 255 local group = exports["ac-groupsys"]:getPlayerGroup(plr) if (not group) then return end if (not exports["ac-groupsys"]:checkGroupAccess(plr, 13)) then return end dbExec(db, "UPDATE turfs SET red=?, green=?, blue=? WHERE owner=?", r, g, b, group ) for w,area in ipairs(getElementsByType("radararea")) do if getElementData(area,"owner") == group then setRadarAreaColor( area, r, g, b, 130 ) end end end addCommandHandler("turfcolor", changeTurfColor) function addTurf(x,y,z,sizeX,sizeY,red,green,blue,owner) -- Load all turfs if not owner then owner = "None" end local colCuboid = createColCuboid( x, y, z-30, sizeX, sizeY, z+30 ) local radArea = createRadarArea( x, y, sizeX, sizeY, red, green, blue, 130 ) addEventHandler( "onColShapeHit", colCuboid, onTurfEnter ) addEventHandler( "onColShapeLeave", colCuboid, onTurfLeave ) setElementData( colCuboid, "owner", owner ) setElementData( radArea, "owner", owner ) setElementData( colCuboid, "posx", x ) setElementData( colCuboid, "posy", y ) setElementData( colCuboid, "area", radArea ) end function loadTurfs(query) local result = dbPoll( query, 0 ) if result then for _, row in ipairs( result ) do addTurf(row["X"], row["Y"], row["Z"], row["sizeX"], row["sizeY"], row["red"], row["green"], row["blue"], row["owner"]) end end end function player_Wasted( ammo, attacker, weapon, bodypart ) if isElement( source ) and isElement( attacker ) and getElementType( attacker ) == "player" then if ( getPlayerTeam( source ) == getTeamFromName( "Criminals" ) or getPlayerTeam( source ) == getTeamFromName( "Gangsters" )) and ( getPlayerTeam( attacker ) == getTeamFromName( "Criminals" ) or getPlayerTeam( attacker ) == getTeamFromName( "Gangsters" )) and getElementData( source, "Group" ) ~= getElementData( attacker, "Group" ) and not isTimer( cooldown[attacker] ) and getElementData(source,"isInTurf") then local victim_money = getPlayerMoney( source ) if victim_money > 1000 then victim_money = 1000 elseif victim_money < 50 then victim_money = 50 end local money = math.floor(victim_money*(math.random(1,50)/25)) -- Advantages takePlayerMoney( source, math.floor( money )) givePlayerMoney( attacker, math.floor( money )) -- Move victim to gangsters team if inside turf local gangsterTeam = getTeamFromName("Gangsters") setPlayerTeam(source,gangsterTeam) setPlayerNametagColor(source,255,0,255) -- Health (armor) local armor = 0 if getPedArmor ( attacker ) < 50 then armor = math.random(5,35) setPedArmor( attacker, getPedArmor( attacker )+armor) end -- Status message local gangmems = getGroupMembers(hitElement) local px,py,pz = getElementPosition(hitElement) local currturf = getZoneName(px,py,pz) for w,mem in ipairs(gangmems) do exports["ac-message"]:outputTopBar( "TURFS: One of your members died in the turf at: "..currturf.."!", mem, 255, 0, 0 ) end -- Weapon stats local wepSlot = getSlotFromWeapon( weapon ) local stats = 0 if getPedStat( attacker, wepSlot+68 ) < 950 then stats = math.random( 1,50 ) setPedStat( attacker, wepSlot+68, getPedStat( attacker, wepSlot+68 )+stats) end -- Status outputChatBox( "#007700(GangInfo) #bbbbbbMoney: #eeeeee+"..tostring(money)..", #bbbbbbArmor:#eeeeee +".. tostring(armor)..", #bbbbbbStats: #eeeeee+"..tostring(stats), attacker, 0, 255, 0, true ) cooldown[attacker] = setTimer( function() end, 15000, 1 ) end end end addEventHandler( "onPlayerWasted", getRootElement(), player_Wasted ) -- Adds a new turf function createTurf( player, cmd, sx, sy ) local acc = getPlayerAccount( player ) if isObjectInACLGroup("user."..getAccountName(acc), aclGetGroup( "Admin" )) then if not sx then sx = math.random(50,250) end if not sy then sy = math.random(50,250) end local x,y,z = getElementPosition(player) dbExec(db, "INSERT INTO turfs VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", math.floor(x), math.floor(y), math.floor(z), math.floor(sx), math.floor(sy), 255, 255, 255, "None") addTurf(x,y,z,sx,sy,255,255,255,"None") exports["ac-message"]:outputTopBar( "TURFS: A new turf was added syccessfully", player, 0, 255, 0 ) end end Link to comment
Mr_Moose Posted April 18, 2014 Share Posted April 18, 2014 Well this is a beta version and the current version of this turf system (0.8.9) is currently only available in AC RP, there are still a couple of bugs to resolve before the next version will be uploaded, you can follow the bugs and their solutions here: http://mta.albonius.com/index.php?board=8.0 and report other bugs you may find in the AC RP scripts. The recommended group system is this: https://community.multitheftauto.com/index.php?p=resources&s=details&id=8291 and you might also modify it since it doesn't use "Group" as default name for groups or gangs by default. It must be manually changed to make it synced between the group system and the turf system. Link to comment
Glizzy. Posted April 18, 2014 Author Share Posted April 18, 2014 Yeah I've already installed that groupsystem, but when I type /turfcolor R G B, Nothing apear on my screen, So idk if the turfcolor is changed or no, Now please tell me how do i fix it? Give me a code or something I can't find anything same as my problem in your forum, There is alot of bugs in that topics, wheree is mine? if you can give me the code here please Link to comment
Mr_Moose Posted April 19, 2014 Share Posted April 19, 2014 function changeTurfColor(plr, cmd, r, g, b) local r, g, b = r or 255, g or 255, b or 255 local group = exports["ac-groupsys"]:getPlayerGroup(plr) if (not group) then return end if (not exports["ac-groupsys"]:checkGroupAccess(plr, 13)) then return end dbExec(db, "UPDATE turfs SET red=?, green=?, blue=? WHERE owner=?", r, g, b, group ) for w,area in ipairs(getElementsByType("radararea")) do if getElementData(area,"owner") == group then setRadarAreaColor( area, r, g, b, 130 ) end end end addCommandHandler("turfcolor", changeTurfColor) This is the part where the turf color is changed, in the groupsystem you'll find a command handler with the exact same name which saves the turf color to the group system database, meanwhile this will save the same data to the turf system database. First of all you need to make sure that the filenames matches, the groupsystem default filename is not "ac-groupsys" so make sure that you change the code to the same file name as the groupsystem has. Secondly make sure that you have the resource ac-message installed: https://community.multitheftauto.com/index.php?p=resources&s=details&id=8620 (Works out of the box) And finally, make sure that all required functions are exported in the group system by checking it's meta.xml file. These two should be added: <export function="getGroupChatColor" type="server"/> <export function="getGroupTurfColor" type="server"/> Version 0.8.9 will have it's own settings file and use less exports so another option is to wait for that to be released. Probably within a week or so. Edit: You might also look at the element data in which a player group is stored, the groupsystem may use something else than "Group" by default and that would cause issues, add "Group" to the scoreboard and see if your group is there or not. There might also be a couple of modifications in the group system related to the turfcolors, this is what I'm using currently in the group system: function changeTurfColor(plr, cmd, r, g, b) local r, g, b = r or 255, g or 255, b or 255 local group = getPlayerGroup(plr) if (not group) then return end if (not checkGroupAccess(plr, 13)) then return end if (not groupTable[group]) then return end local color = {r, g, b} dbExec(db, "UPDATE groups SET turfcolor=? WHERE name=?", toJSON(color), group) groupTable[group][6] = toJSON(color) exports["ac-message"]:outputTopBar("Turf colour changed to R: "..r.." G: "..g.." B: "..b, plr, r, g, b, "default-bold", true, 0.15) groupLog(group, getPlayerName(plr).." has set turf color to: "..r..", "..g..", "..b) end addCommandHandler("turfcolor", changeTurfColor) Compare with yours and maybe you find something more that isn't synced. Also try to download the latest version to make sure that there isn't more than this to change. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now