[MOD] Character Count Limiter

Place for sharing your game modifications for Life is Feudal: Your Own
User avatar
Chessmaster42
 
Posts: 23
Joined: 30 Sep 2014, 22:05

[MOD] Character Count Limiter

Post by Chessmaster42 » 26 Oct 2014, 00:33

Another mod! This time this one is for limiting the number of characters allowed per account. To change the limit simply change the IF-THEN statement to match the limit that you wish to impose

Code: Select all
CREATE DEFINER=`root`@`localhost` TRIGGER `t_characterLimit` AFTER INSERT ON `character` FOR EACH ROW BEGIN
   SET @characterCount = (SELECT COUNT(*) FROM `character` ch WHERE ch.AccountID = NEW.AccountID);
   IF @characterCount > 2 THEN
      SET @msg = "Cannot create more than 2 characters per account";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
   END IF;
END


Heinrich_von_Leipa
Alpha Tester
 
Posts: 198
Joined: 26 Aug 2014, 16:05

Re: [MOD] Character Count Limiter

Post by Heinrich_von_Leipa » 26 Oct 2014, 02:34

I was looking for such a thing for my server. Can you please explain where to put this code, what to do to apply this "mod"? Thanks :)
Last edited by Heinrich_von_Leipa on 29 Oct 2014, 17:53, edited 1 time in total.

User avatar
Chessmaster42
 
Posts: 23
Joined: 30 Sep 2014, 22:05

Re: [MOD] Character Count Limiter

Post by Chessmaster42 » 26 Oct 2014, 03:27

If you are using the standalone dedicated server with a MariaDB setup then it's pretty straightforward. Anything else is complicated and I'm not going to try to explain for that.

As for setup using a standalone instance of MariaDB the simplest way would be to put this SQL code into the patch.sql file at the end and restart the server. An alternative is to use the included utility, HeidiSQL, as this will provide a GUI interface to the SQL data.

If using the patch.sql method you can verify by two methods. First, by testing character creation. If the SQL is setup correctly you will get an error on the character creation page as soon as you hit the Create/Done button at the bottom. Second, it can be verified by opening something like HeidiSQL that is connected to the SQL server and open up the lif_1 database. Scroll down and you should see an entry named 't_characterLimit' in with the other SQL tables and procedures.

If you don't want to restart the server or are nervous about putting it in patch.sql then you can use the HeidiSQL GUI to create the trigger. For this you need to load up the lif_1 database. Once it's open right click on any table/proc entry and select Create new -> Trigger. From there fill in the options details so that the CREATE code tab matches the raw SQL code of the mod. Hit save when everything is entered and that's it.

If you don't have knowledge of SQL DB administration then the first method using patch.sql and a server restart is going to be the way to go. Hope this helps :)

User avatar
dingusmcgeehee
 
Posts: 21
Joined: 02 Oct 2014, 23:04

Re: [MOD] Character Count Limiter

Post by dingusmcgeehee » 29 Oct 2014, 18:42

How would I go around creating an IF statement in this script so that I can specify certain accounts that would be allowed more (aka staff)?

Thanks for the script by the way, great work!

User avatar
Chessmaster42
 
Posts: 23
Joined: 30 Sep 2014, 22:05

Re: [MOD] Character Count Limiter

Post by Chessmaster42 » 29 Oct 2014, 18:48

Something like this would work for ya:

Code: Select all
CREATE DEFINER=`root`@`localhost` TRIGGER `t_characterLimit` 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 != 42 THEN
      SET @msg = "Cannot create more than 2 characters per account";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
   END IF;
END


Just change the 42 there in the IF-THEN to whatever account you'd want to have unlimited characters. And just copy-paste the "AND NEW.AccountID != 42" part to keep adding in more accounts that don't have the restriction.


Mighty7788
 
Posts: 6
Joined: 27 Oct 2014, 19:03

Re: [MOD] Character Count Limiter

Post by Mighty7788 » 25 Nov 2014, 06:08

Ive got a dedicated server with a MariaDB

