Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 20/02/22 in all areas

  1. Welcome to San Andreas Extreme Community(SAEC) About us: System User Control Panel (UCP): Help Panel (F3): Login Panel : Bank System: Ammunation Panel: Skillshop for weapon's Spawner's: HUD :
    1 point
  2. Hey @xTiinchosKy, information on how to appeal your ban can be found in the ban reason.
    1 point
  3. Thank you again! I will try to make and implement it! Really appreciate your time, have a nice day!
    1 point
  4. Yup, you can. local Highlight local HighlightConstructor do local register = {} -- depending were you want it. Highlight = { register = register } HighlightConstructor = { register = register } end function Highlight:new( element, style, color, flashSpeed, intensityOrThickness ) local register = self.register if register[element] then return end local data = { element = element, style = style, color = color, flashSpeed = flashSpeed, intensityOrThickness = intensityOrThickness } register[element] = data -- ... -- newHightlight = Highlight:new() iprint(Highlight.register) iprint(newHightlight.register)
    1 point
  5. Finally, thank you so much!! This is what I was looking for, I just couldn't figure out how to implement it, I already knew in my mind that I will have to make 2 tables for this. For some reason I thought I can make the 'update' and 'destroy' functions in the same table as the 'new' function, turns out I can't if I want to avoid bad things to happen. Now I have this setup at the beginning and it works fine as intended local Highlight = {} --Highlight.__index = Highlight -- I DONT THINK I WILL NEED THIS ANYMORE setmetatable(Highlight, {__call = function(_,...) return Highlight:new(...) end}) -- calling Highlight will call the Highlight:new method local HighlightConstructor = {} HighlightConstructor.__index = HighlightConstructor -- I NEED THIS INSTEAD playerHighlight.style returns given style, playerHighlight.new or playerHighlight:new doesn't work like I wanted to. Yes, I knew that, thank you for giving a heads up! I changed it from . to : because you did it that way as well in your response, I am not sure tho what difference it makes in this case. I mean it should make no difference right here, if I am correct, since I am not using self inside the Highlight:new method. Anyways thank you once again! I learned new stuff and I am happy for that, also I can finally finish this resource xd EDIT: By the way, can I get rid of CREATED_HIGHLIGHTS and make it part of Highlight table? Will it work with a Highlight = {created = {}} setup or something like this? Or should I just keep them seperate? Since I was thinking about making methods like Highlight.getAllByElementType and such so I can get every created highlight of vehicles for example.
    1 point
  6. You were almost there, you are doing great The trick here is to split of the constructor. So that your new table will only inherit methods from the constructor. local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor local CREATED_HIGHLIGHTS = {} local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor function HighlightConstructor:destroy() iprint( self, 'destroy' ) end --[[ function HighlightConstructor:test() iprint( self ) end ]] function Highlight:new( element, style, color, flashSpeed, intensityOrThickness ) if not isElement( element ) then return false end if CREATED_HIGHLIGHTS[element] then return false end local data = { element = element, style = style, color = color, flashSpeed = flashSpeed, intensityOrThickness = intensityOrThickness } return setmetatable( data, { __index = HighlightConstructor } ) end newHightlight = Highlight:new() newHightlight:destroy() Note keep in mind there is a difference in . and : calls, depending on the set-up. Just in case you didn't know, which you probably did know. test = {} test.a = function (self) -- first parameter iprint(self) end test.a() function test:b () iprint(self) -- already available. end test:b()
    1 point
  7. 1 point
  8. Can you try using the ignoredElement parameter processLineOfSight(px, py, pz, tx, ty, tz, true, true, true, true, true, false, false, false, localPlayer)
    1 point
  9. For more explanation, please read the comments I made in the scripts as well; I am sorry, but I don't really understand how should I change my code. Could you please provide me a solution for this? So I have a Highlight table, each time this table gets called, a new Highlight is being created for the given element variable (I would like to make it function like the default MTA OOP stuff, like Vehicle(model, position) instead of Vehicle.new(model, position), so I have this setup here: local CREATED_HIGHLIGHTS = {} local Highlight = {} Highlight.__index = Highlight setmetatable(Highlight, {__call = function(_,...) return Highlight.new(...) end}) function Highlight.new(element, style, color, flashSpeed, intensityOrThickness) if not isElement(element) then return false end if CREATED_HIGHLIGHTS[element] then return false end local data = setmetatable({}, Highlight) -- this has something else to do with it I guess -- set variables -- data.element = element -- and so on return data end And I have methods for it like Highlight:update() and Highlight:destroy(), the way I did it for example: function Highlight:destroy() if not CREATED_HIGHLIGHTS[self.element] then return false end if self.shader then self.shader:destroy() end CREATED_HIGHLIGHTS[self.element] = nil return true end When I create a new highlight for the localPlayer, like: local playerHighlight = Highlight(localPlayer, "outline", {255,0,0,255}, 0, 1) Now everything works fine above, highlight gets created, I can access the data with playerHighlight.thickness and such, BUT I can then use the playerHighlight table (which should contain only data, like style, thickness etc) to create a new highlight on a totally different element like: local dumpster = Object(1337, localPlayer.position + Vector3(0,3,1)) print(playerHighlight.new(dumpster, "fresnel", {100,200,255,255}, 2, 0.5)) -- returns table, I don't want to use .new here -- how can I make it return nil, or avoid calling of .new, but keep the :update() and :destroy() methods -- I would like playerHighlight to contain only the data given before Now I understand that the data table inherits from Highlight table at the Highlight.new function, so to the data table the methods get passed as well, but how should I change it so it won't inherit all the functions, I would like to access actual data and only methods with colon (:update, :destroy), not with dot (.new) . So my guess is that this line should be changed to something else instead of Highlight, I imagine local data = setmetatable({}, Highlight) -- change Highlight to what? Am I missing the creation of another table? Sorry if it looks like I am asking the same question twice, I am not ignoring your reply but I don't understand your explanation @IIYAMA, I mean I don't understand how should I implement it in this case.
    1 point
  10. 1 point
×
×
  • Create New...