-
Posts
6,089 -
Joined
-
Last visited
-
Days Won
216
Everything posted by IIYAMA
-
I honestly do not understand why people add so many addEventHandlers, one on the parent is enough. local peds = { -- {model, x, y, z, rotZ, animblock, animname} {287, 1877.8, -2291.6, 13.6, 88, "SHOP", "SHP_serve_loop"}, {287, 1878.3, -2288.5, 13.6, 58, "SHOP", "SHP_serve_loop"}, {287, 1878.4, -2294.7, 13.6, 112, "SHOP", "SHP_serve_loop"}, {61, 1883.36, -2291.3, 13.6, 273.25, "COP_AMBIENT", "coplook_loop"}, } local pedsParent = createElement("pedsParent") local id = {} -- do not edit this table local function spawnPed(data, index) local p = createPed(data[1], data[2], data[3], data[4], data[5]) -- spawn ped with model, x, y, z and rotZ setPedAnimation(p, data[6], data[7]) -- set the ped's animation (you might want to change this into a setTimer statement if the animation doesn't apply correctly) setElementParent(p, pedsParent) id[p] = index -- save the ped's key of the table (so we can find his data) end local function handleRespawn() -- source: the ped that died -- id[source] = the key/id of the ped that died -- peds[id[source]] = data on the ped's key/id local index = id[source] if index then id[source] = nil -- clean up! Important, else data leak! local data = peds[index] -- find the ped's data if data then setTimer(destroyElement, 1000, 1, source) -- destroy ped after 1s setTimer(spawnPed, 1500, 1, data, index) -- use our cusom function to spawn ped after 1.5s end end end addEventHandler("onPedWasted", pedsParent, handleRespawn) -- attach handler for respawning -- initialize for i, ped in ipairs(peds) do -- iterate through all ped data spawnPed(ped, i) -- use our custom function to spawn ped end (credits to MrTasty)
-
Debug your code properly. And make sure you enable screenshot upload in you MTA settings.
-
Wiki: https://wiki.multitheftauto.com/wiki/PlaySound3D Creates a sound element in the GTA world and plays it immediately after creation for the local player. setElementPosition can be used to move the sound element around after it has been created. Remember to use setElementDimension after creating the sound to play it outside of dimension 0. Possible solution: local sound = playSound3D(MusicLink,Playerx,Playery,Playerz,true) local customMusicElement = createElement("customSoundElement") setElementParent(sound, customMusicElement) setElementParent(customMusicElement, MusicPlayer) addEventHandler("onClientRender", root, function () local customMusicElements = getElementsByType("customMusicElement", resourceRoot) for i=1, #customMusicElements do local customMusicElement = customMusicElements[i] local player = getElementParent(customMusicElement) if player then local soundElement = getElementChild(customMusicElement, 0) if soundElement then local x, y, z = getElementPosition(player) setElementPosition(soundElement, x, y, z) end end end end) It is a shame that not many people are using the element tree, since it saves you a lot table cleaning trouble.
-
Server side variables, on clientside, under onClientRender()?
IIYAMA replied to TrickyTommy's topic in Scripting
function RecieveDatas(BoolTeam_, BoolChar_) if BoolChar_ then BoolTeam = BoolTeam_ BoolChar = BoolChar_ end end Parameters are local variables. They can't leave the function block. A simple underline _ after the variable makes it a different variable. function functionName(parameter1, parameter2) -- function block end -
Reading(+decrypting) and loading of the scripts takes probably much longer.
-
If you are not inside a vehicle, there is no vehicle you can point at. To solve that issue: local vehicle = getPedOccupiedVehicle ( player ) if vehicle then -- the rest of the code end -------------------------------------------------- -------------------------------------------------- local vehicle = getPedOccupiedVehicle ( source ) if vehicle then -- the rest of the code end function czest(player,CommandName,wartosc) tonumber(wartosc) czas = wartosc end addCommandHandler("hz", czest) function czest(player,CommandName,wartosc) wartosc = tonumber(wartosc) if wartosc then czas = wartosc end end addCommandHandler("hz", czest)
-
There was something strange about the <load> function. Afaik it didn't work for me because of some sort of security(MTA) problem. But that was a while ago, so it might be changed over time. Well, try first figure out where you crash starts. Probably line: 16 or 22 (Your default code) Run this. Write /doit and after that /testNext until your MTA starts to crash. local filePath = ":theScript/temporalCache/mapTest/water.lua" function hold (reason) iprint("Code pauses, reason:", reason) coroutine.yield() end local coroutineOfscriptReadaa function scriptReadaa() hold("Called function scriptReadaa") local file = fileOpen(filePath) if not file then error("Error opening File.") return end hold("File file is open") local data data = fileRead(file, fileGetSize(file)) hold("I did read the file") fileClose(file) hold("I did close the file") loadScript(data) hold("Everything seems to be OK") end addCommandHandler("doit", function () if not coroutineOfscriptReadaa then hold("Lets get started. I am your slave. Write: /testNext To go to the next step(s).") coroutineOfscriptReadaa = coroutine.create(scriptReadaa) coroutine.resume(coroutineOfscriptReadaa) end end) addCommandHandler("testNext", function () if coroutineOfscriptReadaa then local state, error = coroutine.resume(coroutineOfscriptReadaa) if not state then iprint("coroutine ended. You can use /doit again.") coroutineOfscriptReadaa = nil end end end) function loadScript(scriptData) hold("Called the loadScript function") local simpleContador = 0 local Xfunction = load(function() simpleContador = simpleContador + 1 return scriptData end) hold("Called the load function.") if Xfunction then hold("Xfunction does exist.") pCallPrev = Xfunction pcall(pCallPrev) hold("Called the pcall function") else outputDebugString("Couldn't load the script") return end triggerEvent("onClientResourceStart", resourceRoot, getResourceFromName("SHIscriptloader")) hold("triggerEvent onClientResourceStart has been called.") end --##water.lua containts the following function function startclient() setWaterColor(0, 0, 255) end addEventHandler("onClientResourceStart", resourceRoot, startclient) This example gives also answer on your question here:
-
https://wiki.multitheftauto.com/wiki/OnClientClick > GUIEditor.button[1] function () https://wiki.multitheftauto.com/wiki/GuiStaticImageLoadImage > GUIEditor.staticimage[1] end
-
Refresh the resources before you show the state of the resources. You might want to consider add a timer between the two actions. (refresh and show states) Try to give the resources the right to use the function refreshResources. (not sure if that is required for this function, but I think it is)
-
if isElement(atmObject["object"]) and getElementType(player) == "player" and atmObject["object"] == source then if isElement(atmObject["object"]) and getElementType(player) == "player" and atmObject["object"] == source then You forgot to add this. Note: playerWhoClicked is always a player. > and getElementType(player) == "player"
-
You shouldn't be using string manipulate functions on JavaScript Object Notation, it might corrupt your file. Make sure you check your string after you generate it, afaik it should be converted correctly both ways. Debugging = understanding. iprint(tablaPrueba) local json = toJSON ( tablaPrueba ) iprint(json) iprint(fileR) fileR = fromJSON(fileR) iprint(fileR)
-
I wasn't 100% sure what you were asking for so, I thought I gave it a try. The example does it showing how long lua is busy processing the code in between. But maybe you want to show all messages within X amount of time. local myTableA = {"Message1","Message2","Message3","Message4","Message5","Message6","Message7","Message8"} local messageIndex = 1 local totalDuration = 5000 local durationTimer = math.max(math.ceil(totalDuration / #myTableA), 50) -- can't be lower than 50 ms else the timer doesn't work. addEventHandler("onClientResourceStart", resourceRoot, function () setTimer(function () outputChatBox(myTableA[messageIndex]) messageIndex = messageIndex + 1 end, durationTimer, #myTableA) end) Is this what you are looking for instead? (untested) P.s. loops can be delayed by pause the code, but that is dangerous because you have to manually resume them. (experts only recommended) If you want to know that, I am to happy to send you a link.
-
local operationStartTime = getTickCount() --------------- -- operation -- --------------- outputChatBox("It took " .. (getTickCount() - operationStartTime) .. " ms to execute this operation.")
-
You could try to resave the files with ANSI or UTF-16(not sure if UTF-16 is supported in MTA) encoding.
-
Yes it is possible. I just don't know how to do it with the shader file. But you can do it with lua: First draw the image: https://wiki.multitheftauto.com/wiki/DxDrawImage And then draw a section of the same image on top of it: https://wiki.multitheftauto.com/wiki/DxDrawImageSection
-
If you do not want to contact the owner then it means it is leaked. I can understand that you want to get rid of me if that is the case. But even so I gave you a legal and cheap way to solve your problem and yet you call that not helping, OK. Good luck with it.
-
Go to the owner of the script and inform him about it. You are now posting his code on the community. I am not sure if you are using a leaked version, but technically this is not allowed to be post without reference to the owner.
-
It looks fine to me as it is. If you want super - super optimization. You could pre-define the colors on top of the function. Not using a table on line 3, but 2 separated variables. (indexing tables cost time) Put this on top of the function: local ceiling = math.ceil Even though I do not recommend you to optimize it that far, except if you execute 100+ dx functions per frame. Scripts should stay readable. And you can also compile it to improve the performance.
-
Oh ops, misread that. What is the timer for? If you want to use the method, I would recommend you to add this: addEvent("onMapStarting", true) function setLicencePlate() setTimer(function() for k,v in ipairs(getElementsByType("player")) do local account = getPlayerAccount(v) if account and isGuestAccount(account) then return end local veh = getPedOccupiedVehicle(v) local plateText = getElementData(v, "plate") if veh and plateText and plateText ~= nil then -- if getVehiclePlateText ( v ) ~= plateText then setVehiclePlateText(veh, plateText) end -- end end end, 50, 1) end addEventHandler("onMapStarting", root, setLicencePlate) addEventHandler("onPlayerSpawn", root, setLicencePlate) addEventHandler("onPlayerJoin", root, setLicencePlate) It will save you MAX 100% network bandwidth.(that's when no plates have been changed) Even if the plate is the same as before, the server will send a message to all the clients that the value has changed. This due the fact that clients can modify this value and serverside has to overwrite it. You should compare it. Even so, it is not an efficient method > performance.
-
It will reset the health to the max player health, which is limited by the playerstats: https://wiki.multitheftauto.com/wiki/SetPedStat (default is 100 health, but can be increased to 200)
