[MOD] Refund Skill After DEATH

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

MacDante
 
Posts: 95
Joined: 12 May 2015, 10:08

[MOD] Refund Skill After DEATH

Post by MacDante » 17 Dec 2015, 22:41

If you don't want loss any skill after death you should implement this trigger to DB.

Some condition:
1. It work for skills with status 0 (lock) or 1 (incrase).
2. For skill with status -1 (Decrased) triger don't work.

IMPORTANT: YOU MUST MAKE RELOG AFTER DIE IF YOU WANT SKILL BACK!

Code: Select all

CREATE DEFINER=`root`@`localhost` TRIGGER `t_skill_refund` BEFORE UPDATE ON `skills` FOR EACH ROW BEGIN

   SELECT LockStatus into @status from `skills` where `skills`.ID = new.ID;
   
   IF (old.SkillAmount > new.SkillAmount) and @status >-1 THEN
      SET new.SkillAmount = old.SkillAmount;
   END IF;

END



And here some modified script to RP + PVP servers.
how it work??
Simple. Refund OLD.LOST.SKILL.Value in PERCENT-1% lost points.

EXAMPLE 1: Skill 100 lost 10 points: refund: 99% then after relog skill should be on : 99,90 value
EXAMPLE 2: Skill 90 lost 10 points: refund: 89% then after relog skill should be on : 88,90 value
EXAMPLE 3: Skill 60 lost 10 point: refund: 59% then after relog skill should be on : 55,90 value
EXAMPLE 4: Skill 30 lost 10 point: refund: 29% then after relog skill should be on : 22,90 value

IMPORTANT: YOU MUST MAKE RELOG AFTER DIE IF YOU WANT SKILL BACK!

Code: Select all

CREATE DEFINER=`root`@`localhost` TRIGGER `t_skill_refund` BEFORE UPDATE ON `skills` FOR EACH ROW BEGIN

   SELECT LockStatus into @status from `skills` where `skills`.ID = new.ID;
   
   IF (old.SkillAmount > new.SkillAmount) and @status >-1 THEN
   
      SET @OldSkillValue = (old.SkillAmount-10000000);
      if ( @OldSkillValue < 0 ) THEN
         SET @OldSkillValue = 0;
      END IF;
         
      SET @Percent = 1 - (@OldSkillValue / 1000000000);
      
      SET new.SkillAmount = old.SkillAmount-(old.SkillAmount-new.SkillAmount)*@Percent;
      
   END IF;

END


Aircode
 
Posts: 16
Joined: 23 Mar 2015, 13:57

Re: [MOD] Refund Skill After DEATH

Post by Aircode » 07 Feb 2016, 10:54

First i like to thank you for this nice Trigger. What i like to do now is to add one statement more, to check for a positive alignment.
But all my results are negative, i always get refund of the skillloss.

What ive tried(and many other way);
Code: Select all
BEGIN
   SELECT LockStatus INTO @status FROM `skills` WHERE `skills`.ID = new.ID;
   
   IF (`character`.Alignment > 1) AND old.SkillAmount > new.SkillAmount AND @status >-1 THEN
      SET new.SkillAmount = old.SkillAmount;
   END IF;

END


maybe one of you is more experienced in SQL and like to help me ...


Aircode
 
Posts: 16
Joined: 23 Mar 2015, 13:57

Re: [MOD] Refund Skill After DEATH

Post by Aircode » 19 Feb 2016, 21:45

this gives only a refund with a +10 Alignment

1.) create a helper column in skills and fill it up with data
Code: Select all
-- creates a helper column in skills (query this)
alter table skills add column if not exists Alignhelp int;
-- fill the helper column with the needed Alignment Data
UPDATE skills s, `character`c SET s.Alignhelp = c.Alignment WHERE s.CharacterID=c.ID;


2.) edit the table skills and add a foreign key to autoupdate the Alignment
Code: Select all
-- and then create add a foreign Key for Auto update this helper column in skills table
  CONSTRAINT FK_skills_character_Alignment FOREIGN KEY (Alignhelp)
  REFERENCES lif_1.`character` (Alignment) ON DELETE CASCADE ON UPDATE CASCADE,


3.) create a trigger for the refund
Code: Select all

-- final add a Trigger for a +10 Alignment get refund
BEGIN
   SELECT LockStatus into @status from `skills` where `skills`.ID = new.ID;
    IF (old.SkillAmount > new.SkillAmount and new.Alignhelp>9999999) and @status >-1 THEN
      SET new.SkillAmount = old.SkillAmount;
     END IF;
END


thanks to MacDante for creating the Trigger...


Everettham
Alpha Tester
 
Posts: 56
Joined: 22 Apr 2014, 02:16

Re: [MOD] Refund Skill After DEATH

Post by Everettham » 09 May 2016, 03:20

Aircode wrote:this gives only a refund with a +10 Alignment

1.) create a helper column in skills and fill it up with data
Code: Select all
-- creates a helper column in skills (query this)
alter table skills add column if not exists Alignhelp int;
-- fill the helper column with the needed Alignment Data
UPDATE skills s, `character`c SET s.Alignhelp = c.Alignment WHERE s.CharacterID=c.ID;


2.) edit the table skills and add a foreign key to autoupdate the Alignment
Code: Select all
-- and then create add a foreign Key for Auto update this helper column in skills table
  CONSTRAINT FK_skills_character_Alignment FOREIGN KEY (Alignhelp)
  REFERENCES lif_1.`character` (Alignment) ON DELETE CASCADE ON UPDATE CASCADE,



Does this restore skillpoints when a player dies. I'm not understanding how to do number 1 or 2. Create a helper column in skills (query this). What do I query? I'm not sure how to alter table skills and add column Alignhelp int. What do I put in Alignhelp int.


MacDante
 
Posts: 95
Joined: 12 May 2015, 10:08

Re: [MOD] Refund Skill After DEATH

Post by MacDante » 10 May 2016, 07:14

if you want FULL RESTORE SKILLS AFTER PLAYER DEATH use only this trigger:
Code: Select all
CREATE TRIGGER `t_skill_refund_full` BEFORE UPDATE ON `skills` FOR EACH ROW BEGIN

   SELECT LockStatus into @status from `skills` where `skills`.ID = new.ID;
   
   IF (old.SkillAmount > new.SkillAmount) and @status >-1 THEN
      SET new.SkillAmount = old.SkillAmount;
   END IF;

END

remember, you must re-log after death to update stats. If you do something before you re-log in lost skill you lost refund in this skill.

Return to Game mods