EDIT SQL Trigger is work nowWith this tiny SQL modification you can limit the guild_lands Radius. The goal is to prevent single players or small guilds to own a to large land.
What is done now;
- create a helper table (auto) "CharCount" and count how many characters have the same GuildID
- set the guild_lands.Radius VALUE like your need
- prevent a claim Radius to grow up more then the Value you desired
- bind the radius on the existing GuildMembers
- you have an exeption for your wanted guild
- the Trigger now react on UPDATE of guild_lands works with charm.
What will be done next;
- count the Guild Members on update guild_lands. At the moment, the GuildMembers are count on Server startup only.
YOU NEED TO ADD THE FOLLOWING CODE AS DESCIBED BELOW!-- 1. ADD BLOCK (1)- Code: Select all
-- BLOCK (1)
-- CREATE a procedure IN SQL!
-- TO USE THE PROCEDURE "AddColumnUnlessExists" you need to add it!
-- I FOUND THIS USEFULL SCRIPT ON http://www.cryer.co.uk/brian/mysql/howto_add_column_unless_exists.htm
-- Copyright (c) 2009 www.cryer.co.uk
-- Script is free to use provided this copyright header is included.
create procedure AddColumnUnlessExists(
IN dbName tinytext,
IN tableName tinytext,
IN fieldName tinytext,
IN fieldDef text)
begin
IF NOT EXISTS (
SELECT * FROM information_schema.COLUMNS
WHERE column_name=fieldName
and table_name=tableName
and table_schema=dbName
)
THEN
set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName,
' ADD COLUMN ',fieldName,' ',fieldDef);
prepare stmt from @ddl;
execute stmt;
END IF;
end;
-- 2. ADD BLOCK (2)- Code: Select all
-- BLOCK (2)
-- Query this in SQL!
-- THEN Copy this to patch.sql for inital handling!
-- Call The Procedure "AddColumnUnlessExists" to check if "CharCount" COLUMN exist and create IF NOT
call AddColumnUnlessExists(Database(), 'guild_lands', 'CharCount', 'smallint');
-- Count the "characters" with a GuildID and write it down to CharCount
UPDATE lif_1.guild_lands g SET CharCount = (SELECT COUNT(ID) FROM lif_1.`character` c WHERE c.GuildID = g.ID);
-- 3. ADD BLOCK (3)- Code: Select all
-- BLOCK (3)
-- CREATE a Trigger in SQL!
-- and always BEFORE UPDATE new Radius from server it will be reset (automatic) to your given values
CREATE
DEFINER = 'root'@'localhost'
TRIGGER lif_1.Guild_Land_limiter
BEFORE UPDATE
ON lif_1.guild_lands
FOR EACH ROW
BEGIN
DECLARE CharCount smallint;
DECLARE Radius smallint;
IF new.CharCount<4 AND new.Radius>40 AND new.GuildID !=4 THEN SET new.Radius = 55;
END IF;END
new.CharCount = how many Members a Guild need to not be affected by this Trigger.
new.Radius = how big a claim can be before affected by this Trigger.
new.GuildID = makes an exception for a Guild (eg. your Admin Claim...)
SET new.Radius = the value you like to give to a claim.