Jump to content

Hoffmann

Members
  • Posts

    65
  • Joined

  • Last visited

Everything posted by Hoffmann

  1. Hoffmann

    Chat Write

    You will need event onPlayerChat and the following functions: getPlayerAccount() isGuestAccount() getAccountName() aclGetGroup() isObjectInACLGroup() getPlayerTeam() getTeamName() outputChatBox() cancelEvent() Take attempts to make this script yourself and ask for help here, if needed.
  2. I see no blips in your code except some variables that might be related to them.
  3. Learning pure Lua might be too difficult and boring for beginners who have never had any programming experience. I advise you to begin with simple scripts from MTA Wiki. You should take attempts to edit original code, experiment with it. For example, script with command "/ping" that will output your ping in the chatbox: function outputMyPing(player, cmd) local ping = getPlayerPing(player) outputChatBox("* Your ping: ".. ping, player, 255, 255, 255, false) end addCommandHandler("ping", outputMyPing) How would you improve this command? You may add some colors in the chat message, some conditions(if ping is low then message is green, red otherwise) and etc. There're no limits in ideas, and everything depends on your imagination. Note that you should have some basic programming knowledges including variables, arrays, loops and etc.
  4. Your code doesn't work because you used unknown "thePlayer" element instead of passing getRootElement which literally means "all players". Passing "thePlayer" instead of "source" in the bindKey function also causes errors.
  5. Try to check if your marker is successfuly created. Also make sure your script is server-sided in meta.xml
  6. I'm not sure if this line makes sense: if (tonumber(getPlayersInDimension(860)) >= 1) then It supposed to be if (tonumber(getPlayersInDimension(plr)) >= 1) then If I'm not wrong. Write number of line where error appears.
  7. I suppose you should give us any explanations of issues you've faced.
  8. Add this check in function which opens freeroam menu: if getElementData(playerElement, "jailed") then outputChatBox("* You can't use freeroam menu in jail!", playerElement, 255, 0, 0, false) return end * change playerElement variable to one which is in function.
  9. Find ids of those objects, then create them and attach to player element or use resource boneattach.
  10. There's awesome default resource that provides this feature from singleplayer. https://wiki.multitheftauto.com/wiki/Resource:Interiors
  11. I think, you should get original acl.xml file and admin resource, then edit acl as you want. This would take less time.
  12. Hoffmann

    loadstring

    I will try to explain how it works. Every function has it's own environment containing variables to which function has access. But as you're using loadstring it returns function that could be called by func() or pcall(func) and this function's environment would be set to global state(_G) by default. Because of that, if you're loading scripts from maps made by people, they will be able to call any function or trigger any event, finally, ruin your server. Function environment won't let do that, because you can manage what functions can script use. For instance, local code = "a = 6 outputChatBox(a)" local loadedCode = loadstring(code) -- returns function. loadedCode() will also work to call this code local newEnv = {outputChatBox = outputChatBox} -- we put function to use it in code setfenv(loadedCode, newEnv) -- now this code is safe and can't access _G local executedCode = pcall(loadedCode) if executedCode then outputDebugString("Code loaded!", 3) end About perfomancebrowser, run ipb resource and use /ipb to open ingame browser. Also useful posts by Arezu: Hope, I helped a bit.
  13. Hoffmann

    loadstring

    It works for me if I load script again and again, current Lua memory will change . function loadScript(stringCode) local code = loadstring(stringCode) setfenv(0, newENV) local executeCode = pcall(code) if executeCode then outputChatBox("Code has been loaded.") end
  14. This code is actually terrible because it gets player's account and set it's data every iteration but anyway code is fixed, I think.
  15. function teamspawnset ( player, cmd ) local x, y, z = getElementPosition( player ) local dim = getElementDimension( player ) local int = getElementInterior( player ) local gang = getPlayerTeam(player) local teamName = getTeamName ( gang ) for _, plr in pairs(getPlayersInTeam(gang)) do local account = getPlayerAccount(plr) if acc then setAccountData(account, "X", x) setAccountData(account, "Y", y) setAccountData(account, "Z", z) setAccountData(account, "dim", dim) setAccountData(account, "int", int) -- spawnPlayer(plr, x, y, z) UNCOMMENT THIS TO SPAWN EVERY PLAYER ON NEW COORDS end end outputChatBox ( "Succes!", source, 0, 255, 0, true ) end addCommandHandler ("setspawn", teamspawnset) function spawnTeammates(p) local acc = getPlayerAccount(p) if acc then local x, y, z = getAccountData(acc, "X"), getAccountData(acc, "Y"), getAccountData(acc, "Z") spawnPlayer(p, x, y, z) end end addEventHandler ( "onPlayerWasted", root, function() setTimer(spawnTeammates, 5000, 1, source) end) Try this code. Didn't test it.
  16. It's resource from community. I don't really think this script is too hard for scripters and they didn't put much effort creating it. So don't be too right and try to help him or just don't answer.
  17. I use this method: local X,Y = guiGetScreenSize() local xReal = X/your screen X local yReal = Y/your screen Y -- example: local X,Y = guiGetScreenSize() local xReal = X/1366 -- my screen's X local yReal = Y/768 -- my screen's Y dxDrawText("text", xReal*683, yReal*384....) -- it will draw a text in the middle of your screen
  18. I have a string "sometext*sometext". How to get "sometext" before symbol " * " and get "sometext" after this symbol?
  19. Thank you but I have already solved my problem and made solution!
  20. I want to use colors to send them in my function ProxDetector. But there are trg colors, idk how to define and use them. Maybe table and unpack?
  21. Hello, community! Can you help me? What is the best method to send RGB/HEX colors in function? function meChat(thePlayer, cmd, ...) ProxDetector(30, thePlayer, ..., color1, color2, color3, color4, color5) end addCommandHandler("do", meChat) function ProxDetector(radius, thePlayer, ..., color1) local text = table.concat({...}," ") local oldposx, oldposy, oldposz = getElementPosition(thePlayer) for k, v in pairs(getElementsByType("player")) do local posx, posy, posz = getElementPosition(v) if getElementDimension(v) == getElementDimension(thePlayer) then local getRadius = getDistanceBetweenPoints3D(oldposx, oldposy, oldposz, posx, posy, posz) if (getRadius < radius / 16) then outputChatBox(getPlayerName(thePlayer).." "..text, v, color1, false) elseif (getRadius < radius / 8) then outputChatBox(getPlayerName(thePlayer).." "..text, v, color2, false) elseif(getRadius < radius / 4) then outputChatBox(getPlayerName(thePlayer).." "..text, v, color3, false) elseif(getRadius < radius / 2) then outputChatBox(getPlayerName(thePlayer).." "..text, v, color4, false) elseif(getRadius < radius) then outputChatBox(getPlayerName(thePlayer).." "..text, v, color5, false) end end end return true end I tried something like COLOR_PURPLE = 0xC2A2DAAA and then convert in to RGB in outputchatBox function but it says that ")" expected near "," in function string.
×
×
  • Create New...