Example script: AreaProtection

  • I don't know how the BD is build, but basically, in pseudo-code it would be something like :


    [lua]
    elseif cmd[1] == "/viewaddedplayers" then
    local areaID = event.player:getAttribute("areaID");
    local added_players {};
    for value in database:query("SELECT 'playerID' FROM 'rights' WHERE 'areaID' = '".. areaID .. "'") do
    actual_player = server:findPlayerByID(value);
    actual_player_name = actual_player:getName();
    event.player:sendTextMessage(""..actual_player_name.."");
    end
    [/lua]


    I'm not sure how the BD works, I just take a very quick look at some piece of the code, so ...
    Plus, I'm not sure for my "for each" I didn't watch closer how this works in LUA, so I did it with the python way in mind ^^'

  • i would like to see /viewplayersaddedtoarea to see what player was added


    /listplayersinarea perhaps? But, yeah, this should definitely be added.


    Also, the group Owner have no rights to destroy blocks. This is a problem; I don't see why anyone could be added as a Owner without running into problems when misplacing something. This is odd and not very practical. Basically, owners should be free to modify the area at will. And Admin players (belonging to the Admin group of AreaProtection) should be able to add and remove other players as Guest or Owner. RW admins should be able to create and remove areas, and manage players in areas, too. Also, a Owner should be able to add/remove Guest, too.


    I would like to put AreaProtection to Github, so it is available to the community, so things like that can be discussed and actions taken more easily. @KingGenius I can add you as admin of that repo. All that, if you don't mind, of course.

  • 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

  • Thank you for sharing your concerns. I am currently modifying the AreaProtection script, with the help of others, to add features and fix things like that. You can come on IRC (freenode.net, channel #risingworld) if you want to chat with us!


    Cheers!

  • Sorry, my idea above was a written with good intention but..
    My solution does NOT work as written above(it will run into the same error again).

  • 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..

  • 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]

  • @DHLF, your concerns have been noted.


    Concerning player names, there is already an API to get a player from it's ID. Since players are not deleted, it's ID will always return it's name. There's really no need to duplicate this value locally, in the script's DB.


    As for the area name still showing on screen, even after removing it, yes, this will be addressed in the upcoming changes.

  • thanks for answering but I still have a small problem. I am new to all of this (my own server) i downloaded the link for area protection but the problem is I do not have a game folder, my game is on steam and I do not know if that matters. i extracted the file but i do not know where to go to from here. Can you please help?

  • i downloaded the script but i do not know what to do now; my game is on steam and i do not have a rising world folder in my computer. after i extract the file what do i do?

  • i downloaded the script but i do not know what to do now; my game is on steam and i do not have a rising world folder in my computer. after i extract the file what do i do?


    I was letting someone else answer this. I don't play on steam. I have the stand alone version of the game. Plus, I'm on Linux and I doubt I can be of assistance to you. However, I think I have seen some post on the forum talking about using the game on steam, somewhere...

  • most games will be installed at C:\Program Files (x86)\Steam\steamapps\common\ here you should find risingworld folder open that and inside i think i say think because i don't do this myself i only do this with the server files anyway i think you need to make the folder name it script the path should end up looking like this C:\Program Files (x86)\Steam\steamapps\common\risingworld\scripts then just copy the unziped scripts in there own folders into the script folder and restart the game



    tip the scripts you install will only work on your own games any other server you connect to wont run your script, so this is for solo game only but in saying that you can have friends use lan to connect to your game and turn your solo into multi player.

    Yahgiggle Steam Signature, real name Deon Hamilton :thumbsup: Server @ ip 139.99.136.76:4255 Name (The Federation of territory) Unity :thumbsup:

    If at first your code does not work call it version 0.1 with the odd bug :thinking:

    My Own Website




    31245-logo-png
  • i did this just like it says to do the folder is in my game scripts folder and i restarted the server but it still won't work. is there anything else i needed to download?

  • We are having issues with area protection. Protection disappears shortly after setting it. This seems to only happen to one player.


    EDIT: The name of said area had an apostrophe in it. Removing the apostrophe appears to have fixed the issue...still testing.

  • We are having issues with area protection. Protection disappears shortly after setting it. This seems to only happen to one player.


    EDIT: The name of said area had an apostrophe in it. Removing the apostrophe appears to have fixed the issue...still testing.


    yes that was your problem i found this out a long time ago just keep the names simple and it will be fine

    Yahgiggle Steam Signature, real name Deon Hamilton :thumbsup: Server @ ip 139.99.136.76:4255 Name (The Federation of territory) Unity :thumbsup:

    If at first your code does not work call it version 0.1 with the odd bug :thinking:

    My Own Website




    31245-logo-png
  • Can someone kind person help me? How does this actually work, i have rented a server and want to use this script.


    I have done this:


    downloaded and unpacked the script in the scrips folder on server.


    How do i use it? Tried the commands above but only says unknown commands :(

  • Commands for LUA scripts must entered in the chat. It opens with the key t


    Do you entered the commands in the chat or in the console?

  • SOLVED ISSUE
    Hi everyone.


    Quick question, is there a limit in the amount of areas you can protect ?


    Problem
    I cant seem to add anymore areas after having a high amount of protected areas
    note: I dont know exactly how many already due to lots of players on the server

    Symptom



    Troubleshooted methods:



    Conclusion


    --


    EDIT: result
    Server restart fixed the issue. :thumbsup:
    unsure about how/why it bugged out.

  • So i just drop the folder "AreaProtection" into the main directory of my server?
    Do i need to edit anything in my config to include it.
    \
    Well i see it shows up after i placed it inside scripts/ but commands don't work.
    I will keep messing around with it.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!