• Announcements

    • jhxp

      Forums are online again after a maintenance.   18/03/17

      MTA Forums maintenance is completed, although some automatic time-heavy tasks are still in process and will be finished eventually in background. Expect some features such as Forum Search to not display all results until all processes are finished. Please let us know if you spot a forum feature that worked correctly before the maintenance but does not work anymore now. Thanks. --MTA Team

koragg

Members
  • Content count

    344
  • Joined

  • Last visited

Community Reputation

40 Good

4 Followers

About koragg

  • Rank
    Fool
  • Birthday 11/02/97

Details

  • Gang
    [SiK] Speed is King
  • Location
    Sofia, Bulgaria
  • Occupation
    Racer
  • Interests
    (: Android, Mountain Biking, GTA SA & Selena Gomez :)

Recent Profile Visitors

1,156 profile views
  1. 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.
  2. 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
  3. Won't this work? It's officially from Google: https://developers.google.com/youtube/v3/
  4. 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.
  5. .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
  6. Well I can only hope that it works correctly now Hate fixing things which require other players for testing
  7. Not really sure how to make it in an 'else'
  8. 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).
  9. 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.
  10. 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.
  11. What does this have to do with MTA or lua
  12. Check this out : https://wiki.multitheftauto.com/wiki/GuiGetScreenSize It helped me when i was hopeless like you It's pretty easy actually heh
  13. https://forum.mtasa.com/forum/127-programação-em-lua/
  14. 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.
  15. Try this, maybe @StormFighter is right about the player not being created so early. function onPlayerJoin() setTimer(function(source) fadeCamera(source, true) setElementFrozen(source, true) setCameraTarget(source, source) randomSpawn(source, randomSpawnTable) end, 1000, 1, source) end addEventHandler("onPlayerJoin", root, onPlayerJoin) function onPlayerLogin() setElementFrozen(source, false) end addEventHandler("onPlayerLogin", root, onPlayerLogin) Experiment with the timer's duration a bit, if this^ does nothing, try setting it from 1000ms to 10000ms (from 1second to 10 seconds) just to see if it will do anything when the player has for sure been created.