MariaDB New Character Triggers

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

NavyS34l
 
Posts: 41
Joined: 15 Jun 2015, 16:12

MariaDB New Character Triggers

Post by NavyS34l » 25 Jun 2015, 18:28

Hey Everyone,

So im having an issue with my triggers on my new server. I am using HeidiSQL to manage the DB hosted with blackbox. So Ive added the following triggers that appear to have correct syntax.

BEFORE INSERT - Does nothing at all on new character load
Code: Select all
CREATE TRIGGER `skills_before_insert` BEFORE INSERT ON `character` FOR EACH ROW
BEGIN
  /* Set Piety to 30 so character can pray without needing to pray for homecoming several times */
   IF (New.SkillTypeID = 54 and New.SkillAmount < 300000000) then
      set New.SkillAmount = 300000000;
   end if;

/* Set Warhorse handling to 60 since it is not implemented yet  */
   IF (New.SkillTypeID = 26 and New.SkillAmount < 600000000) then
      set New.SkillAmount = 600000000;
   end if;
/* Set Prospecting to 60 */
 IF (New.SkillTypeID = 1 and New.SkillAmount < 600000000) then
      set New.SkillAmount = 600000000;
   end if;
/* Set Mining to 60 */
 IF (New.SkillTypeID = 2 and New.SkillAmount < 600000000) then
      set New.SkillAmount = 600000000;
   end if;
END


The next part here causes a few different issues, mainly directed at the the add items portion. If i use the character limiter by itself, that works fine.

AFTER INSERT
Code: Select all
CREATE TRIGGER `character_after_insert` AFTER INSERT ON `character` FOR EACH ROW
BEGIN
SET @characterCount = (SELECT COUNT(*) FROM `character` ch WHERE ch.AccountID = NEW.AccountID);
   IF @characterCount > 2 AND NEW.AccountID != 2 AND NEW.AccountID != 3 THEN
      SET @msg = "Cannot create more than 2 characters per account";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
   END IF;
   SET @backpack = NEW.RootContainerID;
   SET @temp = f_insertNewItemInventory(@backpack, 1059, 100, 16, 50000, 50000, '',''); /* copper coins */
   SET @temp = f_insertNewItemInventory(@backpack, 1060, 100, 8, 50000, 50000, '',''); /* silver coins */
   SET @temp = f_insertNewItemInventory(@backpack, 1061, 100, 8, 50000, 50000, '',''); /* gold coins */
   SET @temp = f_insertNewItemInventory(@backpack, 48, 100, 1, 50000, 50000, '',''); /* pickaxe */
   SET @temp = f_insertNewItemInventory(@backpack, 46, 100, 1, 50000, 50000, '',''); /* hatchet */
   SET @temp = f_insertNewItemInventory(@backpack, 974, 50, 25, 50000, 50000, '',''); /* 25x q50 Apple Buns */
   SET @temp = f_insertNewItemInventory(@backpack, 299, 50, 1, 15000, 15000, '',''); /* simple clothes */
   SET @temp = f_insertNewItemInventory(@backpack, 890, 50, 1, 15000, 15000, '',''); /* novice padded greaves */
   SET @temp = f_insertNewItemInventory(@backpack, 38, 50, 1, 15000, 15000, '',''); /* torch */
END;


So what did I do wrong here? For the AFTER INSERT, if I run the query above I get a syntax error at SET @backpack = NEW.RootContainerID;, yet if I add that to the existing character limiter trigger there is no issue. With the SET *** in the trigger I get the 1024 error on new character creation attempt.

Again I reviewed all the current threads on this and have tried them all, not too sure whats going on. And MariaDB is limited to 1 BEFORE and 1 AFTER right now so I cant split them.

Thanks!
Last edited by NavyS34l on 26 Jun 2015, 00:22, edited 1 time in total.
Image

User avatar
Rjmspoel
True Believer
 
Posts: 69
Joined: 01 Oct 2014, 12:44

Re: MariaDB New Character Triggers

Post by Rjmspoel » 25 Jun 2015, 23:31

I am not that fancy with code though but looking with common sense at it you have this

Code: Select all
IF @characterCount > 2 AND NEW.AccountID != 2 AND NEW.AccountID != 3 THEN


It seems to me you want to check for the trigger two times in row if the accountID has 2 characters allready while it should check for 1 character first like

Code: Select all
IF @characterCount > 1 AND NEW.AccountID != 3 THEN


so it checks now if created character on accountID is larger than 1 so this would be 3 or more then set @msg.

