Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/09/19 in all areas

  1. addEventHandler + group elements I noticed that some people like to add 10000000000000000 addEventHandlers for each element, while you probably only need 1 addEventHandler. Using ONE addEventHandler on a group of elements? Answer: local group = createElement("groupMyCutePeds") -- Create a custom element and save it in to the variable <group>. -- Create 3 peds. local ped1 = createPed(120, 5540.6654, 1020.55122, 1240.545) local ped2 = createPed(120, 5541.6654, 1021.55122, 1240.545) local ped3 = createPed(120, 5542.6654, 1022.55122, 1240.545) -- Set the parent of the 3 peds. setElementParent(ped1, group) setElementParent(ped2, group) setElementParent(ped3, group) -- Add an addEventHandler and use the <group> as <attachedTo> element. addEventHandler("onPedWasted", group, -- "onPedWasted" = serverside. "onClientPedWasted" = clientside. function () outputChatBox("One of my cute peds just died. ;'( No exceptions!") end) Code is untested, but the method is tested. Syntax for functions in example createElement syntax element createElement ( string elementType, [ string elementID = nil ] ) setElementParent syntax bool setElementParent ( element theElement, element parent ) addEventHandler syntax bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [ bool getPropagated = true, string priority = "normal" ] ) DO NOT disable getPropagated getPropagated: A boolean representing whether the handler will be triggered if the event was propagated down or up the element tree (starting from the source), and not triggered directly on attachedTo (that is, handlers attached with this argument set to false will only be triggered if source == this). If you disable this, children of the <group> element are not included. Make use of the element tree Element tree For applying addEventHandlers to elements created by the resource: Use: resourceRoot / getResourceRootElement For applying addEventHandlers to elements created by scripts of the resource: Use: getResourceDynamicElementRoot For applying addEventHandlers to elements created by maps of the resource: Use: getResourceMapRootElement I hope your code will be without... print(10^10^10^10) -- Print here: https://www.lua.org/cgi-bin/demo ...addEventHandlers in the future.
    1 point
  2. MTA-Communication-Enhancement This is an enhancement that allows you to communicate between clientside and serverside a bit easier. If you know how to work with events, then you probably do not need this, but it has some nice features which allows you to sit back and write less code + achieve some nice results. Note: It is important to keep in mind that this is an enhancement. Which means it is just an layer on top of the basic functionalities of MTA. And most enhancements come with a cost, in this case that is bit of performance. I will keep the information of topic to the minimal, as I have written most of the information already on the repository. You can find the repository here. Examples Syntax Installation What can you do with it? Calling from clientside to serverside Client callServer("hello") Server function hello () outputChatBox("Hello client!") end Calling from serverside to clientside Server addCommandHandler("callclient", function (player) -- An addCommandHandler is needed, because the client hasn't loaded it's scripts yet. callClient(player, "hello") end, false, false) Client function hello () outputChatBox("Hello server!") end Ok, ok, that was boring. The next one this is a bit nicer! Hello are you there? Just Call-me-back... I miss(ed) you too Callback Client callServer( "callbackMe", "argument", function (argument) -- < This is the callback function outputChatBox(argument) end ) Server function callbackMe (argument) return argument .. " < I looked at it :)" end Callback + internal arguments Sometimes you have arguments that you simply can't send over. > functions Or arguments that shouldn't be send over. > LARGE quantities of database data Internal arguments can be used to pass information to a callback without exposing it to the other side(client/server). Client callServer( "callbackMe", -------------------------------- -- arguments that are send over "argument", -- -------------------------------- function (internalArgument, argument) -- < This is the callback function. outputChatBox(internalArgument) outputChatBox(argument) end, -------------------------------- -- arguments that are not send over "internalArgument" -- < internal argument -- -------------------------------- ) Server function callbackMe (argument) return argument .. " < I looked at it :D" end Ha! Serverside what is that? No need for complicated things! Communicate between clients without writing a single line of serverside. Magic! Note: There is serverside used behind the scenes, you just don't have to write it. Client function smile (player) outputChatBox((isElement(player) and getPlayerName(player) or "[unknown]") .. " has send you a: :)") local x, y, z = getElementPosition(localPlayer) setElementPosition(localPlayer, x, y, z + 100) end addRemoteClientAccessPoint(smile) -- < This function allows other clients to call this function. --------------------------------------- -- -- function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end -- Author: TAPL -- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName -- -- --------------------------------------- addCommandHandler("smile", function (cmd, playerName) local player = getPlayerFromPartialName(playerName) if player then outputChatBox("Sending smile!") callRemoteClient(player, "smile", player) else outputChatBox("Can't find player!") end end) Turtle, I will wait for you to catch up. So don't worry, you are still cute. Await functions When a player has joined the server, he or she doesn't have download + loaded his scripts yet. This means that you can't deliver your love letter yet and all your work will be for nothing. But what if you don't have to worry about that? You can just wait now! Server addEventHandler("onPlayerJoin", root, function () callClientAwait(source, "testCallClientAwait") end) Client function testCallClientAwait () outputChatBox("Yes this works!") end Security Worried about security issues? Remote calls for C++/MTA functions have been blocked. There is a whitelist feature included, if enabled your code can only remote-call whitelisted functions. (this is disabled by default) Read the docs for that. Here and here
    1 point
  3. Já depurou o código pra ver se ele está lendo tudo?
    1 point
  4. Just so you know, the actual max value for engineSetModelLODDistance is 325
    1 point
  5. Bom fiz os testes aqui e ta tudo certo com o seu script, só não entendi os else e tbm do jeito que vc fez qualquer player vai poder ter acesso aos comandos policiais! Refiz essa parte da verificação, da uma olhada e verifica se esta tudo certo mesmo na acl Admin. marker = createMarker(1557.796, -1604.656, 13.383 ,"cylinder", 1.1, 255 ,0 ,0 ,255) function pegarTag ( Jogador ) if isElementWithinMarker (Jogador, marker ) then if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(Jogador)), aclGetGroup("AclPolicial")) then aclGroupAddObject (aclGetGroup("ComandosPolicia"), "user."..getAccountName(getPlayerAccount(Jogador))) outputChatBox ("|#FFFF00Policia Federal#FFFFFF|-Agora você está em seviço na PF", Jogador, 255, 255, 255, true) else outputChatBox ('|#FF0000Aviso#FFFFFF|- Você não tem permissão! Saia deste local', Jogador, 255, 255, 255, true) end end end addCommandHandler ( "trabalhar", pegarTag ) function tirarTag ( Jogador ) if isElementWithinMarker (Jogador, marker ) then if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(Jogador)), aclGetGroup("AclPolicial")) then aclGroupRemoveObject (aclGetGroup("ComandosPolicia"), "user."..getAccountName(getPlayerAccount(Jogador))) setPedSkin ( Jogador, 0 ) outputChatBox ('|#FFFF00Policia Federal#FFFFFF|-Você está fora de serviço da PF.', Jogador, 255, 255, 255, true) else outputChatBox ('|#FF0000Aviso#FFFFFF|- Você não tem permissão! Saia deste local', Jogador, 255, 255, 255, true) end end end addCommandHandler ( "sair", tirarTag )
    1 point
  6. Troque todos os sources por thePlayer. Não se usa source como parâmetro de função. E remova aqueles else
    1 point
  7. I used dbPrepareString in other way (adding items only by modyfing table), could you check if everything is correct? Looks like table and columns created normally. local query_table = {} query_table[#query_table + 1] = dbPrepareString(serverTable.db, "CREATE TABLE IF NOT EXISTS `Items` (`Serial`, ") for i = 1, #serverTable.config.save_items do local item = serverTable.config.save_items[i] local check_index = i == #serverTable.config.save_items and ")" or ", " query_table[#query_table + 1] = dbPrepareString(serverTable.db, "`"..item.."` INT"..check_index) end dbExec(serverTable.db, table.concat(query_table))
    1 point
  8. Not really, I do not look at community resources that much. But there is a book called SQL in 10 minutes, which has tons of good examples in it. Try to find yourself a copy of it on the internet.
    1 point
  9. 1 point
  10. Do not use dbPoll with -1 query time, its will couse server side freeze if one of the query comeback with timeout. You can use the dbQuery's callback function with zero timeout instead of, like this: function LoadMessages() local query = dbQuery(function(qh) result = dbPoll(qh,0) end,connection, "SELECT * FROM messages WHERE characterID = 1") for x, ad in ipairs( result ) do local res = result[x]['message'] end end addEvent("LoadMsg", true) addEventHandler("LoadMsg", resourceRoot, LoadMessages) You can read more about there: https://wiki.multitheftauto.com/wiki/DbQuery
    1 point
  11. local shapes = { {X,Y,Z}; {X,Y,Z}; {-X,Y,Z}; {X,Y,Z}; } for i=1, #shapes do shape1[i] = createColSphere(shapes[i][1], shapes[i][2],shapes[i][3]) end Se eu nao me engano nessa script tem o evento destroyMyVehicle, nesse voce especifica se o player está em um veiculo e dentro de um colshape isElementWithinColShape
    1 point
  12. SetElementRotation não é como o moveObject. Ele não vai rotacionar 90º, ele vai ficar no ângulo de 90º em relação ao mundo. Isto é, ele vai ficar apontado para Oeste. Você está setando interior, dimensão, posição e rotação ao mesmo tempo. Experimente colocar a rotação em um pequeno timer. setTimer (setElementRotation, 100, 1, liberado, 0, 0, 90)
    1 point
  13. Hello again to everyone. Today I installed the latest version of the server for Windows. The client is also the latest version. And still, the local path for browsers does not work. Checked on another system, also does not work. I ask you, dear reader, to try to run the code from the first post in version 1.5.7 and unsubscribe here about the results.
    1 point
  14. That table structure will not work well. Back to basic: local list = { {value = 25, id = "a"}, {value = 50, id = "b"}, {value = 75, id = "c"}, {value = 100} } function findSomething(value) for i = 1, #list - 1 do if value >= list[i].value and value < list[i + 1].value then return list[i] end end end local result = findSomething(27) if result then print(result.id) end
    1 point
  15. EngineLoadIFP EngineReplaceAnimation
    1 point
  16. It took a while before I had time for explaining an enchantment which I created a while back, but I finally wrote a topic for it. Just another enchantment topic/tutorial. This time it is about communication between serverside and clientside. The context of what will be enchanted These 2 sides will have communication with each other: serverside > code that runs in the server application. Program Files (x86)\MTA San Andreas X.X\server\MTA Server(.exe) clientside > code that runs on all clients/players > game application. Program Files (x86)\MTA San Andreas X.X\Multi Theft Auto.exe In most cases there is just 1 server. And there might be more clients / players connected to that 1 server. If you already know how client/server trigger events work, then it is still worth looking at. It is an enchantment, which means it does things for you, so less code is needed to achieve something complex. There are some stupid jokes included, which are actually really bad... sorry. It is suppose reduce the cognitive load of the content by letting the reader first visualize the context before explaining it. (it is a method)
    1 point
  17. You are only setting it ON, even when you are trying to set it OFF. engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 1000 or 150) 1000 is ON. Something below 170 is OFF. ( probably each object has an unique LOD distance value )
    0 points
×
×
  • Create New...