Copied the mod into the patch.sql and restartet.
As i create my third char, nothing happend.. i created the fourth - same story :(



What info do you need?
What is a possible issue?


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

Re: [MOD] Character Count Limiter

Post by RudgerWolvram » 01 Jan 2015, 22:30

I could never get it working, had to fiddle around with mysql page and other examples, but got this "version" working. I don't know why @ didn't work for declaring a variable when it should. Using Maria 5.5. Note, I ran this as a manual query, I haven't tested appending it to patch.sql.

Code: Select all
delimiter $$
CREATE TRIGGER t_characterLimit
AFTER INSERT ON `character`
FOR EACH ROW BEGIN
   DECLARE `characterCount` INT;
   SET `characterCount` = (SELECT COUNT(*) FROM `character` ch WHERE ch.AccountID = NEW.AccountID);
   IF `characterCount` > 2 THEN
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Cannot create more than 2 characters per account';
   END IF;
END;
$$


Sanctifiedevil
 
Posts: 12
Joined: 22 Dec 2014, 07:37

Re: [MOD] Character Count Limiter

Post by Sanctifiedevil » 15 Jan 2015, 19:08

What would happen is this was added after characters have already been created?


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

Re: [MOD] Character Count Limiter

Post by Remystemple » 24 Feb 2015, 00:24

how do i use this with a starter kit script. i can't add this because the starter kit script also effects the character file. i think..


Gorgin
 
Posts: 8
Joined: 12 Mar 2015, 03:16

Re: [MOD] Character Count Limiter

Post by Gorgin » 18 Mar 2015, 00:12

To answer Remystemple question because i had the same thing going on I just put the code at the top on my existing TRIGGER.
Code: Select all
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 @temp = f_insertNewItemInventory(NEW.RootContainerID, 555, 100, 1, 50000, 50000, '', 0,0,0,0, 0,0); /* practice sword */
SET @temp = f_insertNewItemInventory(NEW.RootContainerID, 40, 100, 1, 50000, 50000, '', 0,0,0,0, 0,0); /* shovel */
SET @temp = f_insertNewItemInventory(NEW.RootContainerID, 974, 50, 5, 50000, 50000, '', 0,0,0,0, 0,0); /* 5x q50 Apple Buns */
SET @temp = f_insertNewItemInventory(NEW.RootContainerID, 46, 100, 1, 50000, 50000, '', 0,0,0,0, 0,0); /* hatchet */
SET @temp = f_insertNewItemInventory(NEW.RootContainerID, 38, 100, 1, 50000, 50000, '', 0,0,0,0, 0,0); /* Torch */
END


But I do have a question on the @msg everything is working except that part i just get a error message when trying to create more than 2 it dose stop them from making the 3rd char but doesn't explain why :)


Alakar
Beta Tester
 
Posts: 202
Joined: 23 Jan 2015, 07:39

Re: [MOD] Character Count Limiter

Post by Alakar » 19 Mar 2015, 00:20

Its because the client doesn't get passed that message they can only display the message that an error has occured because that is all the server returns to them.


Gorgin
 
Posts: 8
Joined: 12 Mar 2015, 03:16

Re: [MOD] Character Count Limiter

Post by Gorgin » 23 Mar 2015, 00:06

So how would i go about fixing that? I have been on a server that had a custom message pop up when you tried to make more the there set number and i never had to DL any extra files.

User avatar
HouseHarkonnen
 
Posts: 37
Joined: 30 Sep 2014, 20:22

Re: [MOD] Character Count Limiter

Post by HouseHarkonnen » 28 Jun 2015, 20:01

Works just noticed the code posted is set for a 2 character limit and I only need to edit that to one.
Image


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

Re: [MOD] Character Count Limiter

Post by Zhalls » 13 Aug 2015, 07:06

So it turns out that this script is no longer working as intended, because it also blocks you from deleting existing characters. This isn't exactly a bad thing, assuming you're combining it with a starter kit like me, which means they can't abuse the starter kit at creation by delting/recreating repeatedly for additional loot.

The following is my code, maybe someone can help me figure out why it's blocking me from deleting characters now for in the event I want to actually allow it:

Code: Select all
BEGIN
SET @characterCount = (SELECT COUNT(*) FROM `character` ch WHERE ch.AccountID = NEW.AccountID);
   IF @characterCount > 1 THEN
      SET @msg = "Cannot create more than 1 characters per account";
      SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
         END IF;
   SET @sack = f_createContainer(NEW.RootContainerID, 459, 0);
   SET @temp = f_insertNewItemInventory(@sack, 555, 50, 1, 50000, 50000, NULL, NULL); /* practice sword */
   SET @temp = f_insertNewItemInventory(@sack, 41, 100, 1, 50000, 50000, NULL, NULL); /* primitive shovel */
   SET @temp = f_insertNewItemInventory(@sack, 43, 100, 1, 50000, 50000, NULL, NULL); /* primitive hammer */
   SET @temp = f_insertNewItemInventory(@sack, 45, 100, 1, 50000, 50000, NULL, NULL); /* primitive axe */
   SET @temp = f_insertNewItemInventory(@sack, 50, 100, 1, 50000, 50000, NULL, NULL); /* primitive saw */
   SET @temp = f_insertNewItemInventory(@sack, 30, 100, 1, 50000, 50000, NULL, NULL); /* primitive sickle */
   SET @temp = f_insertNewItemInventory(@sack, 47, 100, 1, 50000, 50000, NULL, NULL); /* primitive pickaxe */
   SET @temp = f_insertNewItemInventory(@sack, 289, 100, 1, 50000, 50000, NULL, NULL); /* primitive knife */
   SET @temp = f_insertNewItemInventory(@sack, 974, 50, 25, 50000, 50000, NULL, NULL); /* 25x q50 Apple Buns */
   SET @temp = f_insertNewItemInventory(@sack, 1028, 50, 1, 15000, 15000, NULL, NULL); /* primitive cooking pot */
END


DonSmirelo
 
Posts: 1
Joined: 10 Jul 2017, 17:47

Re: [MOD] Character Count Limiter

Post by DonSmirelo » 10 Jul 2017, 17:49

Добрый день, подскажите когда я устанавливаю данный код в файл patch.sql у меня падает сервер. Может там надо вместо root и lovalhost данные базы данных ввести? Прошу прощения не очень разбираюсь в программировании)) :D

Return to Game mods

cron