Cuberite Forum
[Plugin] Homes Plugin!? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: [Plugin] Homes Plugin!? (/thread-1661.html)

Pages: 1 2 3


[Plugin] Homes Plugin!? - nouseforname - 11-25-2014

Hi folks,

even if i dont use MC-Server for some reason, i am interested in creating a plugin.

Right now i am in process with a new home plugin:

- multiworld support (same home count each world for each level)
- User ranking support with different user home limits
- config.ini
- using sqlite database

Commands:
- homeset <HOMENAME>
- home <HOMENAME>
- homedel <HOMENAME>


Is anybody interested in this? If yes, any requests for functions?

If the feedback is good enough i may will try to release it, otherwhise i only use it to learn bit lua.


RE: [Plugin] Homes Plugin!? - NiLSPACE - 11-25-2014

I moved this to "Plugin / Lua Discussion".


RE: [Plugin] Homes Plugin!? - sphinxc0re - 11-25-2014

+1Big Grin


RE: [Plugin] Homes Plugin!? - xoft - 11-25-2014

So what exactly will the plugin do? I'm not familiar with this "home" topic.


RE: [Plugin] Homes Plugin!? - nouseforname - 11-25-2014

(11-25-2014, 06:23 AM)xoft Wrote: So what exactly will the plugin do? I'm not familiar with this "home" topic.

Player will be able to save positions and teleport to that save ones. Mainly its a simple but individual teleporting function for each player.

In config you can set the max amount of "homes" per world for each rank


RE: [Plugin] Homes Plugin!? - xoft - 11-25-2014

Sounds fun, enjoy coding this Smile And don't forget to document it just the way you documented it for me.


RE: [Plugin] Homes Plugin!? - nouseforname - 11-26-2014

Ok, still doing this, but i ran into an issue.

I want to do a sqlite query to get a list of tables. But somehow i am not able to return the query result.

The query function gets the playername as argument and should return a table of tables (a_List):
function cStorage:GetList( player )
    
    local a_List = {}
    
    -- get data from query
    function getResult(udata, cols, values, names)
        
        for i=1,cols do print(\'\',names[i],values[i]) end
        
        return 0
    end
    
    -- get all player homes
    local sql = "SELECT * FROM " .. PluginName .. " WHERE Player=\'" .. player .. "\'"
    self:DBExec(sql, getResult) 
    return a_List 
end


This is a sample result which should go into the table:
        ID      1
        Player  no_use_for_name
        Name    default
        World   world
        X       -68.877814274714
        Y       64
        Z       205.5105932393
        ID      2
        Player  no_use_for_name
        Name    hill
        World   world
        X       -66.54712734459
        Y       64
        Z       209.61457523444
        ID      3
        Player  no_use_for_name
        Name    hil
        World   world
        X       -66.54712734459
        Y       64
        Z       209.61457523444

I would expect something like:
a_List = {{row1,...}, {row2,...}...}

But maybe there is a better way?! I tried several things already, but didnt get it yet. Returning a single result is easy.

Any help would be nice


RE: [Plugin] Homes Plugin!? - xoft - 11-26-2014

You're not putting anything into the a_List variable anywhere. The getResult() function should add an item into it. Most likely like this (note the use of the nrows() function instead of DBExec() ):
local theResult = {}
DB:nrows(
  "SELECT * FROM " .. PluginName .. " WHERE Player = \"" .. player .. "\"",
  function getResult(a_RowValues)
    -- add the returned row to our result table:
    table.insert(theResult, a_RowValues)
  end
)
return theResult

This will return the table as an array of dictionaries:
theResult = { {col1 = val1A, col2 = val2A}, {col1 = val1B, col2 = val2B}, {col1 = val1C, col2 = val2C}, ...}

EDIT: No, sorry, this code won't work either.


RE: [Plugin] Homes Plugin!? - xoft - 11-26-2014

Where is your DBExec function coming from? Are you using one of the sqlite wrappers from any of the plugins?


RE: [Plugin] Homes Plugin!? - xoft - 11-26-2014

If so, use the ExecuteStatement() function instead, it's more high-level and provides the right interface that you need, the code I posted earlier will work with ExecuteStatement, if you add a middle parameter to it:
local theResult = {}
DB:ExecuteStatement(
  "SELECT * FROM " .. PluginName .. " WHERE Player = ?",  -- Note the use of placeholders for increased safety
  { playerName },  -- Placeholders will be replaced with values from this table
  function getResult(a_RowValues)  -- This callback will be called for each retrieved DB row
    -- add the returned row to our result table:
    table.insert(theResult, a_RowValues)
  end
)
return theResult