-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
A small example/hack to rotate (multiple) vehicles. With very little code. This code is untested local rotationElement = createElement("rotationElement") local duration = 1000 addEventHandler("onClienRender", root, function () setElementRotation(rotationElement, 0,0, (getTickCount() % duration) / duration * 360 ) end) local vehicle1 = createVehicle(--[[ fill in]]) setElementParent(vehicle1, rotationElement) local vehicle2 = createVehicle(--[[ fill in]]) setElementParent(vehicle2, rotationElement) local vehicle3 = createVehicle(--[[ fill in]]) setElementParent(vehicle3, rotationElement) setElementFrozen(rotationElement, true)
-
You can also change the rotate (velocity) with this function: https://wiki.multitheftauto.com/wiki/SetElementAngularVelocity But for exact 360, you will need the setElementRotation function. It just depends on what you are going to make.
-
Correct. This section has as start point "learning how to code", which is for everyone to make use of. So private code and requests(like this one without code) will not fit in this section.
-
Incorrect MySQL syntax, see here an insert example. https://www.tutorialspoint.com/mysql/mysql-insert-query.htm SET is afaik for variables.
-
Yup. if args[1] == "success" then if minigameData.successEvent then triggerEvent(minigameData.successEvent, localPlayer, unpack(minigameData.customData)) end else if minigameData.failEvent then triggerEvent(minigameData.failEvent, localPlayer, unpack(minigameData.customData)) end end From saving minigameData.customData = {select(5, ...)} to loading + unpacking as arguments. unpack(minigameData.customData)
-
This is a bit complex. Note: ... = leftover parameter that doesn't have variables to store in. Doesn't matter how much arguments you pass in to the function. function functionName (parameter1, parameter2) end functionName(argument1, argument2) -- calling the function There are the first 3 parameters:(line 1) (gameType, successEvent, failEvent, ...) This table(arguments) will collect all leftover parameters: (line 4) local args = {...} After: gameType, successEvent, failEvent From those leftover parameters, until the 4e are used for something. (line 17) minigameData.maxButtonNum = args[4] or 75 If we want to be able to save everything after parameter 4. We can use the select function. print(select(5,"arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9","arg10")) Run this code here, to see how it works: https://www.Lua.org/cgi-bin/demo So what you need to do, is modifying it, so that it saves data in the minigameData. The function select, will select from a specific index (5) it's item and all items that come after that. minigameData.customData = {select(5, ...)} Add it for example on line 10. In your code: startMinigame("balance", "successPlayerHelpup", "failedPlayerHelpup", 1, 10000, nil, nil, playerSource, "you can add here something else", "etc...") Arguments 1. "balance", 2. "successPlayerHelpup", 3: "failedPlayerHelpup" ... 4 | 1: 1 5 | 2: 10000 6 | 3: nil 7 | 4: nil 8 | 5: playerSource < saving from here. 9 | 6: more? The thing left to do, is sending it with the triggerClientEvent. But that code is not visible for me.
-
You go from your code. To the Minigame code And back to Your code But currently your target player, is not passed in to the minigame. See: exports.s_minigames:startMinigame("balance", "healSuccess", "healFailed", 1, 10000) There is no sourcePlayer included in to the export. Which means it is not available there and also not available to where you want to re-use that specific player. So what you need to figure out is the syntax of this export function and if it allows you to add your own data to it. If not, then you need to modify it, so that it does: Yes We Can.
-
A lot more than exports yes. Events are global. But that doesn't mean they are bad. They can be very useful for `events`. But if you can use exports, those can handle really a lot of data. If you observe those closely, you could even write your own event scope based on exports. The main issues lie with: Propagation (while triggering) Like you do this: setElementPosition(root, 0,0,0) This will move every possible element to 0,0,0. Players, vehicles, objects, peds, elements without physics. And for triggerServerClient event, no it probably doesn't send multiple messages (I hope lol). But it does go over every element. This might give the lowest impact. Not sure if propagation will help if there are no children, but at least it will not search for children. local element = createElement("triggerElements", "resource-" .. getResourceName(getThisResource())) setElementCallPropagationEnabled ( element, false) With the amount of listeners. The longer this list the longer it takes. (depending on the context)
-
This is a loop, it goes trough all items, in this case all players. And can be stopped with the keyword break or return. What if you add another export function, for the call : (The only strange thing about it is that in the orginal code the slot id is not being used. Could itemsTable be a meta table?) function hasItemAndData1(sourceElement, itemId, data1) if itemsTable[sourceElement] then for k, v in pairs(itemsTable[sourceElement]) do if v.itemId == itemId and v.data1 == data1 then return v end end end return false end
-
Are you telling me that there is no function for? Maybe search a little bit more? local ownerId = tonumber(getElementDatabaseId(player)) local ownerType = getElementType(player) -- "player" if ownerId then end query should look a bit like this. SELECT data1 FROM items WHERE itemId = 43 AND ownerId = ? AND ownerType = ? LIMIT 1
-
No. The bug is caused, because you are only storing the phonenumber. But not using it when checking if the number is matching. Where in this code do you see that value is used? function hasItem(sourceElement, itemId) if itemsTable[sourceElement] then for k, v in pairs(itemsTable[sourceElement]) do if v.itemId == itemId then return v end end end return false end I do not see it. Only matching the itemid, which is not the value. Is there perhaps this function: getItemValue ?
-
exports.s_inventory:hasItem(v, 43, number) function hasItem(sourceElement, itemId) The number is not being used. How does the giveItem looks like? One thing that could work is: exports.s_inventory:giveItem(playerSource, "phoneNumber-" .. tostring(tonumber(phoneID)), 1) if v and number and exports.s_inventory:hasItem(v, "phoneNumber-" .. tostring(tonumber(number))) then
-
This goes wrong. It seems like Jeff has an item with the selected number. Make sure to check the syntax of this function, the function itself and his data in the database.
-
Add local in front of it, it should be scoped. local targetPlayer = callMember(number) With other words the callMember function does not work correctly. Go debug it! It is not an MTA function, so you will have to search for it in your files.
-
Is the callMember function not broken then? Or is the number incorrect? Debug this! This loop makes no sense. What if there are accidentally two phones with the same number? for k, v in ipairs(checkID) do Limit the query "SELECT * FROM phones WHERE number = ? LIMIT 1" And get only the first result: if #checkID == 1 then local v = checkID[1]
-
Send the message to the root. Which includes all players.(currently ingame) triggerClientEvent(root, "showMenu",
-
That is line 5 for us. If table is higher than 0? OR If table item count is higher than 0? if #result > 0 then
-
You will need triggerClientEvent for that. exports only work on the same client/server-side. Server (resource 1) triggerClientEvent (source, "fill in eventName", source, itemValue) Client (resource 1) It is important to place the addEvent on the resource that is triggering, this reduces errors: "event isn't added" addEvent("fill in eventName", true) Client (resource 2) addEventHandler("fill in eventName", localPlayer, showPhoneFunction, false)
-
localPlayer doesn't exist on serverside. It only exist on your own MTA san application, which is clientside. You need to define which player is going to receive the message on serverside. You wrote two times lang1. You forgot to write a fallback when no language is selected. local language = getElementData(source,"language") if not language or language == lang1 then outputChatBox("#FFFFFF "..nickA.. " #00CC40killed #FFFFFF ["..kills.."] #00CC40players!", source,255,0,0,true) elseif language == lang2 then outputChatBox("#FFFFFF "..nickA.. " #00CC40zabil #FFFFFF ["..kills.."] #00CC40hračov na CW!", source,255,0,0,true) end
-
You are already using elementdata, in the most possible global way. So the selected language is also available there.
-
Is it just me being blind or are you making a call from serverside to clientside? (Which is not allowed)
-
Debug the export list and see if the resource can be found. iprint(exports["s_phone"]) Else as I said before, use the call function. That one has never failed for me without a logic error.
-
You could save it in to an XML file > clientside There is a resource that does that automatic for you: https://community.multitheftauto.com/index.php?p=resources&s=details&id=16187 Including a wiki guide: https://wiki.multitheftauto.com/wiki/XmlSaveData No need for saving such data in to a database, as the user wants to have this info when he joins and not when he logins.
