Jump to content

Sorata_Kanda

Members
  • Posts

    76
  • Joined

  • Last visited

Everything posted by Sorata_Kanda

  1. Looks a bit complex to me but I'll take a deeper look later on. My idea behind this Race class was to sort of make a Race element, which inherits the function of the element itself, and functions like setTitle can be used. But inheritance in MTA OOP looks a bit messy.
  2. Do you define your classes the same way as I do? I gave it a try to use MTA OOP classes and thus learned how to use OOP in Lua. It's sort of syntactic sugar, but OOP doesn't work the way I thought it would. Maybe because I store those objects in element data and some strange magic happens.
  3. Is there a predefined variable to specifically set resource root map elements? If I do something like this in my resource: setElementDimension(resourceRoot, -1) Wouldn't it also change any other elements' (vehicles created by resource etc.) dimension to -1 as well?
  4. Hmm, I get a bad feeling when using OOP. It's not the same in lua as in e.g. Java. Maybe that's because first of Lua wasn't made for this and second of, you got client side and server side, which can't be able to share OOP objects.
  5. setElementData doesn't change self.title. I stored the Race object in its element. (see line 14 first code block) However, when changing the title and grabbing the race object from Race element with getElementData again, nothing changes. So basically, you can't edit a table's value when it's stored as elementData, right?
  6. Hey everyone! So there is something that I noticed while working in OOP-style with setElementData and getElementData. Imagine you have something like this: Race = {} Race.__index = Race function Race.new() local self = setmetatable({}, Race) self.title = 'Great 8-Track' self.laps = 10 self.element = Element('race', 'Race 1') self.checkpoint = Marker(...) self.checkpoint:setParent(self.element) self.element:setData('sourceobj', self) return self end function Race:setTitle(string) self.title = string end function Race:getTitle() return self.title end function Race:getCheckpoint() return self.checkpoint end After pushing an instance of Race through some events (let's say from server -> client -> server), you'd like to change the title (i. e. you changed the title of the race through a GUI): addEvent('races-updateTitle', true) function updateTitle(raceObj, title) Race.setTitle(raceObj, title) end addEventHandler('races-updateTitle', resourceRoot, updateTitle) Something strange I've noticed is that when updating with Race.setTitle(...), checking the title afterwards with Race.getTitle(...) shows my changes correctly, while checking the title like this: addEvent('races-updateTitle', true) function updateTitle(raceObj, title) Race.setTitle(raceObj, title) iprint(tostring(Race.getCheckpoint(raceObj):getParent():getData('sourceobj'))) end addEventHandler('races-updateTitle', resourceRoot, updateTitle) just shows the old state before changing the title. Is this the way how OOP seem to behave or am I handling this stuff wrong? Because when simply using setElementData and getElementData on my Race element (not Object), everything works fine. Thanks in advance!
  7. Or: Set something like this in case you don't like localPlayer as a variable name: local me = getLocalPlayer() -- This should work as well local me = localPlayer
  8. Thought about loading client scripts when and then remove them. Dunno if it's effective enough.
  9. @Tails Wow, thanks. I'll try that out. Did you always use this when using OOP or did you go back to "normal" scripting?
  10. @IIYAMA Can you do it like this? -- In resource 'myOOP' MyOOPClass = {} -- ... some code with function declarations ... function getOOPClass() return MyOOPClass end -- in another "resource" loadstring(exports.myOOP:getOOPClass)
  11. I sort of made my own 'staff system', but I'm a little bit unhappy with it, as I have to export all functions I need to in order check if a player is an admin or not. Furthermore, I'm not sure if having MTA account + ACL would create a security risk as the permissions are rather tied to a MTA account instead of my custom account system, thus making it possible for someone to steal credentials of the MTA account without having them additionally logged in into the account that is associated with the MTA account to be stolen. Guess I need to take a look at ACL. Maybe you can revoke permissions for normal players to log in into MTA accounts, as they don't need to do it.
  12. Hello everyone, I stumbled across several topics about exporting OOP stuff. I'm wondering if you're still not able to export OOP classes as the date of creation was 2 years ago and things might have changed. Just got somewhat familiar with OOP in MTA. Sadly, if you're not able to export those classes, it is somewhat useless to implement stuff with OO style Thanks in advance!
  13. My problem is that I probably have to rely on MTA's account system if I really want to use ACL. It seems practical, but I don't know if it's ideal to stick to MTA's account system. Something that I don't know is if I'm able to sync them to my database.
  14. @IIYAMA Well, seems like I have fixed it. I think it didn't work out quite well because the kind of formats I used were still saved in my database, thus failing to be parsed wrong. Oh, and thanks for the tip with iprint. I'll take a look at that. /close
  15. I did a sort of a "serializer/deserializer" too, but I don't really understand how the concatation on fromJSON(...) Following example: local json = "[\"[123, 1, 3]\"]" outputDebugString(tostring(fromJSON(json)) -- Delivers [123, 1, 3] local x, y, z = fromJSON(json) -- Results in nil values -- But ... for k, v in ipairs(fromJSON(json)) do outputDebugString(k .. " " .. v) --[[ Delivers... 1 123 2 1 3 3 ]] end -- I also tried this local jsonTbl = fromJSON(json) outputDebugString(jsonTbl[1] .. " " .. jsonTbl[2] .. " " .. jsonTbl[3]) -- Results in error due to nil value On the wiki page, it shows that it's supposed to work like I did with local x, y, z ...
  16. Hey everyone, as far as I know, creating Vector3() is just basically a table containing x, y, z, isn't it? If so, why can't you just use toJSON(Vector3()) in order to convert it to JSON so you can store it in a database? Thanks in advance!
  17. Gonna take a look at that. Thanks for your response!
  18. Hey everyone, while working on my project again, I stumbled upon ACL. Seems like a good thing, but I'm not sure whether to really use it or like use a custom-made permission system. (Especially as certain actions are tied to admin ranks which are stored in MySQL) What can you recommend? Thanks in advance!
  19. If you want to change the GTA time, you can simply use bool setTime ( int time, int minutes ) In case you want to freeze the time, you need to attach it to onClientRender like this: addEventHandler('onClientRender', root, function () setTime( hours, minutes ) -- Please replace 'hours' and 'minutes' with the value you want the time to freeze in. end ) If you just want a Day cycle, you probably have to use if-checks to the point when the time should be changed back to noon or morning.
  20. I do use db* function, but the point of putting everything in one resource is not to create multiple database connections throughout multiple resources. Therefore you have one single resource handling MySQL stuff. But I didn't really notice any performance impact when using exported function. Also, why should I use a callback function instead of a -1? @Pirulax
  21. I do use the db functions too, but I'm sort of worried that my meta.xml turns to a mess due to the amount of functions I export.
  22. Hey everyone, as the title might tell you, I'm wondering what's more efficient: Having a single MySQL resource handling all the MySQL work and have something like a MySQL script in each of my scripts where I need it? At the moment, I use a single MySQL resource which manages all the MySQL stuff, but I'm not sure if that's the right way or not. It manages really everything related to MySQL where required: admin system, ticket system, etc. What's your opinion on that? Thanks in advance!
  23. Appearently, you are not supposed to set a formatting on TIMESTAMP. Which means, you simply have to use this command: CREATE TABLE `testrole`.`characters` ( `lastLogin` TIMESTAMP NOT NULL ) ENGINE = InnoDB
  24. x, y, size = -2095.97632, -280.48669, 120 local greenzone = createColRectangle ( -2095.97632, -280.48669,85, 200) local greenzonemaparea = createRadarArea (-2095.97632, -280.48669,85, 200, 255,215,0, 120) function greenzoneEnter ( thePlayer, matchingDimension ) if getElementType( thePlayer ) ~= "player" then return end if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Owner"))) then outputChatBox ( "* You Entered The VIP Vehicle recover Area", thePlayer, 0, 255, 0 ) toggleControl ( thePlayer, "fire", false ) toggleControl ( thePlayer, "next_weapon", true ) toggleControl ( thePlayer, "previous_weapon", true ) setPedWeaponSlot ( thePlayer, 0 ) toggleControl ( thePlayer, "aim_weapon", false ) toggleControl ( thePlayer, "vehicle_fire", false ) toggleControl ( thePlayer, "vehicle_secondary_fire", false ) else outputChatBox("exit your not allowed here xd leave madafaker",root,255,0,0) end end addEventHandler ( "onColShapeHit", greenzone, greenzoneEnter ) function greenzoneExit ( thePlayer, matchingDimension ) if getElementType( thePlayer ) ~= "player" then return end outputChatBox ( "* You Left The VIP Vehicle recover Area", thePlayer, 0, 255, 0 ) toggleControl ( thePlayer, "fire", true ) toggleControl ( thePlayer, "next_weapon", true ) toggleControl ( thePlayer, "previous_weapon", true ) toggleControl ( thePlayer, "aim_weapon", true ) toggleControl ( thePlayer, "vehicle_fire", true ) toggleControl ( thePlayer, "vehicle_secondary_fire", true ) end addEventHandler ( "onColShapeLeave", greenzone, greenzoneExit ) Just as a tip: Try to keep your code clean and intented. Makes it much more readable and easier to spot errors like <eof>
  25. Or <!-- Open up the mtaserver.conf and look at the bottom of the script. You can either way just delete the line, replace or simply surround it with the comment tag of XML. See below. --> <resource src="play" startup="1" protected="0" /> <!-- ... turns to ... --> <!-- <resource src="play" startup="1" protected="0" /> -->
×
×
  • Create New...