franku Posted August 16, 2016 Share Posted August 16, 2016 Sup guys, so before I get into the actual question, I'd like to tell you that I haven't scripted in almost a year and I just started like a week ago again. So what i'm asking is, I have this code here (Below) from a script I made 3 days ago, what I'd like to know is, how do I turn it into OOP? And throw a metatable in it, plus making use of it. And why is OOP useful and how? (If you'd like to help explaining, mind not linking me to different pages? explain using your own words please, that'd be easier for me to understand. ) Once I know why it's useful and how to use it, I'ma start using both OOP and metatables in future scripts of mine Code: function stopEvent( thePlayer ) local groupName = "EventManager" local zzz= getPlayerAccount( thePlayer ) if ( zzz) then local accName = getAccountName( zzz) if ( isObjectInACLGroup ( "user."..accName, aclGetGroup ( groupName ) ) ) then -- for k, thePlayer in pairs( getElementsByType( 'player' ) ) doe removeEventHandler( "onFreezFight", resourceRoot, freezHandlar ) removeEventHandler( "onFightStart", resourceRoot, spawnHandlre ) for _, thePlzzayer in pairs( getElementsByType( 'player' ) ) do takeAllWeapons( thePlzzayer ) setElementFrozen( thePlzzayer, false ) toggleControl ( thePlzzayer, "fire", true ) spawnPlayer ( thePlzzayer, xw, yw, zw ) end -- end outputChatBox( '[Event] Event has stopped.', localPlayer, 255, 0, 0, true ) end end end addCommandHandler( 'stopit', stopEvent ) Thank you. Link to comment
Simple0x47 Posted August 18, 2016 Share Posted August 18, 2016 Lua is not the right choice for making OOP, but no one is gonna remove you that right. I'd help you with it, but I'm on vacations :v add me on skype: killer.68x and I can give you a hand with it. Link to comment
Captain Cody Posted August 18, 2016 Share Posted August 18, 2016 If this helps at all https://wiki.multitheftauto.com/wiki/OOP_Introduction Link to comment
LabiVila Posted August 19, 2016 Share Posted August 19, 2016 So, I'll try to sum it up quickly, the advantage of OOP is that you don't have to rewrite the whole thing over and over like "normal" scripts do. Even tho OOP is much harder, once you get used to it you won't ever script in the "normal" way again. In the script you posted, if you turn it into OOP nothing would change but the syntax. It's the same stuff literary, but I have a very good example that progressed me very much. https://forum.multitheftauto.com/viewtopic.php?f ... le#p753385 a cool example of metatables and OOPs. Link to comment
Simple0x47 Posted August 19, 2016 Share Posted August 19, 2016 You've got to think where to use OOP and where to use the classic way. Using OOP in some cases make's the stuff unoptimized and larger. I like OOP but with limit in a language like Lua. 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