kieran

Members
  • Content count

    265
  • Joined

  • Last visited

Community Reputation

23 Decent

1 Follower

About kieran

  • Rank
    Peon
  • Birthday August 21

Details

  • Gang
    n/a, I am a cat!
  • Location
    United Rainy Kingdom.
  • Occupation
    Newb scripter.
  • Interests
    I love GUI's and MTA, but I am lazy so don't ask for any help. (I also have a peanut brain haha)

Recent Profile Visitors

1,129 profile views
  1. Yes but I am beginning to learn 3 alongside it, so it just gets confusing
  2. ^^^Never mind that I forgot to start the script. Thanks again
  3. Thanks @IIYAMA, this helps, I need to learn C# and Python, so this is why I find lua so confusing at times, especially on MTA. Some things seem a little, backwards. Also I noticed a big problem, if I die miles out at sea off the map, I can't re-spawn.
  4. Thanks came up with the code below and works great! 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 --if site:sub(0, 7) ~= "http://" then 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 x = (inspect(closestPoint[1])) -- debug the closestPoint variable, should be a table! y = (inspect(closestPoint[2])) z = (inspect(closestPoint[3])) r = (inspect(closestPoint[4])) spawn = x..", "..y..", "..z..", "..r outputChatBox(spawn, thePlayer, 255, 170, 85) end addCommandHandler( "loc", getDistance, false )
  5. @IIYAMA Thanks, but um, final question on this... How can I get it to show only the numbers? Sorry... never used inspect before, and I can't think of a way to get length or use sub/gsub
  6. Thanks @IIYAMA, but do you know of a way to get the x y z position though? So instead of output being distance, it would be the closest 3D point x,y,z in table? instead of meters to point... Also is there any other way of getting minimum number? I can only use one value it will do it for all locations, I just want the closest locations x y z to be returned so I can use it on spawn...
  7. I want to make a script that will get distance between player and locations in a table, I have done this, but... I want to get the minimum distance and targets x, y, z. Basically, get distance between player and hospital, get the smallest distance only, then get the x, y, z of the targets distance from the table and output the x,y,z, so if I'm closest to all saints, it outputs those coordinates only. hosp_loc = { --Table of hospitals -- x, y, z, rot { 1173, -1323, 15, 270}, -- All Saints { 2038, -1411, 17, 130}, --Jefferson { 1242, 327, 19, 340}, -- Red County { 1609, 1816, 12, 360}, -- Las Venturas { -2655, 635, 14, 180}, -- San Fierro { -2200, -2311, 30, 320} -- Angel Pine } function getDistance(thePlayer) 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 px,py,pz = getElementPosition( thePlayer ) --Player location distance = getDistanceBetweenPoints3D (hx, hy, hz, px, py, pz) --Get the distance between player and hospitals output = math.min(distance) --Trying to get the minimum distance of one hospital outputChatBox(""..output, thePlayer, 255, 170, 85) --Ouput the x,y,z of that specific hospital to the chat end end addCommandHandler( "loc", getDistance, false ) --To get the distance Anyone know how to do this? was one of the first things I tried to script and trying to come back to do it now I know a little more (just not enough to do it). Thanks.
  8. Believe it or not it's exactly what I wanted the idea is adding the /atm command for a player to find the closest ATM, not to set the blip visible when the player hits the marker.... Here's the code, trying to educate myself a little on distance so I can make a proper hospital script and other stuff needed on most servers for the community (once I find out why I can't upload images to my resources). local destroyTimer function blips() if isTimer (destroyTimer) then --If timer is active return --Do nothing end local blipGroupElement = createElement("blipGroupElement") --Create an element for the blip for i=1,#ATM_Locations do --For all the locations in the table --Get the ATM xyz local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3]--We will get there x y z coordinates --Get the Players xyz local lx,ly,lz = getElementPosition( localPlayer ) --Get the distance between the ATM's and the Player distance = getDistanceBetweenPoints3D (x, y, z, lx, ly, lz) --If the distance is under 500 then create a blip for each location in the table if (distance) <= tonumber(500) then blip = createBlip ( x, y, z, 52, 1, 0, 0, 0, 255, -32767) setElementParent(blip, blipGroupElement) --Set the parent of the blip to the previously created element destroyTimer = setTimer( destroyBlips, 10000, 1, blipGroupElement)--And set a 10 second timer to destroy the blips end end end addCommandHandler( "ATM", blips, false )--Command function destroyBlips(blipGroupElement) --Honestly a little puzzled here, guess you carry this here so it can find all elements if isElement(blipGroupElement) then --If it's there destroyElement(blipGroupElement) --Destroy it. end end --See? It is simple! I just got a bit puzzled as I have never done a script like this, it's usually simple stuff. ^.^
  9. @IIYAMA OMG thanks so much. works perfect!
  10. I tried setting visible distance, all blips are created on map, and visible distance works on HUD, but not on the map, every blip still shows on map... And what do you mean by add blips? I tried this and it failed. 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] blip = createBlip ( x, y, z, 52, 1, 0, 0, 0, 255, 0, 500) setElementParent(blip, blipGroupElement) destroyTimer = setTimer( destroyBlips, 10000, 1) end end addCommandHandler( "ATM", blips, false ) function destroyBlips() if isElement(blipGroupElement) then destroyElement(blipGroupElement) end end
  11. So I have been struggling with one thing in particular lately, I made a script for am ATM system, and added a command to show blips for all the ATM's, I have used getDistanceBetweenPoints3D and it works, showing the nearest blips, the only problem is they will not all go away when I use my function to destroy them, only a small amount go away after the timer is completed. local ATM_Locations = { --Location table, numbers are commented so I know what goes where {1505.16626, -1750.68909, 13.54688},--1 <-This one goes away after 10 seconds as well as 3 others close to it. {1690.0927734375, -2334.8369140625, 13.546875},--2 {1951.19543, -2175.53784, 13.55421},--3 {2041.50390625, -1430.728515625, 17.1640625},--4 <-Yet this one doesn't or any others north of it. {1878.06372, 2073.94067, 11.06250},--5 {2280.76465, 2431.10596, 10.82031},--6 {2020.86316, 1016.50653, 10.82031},--7 {-1210.31104, 1834.64917, 41.92969},--8 {174.82074, 1175.05469, 14.75781},--9 {1380.58093, 260.50055, 19.56693},--10 {1238.48145, 327.90039, 19.75551},--11 {1626.68469, 1815.06384, 10.82031}--12 } local Blips = {}--My table to store the blips local destroyTimer --So I can get the timer function blips() if isTimer (destroyTimer) then --If my timer exists I stop the function here return end for i=1,#ATM_Locations do --For all the locations in the table at the top of the script local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3]--Get the x y z coordinates of ATM_Locations table local lx,ly,lz = getElementPosition( localPlayer ) --Get the Players x y z position distance = getDistanceBetweenPoints3D (x, y, z, lx, ly, lz) --Get the distance between the ATM's and the Player if (distance) <= tonumber(500) then --If the distance is under 500 then create a blip Blips[i] = createBlip ( x, y, z, 52, 1) --I create the blips destroyTimer = setTimer( destroyBlips, 10000, 1)--And set a 10 second timer to destroy the blips end end end addCommandHandler( "ATM", blips, false )--This is the command to show blips function destroyBlips() for i=1, #Blips do --For the blips in the table local blip = Blips[i] --Get the blips if isElement(blip) then --If the blip is in the table destroyElement(blip) --Destroy it. end end end So if you try it at LS airport you'll get 4 blips that will go away, but if it's anywhere else and distance is still 500, then the blips will stay anyone see where I went wrong? it's as if it only gets a select amount from the Blips table then stops. Thanks for any help, been struggling and don't know why it's doing this, all blips go after 10 seconds when it doesn't use distance...
  12. [Help] Team

    Okay, instead of using that for your gate function, maybe try this... Oh and make use of using "not" in your if's, it can come in handy . local gate = createObject(2938, 1534.9000244141, -1451.3000488281, 15, 0, 0, 90)--The gate local marker = createMarker(1534.9000244141, -1451.3000488281,13, "cylinder", 10, 255, 255, 255, 100)--The marker IronJobBlip = createBlipAttachedTo ( marker, 56 ) is_gate_open = no --So we can check if gate is open. function moveGate(thePlayer, matchingDimension) if isElement(thePlayer) and getElementType(thePlayer) == "player" and matchingDimension then --If it's a player in the same dimension local checkTeam = getTeamFromName("Police") --We will get the police team if ( checkTeam ) then local playerTeam = getPlayerTeam(thePlayer) --We will then get the players team if ( playerTeam == checkTeam ) then --If the players team is Police outputChatBox ("You may not enter as police", thePlayer, 255,0,0 ) --Tell him return --And stop our script here end if not isPedInVehicle ( thePlayer ) then --if our player is not in a vehicle outputChatBox ("You need to be in vehicle, to enter.", thePlayer, 255,0,0 )--We will tell him if is_gate_open == no then --If our gate is not open moveObject(gate, 2000, 1534.9000244141, -1451.3000488281, 17, 0, -90, 0) --Move the gate is_gate_open = yes --Update our is_gate_open end end end end end addEventHandler("onMarkerHit", marker, moveGate) function GateClose ( thePlayer, matchingDimension ) if isElement(thePlayer) and getElementType(thePlayer) == "player" and matchingDimension then local detection = isElementWithinMarker ( thePlayer, marker ) --If a player is inside the marker detection = detection and getElementDimension( thePlayer ) == getElementDimension( gate ) --I honestly lost words and forgot how to explain this if is_gate_open == yes and not detection then --If gate is open and player isn't in the marker moveObject(gate, 2000, 1534.9000244141, -1451.3000488281, 15, 0, 90, 0) --Move it back is_gate_open = no --Our gate is no longer open end end end addEventHandler ( "onMarkerLeave", marker, GateClose ) Second function needs a little tweaking, maybe you'll want to consider using col shapes, here is an example of an old script I have using col shapes. This should help you, got any other questions feel free to send me a message! But if I can't help, there are smarter people on forums... Also you might want to look at some of the stuff in above 2 code sections on the wiki, then you should just about be set with moving objects when a player hits them
  13. [Help] Team

    Untested function team(hitElement, matchingDimension) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then local checkTeam = getTeamFromName("Police") if ( checkTeam ) then local playerTeam = getPlayerTeam(hitElement) if ( playerTeam == checkTeam ) then outputChatBox ("text.", source, 255,0,0 ) cancelEvent() end end end end end addEventHandler("onMarkerHit", marker, team) Might work, might not, use debugscript 3 and tell me what happens, just quickly took it out an old script I had. By the way, source gets the source element, so when a player hits a marker, the player is the source, so you don't need to define source in your function.
  14. [Question] How to destroy elements from a table

    thanks @quindo, was thinking it would get the button instead of the image haha, makes sense now, if you want to get the button, you gotta declare it if you want to get the element, get the source.
  15. Hello, I know how to add, and get elements from a table, but I have made a GUI for a job script, when I click it triggers a function, and I want the clicked image to be destroyed once I click it and the function is triggered, code is below. Problem on line 20, debugscript 3 shows: Bad argument @ 'destoyElement' [Expected element at argument 1, got string 'table: 534E2AD0] So obviously it got the table as a string, but how can I get the clicked image from the table? Thanks for the help once GUI is neat and working going to put script on community