Jump to content

Search the Community

Showing results for tags 'Lua'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Multi Theft Auto: San Andreas 1.x
    • Support for MTA:SA 1.x
    • User Guides
    • Open Source Contributors
    • Suggestions
    • Ban appeals
  • General MTA
    • News
    • Media
    • Site/Forum/Discord/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • MTA Community
    • Scripting
    • Maps
    • Resources
    • Other Creations & GTA modding
    • Competitive gameplay
    • Servers
  • Other
    • General
    • Multi Theft Auto 0.5r2
    • Third party GTA mods
  • Archive
    • Archived Items
    • Trash

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Gang


Location


Occupation


Interests

  1. O vídeo que você assistiu sobre persistência na programação, especialmente em Lua ou em qualquer linguagem, aborda um conceito fundamental para o desenvolvimento de habilidades em programação. A persistência é a capacidade de continuar tentando, mesmo diante de desafios e frustrações. No vídeo, provavelmente foram apresentados exemplos práticos que mostram como enfrentar erros e dificuldades de forma construtiva. A programação, por natureza, envolve resolução de problemas, e a persistência é essencial para superá-los. Ao lidar com bugs ou conceitos complexos, é importante manter a calma, buscar soluções e aprender com os erros. Além disso, o vídeo pode ter enfatizado a importância de praticar regularmente, estabelecer metas de aprendizado e não ter medo de pedir ajuda, não fazer modificações medíocres como forma de treinamento. Lembre-se que tem o fórum para você pedir ajuda, sempre terá alguém que terá prazer em ajudar você.
  2. I have designed a Snake game in my Multi Theft Auto project using the Lua programming language, implementing all functionalities and dynamics. Additionally, I have designed the controls to be very functional, allowing gameplay with either a keyboard or Xbox/PlayStation controllers. Here’s a link for you to watch.
  3. Hello dear forum members, I am deeply interested in a persistent question regarding my shader for the effect of raindrops flowing down the sides of the car, as well as the effect of raindrops (spots) on the surface of the car (roof, bumper). I’ve been struggling with these issues for a long time and still can’t figure out how to solve my two problems. I hope someone can help me and explain to a beginner in HLSL how to properly implement the shader. The first problem is that I don’t understand how to make the raindrops flow down the different sides of the car. Essentially, I have a single texture applied to the car, and I can't figure out how to split it into multiple segments and adapt it to flow around the sides of the car. (I also need to account for the unique features of each car model so that the flow looks realistic on each vehicle.) The second problem is the effect of tiny raindrops on the roof, hood, and bumper of the car (the generation of small droplets that gradually appear and disappear). The issue is that I’m trying to apply both effects in one shader, but the problem is that either only one of them works under certain settings, or nothing works at all. I can't get both effects to work harmoniously together. I’ll also provide an example of the Lua script and the textures used for the shader. I really hope for your help. I've been spending too much time on this, and I can't seem to find a solution. float4x4 gWorld : WORLD; float4x4 gView : VIEW; float4x4 gProjection : PROJECTION; float gTime : TIME; // Rain parameters float gDropSpeed = 0.03; // Speed of droplet flow float2 noiseScale = float2(0.2, 0.8); // Noise texture scale float3 lightDirection = float3(1.0, 1.0, -1.0); // Light direction float gDropSpread = 0.3; // Droplet spread float gDropDepth = 0.3; // Droplet depth texture gTexture; // Main car texture texture texRain; // Raindrop texture texture texNormalRain; // Raindrop normals texture texNoise; // Noise texture // Variables for controlling the effect float gAlpha = 0.01; // Alpha channel for the car float rainAlpha = 1.8; // Alpha channel for raindrops sampler2D gTextureSampler = sampler_state { Texture = ( gTexture ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texRainSampler = sampler_state { Texture = ( texRain ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texNormalRainSampler = sampler_state { Texture = ( texNormalRain ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texNoiseSampler = sampler_state { Texture = ( texNoise ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; struct VertexShaderInput { float4 Position : POSITION; // Using standard POSITION semantics for the vertex shader float2 TextureCoordinate : TEXCOORD0; // Passing texture coordinates }; struct PixelShaderInput { float4 Position : POSITION; // Passing position as float4 for proper operation float3 WorldPos : TEXCOORD1; // Passing world coordinates for calculations float2 TextureCoordinate : TEXCOORD0; // Passing texture coordinates }; PixelShaderInput VertexShaderFunction(VertexShaderInput input) { PixelShaderInput output; // Position in world coordinates float4 worldPos = mul(input.Position, gWorld); // Storing position for further projection output.Position = mul(mul(input.Position, gWorld), gView); output.Position = mul(output.Position, gProjection); // Applying projection // Storing world coordinates (for droplet flow) output.WorldPos = worldPos.xyz; // Passing texture coordinates output.TextureCoordinate = input.TextureCoordinate; return output; } float4 PixelShaderFunction(PixelShaderInput output) : COLOR0 { float2 textureCoordinate = output.TextureCoordinate; // Main car texture float4 baseColor = tex2D(gTextureSampler, textureCoordinate); baseColor.rgb = max(baseColor.rgb, 0.1); // Brightening dark areas // Getting noise for random movement float noise = tex2D(texNoiseSampler, textureCoordinate * noiseScale).r; // World coordinates to determine droplet direction float3 worldPos = output.WorldPos; // Using world coordinates // Determining droplet direction based on normals and world position float3 normal = normalize(output.WorldPos); // Normal to the surface // Checking direction by normals to determine which side of the car we're on if (abs(normal.x) > abs(normal.y) && abs(normal.x) > abs(normal.z)) { // Side surfaces textureCoordinate.y += gDropSpeed * gTime; // Flowing down the sides } else if (normal.y > 0.5) { // Top surface (roof) textureCoordinate.y -= gDropSpeed * gTime; // Droplets flow down } else { // Other sides (front and back) textureCoordinate.x -= gDropSpeed * gTime; // Optionally add droplet flow forward/backward } // Reducing random offset for more precise flow float2 offset = gDropSpread * (noise * 4.0 - 0.5) * float2(1.0, 2.5); // Using float2 for offset textureCoordinate -= offset; // Applying deviation in both axes // Raindrop texture float4 rainColor = tex2D(texRainSampler, textureCoordinate); // Adjusting droplets to the car color rainColor.rgb = baseColor.rgb * 0.8 + float3(0.1, 0.1, 0.1); // Adding body tint to droplets rainColor.a = rainAlpha; // Alpha channel of droplets // Normals for droplets float4 tempRainNormal = tex2D(texNormalRainSampler, textureCoordinate); // Explicitly using float4 float3 rainNormal = normalize(tempRainNormal.rgb * 2.5 - 0.75); // Normalizing normals // Lighting on droplets float diffuse = saturate(dot(normalize(rainNormal), normalize(lightDirection))); // Correct lighting // Combining colors float4 finalColor = lerp(baseColor, rainColor, rainAlpha * diffuse); finalColor.a = lerp(gAlpha, rainAlpha, diffuse * 0.9); // Adding droplet depth finalColor.rgb += gDropDepth * 0.9; // Depth effect of droplets float3 v = float3(0.0, 0.0, 0.0); float Tr2 = gTime * 11000.0; float2 n = tex2D(texNoiseSampler, textureCoordinate * 0.5).rg; for (float r = 4.0; r > 0.0; r--) // Reducing the number of iterations { float2 x = 2100.0 * r * 0.015; float2 p = 6.28 * textureCoordinate * x + (n - 0.5) * 2.0; float4 d = tex2D(texNoiseSampler, round(textureCoordinate * x - 0.25) / x); float t = (sin(p.x) + sin(p.y)) * max(0.0, 1.0 - frac(Tr2 * (d.b + 0.1) + d.g) * 2.0); if (d.r < (2.0 - r) * 0.08 && t > 0.5) { v += normalize(float3(-cos(p.x), lerp(1.2, 2.0, t - 0.5), 0.0)); } } finalColor.rgb += v * rainAlpha; return finalColor; } technique Replace { pass P0 { DepthBias = -0.0001; AlphaBlendEnable = TRUE; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA; VertexShader = compile vs_1_1 VertexShaderFunction(); PixelShader = compile ps_3_0 PixelShaderFunction(); } } LUA CODE: local shader = dxCreateShader("fx/shader.fx", 2, 300, true, "vehicle"); local zapylyayushiesyaDetali = { "remap_body", }; local rainTexture = dxCreateTexture("assets/RainCar.png") local normalRainTexture = dxCreateTexture("assets/RainNormal.png") local noiseTexture = dxCreateTexture("assets/enbnoise.png") dxSetShaderValue(shader, "texRain", rainTexture) dxSetShaderValue(shader, "texNormalRain", normalRainTexture) dxSetShaderValue(shader, "texNoise", noiseTexture) -- Применение шейдера к машине local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then --engineApplyShaderToWorldTexture(shader, "vehiclegrunge256", vehicle) for _, name in ipairs(zapylyayushiesyaDetali) do engineRemoveShaderFromWorldTexture(shader, name, localPlayer.vehicle) engineApplyShaderToWorldTexture(shader, name, localPlayer.vehicle) end end renderTarget = dxCreateRenderTarget(512, 512, true) addEventHandler("onClientRender", root, function() iprint(shader) if shader then if renderTarget then dxSetRenderTarget(renderTarget, true) dxDrawImage(0, 0, 512, 512, shader) dxSetRenderTarget() dxDrawImage(50, 50, 256, 256, renderTarget) end end end)
  4. Lua Language Server - Definition files The Lua language server is a powerful tool that enhances the development experience for Lua programming. It provides a comprehensive set of code editing features, including suggestions, auto-completion, and error checking. With the Lua language server, developers can effortlessly navigate through their resource files, access documentation easily, and ensure code correctness by giving warnings. Why should you care? The language server will inform you about all sorts of problems: type mismatches, missing function arguments, missing variables, etc. You have access to a lot of MTA syntax/autocomplete out of the box. The syntax information will remain while writing. You do not have to restart your resource so often in order to validate if everything is working. Type validation Having value type validation in your code editor is one of the main key features of the Lua Language Server. When working with variables, parameters, and arguments in Lua, you are not restricted to specific value types. This flexibility can make mistakes more likely to happen. However, being able to validate those mistakes instantly saves you a lot of time and frustration. Type annotations for your own functions Adding type annotations to your own functions can help improve validation and catch logic mistakes. It is particularly useful when calling functions from different parts of your code, as the annotations provide clarity on the expected input (arguments) and output (return values). Additionally, comments that are placed above or adjacent to a variable or function are visible when hovering over them in another file or line. This can provide helpful information and context when working with the code. How that looks like: How can I quickly add annotations in less than a second? Open the spoiler: AddEventHandler auto-complete Most MTA addEventHandler functions have full eventName autocompletion. And the attached anonymous function is fully autocompleted and typed as well. Navigation features of Lua Language Server It can be time consuming to find out where a (global) function or variable is located. Being able to jump right to it, saves you a lot of time. Other information which you can find in the readme Installation for the Lua Language Server How to use the definition files? Known issues Make sure to always have an empty new line at the end of your files, as recommended in this issue. Currently, the Lua server language definition files do not have a clear separation between serverside functions/events and clientside functions/events. However, it is possible to enforce this separation for specific functions if needed. outputChatBox--[[@as outputChatBox_server]]("Serverside", player) In certain cases, certain functions in the Lua server language definition files may return multiple types, even if you have selected a different syntax. To handle this situation, you can use the `cast` or `as` notation to explicitly specify the desired type or adjust the returned type. See `Casting and as` syntax below. Casting and as In certain situations, you may have a strong understanding of the type(s) that a variable or expression will have. This is where the keywords "cast" and "as" come into play. These keywords enable you to explicitly specify the intended type, ensuring proper type handling. local varName = exampleFunc() ---@cast varName string local varName = exampleFunc() ---@cast varName string | number local varName = exampleFunc() --[[@as string]] local varName = exampleFunc() --[[@as string | number]] Download The definition files can be downloaded here.
  5. function Hud_() local colete = math.floor (getPedArmor (getLocalPlayer())); dxDrawImageSection(653, 354, 51, 51, 0, 0, 51, 51, 'assets/Circle.png', 360/100 * colete, 0, 0, tocolor(21, 4, 252, 255), false) end; addEventHandler('onClientRender', root, Hud_)
  6. can somebody help me fix this issue its says the issue is in the 1256 line but i cant solve that [FACTION]\btc_dashboard\exServer.lua:1256: Bad argument @ 'dbExec' [Expected db-connection at argument 1, got nil] addEvent("savePayTime",true) addEventHandler("savePayTime",getRootElement(),function(player) dbExec(connection,"UPDATE characters SET fizuTime = ? WHERE id = ?",getElementData(player,"fizuTime"),getElementData(player,"acc:id")) end)
  7. Hello Forum! I need yor help I am just starting to learn programming in Lua, there are not many guides, so I turn to you. I wrote my own passport emulation, but I don't understand how I can put the entered data into the database. Below I will attach my code. Also, I would be happy if you could help me and tell me how I can add the display of this "passport" when entering a marker using addEventHendler. Thank you in advance! My code local dgs = exports.dgs local sw,sh = guiGetScreenSize() -- разрешение экрана игрока local px,py = sw/1920,sh/1080 -- адаптация экрана local window = dgs:dgsCreateWindow(((sw-800)/2)*px,((sh-600)/2)*py,800*px,600*py,"Паспорт",false) local buttonExecute = dgs:dgsCreateButton(325*px,530*py,150*px,40*py,"Подтвердить",false,window,nil,nil,nil,nil,nil,nil,tocolor(255,0,0),tocolor(100,0,0),tocolor(255,0,0)) local labelFirstName = dgs:dgsCreateLabel(200*px,200*py,400*px,30*py," Имя: ",false,window) local editFirstName = dgs:dgsCreateEdit(200*px,220*py,400*px,30*py,"",false,window,tocolor(255,255,255),nil,nil,nil) dgs:dgsSetProperty(labelFirstName,"alignment",{"center"}, {"center"}) dgs:dgsSetProperty(editFirstName,"alignment",{"center"}, {"center"}) local labelLastName = dgs:dgsCreateLabel(200*px,270*py,400*px,30*py," Фамилия: ",false,window) local editLastName = dgs:dgsCreateEdit(200*px,290*py,400*px,30*py,"",false,window,tocolor(255,255,255),nil,nil,nil) dgs:dgsSetProperty(labelLastName,"alignment",{"center"}, {"center"}) dgs:dgsSetProperty(editLastName,"alignment",{"center"}, {"center"}) local labelAge = dgs:dgsCreateLabel(200*px,340*py,400*px,30*py," Возраст: ",false,window,tocolor(255,255,255),nil,nil,nil) local editAge = dgs:dgsCreateEdit(200*px,360*py,400*px,30*py,"",false,window) dgs:dgsSetProperty(labelAge,"alignment",{"center"}, {"center"}) dgs:dgsSetProperty(editAge,"alignment",{"center"}, {"center"}) local labelCountry = dgs:dgsCreateLabel(200*px,410*py,400*px,30*py," Страна: ",false,window,tocolor(255,255,255),nil,nil,nil,tocolor(100,100,100,100)) local editCountry = dgs:dgsCreateEdit(200*px,430*py,400*px,30*py,"",false,window) dgs:dgsSetProperty(labelCountry,"alignment",{"center"}, {"center"}) dgs:dgsSetProperty(editCountry,"alignment",{"center"}, {"center"}) dgs:dgsWindowSetMovable(window,false) dgs:dgsWindowSetSizable(window,false) dgs:dgsWindowSetCloseButtonEnabled(window,false) dgs:dgsSetVisible(window,true) dgs:dgsSetVisible(window,true) showCursor(true) function openPanel() dgs:dgsSetVisible(window,true) showCursor(true) end function colsePanel() dgs:dgsSetVisible(window,false) showCursor(false) end local currentChose = "register" addEventHandler("onDgsMouseClick",root,function(btn,state) if btn == "left" and state == "down" then if source == buttonExecute then local firstName = dgs:dgsGetText(editFirstName) local lastName = dgs:dgsGetText(editLastName) local age = dgs:dgsGetText(editAge) local country = dgs:dgsGetText(editCountry) if not string.find(firstName,"%S") then outputChatBox("Name") return end if not string.find(lastName,"%S") then outputChatBox("LastName") return end if not string.find(age,"%d") then outputChatBox("Age") return end if not string.find(country,"%S") then outputChatBox("Country") return end triggerServerEvent("playerPassportEnter",localPlayer,firstName,lastName,age,country) end end end) If you do help me, please write this with explanations, thank you in advance! I LOVE YOU FORUM
  8. se busca scripters para este servidor que sepa programar en lua de forma voluntaria si quiere puede unirse al proyecto estamos con la gamemode de chicago roleplay / pop life / life stealh roleplay son de la misma base las 3 se maneja algo similar por lo que tengo entendido el que este interesado entre al servidor de discord, verifiquense y abran un ticket para hablarme de forma privada adamas buscamos nuevos usuarios que sean activos para poder poner en pie el servidor, gracias. Discord: https://discord.gg/Ecjn6AyUQN
  9. se busca scripters para este servidor que sepa programar en lua de forma voluntaria si quiere puede unirse al proyecto estamos con la gamemode de chicago roleplay / pop life / life stealh roleplay son de la misma base las 3 se maneja algo similar por lo que tengo entendido el que este interesado entre al servidor de discord, verifiquense y abran un ticket para hablarme de forma privada adamas buscamos nuevos usuarios que sean activos para poder poner en pie el servidor, gracias. Discord: https://discord.gg/Ecjn6AyUQN
  10. Hello everyone, i was wondering if there's a way to make some models exceptions on this code, that is supposed to delete all GTA default models but i need the ints to not be deleted so i want to know how can i make exceptions for some interior models.. addEventHandler("onResourceStart", resourceRoot, function() for i=550, 20000 do removeWorldModel(i, 10000, 0, 0, 0) setOcclusionsEnabled(false) end end)
  11. Hello guys, does anyone have an idea how to send Lua values to JavaScript to display them in the game, or for example, to show a list of players or run a JavaScript function?
  12. I made a hud but it has a bug. For those who register and login, setElementData is not set. How to fix it ? If the resource is restarted, the element data will be set and saved in the account data Server Side addEventHandler("onPlayerQuit", root, function(type) if type == "Quit" then local health = getElementHealth(source) local armor = getPedArmor(source) local water = getElementData(source, "water") local food = getElementData(source, "food") local account = getPlayerAccount(source) setAccountData(account, "health", health) setAccountData(account, "armor", armor) setAccountData(account, "water", water) setAccountData(account, "food", food) end end) addEventHandler("onPlayerLogin", root, function(pa, ca) local account = getPlayerAccount(source) if not isGuestAccount(account) then local health = getAccountData(account, "health") local armor = getAccountData(account, "armor") local water = getAccountData(account, "water") local food = getAccountData(account, "food") setElementHealth(source, health) setPlayerArmor(source, armor) setElementData(source, "water", water) setElementData(source, "food", food) end end) function drinkWater(player, price, size) if getPlayerMoney(player) < System.prices.food_price then outputChatBox("water cannot be given because you have no money", player, 255, 0, 0) else if getElementData(player, "water") >= 95 then outputChatBox("You can't get more food because your stomach is full!", player, 255, 0, 0) else setElementData(player, "water", getElementData(player, "water") + 20) takePlayerMoney(player, System.prices.water_price) triggerClientEvent(player, "drinking", player) end end end function eatFood(player, price, size) if getPlayerMoney(player) < System.prices.water_price then outputChatBox("Food cannot be given because you have no money", player, 255, 0, 0) else if getElementData(player, "food") >= 95 then outputChatBox("You can't get more food because your stomach is full!", player, 255, 0, 0) else setElementData(player, "food", getElementData(player, "food") + 20) takePlayerMoney(player, System.prices.food_price) triggerClientEvent(player, "eating", player) end end end addEventHandler("onPlayerWasted", root, function() setElementData(source, "water", 50) setElementData(source, "food", 50) end) addEvent("fireStop", true) addEventHandler("fireStop", root, function(player) toggleControl(player, "fire", false) end) addEvent("fireStart", true) addEventHandler("fireStart", root, function(player) toggleControl(player, "fire", true) end) addEvent("runStop", true) addEventHandler("runStop", root, function(player) toggleControl(player, "sprint", false) end) addEvent("runStart", true) addEventHandler("runStart", root, function(player) toggleControl(player, "sprint", true) end) Client Side local screenW, screenH = guiGetScreenSize() setElementData(localPlayer, "water", 100) setElementData(localPlayer, "food", 100) showPlayerHudComponent("health", false) showPlayerHudComponent("armour", false) showPlayerHudComponent("money", false) showPlayerHudComponent("ammo", false) showPlayerHudComponent("weapon", false) showPlayerHudComponent("clock", false) function render() health = getElementHealth(localPlayer) armor = getPedArmor(localPlayer) water = getElementData(localPlayer, "water") food = getElementData(localPlayer, "food") money = getPlayerMoney(localPlayer) time = getRealTime() hour = time.hour minute = time.minute second = time.second weaponID = getPlayerWeapon(localPlayer) weaponName = getWeaponNameFromID(weaponID) ammo = getPedAmmoInClip(localPlayer) allammo = getPedTotalAmmo(localPlayer) -- health dxDrawCircle((screenW - 225), (screenH / 5000 + 30), 25, -270,(health * 3.6 - 270), tocolor(0, 255, 0), 30) -- health line dxDrawCircle((screenW - 225), (screenH / 5000 + 30), 18, 0, 360, tocolor(26, 26, 26)) -- black circle dxDrawImage((screenW - 225) - (27 / 2), (screenH / 300 + 15), 27, 27, "assets/icons/heart.png") -- health icon -- armor dxDrawCircle((screenW - 160), (screenH / 5000 + 30), 25, -270,(armor * 3.6 - 270), tocolor(194, 194, 194), 30) -- armor line dxDrawCircle((screenW - 160), (screenH / 5000 + 30), 18, 0, 360, tocolor(26, 26, 26)) -- black circle dxDrawImage((screenW - 160) - (27 / 2), (screenH / 300 + 16), 27, 27, "assets/icons/armor.png") -- armor icon -- water dxDrawCircle((screenW - 95), (screenH / 5000 + 30), 25, -270,(water * 3.6 - 270), tocolor(10, 252, 236), 30) -- water line dxDrawCircle((screenW - 95), (screenH / 5000 + 30), 18, 0, 360, tocolor(26, 26, 26)) -- black circle dxDrawImage((screenW - 95) - (20 / 2), (screenH / 300 + 12), 20, 30, "assets/icons/water.png") -- water icon -- food dxDrawCircle((screenW - 30), (screenH / 5000 + 30), 25, -270,(food * 3.6 - 270), tocolor(209, 102, 8), 30) -- food line dxDrawCircle((screenW - 30), (screenH / 5000 + 30), 18, 0, 360, tocolor(26, 26, 26)) -- black circle dxDrawImage((screenW - 28) - (27 / 2), (screenH / 300 + 13), 27, 27, "assets/icons/food.png") -- food icon --background dxDrawRectangle((screenW - 235), (screenH / 5000 + 62), 260, 50, tocolor(23, 23, 23, 230)) dxDrawCircle((screenW - 235), (screenH / 5000 + 87), 25, -90, -270, tocolor(23, 23, 23, 230)) -- money dxDrawText("MONEY: $"..money, (screenW - 203), (screenH / 5000 + 70), 20, 20 , tocolor(0, 186, 43), 0.5, "bankgothic") -- real time dxDrawText(string.format("TIME: %02d:%02d:%02d", hour,minute,second), (screenW - 200), (screenH / 5000 + 90), 20, 20 , tocolor(166, 166, 166), 0.5, "bankgothic") -- weapons if weaponID ~= 0 then dxDrawRectangle((screenW - 235), (screenH / 5000 + 120), 260, 25, tocolor(23, 23, 23, 230)) dxDrawCircle((screenW - 235), (screenH / 5000 + 132.5), 12, -90, -270, tocolor(23, 23, 23, 230)) dxDrawText(weaponName.." | "..ammo.." | "..allammo, (screenW - 203), (screenH / 5000 + 125), 20, 20 , tocolor(237, 186, 0), 0.5, "bankgothic") end if (food <= 2) then triggerServerEvent("fireStop", resourceRoot, localPlayer) else triggerServerEvent("fireStart", resourceRoot, localPlayer) end if (water <= 2) then triggerServerEvent("runStop", resourceRoot, localPlayer) else triggerServerEvent("runStart", resourceRoot, localPlayer) end end addEventHandler("onClientRender", root, render) setTimer(function(player) if (getElementData(localPlayer, "water") <= 2) then return else setElementData(localPlayer, "water", getElementData(localPlayer, "water") - 1) end end, System.decrease.water, 0) setTimer(function(player) if (getElementData(localPlayer, "food") <= 2) then return else setElementData(localPlayer, "food", getElementData(localPlayer, "food") - 1) end end, System.decrease.food, 0)
  13. what is problem this code ? gate = createObject(980, 364.82147, 186.89452, 1019.98438) setElementInterior(gate, 3) bombMarker = createMarker(364.70267, 186.29311, 1019.98438 -0.5, "cylinder", 1, 255, 0, 0) setElementInterior(bombMarker, 3) addEventHandler("onMarkerHit", bombMarker, function(player) outputChatBox("ugh!") end)
  14. Why is outPutChatBox saying false instead of 1 ? What I need is to get the outPutChatBox as 1 marker = createMarker(2093.75464, -1948.29468, 13.54688, "cylinder", 1) addEventHandler("onClientMarkerHit", marker, function(player) setElementData(player, "item", 1) outputChatBox("hitted") end) addEventHandler("onClientRender", root, function(player) count = tostring(getElementData(player, "item")) outputChatBox(count) end)
  15. Why doesn't the vehicle destroy when the player disconnects ? marker = createMarker(2169.62500, -1983.23706, 13.55469, "cylinder", 1) vehicles = {} addEventHandler("onMarkerHit", marker, function(player) vehicles[player] = createVehicle(408, 2169.62500 + 3, -1983.23706, 13.55469) end) addEventHandler("onPlayerQuit", root, function(type) if (type == "Quit") then destroyElement(vehicles[player]) end end)
  16. This is a dirt job script I'm currently working on... There's a bug here, why isn't the marker destroyed when the player exits the vehicle? client side -- client side local screenW, screenH = guiGetScreenSize() local w, h = 400, 330 local jobMarker = createMarker(-1895.57104, -1660.41797, 22.11562, "cylinder", 1.0, 0, 255, 0) local window setMoonSize(1000) function getJob(player, matchingDeminsion) if player == localPlayer and matchingDeminsion then if not isPedInVehicle(player) then if isPedOnGround(player) then if not (window) then window = guiCreateWindow((screenW / 2) - (w / 2), (screenH / 2) - (h / 2), w, h, "garbage job", false) memo = guiCreateMemo(0, 30, w, 200, "this is garbage job!", false, window) guiMemoIsReadOnly(memo) accept = guiCreateButton(0, 290, 100, 40, "Accept", false, window) leave = guiCreateButton(130, 290, 100, 40, "Leave Job", false, window) close = guiCreateButton(250, 290, 100, 40, "Close", false, window) showCursor(true) else guiSetVisible(window, false) window = nil showCursor(false) end end end end end addEventHandler("onClientMarkerHit", jobMarker, getJob) function clicks() if (source == accept) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("acceptJob", resourceRoot, localPlayer) elseif (source == leave) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("leaveJob", resourceRoot, localPlayer) elseif (source == close) then guiSetVisible(window, false) window = nil showCursor(false) end end addEventHandler("onClientGUIClick", root, clicks) Server side -- server side addEventHandler("onResourceStart", root, function() team = createTeam("garbage", 0, 255, 0) end) addEvent("acceptJob", true) addEvent("leaveJob", true) function checkAccept(player) -- [accept job function] if (getElementData(player, "Jobs") == "garbage") then outputChatBox("you have alrady garbage job sorry!", player, 255, 0, 0) else setElementData(player, "Jobs", "garbage") setElementData(player, "trashlocation", 0) outputChatBox("job accept successfully!", player, 0, 255, 0) startJob(player) if (team) then setPlayerTeam(player, team) end end end addEventHandler("acceptJob", root, checkAccept) vehicles = { [408] = true } garbages = { [1] = {-1881.14380, -1707.47888, 21.75000}, [2] = {-1885.83081, -1723.84656, 21.75641}, [3] = {-1896.03723, -1731.46301, 21.75000}, [4] = {-1908.80933, -1733.61536, 21.75000}, [5] = {-1930.82690, -1767.77832, 26.18353}, [6] = {-1938.78809, -1781.46545, 29.32999}, [7] = {-1936.23059, -1760.15820, 24.36698}, [8] = {-1935.32361, -1742.58679, 22.91065}, [9] = {-1935.62610, -1719.10291, 21.75000}, [10] = {-1921.58350, -1706.34143, 21.90317}, [11] = {-1902.96033, -1704.98352, 21.75000} } function pickUpLocation(player, id) local x, y, z = garbages[id][1],garbages[id][2],garbages[id][3] local marker = createMarker(x, y, z, "cylinder", 3.0) -- <<<<<< Marker is here addEventHandler("onMarkerHit", marker, function(player) if getElementModel(getPedOccupiedVehicle(player)) == 408 then destroyElement(marker) marker = nil outputChatBox("hitted") setElementData(player, "trashlocation", getElementData(player, "trashlocation")+1) newLocation = getElementData(player, "trashlocation") pickUpLocation(player, newLocation) end end) end addEventHandler("onPlayerVehicleEnter", root, function(vehicle, seat, jacked) --[on player vehicle enter] if (vehicles[getElementModel(vehicle)]) and (getElementData(source, "Jobs") ~= "garbage") then removePedFromVehicle(source) x, y, z = getElementPosition(source) setElementPosition(source, x+1, y, z) outputChatBox("You don't have a garbage job", player, 255, 0, 0) end end) addEventHandler("onPlayerVehicleExit", root, function(vehicle, seat, jeacked) --[on player vehicle exit] if (getElementData(source, "Jobs") == "garbage") then if (getElementModel(vehicle) == 408) then outputChatBox("exited") setElementData(source, "Jobs", nil) destroyElement(marker) -- <<<<<<< problem is ehere end end end) trashVehicles = {} trashVehiclesBlips = {} function startJob(player) trashVehicle = createVehicle(408, -1879.74951, -1672.44751, 21.75000, 0, 0, 180) trashVehicleBlip = createBlipAttachedTo(trashVehicle, 51) trashVehicles[player] = trashVehicle trashVehiclesBlips[player] = trashVehicleBlip function checkVehicle(player) local vehicle = getPedOccupiedVehicle(source) local vehicleId = getElementModel(vehicle) outputChatBox(vehicleId) if (vehicleId == 408) then pickUpLocation(player, 1) setElementData(player, "trashlocation", 1) end end addEventHandler("onPlayerVehicleEnter", root, checkVehicle) end function leave(player)-- [leave job function] setElementData(player, "Jobs", nil) setPlayerTeam(player, nil) outputChatBox("leave successfully garbage job!", player, 255, 255, 0) end addEventHandler("leaveJob", root, leave)
  17. I made a trashman job. But there is a small problem, how can only those who have the trashman job try to enter the trash vehicle? -- client side local screenW, screenH = guiGetScreenSize() local w, h = 400, 330 local jobMarker = createMarker(-1895.57104, -1660.41797, 22.11562, "cylinder", 1.0, 0, 255, 0) local window function getJob(player, matchingDeminsion) if player == localPlayer and matchingDeminsion then if not isPedInVehicle(player) then if isPedOnGround(player) then if not (window) then window = guiCreateWindow((screenW / 2) - (w / 2), (screenH / 2) - (h / 2), w, h, "garbage job", false) memo = guiCreateMemo(0, 30, w, 200, "this is garbage job!", false, window) guiMemoIsReadOnly(memo) accept = guiCreateButton(0, 290, 100, 40, "Accept", false, window) leave = guiCreateButton(130, 290, 100, 40, "Leave Job", false, window) close = guiCreateButton(250, 290, 100, 40, "Close", false, window) showCursor(true) else guiSetVisible(window, false) window = nil showCursor(false) end end end end end addEventHandler("onClientMarkerHit", jobMarker, getJob) function clicks() if (source == accept) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("acceptJob", resourceRoot, localPlayer) elseif (source == leave) then guiSetVisible(window, false) window = nil showCursor(false) triggerServerEvent("leaveJob", resourceRoot, localPlayer) elseif (source == close) then guiSetVisible(window, false) window = nil showCursor(false) end end addEventHandler("onClientGUIClick", root, clicks) --server side addEvent("acceptJob", true) addEvent("leaveJob", true) function checkAccept(player) -- [accept job function] if (getElementData(player, "Jobs") == "garbage") then outputChatBox("you have alrady garbage job sorry!", player, 255, 0, 0) else setElementData(player, "Jobs", "garbage") outputChatBox("job accept successfully!", player, 0, 255, 0) startJob(player) end end function startJob(player) trashVehicle = createVehicle(408, -1879.74951, -1672.44751, 21.75000, 0, 0, 180) end addEventHandler("acceptJob", root, checkAccept) function leave(player)-- [leave job function] setElementData(player, "Jobs", nil) destroyElement(trashVehicle) outputChatBox("leave successfully garbage job!", player, 255, 255, 0) end addEventHandler("leaveJob", root, leave)
  18. When one of these markers is hit, another marker is destroyed. After that, even if other markers are hit, none of the markers will be destroyed. What is the reason for it ? garbages = { {-1881.14380, -1707.47888, 21.75000}, {-1885.83081, -1723.84656, 21.75641}, {-1896.03723, -1731.46301, 21.75000}, {-1908.80933, -1733.61536, 21.75000} } function pickup(player) for i,garbage in pairs(garbages) do marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0) function picked(player) destroyElement(marker) end addEventHandler("onMarkerHit", marker, picked) end end
  19. How to increase the shooting speed of a weapon ?
  20. This is a script I made. This has been working fine so far and then suddenly stopped working. What is the reason for it? addEvent("startMinerJob", true) function startJob(thePlayer) if not (getElementData(thePlayer, "Jobs") == "miner") then setElementData(thePlayer, "Jobs", "miner") setElementData(thePlayer, "copper", getElementData(thePlayer, "copper")) end mineMarker = createMarker(596.22632, 926.04364, -37.97111, "cylinder", 10.0) addEventHandler("onMarkerHit", mineMarker, function() playerWeapon = getPlayerWeapon(thePlayer) if playerWeapon == 23 then outputChatBox("test", thePlayer) setPedFrozen(thePlayer, true) setTimer(function() setPedAnimation(thePlayer, "SWORD", "sword_4", -1, false, false, false, false) end, 1000, 5) setTimer( function() outputChatBox("relesed", thePlayer) setPedFrozen(thePlayer, false) setElementData(thePlayer, "copper", getElementData(thePlayer, "copper")+3) end , 5000, 1) end end) end addEventHandler("startMinerJob", root, startJob) --[[ Leave Miner Job Section ]] addEvent("leaveMinerJob", true) function leaveJob(thePlayer) if (getElementData(thePlayer, "Jobs") == "miner") then setElementData(thePlayer, "Jobs", nil) outputChatBox("you leaved miner job!", thePlayer, 0, 255, 0) end end addEventHandler("leaveMinerJob", root, leaveJob) --[[ Job Testing Section ]] function test(thePlayer) de = getElementData(thePlayer, "copper") outputChatBox("you have "..de.." coppers") end addCommandHandler("gg", test)
  21. scolen

    [HELP]DATABSE

    No purchased vehicles will be left. In the console, here is an error: "CarShop-System/Server.lua:120: dbExec failed; (1) SQL argument error ".. but the localhost is working fine without any errors, when I put it on the server it happens like this. What is the reason for that ? createBlip ( 2131.88086, -1149.92566, 24.21433, 55, 2, 0, 0, 0, 255, 0, 99999.0, getRootElement( ) ) local vehDB = dbConnect( 'sqlite', 'Loja de veiculos - Database.db' ) dbExec( vehDB, ' CREATE TABLE IF NOT EXISTS `VehiclesSystem_Players` (pSerial, vehID, vehName, vehPrice, Subscription) ' ) --dbExec( vehDB, ' DROP TABLE `VehiclesSystem_Players` ' ) vehPers = { }; vehview = { }; function refreshMyList( ) local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` ' ) local results = dbPoll( check, -1 ) if ( type( results ) == 'table' and #results == 0 or not results ) then triggerClientEvent( root, 'VehiclesSystem;emptyMyList', root ) return end triggerClientEvent( root, 'VehiclesSystem;putMyVehicles', root, results ) end addEvent( 'refreshMyListS', true ) addEventHandler( 'refreshMyListS', root, refreshMyList ) function viewVehiclex( ID, x, y, z, state ) if ( state == 'close' ) then if ( isElement( vehview[source] ) ) then destroyElement( vehview[source] ) end elseif ( state == 'view' ) then if ( isElement( vehview[source] ) ) then if ( getElementModel( vehview[source] ) ) == ID then return end destroyElement( vehview[source] ) end vehview[source] = createVehicle( ID, x, y, z + 0.2, 0, 0, 10 ) setElementDimension( vehview[source], getElementData( root, 'vehiclesSystem;dimension' ) or 1 ) setElementDimension( source, getElementData( root, 'vehiclesSystem;dimension' ) or 1 ) setElementData( root, 'vehiclesSystem;dimension', getElementData( root, 'vehiclesSystem;dimension' ) + 1 or 1 ) end end addEvent( 'VehiclesSystem;createViewVehicle', true ) addEventHandler( 'VehiclesSystem;createViewVehicle', root, viewVehiclex ) addEvent( 'VehiclesSystem;destroyPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;destroyPersonalVehicle', root, function( ) if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end end ) addEvent( 'VehiclesSystem;createRentVehicle', true ) addEventHandler( 'VehiclesSystem;createRentVehicle', root, function( ID, vehName ) if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end vehPers[source] = createVehicle( ID, 2126.08862, -1136.05115, 25.47241 + 1, -0, 0, 224.5189666748 ) fadeCamera( source, false ) setTimer( fadeCamera, 1500, 1, source, true ) takePlayerMoney( source, 1000 ) setElementDimension( vehPers[source], 0 ) setElementDimension( source, 0 ) setTimer( warpPedIntoVehicle, 1500, 1, source, vehPers[source] ) setTimer( destroyElement, 300000, 1, vehPers[source] ) setTimer( function( ) outputChatBox( '#1E90FF[Car Shop] #FFFFFFWarning: Your rental time is up and your vehicle has been removed #FF0000!', source, 255, 255, 255, true ) end, 300000, 1 ) triggerClientEvent( source, 'VehiclesSystem;gridListAddRent', source, ID, vehName ) end ) addEvent( 'VehiclesSystem;lock/unlockPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;lock/unlockPersonalVehicle', root, function( ) if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end if ( isVehicleLocked( vehPers[source] ) == true ) then setVehicleLocked( vehPers[source], false ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSuccess, Your vehicle has been unlocked #2BFF00!', source, 255, 255, 255, true ) else setVehicleLocked( vehPers[source], true ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSuccess, Your vehicle has been locked #2BFF00!', source, 255, 255, 255, true ) end end ) addEvent( 'VehiclesSystem;off/onPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;off/onPersonalVehicle', root, function( ) if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end if ( getVehicleEngineState( vehPers[source] ) == true ) then setVehicleEngineState( vehPers[source], false ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFEngine off #2BFF00!', source, 255, 255, 255, true ) else setVehicleEngineState( vehPers[source], true ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFEngine on #2BFF00!', source, 255, 255, 255, true ) end end ) addEvent( 'VehiclesSystem;off/onLightsPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;off/onLightsPersonalVehicle', root, function( ) if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end if ( getVehicleLightState( vehPers[source], 0 ) == 0 and getVehicleLightState( vehPers[source], 1 ) == 0 ) then setVehicleLightState( vehPers[source], 0, 1 ) setVehicleLightState( vehPers[source], 1, 1 ) setVehicleLightState( vehPers[source], 2, 1 ) setVehicleLightState( vehPers[source], 3, 1 ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFlights off #2BFF00!', source, 255, 255, 255, true ) else setVehicleLightState( vehPers[source], 0, 0 ) setVehicleLightState( vehPers[source], 1, 0 ) setVehicleLightState( vehPers[source], 2, 0 ) setVehicleLightState( vehPers[source], 3, 0 ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFLights on #2BFF00!', source, 255, 255, 255, true ) end end ) addEvent( 'VehiclesSystem;sellMyPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;sellMyPersonalVehicle', root, function( ID, price ) local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehID = ? ', getPlayerSerial( source ), ID ) local results = dbPoll( check, -1 ) if ( type( results ) == 'table' and #results == 0 or not results ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: This vehicle is not permanent, you cannot sell it #FF0000!', source, 255, 255, 255, true ) return end if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end dbExec( vehDB, ' DELETE FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehID = ? ', getPlayerSerial( source ), ID ) refreshMyList( ) givePlayerMoney( source, price ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSold! You have successfully sold your vehicle #2BFF00!', source, 255, 255, 255, true ) end ) addEvent( 'VehiclesSystem;createPersonalVehicle', true ) addEventHandler( 'VehiclesSystem;createPersonalVehicle', root, function( ID ) local x, y, z = getElementPosition( source ) if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end vehPers[source] = createVehicle( ID, x + 2, y + 2, z + 1 ) if ( getElementData( source, 'VehiclesSystem;WarpToVehicle' ) == 'Enabled' ) then warpPedIntoVehicle( source, vehPers[source] ) setElementData( vehPers[source], 'myPersVehicle', getPlayerName( source ) ) end end ) addEvent( 'VehiclesSystem;buyCurrentCar', true ) addEventHandler( 'VehiclesSystem;buyCurrentCar', root, function( ID, Name, Price ) local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehddID = ? ', getPlayerSerial( source ), ID ) local results = dbPoll( check, -1 ) if ( type( results ) == 'table' and #results == 0 or not results ) then dbExec( vehDB, ' INSERT INTO `VehiclesSystem_Players` VALUES(?,?,?,?,?) ', getPlayerSerial( source ), tonumber(ID), Name, Price, 'Permanente' ) vehPers[source] = createVehicle( ID, 2126.08862, -1136.05115, 25.47241 + 1, -0, 0, 224.5189666748 ) warpPedIntoVehicle( source, vehPers[source] ) takePlayerMoney( source, Price ) setTimer(setCameraTarget, 1500, 1, source ) setElementDimension( vehPers[source], 0 ) setElementDimension( source, 0 ) fadeCamera( source, false ) setTimer( fadeCamera, 1500, 1, source, true ) triggerClientEvent( source, 'VehiclesSystem;hideBuyWindow', source ) viewVehiclex( nil, nil, nil, nil, 'close' ) refreshMyList( ) else outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: This vehicle already exists in your list #FF0000!', source, 255, 255, 255, true ) return end end )
  22. Is there a resource that spawns from the nearest hospital after a player dies ?... or how to make it. I have put many respawn resources but there is some error and it doesn't spawn from the nearest hospital.
  23. I created a Miner Job but there is a problem. When I hit the plant command several times, I could mine only the 5 stones in this script, but the other stones are not destroyed. What is the reason for this? Please help? addEvent("startMinerJob", true) function startJob(thePlayer) if not (getElementData(thePlayer, "Jobs") == "miner") then setElementData(thePlayer, "Jobs", "miner") end function plant(thePlayer) if (getElementData(thePlayer, "Jobs") == "miner") then x, y, z = getElementPosition(thePlayer) disx = 611.54028 disy = 878.61017 disz = -42.9609 if (getDistanceBetweenPoints3D(x, y, z, disx, disy, disz) < 90) then outputChatBox("Bomb Planted!", thePlayer, 255, 0, 0) setTimer(function() createExplosion(x, y, z, 10) stone1 = createObject(3930, x+0, y+1, z-0.5) stone2 = createObject(3930, x+1*2, y+3, z-0.5) stone3 = createObject(3930, x+2*2, y+2, z-0.5) stone4 = createObject(3930, x+3*2, y+5, z-0.5) stone5 = createObject(3930, x+4*2, y+4, z-0.5) x1, y1, z1 = getElementPosition(stone1) x2, y2, z2 = getElementPosition(stone2) x3, y3, z3 = getElementPosition(stone3) x4, y4, z4 = getElementPosition(stone4) x5, y5, z5 = getElementPosition(stone5) marker1 = createMarker(x1, y1, z1, "cylinder", 1.0, 0, 0, 0, 0) marker2 = createMarker(x2, y2, z2, "cylinder", 1.0, 0, 0, 0, 0) marker3 = createMarker(x3, y3, z3, "cylinder", 1.0, 0, 0, 0, 0) marker4 = createMarker(x4, y4, z4, "cylinder", 1.0, 0, 0, 0, 0) marker5 = createMarker(x5, y5, z5, "cylinder", 1.0, 0, 0, 0, 0) addEventHandler("onMarkerHit", marker1, function(thePlayer) setPedFrozen(thePlayer, true) setPedAnimation(thePlayer, "FIGHT_B", "FightB_G", -1, false, false, false, false) destroyElement(marker1) setTimer(function() destroyElement(stone1) setPedFrozen(thePlayer, false) givePlayerMoney(thePlayer, 300) end, 3000, 1) end) addEventHandler("onMarkerHit", marker2, function(thePlayer) setPedFrozen(thePlayer, true) setPedAnimation(thePlayer, "FIGHT_B", "FightB_G", -1, false, false, false, false) destroyElement(marker2) setTimer(function() destroyElement(stone2) setPedFrozen(thePlayer, false) givePlayerMoney(thePlayer, 300) end, 3000, 1) end) addEventHandler("onMarkerHit", marker3, function(thePlayer) setPedFrozen(thePlayer, true) setPedAnimation(thePlayer, "FIGHT_B", "FightB_G", -1, false, false, false, false) destroyElement(marker3) setTimer(function() destroyElement(stone3) setPedFrozen(thePlayer, false) givePlayerMoney(thePlayer, 300) end, 3000, 1) end) addEventHandler("onMarkerHit", marker4, function(thePlayer) setPedFrozen(thePlayer, true) setPedAnimation(thePlayer, "FIGHT_B", "FightB_G", -1, false, false, false, false) destroyElement(marker4) setTimer(function() destroyElement(stone4) setPedFrozen(thePlayer, false) givePlayerMoney(thePlayer, 300) end, 3000, 1) end) addEventHandler("onMarkerHit", marker5, function(thePlayer) setPedFrozen(thePlayer, true) setPedAnimation(thePlayer, "FIGHT_B", "FightB_G", -1, false, false, false, false) destroyElement(marker5) setTimer(function() destroyElement(stone5) setPedFrozen(thePlayer, false) givePlayerMoney(thePlayer, 300) end, 3000, 1) end) end, 5000, 1) end end end addCommandHandler("plant", plant) end addEventHandler("startMinerJob", root, startJob) --[[ Leave Miner Job Section ]] addEvent("leaveMinerJob", true) function leaveJob(thePlayer) if (getElementData(thePlayer, "Jobs") == "miner") then setElementData(thePlayer, "Jobs", nil) outputChatBox("you leaved miner job!", thePlayer, 0, 255, 0) end end addEventHandler("leaveMinerJob", root, leaveJob)
  24. da rapaziada, gostaria de saber como faço para modificar um do lados do retangulo, tipo deixar um dos lados dele um pouco na diagonal, tipo assim " / ", poderiam me ajudar?
  25. Lua tables are a fundamental data structure that allows you to store key-value pairs and create complex data structures. Tables in Lua are versatile and can contain values of different types. Let's dive into a detailed explanation with examples : Table Creation: To create a table in Lua, you use curly braces { } and separate the elements with commas. Here's an example: local table = {1, 2, 3, 4, 5} -- table crt In the above example, we created a table named table and populated it with values 1, 2, 3, 4, and 5. Accessing Table Elements: You can access table elements by using square brackets [ ]. Indices in Lua start from 1. Here's an example: -- Accessing table elements print(table[1]) --output : 1 print(table[3]) --output : 3 In the above example, we access the value at the 1st index (1) and the 3rd index (3) of the table. Adding Elements to a Table: To add a new element to a table, you specify the index and the value. If the specified index already exists in the table, the value will be overwritten. Here's an example: -- Removing elements from a table table[3] = nil In the above example, we remove the element at the 3rd index of the table. Getting the Size of a Table: To get the size of a table (i.e., the number of elements), you can use the # operator. Here's an example: -- Getting the size of a table print(#table) -- 5 In the above example, we print the size of the table using the # operator. Table Iteration: You can iterate over the elements in a table using the ipairs or pairs functions. ipairs provides index-based iteration, while pairs provides key-based iteration. Here's an example: -- Table iteration for index, value in ipairs(table) do print(index, value) end In the above example, we iterate over the table using ipairs and print the index and value of each element. +---------------------------------------------------+ | Game Settings | +---------------------------------------------------+ | Difficulty: | Hard | | Sound Volume: | 80% | | Controls: | Keyboard & Mouse | | Graphics Quality: | High | +---------------------------------------------------+ In the above example, an ASCII art representation is used to display a Lua table representing game settings. The table consists of different elements representing various game settings. Here's the Lua code that represents the table: local gameSettings = { difficulty = "Hard", soundVolume = "80%", controls = "Keyboard & Mouse", graphicsQuality = "High" } In the Lua code, a table named "gameSettings" is created, and different elements representing game settings such as difficulty, sound volume, controls, and graphics quality are added to the table. local person = { name = "Eren", age = 20, occupation = "Software Engineer", country = "Germany" } local tableFormat = [[ +-----------------------+ | Person Info | +-----------------------+ | Name: %s | | Age: %d | | Occupation: %s | | Country: %s | +-----------------------+ ]] local formattedTable = string.format(tableFormat, person.name, person.age, person.occupation, person.country) print(formattedTable) In the example above, we create a Lua table named "person" and populate it with some sample information about a person. We then define a string format named "tableFormat" which represents an ASCII table structure. We use placeholders like %s and %d to indicate the places where the values from the "person" table will be inserted. Finally, we use the string.format function to fill in the format with the data from the "person" table and store it in the variable "formattedTable". We print the "formattedTable" to display the final result. I explained string methods in the previous tutorial, here is the link: string methods LINK Output : +-----------------------+ | Person Info | +-----------------------+ | Name: Eren | | Age: 20 | | Occupation: Software Engineer | | Country: Germany | +-----------------------+ Nested Tables: Tables can contain other tables, allowing you to create nested or multidimensional data structures. Here's an example: -- Nested tables local team = { name = "Team A", players = { { name = "Eren", age = 20 }, { name = "Emily", age = 27 }, { name = "Angela", age = 23 } } } print(team.name) -- Team A print(team.players[2].name) -- Emily In the above example, we created a table named team with two elements: name and players. The players element is a nested table that contains information about individual players. We access the name element of the team table and the name of the player at the 2nd index of the players table. Table Insertion and Removal: Lua provides various functions for inserting and removing elements from tables. Here's an example that demonstrates these operations: -- Table insertion and removal local fruits = {"apple", "banana"} table.insert(fruits, "orange") -- Insert an element at the end table.insert(fruits, 2, "grape") -- Insert an element at the 2nd index table.remove(fruits, 1) -- Remove the element at the 1st index for index, fruit in ipairs(fruits) do print(index, fruit) end In the above example, we start with a table named fruits containing two elements. Using table.insert, we add an element at the end and another element at the 2nd index. Then, using table.remove, we remove the element at the 1st index. Finally, we iterate over the modified fruits table and print the index and value of each element. Table Concatenation: Lua allows you to concatenate tables using the .. operator. Here's an example: -- Table concatenation local table1 = {1, 2, 3} local table2 = {4, 5, 6} local mergedTable = {} for _, value in ipairs(table1) do table.insert(mergedTable, value) end for _, value in ipairs(table2) do table.insert(mergedTable, value) end for index, value in ipairs(mergedTable) do print(index, value) end In the above example, we have two tables named table1 and table2. We create an empty table named mergedTable and use table.insert to concatenate the elements from table1 and table2 into mergedTable. Finally, we iterate over mergedTable and print the index and value of each element. for MTA:SA Player Information: Lua tables can be used to store player information in MTA:SA. Below is an example of a player table that contains details such as the player's name, level, and score: local player = { name = "Eren", level = 5, score = 1000 } In the above example, we create a table named "player" and populate it with the player's name, level, and score. Vehicle List: Lua tables can be utilized to store data related to vehicles in MTA:SA. Here's an example of a vehicle table that includes the model names and colors of the vehicles: local vehicles = { { model = "Infernus", color = {255, 0, 0} }, { model = "Bullet", color = {0, 0, 255} }, { model = "Sultan", color = {0, 255, 0} } } In the above example, we create a table named "vehicles" and store each vehicle as a separate table with its model name and color data. Colors are represented using RGB values. NPC (Non-Player Character) List: Lua tables can be used to store in-game NPCs in MTA:SA. Here's an example of an NPC list table that includes the model IDs and coordinates of the NPCs: local npcs = { { model = 23, x = 100, y = 200, z = 10 }, { model = 56, x = 150, y = 250, z = 15 }, { model = 89, x = 200, y = 300, z = 20 } } In the above example, we create a table named "npcs" and store each NPC as a separate table with their model ID and coordinates. I hope you will like it
×
×
  • Create New...