Correct me if I am wrong.

I have the trigger on my server exactly as stated there except not with the character limit anymore, I had the same error as you on code 1024, I deleted the character limiter and all worked like a charm, I am also wondering what changed to accountID


NavyS34l
 
Posts: 41
Joined: 15 Jun 2015, 16:12

Re: MariaDB New Character Triggers

Post by NavyS34l » 26 Jun 2015, 00:30

Thanks for taking a look. I haven't tried it yet, but it looks like the code you suggested should work fine.

Code: Select all
IF @characterCount > 1 AND NEW.AccountID != 3 THEN


Now if I cut out the character limiter as you did i still get the syntax error at the following line

Code: Select all
SET @backpack = NEW.RootContainerID;


Which as you can see is the beginning of the trigger. Initially it did not return the error on the first change, however caused a 1024 error in game. After adjusting again it caused the syntax error, yet not code was changed.

Rjmspoel ; would you mind sharing you after trigger so I can compare the lines?
Image

User avatar
Rjmspoel
True Believer
 
Posts: 69
Joined: 01 Oct 2014, 12:44

Re: MariaDB New Character Triggers

Post by Rjmspoel » 27 Jun 2015, 16:51

Sure here's my code:

Code: Select all
CREATE TRIGGER `character_after_insert` AFTER INSERT ON `character` FOR EACH ROW BEGIN
   SET @backpack = NEW.RootContainerID;
   SET @temp = f_insertNewItemInventory(@backpack, 1059, 100, 16, 50000, 50000, '',''); /* copper coins */
   SET @temp = f_insertNewItemInventory(@backpack, 1060, 100, 8, 50000, 50000, '',''); /* silver coins */
   SET @temp = f_insertNewItemInventory(@backpack, 1061, 100, 8, 50000, 50000, '',''); /* gold coins */
   SET @temp = f_insertNewItemInventory(@backpack, 48, 100, 1, 50000, 50000, '',''); /* pickaxe */
   SET @temp = f_insertNewItemInventory(@backpack, 46, 100, 1, 50000, 50000, '',''); /* hatchet */
   SET @temp = f_insertNewItemInventory(@backpack, 974, 50, 25, 50000, 50000, '',''); /* 25x q50 Apple Buns */
   SET @temp = f_insertNewItemInventory(@backpack, 299, 50, 1, 15000, 15000, '',''); /* simple clothes */
   SET @temp = f_insertNewItemInventory(@backpack, 890, 50, 1, 15000, 15000, '',''); /* novice padded greaves */
   SET @temp = f_insertNewItemInventory(@backpack, 38, 50, 1, 15000, 15000, '',''); /* torch */
END;


Keep in mind though if you had that code allready in it with the character limiter you need to remove that code it created allready in the database, removing it from patch.sql does not remove it from your database, you will have to do that manually.

User avatar
Rjmspoel
True Believer
 
Posts: 69
Joined: 01 Oct 2014, 12:44

Re: MariaDB New Character Triggers

Post by Rjmspoel » 30 Jun 2015, 22:42

Allright, we just opened a second server on BlueFang this time and found out they are running on a MySQL database, as such these triggers do not work, so cancelling this service asap again and go back to Vilayer. shitty support I agree but at least their not running MySQL with this game!!


NavyS34l
 
Posts: 41
Joined: 15 Jun 2015, 16:12

Re: MariaDB New Character Triggers

Post by NavyS34l » 01 Jul 2015, 04:30

Thanks for the code. Ill remove the current AFTER_INSERT and use yours to create a new one. Character limiter really isn't necessary from what I'm seeing as people get too invested into their current one.

Ill report back when I have a chance to test this. hopefully tomorrow.
Image

User avatar
Rjmspoel
True Believer
 
Posts: 69
Joined: 01 Oct 2014, 12:44

Re: MariaDB New Character Triggers

Post by Rjmspoel » 03 Jul 2015, 21:44

NavyS34l wrote:Thanks for the code. Ill remove the current AFTER_INSERT and use yours to create a new one. Character limiter really isn't necessary from what I'm seeing as people get too invested into their current one.

Ill report back when I have a chance to test this. hopefully tomorrow.


The Character Limiter was inserted mostly to not being able to abuse the coins given to a new character, but I am getting reports of server admins that any code is not working anymore as of 0.5.5.2 that affect gameplay drastically.

I will be waiting anctiously to what you might find out as I am to the end of my latin, changing the code every time they upgrade to another version :(

Return to Game mods