Posts by DHLF

A new update is now available, introducing a lot of new content!
Latest hotfix: 0.7.5.2 (2024-09-10)

    And another thought..
    If an area has been removed using /removearea the name will be still shown in the lower left corner until the player enters and leave another protected area.


    As this is ripped from the playerlistener I am not sure if we could add it right into the commandlistener:
    [lua]label:setVisible(false);
    stop = true;[/lua]

    I was thinking about adding the ability for some "trusty" players to use the command /addplayertoarea.
    To keep things easier two new command("legit to use by NOT admins") like /addplayer and /removeplayer< followed by the name of the friendly player should be added.
    Problem is.. with this commands(which are "copies" of the admin-commands /addplayertoarea and /removeplayerfromarea) any player could add players to foreign areas..
    So a check has to be included to be sure the player who uses the new commands is the "admin" of the area.
    Now I noticed I really dont get the db-stuff thing..


    Code
    local area = getCurrentArea(event.chunkOffsetX, event.chunkOffsetY, event.chunkOffsetZ, event.blockPositionX, event.blockPositionY, event.blockPositionZ);
    if area ~= nil then
    local group = getPlayerGroupInArea(event.player, area);
    if group["PlaceBlock"] == false then
    event.player:sendTextMessage("[#FF0000]"This is not YOUR area..");
    else
    * add or remove another player like in the /addplayer or /removeplayer section *
    end
    end


    Well, I dont even know IF there has to be those ";" after the sendTextMessage.. or if I have to RETURN it?


    A closer look at the db showed the following:
    Hint for linux users: you may install sqlite3 to be able to look into the *.db files using the midnightcommander


    Code
    CREATE TABLE 'areas' ('ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'name' VARCHAR, .. , 'playerID' INTEGER);
    INSERT INTO "areas" VALUES(3,'Spawn',15,1,15,5,40,5,16,1,16,9,54,8,1);


    As described in the table the first value is the "index"(3), so I had already created and removed the "Spawn" area two times.
    The last number is the "player ID"(1). Okay, I was the first who joined the server so I assume number "1" belongs to me.
    As ALL areas have the same player ID (1) it shows who created the area. Not who "owns" it!


    Big question: How to get the real player names behind the player IDs?
    In the world folder there should be another *.db which contains the following:

    Code
    CREATE TABLE 'Player' ('ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'Name' VARCHAR(30),
    INSERT INTO "Player" VALUES(1,'DHLF','..


    Here are all players stored which ever connected to the server.


    And a last look into the /AreaProtection.db:

    SQL
    INSERT INTO "rights" VALUES(10,3,1,'Admin');


    10 is the index number, 3 targets the above "Spawn" area and 1 belongs to player DHLF. Admin tells DHLF is the "Owner/Admin" of that area.


    Theoratically I just have to do the following:
    get the 'playerID' of the area in which the player is standing, check if those 'playerID' matches those of the player who commanded /addplayer AND if he is "ADMIN".
    This seems to be tricky as more people could be already at least "owner" of those area..
    We have to be sure not to focus on the first entry alone..

    I was thinking about adding the ability for some "trusty" players to use the command /addplayertoarea.
    A quick look into the script files keeps me speechless.. I really expected some check like "if playerisadmin" like I saw in other scripts.
    Instead of testing IsPlayerAdmin for each "forbidden" command you shortened it by:

    Code
    if event.player:isAdmin() == false then
    event.player:sendTextMessage("[#FF0000]You are not an admin");
    return;
    end
    **your whole code thought for use by admins**


    While this keeps the code smaller it runs into a slight issue:
    If the player is really not an admin and he tries one of the "allowed" commands like /showareas the command will be executed but at the end it will still show "You are not an admin!".
    One possibility to avoid this is to exit this (I dont know lua, so.. ) if there is something to exit the whole function.
    Another possibility could be to change the code with two lines like:

    Code
    if event.player:isAdmin() == true then
    **your whole code thought for use by admins**
    else
    event.player:sendTextMessage("[#FF0000]You are not an admin");
    return;
    end