Jump to content

Leaderboard

Popular Content

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

  1. local values = { [234] = 100, [211] = 200 } local theMarker = createMarker(0, 0, 0, "cylinder", 1.5, 255, 255, 0, 170) addEventHandler("onPlayerMarkerHit",root, function(markerHit, matchingDimension) if (markerHit == theMarker and matchingDimension) then local veh = getPedOccupiedVehicle(source) if (veh and values[getElementModel(veh)) then givePlayerMoney(source,values[getElementModel(veh)]) end end end ) Leia: https://www.Lua.org/pil/2.5.html
    2 points
  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. I had the same results, so nothing has changed. It might even be possible that they are already localized in some unknown way. Just as the predefined source variable is localized when an event has been triggered.
    1 point
  4. 1 point
  5. solved my problem with the first option, thanks
    1 point
  6. @slapz0r Do you want to mute them or mute the audio from other players as well? I haven't done this before, so I do not know the best practice, especially the capability of voice with your gamemode. But let me increase your options: See this event: onPlayerVoiceStart + example on that page. Here you have a list of export functions for the voice resource. See: https://wiki.multitheftauto.com/wiki/Resource:Voice#setPlayerVoiceMuted_2 And https://wiki.multitheftauto.com/wiki/Resource:Voice#setPlayerChannel
    1 point
  7. Hi, thanks for answer. I've checked by myself and probably it worked for Lua functions (looks like), but for some reason on MTA functions it showed mostly less or rarely - more ticks, there was a few times when it taked even more than non-localized things. (maybe fault of fast restart of script but i don't think so).
    1 point
  8. The _G table keeps track of all global variables. Not just functions and not all functions, as some can be saved in local variables. https://www.Lua.org/pil/14.html Yes, they are `shared` or rather copied. I honestly only localize my own functions. The last time I checked, I didn't notice any optimization by localize MTA functions. Every file has it's own scope, so making use of that is not a bad thing. My main reason for localization: You can use it to distinguish functions used within the file, from functions that are called from other files. The only thing I do with some Lua functions is this: local mathRandom = math.random
    1 point
  9. 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
  10. فيه اكثر من طريقة outputChatBox(table.concat(myTable[1], ", "), source, 255, 0, 0) outputChatBox(myTable[1][1]..", "..myTable[1][2], source, 255, 0, 0)
    1 point
  11. مافهمت سؤالك الاول وبالنسبة لسؤالك الثاني لا ماينفع
    1 point
  12. لو يمديك على الاقل ترفعهم على موقع imgur بكون افضل, توب 4 توب محظور عند بعض الدول
    1 point
  13. صراحة شغلك جميل و محترم اهنيك بالتوفيق لك
    1 point
×
×
  • Create New...