MTA Team qaisjp Posted June 10, 2014 MTA Team Posted June 10, 2014 (edited) Hey, I've created a sweet introduction into using the object orientated features of MTA coming soon in MTA 1.4. I hope you enjoy it If you've contributed by editing and tweaking the wiki page, if you've benefited from this tutorial, or if you have anything to say; please give me feedback on here Enjoy. Edited September 27, 2014 by Guest
xXMADEXx Posted June 11, 2014 Posted June 11, 2014 I can't wait for OOP to be implied to MTA The Ultimate Lua Tutorial! | MTA PHP SDK
JR10 Posted June 17, 2014 Posted June 17, 2014 It would be better if you could link to the OOP Wikipedia page, it describes OOP in a more detailed way. Nice work! Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
'LinKin Posted June 19, 2014 Posted June 19, 2014 Oh oh.. OOP in MTA.. Finally, I can keep practicing what I learnt 3 semesters ago After boring structurated programming, OOP is comming. It is a really great improvement for programmers a.k.a scripters Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
xXMADEXx Posted June 19, 2014 Posted June 19, 2014 Oh oh.. OOP in MTA.. Finally, I can keep practicing what I learnt 3 semesters ago After boring structurated programming, OOP is comming. It is a really great improvement for programmers a.k.a scripters Yes, but unfortunately it won't be here for a while. It's scheduled to be here in 1.4. The Ultimate Lua Tutorial! | MTA PHP SDK
'LinKin Posted June 19, 2014 Posted June 19, 2014 Wasn't 1.4 coming soon? Then I read something wrong somewhere, lol. Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
xXMADEXx Posted June 21, 2014 Posted June 21, 2014 (edited) Wasn't 1.4 coming soon?Then I read something wrong somewhere, lol. Well of course adventively it'll be here, but it will take time. Edit: The MTA 1.4 beta release was released on June 21st Edited June 23, 2014 by Guest The Ultimate Lua Tutorial! | MTA PHP SDK
MTA Team botder Posted June 22, 2014 MTA Team Posted June 22, 2014 I dont know if I used the OOP as it is right now properly, but the class Connection doesn't seem to work as it should GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
Castillo Posted June 23, 2014 Posted June 23, 2014 I believe there's a small typo in that page: local vehicle = createVehicle(411, 0, 0, 3) vehicle:setDamageProof(vehicle) -- Here vehicle:setFrozen(vehicle) -- Here vehicle:setHealth(1000) vehicle:setVelocity(0.2, 0.2, 0.2) vehicle:destroy() San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Snow-Man Posted June 24, 2014 Posted June 24, 2014 what the different between Lua and OOP ? USC Informations Head Staff & Owner Of USC. Youtube Channel : My Channel
xXMADEXx Posted June 24, 2014 Posted June 24, 2014 what the different between Lua and OOP ? OOP is Lua, it's just introducing classes and that kind of stuff. Here's an example of the differences: Non-OOP Lua function giveRandMoney ( ) local p = getRandomPlayer ( ) givePlayerMoney ( p, 100 ) end OOP Lua (I'm guessing giveMoney is in the player class, but im not sure) function giveRandMoney ( ) local p = Player.getRandom ( ) p:giveMoney ( 1000 ) end It's somewhat just how the scripter wants to write, but if they program in any other languages then they're going to want to do OOP because most programming languages such as C, C++, PHP, etc... are all OOP. The Ultimate Lua Tutorial! | MTA PHP SDK
Snow-Man Posted June 24, 2014 Posted June 24, 2014 @Made, Player remplace getElementsByType("player") in OOP Lua ? USC Informations Head Staff & Owner Of USC. Youtube Channel : My Channel
xXMADEXx Posted June 24, 2014 Posted June 24, 2014 @Made, Player remplace getElementsByType("player") in OOP Lua ? No, it's a class of functions (or a table as known in Lua) For example, you could write this: for i, v in pairs ( Player ) do outputChatBox ( tostring ( i ).." -> "..tostring ( v ) ) end To output all of the functions in the Player class/table. The Ultimate Lua Tutorial! | MTA PHP SDK
Snow-Man Posted June 24, 2014 Posted June 24, 2014 @Made, Player remplace getElementsByType("player") in OOP Lua ? No, it's a class of functions (or a table as known in Lua) For example, you could write this: for i, v in pairs ( Player ) do outputChatBox ( tostring ( i ).." -> "..tostring ( v ) ) end To output all of the functions in the Player class/table. thanks USC Informations Head Staff & Owner Of USC. Youtube Channel : My Channel
MTA Team botder Posted June 24, 2014 MTA Team Posted June 24, 2014 Is there any reason why I can't save data into any element directly (without setData), e.g. player.myvariable = true ? GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
'LinKin Posted June 24, 2014 Posted June 24, 2014 Guys, is there a Wiki page for MTA OOP? Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
Arnold-1 Posted June 25, 2014 Posted June 25, 2014 Guys, is there a Wiki page for MTA OOP? https://wiki.multitheftauto.com/wiki/OOP Ingame Name: Arnold If you need my help, contact me on Skype @bshr.ara NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP
MTA Team qaisjp Posted June 26, 2014 Author MTA Team Posted June 26, 2014 Thanks guys! Guys, is there a Wiki page for MTA OOP? I'm not quite sure what to put on the page, but I'll link some extra useful links on there. Is there any reason why I can't save data into any element directly (without setData), e.g. player.myvariable = true ? You may want to try this, but I'm going to try to convince the devs to make this possible. However, it wouldn't be applied to element data - something like player.data["myvar"]=value may be done instead. I believe there's a small typo in that page: local vehicle = createVehicle(411, 0, 0, 3) vehicle:setDamageProof(vehicle) -- Here vehicle:setFrozen(vehicle) -- Here vehicle:setHealth(1000) vehicle:setVelocity(0.2, 0.2, 0.2) vehicle:destroy() Ah! Thanks. The procedural code was wrong too (I missed out the boolean values for the functions, so this is probably why the OOP counterpart was incorrect too!)
diesel974 Posted June 27, 2014 Posted June 27, 2014 A small typo : There are children of classes, for example, with players, the system goes like: Element -> Ped -> Player". All Players are Peds and all Peds are Players. Not all Peds are Players, and certainly not all Elements are Players. all Peds are Players. Not all Peds are Players I believe it should have been : all Peds are Elements Thank you for the tutorial gentleman. Have a nice day! Be Kind Skype: darkwarrior.diesel
'LinKin Posted August 9, 2014 Posted August 9, 2014 Is it possible to create a bean? - Like a class having some attributes; Example: class Player{ private nick; private kills; private cash; } and then being able to do something like aPlayer.setNick(hisNick); Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
RottenFlesh Posted August 10, 2014 Posted August 10, 2014 Is it possible to create a bean? - Like a class having some attributes; Example: class Player{ private nick; private kills; private cash; } and then being able to do something like aPlayer.setNick(hisNick); If you have a player variable, you can do something like this: function command(player) player.name = "something" outputChatBox(player.name) player.money = 100 end addCommandHandler("blah", command) But they are predefined by MTA, you can not create your own, unless you make your own implementation of OOP in lua using tables and metatables. We are slowly documenting the OOP syntax in wiki. i've already documented almost every server-side player functions by myself. https://wiki.multitheftauto.com/wiki/Server_Scripting_Functions#Player_functions There, you will see something like this: [b]OOP Syntax[/b] [b]Method[/b]: player:getName() [b]Variable:[/b] .name [b]Pair:[/b] setPlayerName It means you can do things like this: function some_random_function(player) local name = player:getName() -- element -> "player"; method -> ":getName()" local name = player.name -- ".name" is just short for getPlayerName() -- And the pair function is used when you have a variable like the one above and you set a value to it. player.name = "something" -- in this case you are not calling getPlayerName(), but setPlayerName() is used instead. end There is also methods and variables that are declared under some object Class. Like this: function some_other_random_function() Player.getRandom() -- "Player", is a class that contains all player methods and variables, and ".getRandom()" is one of those methods. Player.random -- This is just a short form of the above. Both valid. end I hope you understand what i said, English is not my native language
'LinKin Posted August 10, 2014 Posted August 10, 2014 Yes I understood. So it's not possible to make what I asked, alright. Thanks for the information. Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
RottenFlesh Posted August 10, 2014 Posted August 10, 2014 Nonono! It is totally possible, you just have to implement it yourself. Read this: http://lua-users.org/wiki/ObjectOrientationTutorial This is how you can implement OOP by yourself, with classes and inheritance and everything.
'LinKin Posted August 10, 2014 Posted August 10, 2014 Ahhh! Thank you. Need a clanwar script? Click here! Do you want some free scripts for your DD server? Visit my website.
Recommended Posts