ParadoxTR Posted May 29, 2016 Share Posted May 29, 2016 I make turf system. I need help. Warning;(line 17) function TurfAktif(player) local PlayerClan = getElementData(player,"Clan") if not getElementData(resourceRoot,"ClanTurf1") then setElementData(resourceRoot,"ClanKisi",getElementData(resourceRoot,"ClanKisi")+1) setElementData(resourceRoot,"ClanTurf1",tostring(PlayerClan)) setRadarAreaFlashing ( Turf1Rectangle, true ) local t1 = setTimer(function() if getElementData(player,"Turf1")==true then TurfPercent = TurfPercent+10 _outputChatBox("Turf Yüzdesi: %"..TurfPercent.."", player, 0, 255, 0, true ) if TurfPercent >= 100 then _outputChatBox("Turf Yüzdesi: %100 | Turfu Kazandınız", player, 0, 255, 0, true ) setRadarAreaFlashing ( Turf1Rectangle, false ) setElementData(resourceRoot,"ClanTurf1",tostring(PlayerClan)) setElementData(resourceRoot,"Clan2Turf1","Bos") setElementData(resourceRoot,"WinnerClan",tostring(PlayerClan)) killTimer(t1) return end end end,5000,0) elseif getElementData(resourceRoot,"Clan2Turf1")=="Bos" then setElementData(resourceRoot,"Clan2Kisi",getElementData(resourceRoot,"Clan2Kisi")+1) setElementData(resourceRoot,"Clan2Turf1",tostring(PlayerClan)) setRadarAreaFlashing ( Turf1Rectangle, true ) local t2 = setTimer(function() if getElementData(player,"Turf1")==true then TurfPercent = TurfPercent+10 _outputChatBox("Turf Yüzdesi: %"..TurfPercent.."", player, 0, 255, 0, true ) if TurfPercent >= 100 then _outputChatBox("Turf Yüzdesi: %100 | Turfu Kazandınız", player, 0, 255, 0, true ) setRadarAreaFlashing ( Turf1Rectangle, false ) setElementData(resourceRoot,"ClanTurf1",tostring(PlayerClan)) setElementData(resourceRoot,"Clan2Turf1","Bos") setElementData(resourceRoot,"WinnerClan",tostring(PlayerClan)) killTimer(t2) return end end end,5000,0) elseif getElementData(resourceRoot,"ClanTurf1")==tostring(PlayerClan) then setElementData(resourceRoot,"ClanKisi",getElementData(resourceRoot,"ClanKisi")+1) elseif getElementData(resourceRoot,"Clan2Turf1")==tostring(PlayerClan) then setElementData(resourceRoot,"Clan2Kisi",getElementData(resourceRoot,"Clan2Kisi")+1) end end Please Help! Link to comment
ViRuZGamiing Posted May 29, 2016 Share Posted May 29, 2016 if isTimer(t1) then killTimer(t1) end same goes for t2 Link to comment
ParadoxTR Posted May 29, 2016 Author Share Posted May 29, 2016 I made it but same warning. Link to comment
Moderators Citizen Posted May 29, 2016 Moderators Share Posted May 29, 2016 I made it but same warning. You didn't save or restarted your resource. The warning should have gone.BUT ! The problem here is that the t1 variable is not available inside of the scope of the anonymous function the timer is calling (it's another fuction and is then called outside of TurfAktif function. Same goes for player and PlayerClan variables but those variables can be sent with the setTimer (but t1 can't as a setTimer can't send itself to the function it is calling. Here is the fix for t1 (I let you do the same for t2): (Please read my comments in the correct order to understand the modifications I made. Numbers are going from 1. to 9.) function TurfAktif(player) local PlayerClan = getElementData(player,"Clan") if not getElementData(resourceRoot,"ClanTurf1") then setElementData(resourceRoot,"ClanKisi",getElementData(resourceRoot,"ClanKisi")+1) setElementData(resourceRoot,"ClanTurf1",tostring(PlayerClan)) setRadarAreaFlashing ( Turf1Rectangle, true ) local t1 = setTimer(function(player, PlayerClan) -- 3.I'm receving player and PlayerClan the setTimer sent -- 4.Here player and PlayerClan has values thanks to the setTimer extra arguments local t1 = getElementData(player, "t1_timer") -- 5.getting the timer from the player's element data -- 6.Here t1 is has a value and is the timer you created if getElementData(player,"Turf1")==true then TurfPercent = TurfPercent+10 _outputChatBox("Turf Yüzdesi: %"..TurfPercent.."", player, 0, 255, 0, true ) if TurfPercent >= 100 then _outputChatBox("Turf Yüzdesi: %100 | Turfu Kazandınız", player, 0, 255, 0, true ) setRadarAreaFlashing ( Turf1Rectangle, false ) setElementData(resourceRoot,"ClanTurf1",tostring(PlayerClan)) setElementData(resourceRoot,"Clan2Turf1","Bos") setElementData(resourceRoot,"WinnerClan",tostring(PlayerClan)) if isTimer(t1) then -- 7.Making sure it's a valid and a still running timer killTimer(t1) end return -- 8.this return is useless end end end, 5000, 0, player, PlayerClan) -- 1.I'm sending player and PlayerClan variables to the function -- 2.Here t1 is defined and now I can ... setElementData(player, "t1_timer", t1) -- ... save it into the player element using an element data elseif getElementData(resourceRoot,"Clan2Turf1")=="Bos" then -- 9.Do the same for t2 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