[MOD] Stump Remover

Place for sharing your game modifications for Life is Feudal: Your Own

RudgerWolvram
 
Posts: 37
Joined: 01 Jan 2015, 22:27

[MOD] Stump Remover

Post by RudgerWolvram » 06 Jan 2015, 08:22

WARNING: This mod can make stumps un-clickable. I have worked out the bugs I could find. I strongly recommend using the Mod Logger in post setup-a-sql-mod-logger-t8405/ to keep track of what is changed with it. No warranty is given or implied by using this MOD.

DO NOT run this mod, and leave the server running. If the server is running, then the mod is ran, and someone cuts down a tree and tries to remove the stump, it will bug the stump and it must manually be removed via the f_addForestPatch for the correct GeoDataID and TerID of the stump. This mod will not find the bugged stump because it will be half removed.

This must be ran either while the LiF server is down, or immediately before a restart. I've not tested adding it to the tail of patch.sql (i.e. CALL p_cleanStumps();

Now that all that's out of the way, time to get to the mod itself.
I've left my logging code in this (CALL p_ModLog....) which it can be removed if you want.
This creates a procedure called p_cleanStumps. It only needs to be called via: CALL p_cleanStumps(); in any query.

Code: Select all
delimiter $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_cleanStumps`()
   LANGUAGE SQL
   NOT DETERMINISTIC
   CONTAINS SQL
   SQL SECURITY DEFINER
   COMMENT ''
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE _TerID INT UNSIGNED;
DECLARE _GeoID INT UNSIGNED;
DECLARE cur CURSOR FOR
            SELECT forest.geodataid _GeoID, fp_grouped.TerID _TerID
            FROM forest
            LEFT OUTER JOIN (SELECT GeoDataID, TerID, MAX(Version) AS Version FROM forest_patch GROUP BY GeoDataID, TerID) fp_grouped
               ON fp_grouped.GeoDataId = forest.GeodataID
            WHERE forest.quality = 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;

CALL p_ModLog('StumpRemoval','Opening Cursor');

/*The Cursor will contain the GeoID and TerID for every stump in the game.*/
OPEN cur;

 ForestLoop:LOOP
 FETCH cur INTO _GeoID,_TerID;
 IF done THEN
    CALL p_ModLog('StumpRemoval','Leaving Loop');
    LEAVE ForestLoop;
 END IF;
 /* Restore the terrain to "blank"*/
CALL p_ModLog('StumpRemoval',CONCAT('Patching Forest with TerID:',_TerID,'  GeoID:',_GeoID));
 IF (f_addForestPatch(_TerID,3,_GeoID, NULL, NULL, NULL, NULL)) IS NOT NULL THEN /* If Success is Null, then we know the forest patch could not be updated and should not delete the stump data*/
   CALL p_ModLog('StumpRemoval',CONCAT('Forest Patched, deleting stump with GeoID:',_GeoID));
    /* Remove the stump from the forest table */
   CALL p_deleteForestItem(_GeoID);
 End IF;
END
LOOP ForestLoop;
CALL p_ModLog('StumpRemoval','Closing Cursor and exiting.');
CLOSE cur;

END
$$


During my tests on my dev box, i was able to cut down multiple trees, shut down the server, restart it, log back in and all stumps (that weren't glitched from my original testing) were all gone and the terrain was terraformable again.

Explanation of what this does.
First, it emulates what is done when someone removes a stump via Unroot. The cursor grabs all rows of the forest table that are quality 0 (stumps) and only if the forest_patch data is action 4 (tree cut down from what i can tell.) It then grabs the terrain ID (I'm not sure if it will ever be outside of 446, but i didn't take that chance) of where the stump is, then "patches" it in via f_addForestPatch, if that was sucessful (which is important so the stump does not "glitch" and become stuck in the world) it will call the p_deleteForestItem and remove the stumps data from the forest table.

This was made in response to many talking about how stumps negatively impact a servers performance. Our dedicated server has not cooked long enough to see if this make a performance difference. If someone uses this and has a stump problem, please post a reply, I'd like to know if it make a difference. I'm sure others would too.


EDIT:
Fixed cursor query so it only grabs the forest_patch row's latest version. The rest of the procedure has not changed, only the cursor's initial select statement. Thanks Arthenius!
Last edited by RudgerWolvram on 08 Jan 2015, 07:54, edited 3 times in total.


Arthenius
 
Posts: 29
Joined: 25 Nov 2014, 09:50

Re: [MOD] Stump Remover

Post by Arthenius » 06 Jan 2015, 11:29

hello

really interesseting, but if someone replant a tree on a geodataid where a stump as already been removed, the first select could return this line
you may check that the last line in forest_patch for this geodataid as action=4 ??

but normally i think that if quality is = 0 you should always have a action =4 line in forest_patch...

it give me an idea too remove bad quality tree from our server...


RudgerWolvram
 
Posts: 37
Joined: 01 Jan 2015, 22:27

Re: [MOD] Stump Remover

Post by RudgerWolvram » 06 Jan 2015, 16:39

It does check for action type in forest_patch. it's at the tail of the cursor's join query.

Code: Select all
SELECT forest.GeoDataID _GeoID,forest_patch.TerID _TerID
   FROM forest
   LEFT JOIN forest_patch ON forest.GeoDataID = Forest_patch.GeoDataID
   WHERE forest.quality = 0 AND forest_patch.action = 4;


When you replant a tree in the same location as a stump that was removed via this procedure, the server should update the patch table correctly.


Arthenius
 
Posts: 29
Joined: 25 Nov 2014, 09:50

Re: [MOD] Stump Remover

Post by Arthenius » 06 Jan 2015, 18:22

I know, let me explain

this is the line in forest

Code: Select all
geodata = 55 treetype = 2 quality = 0


in forest_patch ou could have

Code: Select all
action =1 version = 5 geodata = 55 treetype=5
action =4 version = 155 geodata = 55 treetype=NULL
action =3 version = 158 geodata = 55 treetype=NULL
action =1 version = 165 geodata = 55 treetype=2
action =4 version = 255 geodata = 55 treetype=NULL


And if for some reason you dont have the last line it could be ennoying to delete the forest line

but i don't think that would even happen...I guess

but your first query returns you in this case 2 lines with terid and geodata, so you will probabilly generate two line with action =3 ??


RudgerWolvram
 
Posts: 37
Joined: 01 Jan 2015, 22:27

Re: [MOD] Stump Remover

Post by RudgerWolvram » 06 Jan 2015, 18:41

Ahh I see now. i think a limit 1 order by Version desc at the end would take care of that as it does not appear to matter since the terID is the same for that particular GeoID. The f_addForestPatch automatically increments the version of the of the patch so it should always be the latest "patch" version.


Arthenius
 
Posts: 29
Joined: 25 Nov 2014, 09:50

Re: [MOD] Stump Remover

Post by Arthenius » 07 Jan 2015, 08:36

yes i have read the add_forestpatch function :)

it's just to avoid to have a action = 3 line for nothing...wich could be bad interpreted by the game :)


RudgerWolvram
 
Posts: 37
Joined: 01 Jan 2015, 22:27

Re: [MOD] Stump Remover

Post by RudgerWolvram » 08 Jan 2015, 07:57

I added a fix to the procedure, it only grabs the very latest version of the forest_patch for the given geodataID now, so it should never run into a multi row scenario. The edit was done in the cursor query, everything else is the same.

User avatar
HolyCrusader
Beta Tester
 
Posts: 251
Joined: 24 Nov 2014, 15:47

Re: [MOD] Stump Remover

Post by HolyCrusader » 08 Jan 2015, 14:35

Rudger, good work. (Mike Wraith here).

Will be posting the results of the testing hopefully this evening


Gazerano
 
Posts: 4
Joined: 08 Jan 2015, 17:21

Re: [MOD] Stump Remover

Post by Gazerano » 08 Jan 2015, 17:36

Nice work Rudger, I am going to have a play with this.

User avatar
HolyCrusader
Beta Tester
 
Posts: 251
Joined: 24 Nov 2014, 15:47

Re: [MOD] Stump Remover

Post by HolyCrusader » 11 Jan 2015, 19:57

Twiztedmike wrote:Rudger, good work. (Mike Wraith here).

Will be posting the results of the testing hopefully this evening

It worked

User avatar
Eslake
 
Posts: 73
Joined: 30 Dec 2014, 17:15

Re: [MOD] Stump Remover

Post by Eslake » 19 Jan 2015, 09:02

Where do I enter this script?

saving it as a .cs and using exect("scriptname.cs"); doesn't work, and it clearly can't be entered as one long query.

User avatar
HolyCrusader
Beta Tester
 
Posts: 251
Joined: 24 Nov 2014, 15:47

Re: [MOD] Stump Remover

Post by HolyCrusader » 19 Jan 2015, 15:11

Eslake wrote:Where do I enter this script?

saving it as a .cs and using exect("scriptname.cs"); doesn't work, and it clearly can't be entered as one long query.

Using HeidiSQL it can be entered as one long query.

User avatar
Eslake
 
Posts: 73
Joined: 30 Dec 2014, 17:15

Re: [MOD] Stump Remover

Post by Eslake » 19 Jan 2015, 20:39

Twiztedmike wrote:
Eslake wrote:Where do I enter this script?

saving it as a .cs and using exect("scriptname.cs"); doesn't work, and it clearly can't be entered as one long query.

Using HeidiSQL it can be entered as one long query.


Okay... wow. I remember queries being things like select * where name=Frank. This is a whole other thing. :D

I'll work on figuring out why it keeps giving
>>you need (at least one of) the SUPER privilege(s) for this operation

Even after I changed the Definer to myself (All privs)


Remystemple
 
Posts: 80
Joined: 15 Jan 2015, 22:30

Re: [MOD] Stump Remover

Post by Remystemple » 19 Feb 2015, 01:18

says i need "super user Privies" this is the only script i have tried to run that gives me this error. can anyone explain what's happening please?

deleted that section and it runs without error and creates a p_cleanstump but when i get in game the stumps are still there.

oh there was an error later when i tried to call procedure.
said p_Mod not exist or something like that.


RudgerWolvram
 
Posts: 37
Joined: 01 Jan 2015, 22:27

Re: [MOD] Stump Remover

Post by RudgerWolvram » 21 Feb 2015, 23:30

Remystemple wrote:says i need "super user Privies" this is the only script i have tried to run that gives me this error. can anyone explain what's happening please?

deleted that section and it runs without error and creates a p_cleanstump but when i get in game the stumps are still there.

oh there was an error later when i tried to call procedure.
said p_Mod not exist or something like that.


If you're not using the mod logger setup from setup-a-sql-mod-logger-t8405/ then just comment or delete all lines with p_ModLog

User avatar
Eslake
 
Posts: 73
Joined: 30 Dec 2014, 17:15

Re: [MOD] Stump Remover

Post by Eslake » 23 Feb 2015, 10:14

Remystemple wrote:says i need "super user Privies" this is the only script i have tried to run that gives me this error. can anyone explain what's happening please?

deleted that section and it runs without error and creates a p_cleanstump but when i get in game the stumps are still there.

oh there was an error later when i tried to call procedure.
said p_Mod not exist or something like that.


Take out the definer to create the procedure without super priv.
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_cleanStumps`()

=
CREATE PROCEDURE `p_cleanStumps`()

The missing p_Mod means you didn't add the one linked to in the original post.
setup-a-sql-mod-logger-t8405/

You add it first, or you can edit out the references to it in this script.


Zhalls
Alpha Tester
 
Posts: 89
Joined: 14 Mar 2014, 19:30

Re: [MOD] Stump Remover

Post by Zhalls » 10 Apr 2015, 07:40

So where are we at with this progress? I'd like to consider this mod on a new project that I'm building for someone, but can't use it without a fix to the uproot bugged stump issue. Any progress towards an alternative solution to this or is the nature of the mod always going to cause issues when someone tries to manually uproot a stump?

Cheers


MashPotato
 
Posts: 3
Joined: 03 Jul 2015, 02:45

Re: [MOD] Stump Remover

Post by MashPotato » 03 Jul 2015, 17:35

Still works Of of this very second.

Create tool - also mod log highly recommended from this author

Endorsed 4stars. :Yahoo!:

Return to Game mods