-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
Don't ruin the typography Not sure which typo hater invented this option.
-
Just keep the usage at a limit and you will be fine.
-
I appreciate it, if you take me seriously. If you don't show some me motivation(for example by not showing what you tried), then please don't be so surprised. If you think that I get paid to help you, then you are slightly mistaken. I am helping you because I like to help people who want to learn. thePlayer, does not exist in this code. It is fiction. It is not here: And not here: https://wiki.multitheftauto.com/wiki/OnPlayerDamage But there is attacker which you can use over thePlayer. Which is actually a parameter of this event and sample. I recommend you to write it like this: if attacker and getElementType(attacker) == "player" then First it will check if the attacker variable has a value which is not nil/false and then it checks if the attacker is a player.
-
local testEventHandler = function (...) iprint("eventName:", eventName, "has been executed with arguments:", ...) end local addEventHandler_ = addEventHandler function addEventHandler (...) addEventHandler_(...) local arguments = {...} arguments[3] = testEventHandler -- replace the function addEventHandler_(unpack(arguments)) end (untested) For events, you might be able to figure it out with wrappers.
-
Don't post such useless reply and show us what you tried. You have already posted 255 posts and you still can't figure out that you have to try in order to walk, even a baby understands that. ! Here you have two tutorials: https://www.tutorialspoint.com/lua/if_else_statement_in_lua.htm
-
Good, lets get started.
-
Oke now look back at the code I posted, do you think you implement line 3 from my copy in your code?
-
Getting team of nothing = warning What is <nothing>? And how to check that: https://stackoverflow.com/questions/9141217/empty-variable-check
-
function hill_Enter ( thePlayer, matchingDimension ) if getElementType(thePlayer) == "player" then -- check if the hit element is actually a player local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) As @Blast3r said.
-
You can't attach an addEventHandler to an element that doesn't exist yet.(it exist after the addCommandHandler has been executed. Feel free to apply this tutorial: (because a parent element can be created and attached before the children are created)
-
Nice but keep in mind that inspect is actually for debugging. I recommend you to use tostring to convert numbers to strings. Because inspect does a lot more in the background than tostring does. Which is probably using a lot more cpu then needed. local numberToString = tostring(123) -- "123" local x = tostring(closestPoint[1]) local y = tostring(closestPoint[2]) local z = tostring(closestPoint[3]) local r = tostring(closestPoint[4]) local spawn = x..", "..y..", "..z..", "..r Also it is very important to use locals, to improve atleast the hierarchy of the code. In my opinion the most important thing about using locals, is that you as code writer know when data shouldn't be saved for a longer period. It must be GONE, because you don't need it any more. https://wiki.multitheftauto.com/wiki/Local https://www.lua.org/pil/4.2.html Whaaahaha brings back memories, when I started with lua.
-
closestPoint[4] This is what closestPoint is now: { 1173, -1323, 15, 270} {[1] = 1173, [2] = -1323, [3] = 15, [4] = 270} This is how the table index works, when the keys are not defined. The inspect function will convert all data types to a string, please study: https://wiki.multitheftauto.com/wiki/Inspect So a boolean will look like something like this: "true" / "false" A number will look like something like this: "1323435" A table will look like something like this: "{123, 5656}" ETC.
-
The most simplest way is this: function getDistance(thePlayer) -- get the player position local px,py,pz = getElementPosition( thePlayer ) --Player location -- prepare 2 variables, but do not give them a value yet. local closestDistance local closestPoint -- loop through the tables for i=1,#hosp_loc do local hx, hy, hz = hosp_loc[i][1], hosp_loc[i][2], hosp_loc[i][3] --Hospital locations local distance = getDistanceBetweenPoints3D (hx, hy, hz, px, py, pz) --Get the distance between player and hospitals if not closestDistance or distance < closestDistance then -- If the closestDistance is nil/(false) OR the distance is smaller than the closestDistance. closestDistance = distance -- save the distance in closestDistance, which is located outside of the loop. closestPoint = hosp_loc[i] -- save the point in closestPoint, which is located outside of the loop. end end outputChatBox(inspect(closestPoint), thePlayer, 255, 170, 85) -- debug the closestPoint variable, should be a table! end
-
You need to give it atleast two values. output = math.min(distance, output) You can also fill in 3 or 100 values.
-
local destroyTimer function blips() if isTimer (destroyTimer) then return end local blipGroupElement = createElement("blipGroupElement") for i=1,#ATM_Locations do local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3] local blip = createBlip ( x, y, z, 52, 1, 0, 0, 0, 255, 0, 500) setElementParent(blip, blipGroupElement) end destroyTimer = setTimer( destroyBlips, 10000, 1, blipGroupElement) end addCommandHandler( "ATM", blips, false ) function destroyBlips(blipGroupElement) if isElement(blipGroupElement) then destroyElement(blipGroupElement) end end Must be working. Local variables can not leave their block. function blips() -- block local blipGroupElement = createElement("blipGroupElement") -- block end -- blipGroupElement can not be used here. But lucky setTimer accepts custom parameters. destroyTimer = setTimer( destroyBlips, 10000, 1, blipGroupElement) function destroyBlips(blipGroupElement) if isElement(blipGroupElement) then destroyElement(blipGroupElement) end end destroyTimer = setTimer( destroyBlips, 10000, 1, blipGroupElement) function destroyBlips(blipGroupElement) if isElement(blipGroupElement) then destroyElement(blipGroupElement) end end
-
Info: You create for every blip a timer. But when the function is recalled, you only destroy 1 timer. The variable `destroyTimer` can only contain 1 value at the same time, so only one timer. Info: The distance check is within function `blips`, which is only executed when you write the command. So it doesn't recheck after that. Solution: See on page: https://wiki.multitheftauto.com/wiki/CreateBlip visibleDistance If you set this, you don't have to destroy blips any more. It will simply stream them out. Alternative method to destroy multiple elements. See this tutorial, it will make your life a lot easier. In the tutorial you can see that I set a parent element of all children. If you do the same and destroy the parent element instead, all children will also be destroyed. local blipGroupElement = createElement("blipGroupElement") -- for loop -- ADD here your blips setElementParent(blip, blipGroupElement) -- end destroyElement(blipGroupElement) -- All blips are destroyed
-
The sound of an engine exist out of multiple different sounds to make it `sound` differently. Afaik the sound(not sound group) you disable is equal for all vehicles. But I can be wrong.
-
It is a common mistake (I am making sometimes the same mistake), but there is always wiki to find it.
-
hmm Then there is only one way left. Record the sound and play it for every vehicle.
-
YUP
-
https://wiki.multitheftauto.com/wiki/TriggerClientEvent Syntax: bool triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] ) bool triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] ) You forgot to set the sendTo.
-
True. But you never said it was also for the other players. AFAIK the sound is less present for the players near the heli than the player in the heli. It shouldn't be that much of a problem.
-
Yes? Off in a heli On not in a heli Or do I look that stupid?
