-
Posts
730 -
Joined
-
Last visited
-
Days Won
2
Everything posted by koragg
-
Try this this to fix your boolean error: CarshopMenu = {} local renderTarget local MENU_OFFSET = Vector3(-7.5, -7, -0.7) local position = Vector3() local size = Vector2(1.5, 1.9) local rotation = 280 local resolution = size * 250 local headerHeight = 70 local barOffset = 20 local barHeight = 20 local labelHeight = 50 local barsList = { {locale = "carshop_label_speed", value = 0.7, param = "speed"}, {locale = "carshop_label_acceleration", value = 0.4, param = "acceleration"}, {locale = "carshop_label_control", value = 0.85, param = "control"} } local headerFont local labelFont local hasDriftHandling = false local themeColor = {0, 0, 0} local themeColorHex = "#FFFFFF" local function draw() dxSetRenderTarget(renderTarget) dxDrawRectangle(0, 0, resolution.x, resolution.y, tocolor(42, 40, 41)) dxDrawRectangle(0, 0, resolution.x, headerHeight, tocolor(32, 30, 31)) local priceText = "" if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end dxDrawText(priceText, 0, 0, resolution.x - 20, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3]), 1, labelFont, "right", "center") local priceWidth = dxGetTextWidth(priceText, 1, labelFont) local headerText = Carshop.currentVehicleInfo.name local hearderWidth = dxGetTextWidth(headerText, 1, headerFont) local hearderScale = false if priceWidth then hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) dxDrawText(headerText, 20, 0, resolution.x - 20 - priceWidth, headerHeight, tocolor(255, 255, 255), hearderScale, headerFont, "left", "center", true) end local buyButtonActive = true local buyButtonText = exports.dpLang:getString("carshop_buy_button") if Carshop.currentVehicleInfo.level > localPlayer:getData("level") then buyButtonActive = false --"Требуется уровень " .. buyButtonText = string.format(exports.dpLang:getString("carshop_required_level"), tostring(Carshop.currentVehicleInfo.level)) elseif Carshop.currentVehicleInfo.price > localPlayer:getData("money") then buyButtonActive = false buyButtonText = exports.dpLang:getString("carshop_no_money") end if not buyButtonActive then dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(32, 30, 31)) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255, 150), 1, headerFont, "center", "center") else dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255), 1, headerFont, "center", "center") end local y = headerHeight local barWidth = resolution.x - barOffset * 2 for i, bar in ipairs(barsList) do -- Подпись dxDrawText(bar.text, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center") y = y + labelHeight dxDrawRectangle(barOffset, y, barWidth, barHeight, tocolor(65, 65, 65)) dxDrawRectangle(barOffset, y, barWidth * bar.value, barHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) bar.value = bar.value + (Carshop.currentVehicleInfo.specs[bar.param] - bar.value) * 0.2 y = y + barHeight * 2 end local labelText = exports.dpLang:getString("carshop_drift_label") local valueText = "" if Carshop.hasDriftHandling then valueText = exports.dpLang:getString("carshop_drift_label_yes") else valueText = exports.dpLang:getString("carshop_drift_label_no") end dxDrawText(labelText .. ": " .. themeColorHex .. valueText, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center", false, false, false, true) dxSetRenderTarget() local halfHeight = Vector3(0, 0, size.y / 2) local rad = math.rad(rotation) local lookOffset = Vector3(math.cos(rad), math.sin(rad), 0) dxDrawMaterialLine3D( position + halfHeight, position - halfHeight, renderTarget, size.x, tocolor(255, 255, 255, 250), position + lookOffset ) end function CarshopMenu.start(basePosition) position = MENU_OFFSET + basePosition renderTarget = dxCreateRenderTarget(resolution.x, resolution.y, false) headerFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 20) labelFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 18) themeColor = {exports.dpUI:getThemeColor()} themeColorHex = tostring(exports.dpUtils:RGBToHex(unpack(themeColor))) for i, bar in ipairs(barsList) do bar.text = exports.dpLang:getString(bar.locale) end addEventHandler("onClientRender", root, draw) end function CarshopMenu.stop() if isElement(renderTarget) then destroyElement(renderTarget) end if isElement(headerFont) then destroyElement(headerFont) end if isElement(labelFont) then destroyElement(labelFont) end removeEventHandler("onClientRender", root, draw) end Also, I don't see "labelFont" declared to an actual font anywhere. I mean at line 21 you do "local labelFont" but then you don't give it any value before using it at lines 38 and 40. Here's an example of how to import a custom font from a file inside any script: Digital = dxCreateFont("Digital.ttf", 21) --Custom font I added a check at line 45, that should fix the boolean error. Always when it gives boolean errors/warnings that means that the script is not sure if the thing given in the error message is there or not. It can be a file, variable, font, pretty much anything. Most times a simple "if" statement gets rid of the error. This way you tell the script explicitly to check if the wanted/needed thing is actually there or not. Hope something out of this post helps you out.
-
I'll try it in a week or two. Literally buried in exams right now...
-
If this is true then it indeed is a bug with higher resolutions. Never used the resource so no idea how to fix it bt you can PM the developer and report it as a bug. Maybe he'll fix it later on, who knows...
-
function setControlNumber(...) local args = {...} local num = table.remove(args) if getControl(unpack(args) then guiSetText(getControl(unpack(args)), tostring(num)) end end Try this.
-
How about you read the rules and obey them for a change? We're not forced to help you, we do it by free will. And since you don't have an interest in coding that means you also don't have an interest in trying to fix the problem yourself. We help people here, not write whole scripts or waste days trying to fix someone else's problem...bump all you want, only thing you'll get is reputation of a guy who doesn't want to try make things by himself and only relies on someone else's knowledge. You'll understand me better once you read the rules (if you even do so).
-
No problem
-
I searched the wiki and there is no such eventHandler for MTA only for SA-MP
-
3 problems with my server... Please.. help...
koragg replied to CancerousBanana's question in Server
I see you've got some 'Global chat' resource too, probably something is messing with the main chat, you can make a topic in "Scripting" section and post code of the chat resource since it looks like that it's a resource bug (might be wrong). -
"onPlayerInteriorChange" is a SA-MP event http://wiki.sa-mp.com/wiki/OnPlayerInteriorChange Try this for the second warning: function switchGroundSnow(toggle) if getResourceFromName( "shader_snow_ground" ) and getResourceState ( getResourceFromName( "shader_snow_ground" ) ) == "running" then triggerClientEvent( thePlayer, "switchGoundSnow", thePlayer, toggle) end end
-
https://wiki.multitheftauto.com/wiki/DxDrawCircle There are two examples for you to try on wiki.
-
3 problems with my server... Please.. help...
koragg replied to CancerousBanana's question in Server
No idea about chat. Yea, a free host ^^ My server is hosted in France and my ping is between 50 and 80 which is awesome. I won't say that my server is the most secure one Heck, i didn't even put any security resources in it, just one anti-hack preventing players from using modified vehicles. Who will waste time trying to ruin a server though? If a person has that knowledge i think that he'll just create his own server instead lol -
3 problems with my server... Please.. help...
koragg replied to CancerousBanana's question in Server
You mean MTA's normal chat or a custom made chat? If it's the second, post the full script of the custom chat (client and server parts). Yes. Restarting a resource forces everyone to re-download and re-start the resource so that it's up to date with the changes. -
3 problems with my server... Please.. help...
koragg replied to CancerousBanana's question in Server
If you've deleted everything (lines in meta.xml and images) then all you need to do is /restart 'resourceName' to apply changes About the second thing, no idea. We'll need the full code I guess. And the third, there's probably some .xml file which holds the default values. Sadly I've never worked with anything other than Race gamemode so you'll have to figure where it is on your own. TIP: Open Notepad++, press CTRL+LShift+F, select your server's directory and type one of the setting's name in the "Find what:" box, now hit Enter. This way you'll find all files which contain that setting and there's a good chance you'll find the defaultsettings.xml (just example name, idk real xd) one which holds the initial values -
Won't this work? It's officially from Google: https://developers.google.com/youtube/v3/
-
In short, when I press 3 on my keyboard my spawnpoint changes to the one which is closest to the first checkpoint of the map. But I want to compare if my current spawnpoint is actually the one which is closest to first checkpoint. As if I get auto-spawned in the closest spawnpoint by MTA itself there's no point in charging me with 7 coins to 'change' my spawnpoint (it won't change as the one I'm in is already the closest one). Any ideas? This is the whole script: ----------------- --- Spawns --- ----------------- local spawnIndex = {} local allSpawnpoints = {} ------------------------------------------------------------------------------------------------------------------------ function mapRestart(mapInfo, mapOptions, gameOptions) previousSpawn = {} spawnIndex = {} lshift, rshift = {}, {} allSpawnpoints = getElementsByType("spawnpoint", getResourceRootElement(exports.mapmanager:getRunningGamemodeMap())) if #getElementsByType("checkpoint") > 0 then table.sort(allSpawnpoints, function (spawnA, spawnB) local a_x, a_y, a_z, a_id = getSpawnpointPosition ( spawnA ) local b_x, b_y, b_z, b_id = getSpawnpointPosition ( spawnB ) local c_x, c_y, c_z = getElementPosition(getElementsByType("checkpoint")[1]) return getDistanceBetweenPoints3D( a_x, a_y, a_z, c_x, c_y, c_z) < getDistanceBetweenPoints3D( b_x, b_y, b_z, c_x, c_y, c_z) end) end if #allSpawnpoints == 0 then return false end for k,v in ipairs(getElementsByType("player")) do setElementData(v, "hasBoughtSpawn", false) end end addEventHandler("onMapStarting", root, mapRestart) ------------------------------------------------------------------------------------------------------------------------ function callSpawn(player) local spawnPrice = 7 local playeraccount = getPlayerAccount(player) local res = getResourceFromName("cw") if getResourceState(res) == "running" then return end local account = getPlayerAccount(player) if isGuestAccount(account) then outputChatBox("You need to register and login in order to buy spawnpoints!", player, 255, 153, 0, true) return end if #allSpawnpoints == 1 then outputChatBox("This map contains only one spawnpoint.", player, 255, 153, 0, true) return end if #allSpawnpoints == 0 then return false end local elementID local cash = tonumber(getAccountData(account, "knightcoins") or 0) if cash < spawnPrice or not cash then outputChatBox ( "You don't have enough KnightCoins to buy a spawn.", player, 255, 153, 0) return end if getElementData(player, "isOnSpawn") and getElementData(player, "isOnSpawn") == true then if not spawnIndex[player] then elementID, distance, index, rot = changeSpawn(player) outputChatBox("Use shift+3 to go back to a previous spawnpoint", player, 0, 255, 255) elseif getPedOccupiedVehicle(player) then elementID, distance, index, rot = changeSpawn(player) end local model = getElementModel(getPedOccupiedVehicle(player)) local rotation = rot if elementID then outputChatBox("Changed to spawnpoint: "..tostring(index).." / "..round(distance).." m / vehicle: "..tostring(getVehicleNameFromModel(model)).." ("..model..") / rotation: "..round(tonumber(rotation)), player, 0, 255, 255) end if getElementData(player, "hasBoughtSpawn") == true then return end local cash = tonumber(getAccountData(account, "knightcoins") or 0) if cash >= spawnPrice then local newCash = cash - spawnPrice setAccountData(account, "knightcoins", newCash) setElementData(player ,"data.knightcoins", newCash, true) triggerClientEvent(player, "addNotification", root, "#FF0000-"..spawnPrice.." #00FFFFKnightCoins #00FF00("..comma_value(newCash)..")", 2) local oldMoneySpentData = getAccountData(playeraccount, "moneySpent") or 0 local newMoneySpentData = oldMoneySpentData + spawnPrice setAccountData(playeraccount, "moneySpent", newMoneySpentData) setElementData(player, "moneySpent", newMoneySpentData) end else setElementData(player, "hasBoughtSpawn", false) end setElementData(player, "hasBoughtSpawn", true) end ------------------------------------------------------------------------------------------------------------------------ function changeSpawn(player) if not spawnIndex[player] then spawnIndex[player] = 1 else spawnIndex[player] = spawnIndex[player] + (getShiftState(player) and -1 or 1) end if spawnIndex[player] > #allSpawnpoints then spawnIndex[player] = 1 elseif spawnIndex[player] < 1 then spawnIndex[player] = #allSpawnpoints end local newSpawnpoint = allSpawnpoints[spawnIndex[player]] local veh = getPedOccupiedVehicle(player) if not veh then return end local x, y, z, id, vehID, rot = getSpawnpointPosition(newSpawnpoint) setElementPosition(veh, x,y,z) setElementRotation(veh, 0,0, rot) setElementModel(veh, vehID) setElementHealth(veh, 1000) local distance = getElementsByType("checkpoint")[1] and math.floor(100*getDistanceBetweenPoints3D(x,y,z,getElementPosition(getElementsByType("checkpoint")[1])))/100 or 0 return id, distance, spawnIndex[player], rot end ------------------------------------------------------------------------------------------------------------------------ function getSpawnpointPosition(element) local x = tonumber(getElementData(element, 'posX')) local y = tonumber(getElementData(element, 'posY')) local z = tonumber(getElementData(element, 'posZ')) local id = getElementID(element) local vehID = tonumber(getElementData(element, 'vehicle')) local rot = tonumber(getElementData(element, 'rotation') or getElementData(element, 'rotZ')) return x, y, z, id, vehID, rot end --------------------------- --- Shift detection --- --------------------------- local lshift, rshift = {}, {} function shift(player, key, state) if key == "lshift" then lshift[player] = state == "down" and true or nil elseif key == "rshift" then rshift[player] = state == "down" and true or nil end end ------------------------------------------------------------------------------------------------------------------------ function onResStart() for k,v in ipairs(getElementsByType("player")) do bindKey(v, "lshift", "both", shift) bindKey(v, "rshift", "both", shift) bindKey(v, "3", "down", callSpawn) end end addEventHandler("onResourseStart", resourceRoot, onResStart) ------------------------------------------------------------------------------------------------------------------------ function onPlayerJoin() bindKey(source, "lshift", "both", shift) bindKey(source, "rshift", "both", shift) bindKey(source, "3", "down", callSpawn) end addEventHandler("onPlayerJoin", root, onPlayerJoin) ------------------------------------------------------------------------------------------------------------------------ function onPlayerQuit() lshift[source] = nil rshift[source] = nil end addEventHandler("onPlayerQuit", root, onPlayerQuit) ------------------------------------------------------------------------------------------------------------------------ function getShiftState(player) return lshift[player] or rshift[player] end ------------------------------------------------------------------------------------------------------------------------ --http://lua-users.org/wiki/FormattingNumbers function round(val, decimal) if (decimal) then return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) else return math.floor(val+0.5) end end ------------------------------------------------------------------------------------------------------------------------ --http://lua-users.org/wiki/FormattingNumbers function comma_value(amount) local formatted = amount while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end return formatted end And a small command I made to get the coordinates of spawnpoint1 (NOT the closest one to 1st checkpoint) and those of my vehicle in hope to somehow see how to get spawnpoint coords out of my vehicle's coords but no luck so far : local allSpawnpoints = {} function onMapStart() allSpawnpoints = getElementsByType("spawnpoint", getResourceRootElement(exports.mapmanager:getRunningGamemodeMap())) end addEventHandler("onMapStarting", root, onMapStart) function test(player) local newSpawnpoint = allSpawnpoints[1] local x, y, z, id, vehID, rot = getSpawnpointPosition(newSpawnpoint) local xx, yy, zz = getElementPosition(getPedOccupiedVehicle(player)) outputChatBox(x..", "..y..", "..z) outputChatBox(xx..", "..yy..", "..zz) end addCommandHandler("go", test) function getSpawnpointPosition(element) local x = tonumber(getElementData(element, 'posX')) local y = tonumber(getElementData(element, 'posY')) local z = tonumber(getElementData(element, 'posZ')) local id = getElementID(element) local vehID = tonumber(getElementData(element, 'vehicle')) local rot = tonumber(getElementData(element, 'rotation') or getElementData(element, 'rotZ')) return x, y, z, id, vehID, rot end So if a player gets spawned in the closest to the first checkpoint spawn I want to just do 'return' and not take any coins from them as they already will be in the spawn that otherwise they have to buy.
-
.luac files are made like that for a reason. And the reason is that the authors of those scripts don't want anyone else to edit or steal their code. I myself find such compiled resources pure :~ as most of the times the resource itself is great but I can't change a few simple things like position of the elements for example, thus rendering it unusable at my server But you can always try out a compiled resource, see what it does and release an uncompiled version made by yourself for those like me who only want to edit a few things and not steal the script
-
Well I can only hope that it works correctly now Hate fixing things which require other players for testing
-
Not really sure how to make it in an 'else'
-
Isn't this responsible for the time when the player is online (new (different) winner) ? for _, player in ipairs(players) do if player ~= source then if getElementData(player, "Streak") then if getElementData(player, "Streak") > 1 then exports.messages:outputGameMessage(getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." broke "..getPlayerName(player):gsub("#%x%x%x%x%x%x", "").."'s WinStreak of "..getElementData(player, "Streak"), getRootElement(), 2, 30, 144, 255) end setElementData(player, "Streak", nil) end end end It searches for the "Streak" data in all online players and if it's higher than 1 it shows text. And only one player can have "Streak" higher than 1 as it is a winstreak (goes up by 1 only if you win, if someone else wins it goes to nil). If the line "if player ~= source then" is missing the player argument (he left) then it jumps to the "oponentName" part which is identical as this^ just with exchanged values for the opponent as he's left now. Ignore it That was one of my very first scripts I put on my server 2 years ago, haven't really touched it since then. Gonna optimise it a lot soon (if you see how it checks what suffix to give after each number, you'll lol).
-
So I have this script I made edited which counts a player's winstreaks. And if another player wins it shows message that the current winner has broken the previous guy's winstreak. Well, yes but if the previous guy leaves the server then there is no text when someone else beats his streak (as the previous guy is not online anymore and there is no way to get his data). Would the below code show the message even if the previous streak's owner has left the server? local opponentStreak local opponentName ------------------------------------------------------------------------------------------------------------------------- function onQuit() if getElementData(source, "Streak") then opponentStreak = getElementData(source, "Streak") opponentName = getPlayerName(source) end end addEventHandler("onPlayerQuit", root, onQuit) ------------------------------------------------------------------------------------------------------------------------- addEvent("onPlayerRaceWinStreak") function winstreak() local players = getElementsByType("player") local playeraccount = getPlayerAccount(source) local minPlayers = 5 if #players < minPlayers then setElementData(source, "Streak", nil) return end local wins = getElementData(source, "Streak") or 0 wins = wins + 1 if wins > 1 then if isGuestAccount(playeraccount) then exports.messages:outputGameMessage(getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." did a WinStreak of "..wins, getRootElement(), 2, 30, 144, 255) else local knightc = 0 local pointsc = 0 if wins == 2 then knightc = wins pointsc = wins * wins elseif wins == 3 then knightc = wins pointsc = wins * wins elseif wins == 4 then knightc = wins pointsc = wins * wins elseif wins == 5 then knightc = wins pointsc = wins * wins elseif wins == 6 then knightc = wins pointsc = wins * wins elseif wins == 7 then knightc = wins pointsc = wins * wins elseif wins == 8 then knightc = wins pointsc = wins * wins elseif wins == 9 then knightc = wins pointsc = wins * wins elseif wins > 9 then knightc = wins pointsc = wins * wins end local kc = tonumber(getAccountData(playeraccount, "knightcoins") or 0) + knightc local pts = tonumber(getAccountData(playeraccount, "points") or 0) + pointsc exports.messages:outputGameMessage("#FFFFFF"..addTeamColor(source).." earned "..knightc.." KnightCoins and "..pointsc.." Points for his WinStreak of "..wins.." [("..comma_value(kc).."), ("..comma_value(pts)..")]", getRootElement(), 2, 30, 144, 255) local mesaj = "You earned "..knightc.." KnightCoins and "..pointsc.." Points for your WinStreak of "..wins.." [("..comma_value(kc).."), ("..comma_value(pts)..")]" triggerClientEvent(source ,"serverMEsajlarAl", source, mesaj) setAccountData(playeraccount, "knightcoins", kc) setElementData(source ,"data.knightcoins", kc, true) setAccountData(playeraccount, "points", pts) setElementData(source ,"data.points", pts, true) triggerClientEvent(source, "addNotification", root, "#FEFE22+"..knightc.." #00FFFFKnightCoins #00FF00("..comma_value(kc)..")", 1) local oldEarningsData = getAccountData(playeraccount, "totalEarnings") or 0 local newEarningsData = oldEarningsData + knightc setAccountData(playeraccount, "totalEarnings", newEarningsData) setElementData(source, "totalEarnings", newEarningsData) end end local winstreaks = getElementData(source, "Streak" ) or 0 if winstreaks < wins then setElementData(source , "winstreak", wins, true) end setElementData(source, "Streak", wins) -- clear opponents streak for _, player in ipairs(players) do if player ~= source then if getElementData(player, "Streak") then if getElementData(player, "Streak") > 1 then exports.messages:outputGameMessage(getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." broke "..getPlayerName(player):gsub("#%x%x%x%x%x%x", "").."'s WinStreak of "..getElementData(player, "Streak"), getRootElement(), 2, 30, 144, 255) end setElementData(player, "Streak", nil) end end end if opponentStreak and opponentName then if opponentStreak > 1 then exports.messages:outputGameMessage(getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." broke "..opponentName:gsub("#%x%x%x%x%x%x", "").."'s WinStreak of "..opponentStreak, getRootElement(), 2, 30, 144, 255) end opponentStreak = nil opponentName = nil end return end addEventHandler("onPlayerRaceWinStreak", root, winstreak) Basically I save the guy's nickname and winstreaks count to some global variables when he quits and then display those IF the player is no longer online and another one has won 1+ times.
-
Well you don't necessarily need to avoid community resources. What I do is this: 1. I browse a bit at the free resources. 2. If something catches my eye I download it, test it and if I like it's idea I start editing 90% of it so that it works perfectly for my needs 3. Take ideas from a resource and make it myself if it's too bugged.
-
What does this have to do with MTA or lua
-
Check this out : https://wiki.multitheftauto.com/wiki/GuiGetScreenSize It helped me when i was hopeless like you It's pretty easy actually heh
-
https://forum.multitheftauto.com/forum/127-programação-em-lua/
-
You can use https://wiki.multitheftauto.com/wiki/TriggerClientEvent and https://wiki.multitheftauto.com/wiki/TriggerServerEvent to communicate between server and client scripts. Element data is pretty useful but not everytime so you just need to know when to use what This^ can be done with the "triggerClientEvent" thing and tell the resource to load the same stuff to every player on the server.