-
Posts
6,058 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
@Wozi I have moved your topic to tutorials, so that it is better preserved and easier to find. Good luck with your project!
- 1 reply
-
- 1
-
MTA useful functions do not exist unless they are added. See Code and expand the blue box 'Server- and/or clientside Script', there you can find the source code for that function. In that case I only recommend to post on your own language section. It saves some time for both of us. ?
-
Checkout this useful function: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
-
setPedStat ( thePlayer, 24, 1000 ) -- increase upper limit to max setElementHealth ( thePlayer, 200 ) -- fill to upper limit >> or spawn the player
-
Sounds like a synchronous data query, which is writing/reading a lot of data all at once. The real reason 'why' is with the developer...
-
Set it to 1000 ?
-
Default value is used to fill in specific columns when you have no value provided for them. Normally the default value is null, when nothing is provided. Solutions: https://stackoverflow.com/questions/41077044/mysql-can-not-insert-because-no-default-value
-
First of all it is important to understand that tables(arrays) in Lua do not start at index 0, they start at index 1. The pairs function does not always loop in order. (unreliable for looping in order) The ipairs function does, but does not start at 0, it just skips it. So if you want a loop starting at 0, the basic for loop is the best option to be honest.
-
https://wiki.multitheftauto.com/wiki/GetElementSpeed This useful function returns 1 speed value (based on x, y, z) What I explained is how the useful function works and how you can change it more or less from 3D(x,y,z) to 2D(x,y).
-
Normally you would get the direction vector X, Y: https://wiki.multitheftauto.com/wiki/Vector/Vector2 And get the length of it: .getLength() / .length This is the 3D variant (useful function): https://wiki.multitheftauto.com/wiki/GetElementSpeed And this would be the 2D variant: local speedX, speedY = getElementVelocity(theElement) -- element speed local speed = Vector2(speedX, speedY).length -- get the direction vector > get .length = direction speed
-
This is red: (cr == 255 and cg == 0 and cb == 0) -- red This is not red: not (cr == 255 and cg == 0 and cb == 0) -- not red if not (cr == 255 and cg == 0 and cb == 0) then end
-
You can build an ACL manager resource with MySQL. But it doesn't exist yet, so you have to build it yourself. And it is not quick job! Lots of things to take in consideration, especially security.
-
OOP (Object-Oriented Programming) is just a way to organize (Lua) code. Mostly used when working with a lot of entities/objects = things. But this option is not for enabling OOP in Lua, it is for enabling OOP in MTA (user-data). When enabled a lot of methods will available on the user-data of players, vehicles, peds etc. element:setPosition(x, y, z) -- MTA OOP setElementPosition(element, x, y, z) -- non MTA OOP Those methods are also available as functions, so basically it is an enhancement but not required in most cases. That is irrelevant, but feel free to count.
-
@greenops011 If the developer sets another resource as a dependency, then the <include /> tag should ? have been used in the meta.xml. https://wiki.multitheftauto.com/wiki/Meta.xml If not, then indeed as Fernando explains, the functions you should look for.
-
See useful function getPedGender for getting the gender. https://wiki.multitheftauto.com/wiki/GetPedGender (getPedGender and getSkinGender) As for the skins table: local maleSkins = skins[1] -- returns a table print(maleSkins[1]) -- first male skin local femaleSkins = skins[2] -- returns a table print(femaleSkins[1]) -- first female skin
-
Requiring a loop and a table. function generateRandomNumbers (count, maxSize) local randomNumbers = {} for i=1, count do randomNumbers[#randomNumbers + 1] = math.random(maxSize) end return randomNumbers end local randomNumbers = generateRandomNumbers(30, 10) -- Generate 30 random numbers. With a max value of 10 print(1, randomNumbers[1]) -- 1 <random number> print(5, randomNumbers[5]) -- 5 <random number> print(10, randomNumbers[10]) -- 10 <random number> print(30, randomNumbers[30]) -- 30 <random number>
- 1 reply
-
- 1
-
It is a bit tricky, but not impossible. And if the rotation is inverted, then invert the rotation. But yes, changing the engine is not possible, there will always be some limitations.
-
Not sure, but this is how you can get the camera rotation: local cameraElement = getCamera() -- local x, y, z = getElementRotation(cameraElement) --
-
onClientElementDataChange, that is if you do not mis use elementdata. For example setting element data every frame. If the event onClientElementDataChange is triggered more than ~5x each second (9 func calls x 1s vs ~2 func calls each update, 9 / 2 = ~5). The timer will be more optimised than the event. (9x with different element data key) But in general the timer has a slower update timing, which should also taken in consideration.
- 1 reply
-
- 1
-
I agree with XaskeL, clusters are the most efficient way of doing this. @Hydra Feel free to use this cluster library, which I am using for the airplane resource. Or find another library if the cells are too large, there should be more available. (this is size 31x31) local sourceMap = Cluster:new() --[[ SET ]] local cell = sourceMap:getCellFromWorldMap( x, y ) if cell then cell:setData( "key", "<mixing>" ) end --[[ GET using position ]] local centerCell = sourceMap:getCellFromWorldMap( x, y ) local cellCollection = sourceMap:getCellsBetweenCells( sourceMap:getCellFromSourceMap( centerCell.x - 1, centerCell.y - 1 ), sourceMap:getCellFromSourceMap( centerCell.x + 1, centerCell.y + 1 ) ) -- 9 cells returned (but can be less) -- LOOP: cellCollection cell:getData( "key" ) --
-
For the resource servertimesync, I am using this method to solve that problem. 1. I am using the function getServerTime to get the time, if available. local timeNow = exports.servertimesync:getServerTime() 2. If it not available, then I am also listening to the event "onServerTimeInitialized", which is triggered when the data is available. addEventHandler( "onServerTimeInitialized", root, function() end )
-
setElementDoubleSided(obj, true) https://wiki.multitheftauto.com/wiki/SetElementDoubleSided If the object is successful created, you can use this function to make the object doublesided.
-
You can reduce this code btw, by disable caseSensitive. bool addCommandHandler ( string commandName, function handlerFunction [, bool caseSensitive = true ] ) addCommandHandler("buy", detectPanel, false) As for your initial question. local zones_CScns = {["Jefferson"] = true} local zones_GTcns = {["Rodeo"] = true} --- ... if zones_CScns[gps] then CScns() elseif zones_GTcns[gps] then GTcns() end or -- !Order matters local zones --- ... local theFunc = zones[gps] if theFunc then theFunc() else -- do something else... end -- ... functions CScns and GTcns here zones = {["Jefferson"] = CScns, ["Rodeo"] = GTcns}
-
Like this. When adding a subscriber, the data will be automatic synced. Here you have a test resource to see the behaviour of all stages. Very recommended to test it out, so that you do not add too much code.
-
Calculating difference and using repeat until loop
IIYAMA replied to Dzsozi (h03)'s topic in Scripting
Step 1: Find ALL existing slots This method does not do that unfortunately. So you will have to create a new one. local carrySlots = self:findExistingItemSlots(itemID) Step 2: Fill those up. Step 3: Create new slots for the remaining items. Repeat until is fine. ? repeat local slotX, slotY = self:findFreeSlotForItem(itemID) if slotX then local countInsert = math.min(count, itemDetails.stacklimit) -- ... local newItem = { ["itemID"] = itemID, ["count"] = countInsert, ["slot"] = {x = slotX, y = slotY}, } count = count - countInsert -- ... end until count == 0 or not slotX Step 4: Return the items that do not fit, so that you can decide what to do with those. local remainingItems = object:giveItem(1, 8) if #remainingItems > 0 then iprint("items do not fit", #remainingItems) end