Jump to content

JR10

Retired Staff
  • Posts

    2,947
  • Joined

  • Last visited

Posts posted by JR10

  1. You're sending a table, not a string. You need to retrieve the first element of that table, which is the string-type message.

    function infoServer2(szoveg) 
        for i = 3, 0, -1 do 
            szovegek[i+1] = szovegek[i] 
        end 
        szovegek[0] = szoveg[0] 
    end 
    addEvent("infoServer2", true) 
    addEventHandler("infoServer2",getRootElement(), infoServer2) 
    

  2. dbExec(db, "CREATE TABLE IF NOT EXISTS `accountdata`(`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT)") 
    dbExec(db, "CREATE TABLE IF NOT EXISTS `inventory`(`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT)") 
    

  3. When you restart the resource, you want everyone to have 0 as their kills? If so, the above code should still do that for you:

    addEventHandler('onResourceStart', root, function() 
     for index, player in pairs(getElementsByType('player')) do 
      setElementData(player, 'Zombie Kills', 0) 
     end 
    end) 
    

    If you want anyone with 0 kills to have their kills cell empty, then just remove the element data on restart.

    setElementData(player, 'Zombie Kills') 
    

  4. I've written a Node.js module to facilitate calling http exported functions. It's just a class with one function, 'call'. It was originally part of my web panel project for MTA, but I've decided to release it as a module.

    It's published on npm, so it's easy to install with:

    npm install mtasa-sdk 
    

    Example:

    var MTA = require('mtasa-sdk'); 
      
    var server = new MTA(); // [url=http://localhost:22005]http://localhost:22005[/url] 
    server.call(resourceName, functionName, args, callback); 
    

    For more information, check the GitHub repo: http://github.com/jr10/node-mtasa-sdk

    • Like 1
  5. The second function just doesn't make any sense.

    addEvent("onZombieWasted",true) 
    addEventHandler("onZombieWasted",root, 
    function (killer) 
    setElementData(killer, "Zombie Kills", getElementData(killer, "Zombie Kills") + 1) 
    end) 
      
    addEventHandler('onPlayerJoin', root, function() 
     setElementData(source, 'Zombie Kills', 0) 
    end) 
      
    addEventHandler('onResourceStart', root, function() 
     for index, player in pairs(getElementsByType('player')) do 
      setElementData(player, 'Zombie Kills', 0) 
     end 
    end) 
    

    Try to not use Zombie Kills as the element data, use something like 'zo' and a friendly name.

  6. -- RESOURCE A 
    local myObject = createObject(...) 
    myObject = exports.B.manipulateObject(myObject) 
      
    -- RESOURCE B 
    function manipulateObject(object) 
     local anotherObject = createObject(...) 
     return anotherObject 
    end 
    

    You can send and return any element. So, yes, you can do that.

    IIYAMA's explanation is irrelevant to your scenario here, if I understood you correctly.

  7. Lua is not an object oriented language, but you can make it so using tables and metamethods.

    You can mix up both ways in the same resource, since, again, Lua is not really an OO language.

    In Lua, calling a function with class:function is simply syntatic sugar for class.function(self). For example:

    myInstance:func(arg1, arg2) 
    -- is the same as 
    myInstance.func(myInstance, arg1, arg2) 
    

    It's usually the opposite in Lua, you'll mostly use Class.func for static calls and instance:func for instance calls.

    Here's a few tutorials about OOP and metamethods:

    http://www.lua.org/pil/16.html

    http://lua-users.org/wiki/ObjectOrientationTutorial

    http://www.tutorialspoint.com/lua/lua_o ... iented.htm

×
×
  • Create New...