Jump to content

Addlibs

Members
  • Posts

    1,060
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by Addlibs

  1. cancelEvent() won't cancel any other event handles of onPlayerChat. Check if another resource is cancelling and giving own output onPlayerChat is running -- of the default resources, freeroam and playercolors are the most common offenders of this.
  2. In the server-side function spawnTheTruck, you're testing whether matchingDimension is true but it is undefined therefore a nil value, a false. The first if-scope evaluation returns false and the body of the if does not get executed.
  3. Your main problem is the fact that you declare soundd as a local variable and then attempt to refer to it in another call to the function. Once the function ends, the local variables are gone and you can no longer refer to them. This is why detachElement received a nil value -- soundd was nil after the function was exited. addEventHandler("khifizene", root, function() if isElement(soundd) then stopSound(soundd) return end --if the soundd still exists, destroy it (no need to detach if it's getting destroyed) and exit the function without creating a new one (so it works like a toggle - creates sound when there is none, destroys it if there is one) local x, y, z = getElementPosition(localPlayer) soundd = playSound3D(streamURL, x, y, z, true) --don't do this local otherwise you won't be able to refer to it after you exit out of the function setSoundVolume(soundd , volume) setSoundMaxDistance(soundd , radius) attachElements(soundd, localPlayer) end )
  4. Wrong section. Here we help with scripts, answer questions etc., not fulfil requests. You should try in https://forum.multitheftauto.com/forum/149-looking-for-staff/ or somewhere, perhaps in your native language section it's obvious you don't know English well enough.
  5. --# Client local enableBlips = true local renderNorthBlip = true local alwaysRenderMap = false local worldW, worldH = 1800,1800 local blip = 8 local sx, sy = guiGetScreenSize() local rt = dxCreateRenderTarget(290,175) local xFactor, yFactor = sx/1366,sy/768 local yFactor = xFactor function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end function RADAR() --Radar config showPlayerHudComponent("area_name", false) showPlayerHudComponent("vehicle_name", false) showPlayerHudComponent("radar", false) local mW, mH = dxGetMaterialSize(rt) local x, y = getElementPosition(localPlayer) local X, Y = mW/2 -(x/(6000/worldW)), mH/2 +(y/(6000/worldH)) local camX,camY,camZ = getElementRotation(getCamera()) dxSetRenderTarget(rt, true) if alwaysRenderMap or getElementInterior(localPlayer) == 0 then dxDrawRectangle(0, 0, mW, mH, 0xFF7CA7D1) dxDrawImage(X - worldW/2, mH/5 + (Y - worldH/2), worldW, worldH, "gfx/world.png", camZ, (x/(6000/worldW)), -(y/(6000/worldH))) -- dxSetRenderTarget() dxDrawImage((18)*xFactor, sy-((216))*yFactor, (293)*xFactor, (177)*yFactor, "gfx/radarbg.png", 0, 0, 0, tocolor(0, 0, 0, 180)) dxDrawImage((30+5)*xFactor, sy-((200+5))*yFactor, (270-10)*xFactor, (155)*yFactor, rt, 0, 0, 0, tocolor(255, 255, 255, 80)) end -- //// the end is supposed to be here //// --# Blips local rx, ry, rz = getElementRotation(localPlayer) local lB = (33)*xFactor local rB = (8+290)*xFactor local tB = sy-(208)*yFactor local bB = tB + (155)*yFactor local cX, cY = (rB+lB)/2, (tB+bB)/2 +(35)*yFactor local toLeft, toTop, toRight, toBottom = cX-lB, cY-tB, rB-cX, bB-cY for k, v in ipairs(getElementsByType("blip")) do local bx, by = getElementPosition(v) local actualDist = getDistanceBetweenPoints2D(x, y, bx, by) local maxDist = getBlipVisibleDistance(v) if actualDist <= maxDist and getElementDimension(v)==getElementDimension(localPlayer) and getElementInterior(v)==getElementInterior(localPlayer) then local dist = actualDist/(6000/((worldW+worldH)/2)) local rot = findRotation(bx, by, x, y)-camZ local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.min(dist, math.sqrt(toTop^2 + toRight^2)), rot) local bpx = math.max(lB, math.min(rB, bpx)) local bpy = math.max(tB, math.min(bB, bpy)) local bid = getElementData(v, "customIcon") or getBlipIcon(v) local _, _, _, bcA = getBlipColor(v) local bcR, bcG, bcB = 255, 255, 255 if getBlipIcon(v) == 0 then bcR, bcG, bcB = getBlipColor(v) end local bS = getBlipSize(v) dxDrawImage(bpx -(blip*bS)*xFactor/2, bpy -(blip*bS)*yFactor/2, (blip*bS)*xFactor, (blip*bS)*yFactor, "gfx/blip/"..bid..".png", 0, 0, 0, tocolor(bcR, bcG, bcB, bcA)) end -- //// (this end is correct) //// -- //// end was incorrectly placed here //// if renderNorthBlip then local rot = -camZ+180 local bpx, bpy = getPointFromDistanceRotation(cX, cY, math.sqrt(toTop^2 + toRight^2), rot) local bpx = math.max(lB, math.min(rB, bpx)) local bpy = math.max(tB, math.min(bB, bpy)) local dist = getDistanceBetweenPoints2D(cX, cY, bpx, bpy) local bpx, bpy = getPointFromDistanceRotation(cX, cY, dist, rot) if bpx and bpy then local bpx = math.max(lB, math.min(rB, bpx)) local bpy = math.max(tB, math.min(bB, bpy)) dxDrawImage(bpx -(blip*2)/2,bpy -(blip*2)/2,blip*2,blip*2,"gfx/blip/4.png",0,0,0) end end dxDrawImage(cX -(blip*2)*xFactor/2,cY -(blip*2)*yFactor/2,(blip*2)*xFactor,(blip*2)*yFactor, "gfx/player.png", camZ-rz, 0, 0) end end addEventHandler("onClientRender", root, RADAR) function Visible() if isVisible then addEventHandler("onClientRender", root, RADAR) else removeEventHandler("onClientRender", root, RADAR) end isVisible = not isVisible end bindKey ("F11", "down", Visible) There was a misplaced 'end' at the end of blips section instead of being at the end of map-render section. The above code is corrected, and I've included comments regarding where the error was, marked by -- //// comment //// to distinguish it from the original comments. The code will not render the map when inside an interior. If you prefer the map to be rendered at any time, regardless of interior world, set the variable alwaysRenderMap to true. P.S. Next time, when including any code, use [­code­] markup as it's easier to read.
  6. As far as I'm aware, you can't have C++ modules that run on the client side, thus you cannot change a client's memory. You only get access to the servers' memory.
  7. Triggering of server events is, by definition, sent to the server - always. 'Send to' is only a parameter of triggering client events, to choose on whose client to trigger the event on. What you're discussing is the event source element, and the wiki doesn't say it's bad practise to send localPlayer. In fact, using localPlayer as the source will use less CPU than sending on root, since after an event is triggered, it is also triggered on all elements under it. Since everything is under root, it means that the event will be triggered on every single element, increasing the CPU usage. The wiki only states not to use the source of the event to verify which client actually triggered the event, and instead use the predefined variable client, as the event source can be spoofed by fake packets sent from dishonest clients. You should be aware that there's a difference between an event's source and the trigger. A source is simply a reference to the element that is central to the event. For example, let's use the event onVehicleEnter, (the following is just a generic description of a hypothetical event I named onVehicleEnter for the sake of example, and not actual inner workings on the triggering of onVehicleEnter) although the source is the vehicle that was entered, the event would actually be triggered by the client that entered the vehicle.
  8. fileOpen fileRead loadstring Have you tried using loadstring()?
  9. If you plan to use MySQL to store data, your first step should be to make a resource that would handle all of that, and export its functions to allow other resources to just use that resource instead of creating a new MySQL connection on each resource.
  10. As I've said, it would be a easier, cleaner and more efficient if you used just one handler. And because it's cleaner, it's easier to see and fix problems. 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 id = {} -- do not edit this table local function spawnPed(data) 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) addEventHandler("onPedWasted", p, handleRespawn) -- attach handler for respawning id[p] = i -- 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 data = peds[id[source]] -- find the ped's data setTimer(destroyElement, 1000, 1, source) -- destroy ped after 1s setTimer(createPed, 1500, 1, data) -- use our cusom function to spawn ped after 1.5s end -- initialize for i, ped in ipairs(peds) do -- iterate through all ped data spawnPed(ped) -- use our custom function to spawn ped end
  11. Your code only binds the key to every connected player at the time of starting the script. You also need to add the following event handler: addEventHandler("onPlayerJoin", root, function() bindKey(source, "x", "down", SuperStop) end )
  12. 4.31 is the gradient of the graph. I.e., the amount of stat difference between max health of 100 (stat value 569) and 200 (stat value 100) is 431. Difference between 100 and 200 is 100. 431/100 = 4.31. For every 4.31 units of increase in stat above the default of 569, you get extra 1 health point above 100. Shoulda paid attention in math class
  13. It's capped at 200 because that's the maximum health a ped/player can have at max-health skill level 100. Here is the actual equation for the max health: maxhealth = 100 + (stat - 569) / 4.31 Source: getPedMaxHealth (useful function)
  14. What do you mean? Duplicate resources? If there's literally no identifying information on those resources then perhaps your only option is to loop through all resources (perhaps limited to those which meet the criterion getResourceInfo(theResource, "type")=="map"), open each file, store the MD5 or SHA hash (don't forget to close the files) and then delete those resources which are duplicates.
  15. That's probably because you've used the wrong syntax for addEventHandler. The first 4 handlers should be as follows: addEventHandler("onPedWasted", ped1, peddestroy1 ) addEventHandler("onPedWasted", ped2, peddestroy2 ) addEventHandler("onPedWasted", ped3, peddestroy3 ) addEventHandler("onPedWasted", ped4, peddestroy4 ) And the following handlers should be: addEventHandler("onPedWasted", ped1, pednewadeath1 ) addEventHandler("onPedWasted", ped2, pednewadeath2 ) addEventHandler("onPedWasted", ped3, pednewadeath3 ) addEventHandler("onPedWasted", ped4, pednewadeath4 ) Anyway, I'd additionally advise you to use just one handler to handle all of that instead of having 8 different handlers.
  16. dxCreateScreenSource ( int width, int height ) dxUpdateScreenSource ( element screenSource [, bool resampleNow = false ] ) dxDrawImage ( float posX, float posY, float width, float height, element screenSource, ... )
  17. It would be nice it you actually told us what problem you're having. And the topic's title is very unhelpful.
  18. Actually, you don't need a modified scoreboard resource to display images. You need to, however, properly set up the element data. local data = { type = "image", src = ":(name of resource with the images)/(path to image).png", color = tocolor(255,255,255,255), width = 20, height = 20 } setElementData(element, elementdataKey, data) This is adapted from the "voice" resource https://github.com/multitheftauto/mtasa-resources/blob/master/[gameplay]/voice/cPlayerMuting.lua#L4-L26
  19. Right here: https://wiki.multitheftauto.com/wiki/Resource_Web_Access#Parsed_files
  20. You have to remove the extension from the file name, and correct the meta.xml too. <html src="call" /> <!-- no file extension, since the actual file doesn't have it --> And then place it in a resource such as "api". Then you access it like so: http://forapis:yourpw@ip:port/api/call?whateveryouwanthere
  21. Actually, arg is indeed predefined, and does contain a key-value pair of n which lists the number of arguments. You can check it yourself using the following function (perhaps on HTTP runcode): function hey(...) return inspect(arg) end --then call hey(553, 674, "test", "foobar") -- This will return a formatted table containing all the arguments you've inputted, without actually defining the variable "arg", and there's also the "n" key in there.
  22. Alright, I've checked the following: The HTML file does not have to have .htm or .html at the end, you can remove it and it'll still work and process Lua correctly. You can grant public access to a HTTP resource, by adding the following right in the Default ACL: resource.(resourcename).http (this is an ACL right, not an object of an ACL group) However, I would still advise you to just add an account for "remote", place it within an elevated ACL group, for example, RPC (or your own ACL group) and add the aforementioned right only to that ACL instead of making it public. Then just connect to the HTTP as follows: http://remote:(remoteaccountpassword)@(serverip):(serverhttpport)/(resourcename)/call?do=(whatever)
  23. HTTP Authentication can be disabled if you allow access to general.http in the ACLs for Default ACL. This, however, allows access to anyone to any part of the HTTP interface so you should either turn off anything that's restricted access, or don't disabled the HTTP authentication. You can always just add authentication within the URL (i.e. http://username:password@ip:port/api/call.htm) I have no idea whether .htm or .html is required. You could try it without and let us know.
  24. Since you barely put any effort in your topic, I'm going to respond with a similar level of effort. You need to write a script. Also, read this
×
×
  • Create New...