[MOD] Set New Char Spawn Point

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

Moderator: Teleon


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

[MOD] Set New Char Spawn Point

Post by RudgerWolvram » 08 Jan 2015, 05:08

OK, so this came about because we created a "spawn area" in the center of our map for any new players. If you get any errors adding this trigger, make sure you don't have another trigger that is on the same time and table. For example, if you have trigger that gives new characters croc sandals, your trigger would be BEFORE INSERT on `Character`. The contents of this trigger will need to be added to your croc sandals trigger.

OK, so this requires a bit of setup on your side first. Take your character to the spawn location you want new players to come into. Log out, then:

Code: Select all
SELECT * FROM `character`;


Find the character name you just logged out of and copy the GeoID and GeoAlt values from its row.

Add a few numbers to your GeoAlt. like, if it's value is 5000, make it like 5025. This will cause the new player to drop into that location and prevent any "stuck in the terrain" issues.

The below code will set all new characters to spawn in that same exact location, every time.
Code: Select all
delimiter $$
CREATE TRIGGER `t_set_first_spawn` before INSERT ON `character` FOR EACH ROW BEGIN
   set New.GeoID = 117052637;
   set New.GeoAlt = 5100;
END;
$$


But what if you want multiple locations around an area and want it to be random? Repeat the go to X spot, logout, get GeoID and GeoAlt for each possible spawn location you want, then, for each location, say we have 3 possible location, update the below code with the correct GeoID and GeoAlt values. Adding a bit to each GeoAlt.

Code: Select all
delimiter $$
CREATE TRIGGER `t_set_first_spawn_rand` before INSERT ON `character` FOR EACH ROW BEGIN
declare rd int default 0;
set rd =  (select truncate((RAND()*10 MOD 3),0));
   CASE rd
      when 0 then
            set New.GeoID = 117052637;
            set New.GeoAlt = 5100;
      when 1 then
            set New.GeoID = 1170123637;
            set New.GeoAlt = 6100;
      when 2 then
            set New.GeoID = 126052637;
            set New.GeoAlt = 4500;
      else
            set New.GeoID = 117052637;
            set New.GeoAlt = 5100;
   end CASE;
END;
$$


Explanation of RAND() selection:
Select RAND(); (which you can just run as a query) will return a 0.xxxxxxxx number.
To get an integer out of it, first we need it above 0, so in this case I multiplied by 10 since there are less than 10 possible spawn points in the case statement. You can just as easily multiple it by 1,000,000 if you really wanted.
The Modulus operator MOD will give the division remainder of the value to the right. e.g. 10 MOD 3 is 1 (3*3 = 9 + 1 = 10). 10 mod 5 = 0 (5 * 2 + 0 = 10 0 remainder). MOD is used to put the random number into a range of number from 0 to n-1. n being the amount of numbers you need.

So with that, if you needed say 6 spawn points you would use MOD 6 and the SELECT RAND would be changed to:
Code: Select all
set rd =  (select truncate((RAND()*10 MOD 6,0));


The CASE statements start at 0 and go to 2 (3 numbers including 0).
If you need more spawn points, copy the WHEN statement, add 1 to the value, and add 1 to the number on the MOD number for each spawn point you need.

The ELSE statement is there as a catch all, just in case MySQL/Maria's RAND() has an aneurysm and returns and elephant in a leisure suit. Just update the ELSE's geo data with the data from the 0 case and you'll be fine.


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

Re: [MOD] Set New Char Spawn Point

Post by Sanctifiedevil » 03 Feb 2015, 16:08

Quick question, would this also work for the spawns for praying? Someone on my server seems to have set up base camp right at a spawn point and people are starting to abuse the pray function to get over their walls.


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

Re: [MOD] Set New Char Spawn Point

Post by RudgerWolvram » 05 Feb 2015, 05:46

In order to prevent that, you'd have to go into the database and find where the player was bound (i'm still looking for that info in the tables) and manually change that geoid value.

Though, if you really wanted to, you could disable the pray for home coming skill by changing the skill requirements on the serverside and upping the stam required to like 300. But that affects all players and may not be beneficial.


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

Re: [MOD] Set New Char Spawn Point

Post by Sanctifiedevil » 05 Feb 2015, 17:12

Yeah I'm not over sure how it calculates where non-bound players (players without a home set) will go when they pray. It seems to be specific GeoDataIDs that are tied to the regular spawnpoints but beyond that I don't see it in the database or the .xml files. It very well may be hard coded with the player spawns.

My idea for this script would be to trigger it on what ever function is being called when praying by non-bound characters and revert them to specified spawn points.


SKuDD3r
 
Posts: 15
Joined: 01 Feb 2015, 19:41

Re: [MOD] Set New Char Spawn Point

Post by SKuDD3r » 05 Feb 2015, 21:49

This gives me a good idea.... for making a new GM command for teleporting to players.

User avatar
Respectful
 
Posts: 8
Joined: 26 Jan 2015, 18:43

Re: [MOD] Set New Char Spawn Point

Post by Respectful » 17 Feb 2015, 11:00

Bit of a noob with this sort of thing, how exactly would I add the trigger? A new file, or no?


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

Re: [MOD] Set New Char Spawn Point

Post by RudgerWolvram » 17 Feb 2015, 19:19

Copy the SQL code and run it as a query in Heidi or MySQL Workbench against the server. It will create the trigger in the database. Refresh the database tree and you'll see it towards the bottom.

User avatar
Respectful
 
Posts: 8
Joined: 26 Jan 2015, 18:43

Re: [MOD] Set New Char Spawn Point

Post by Respectful » 17 Feb 2015, 21:13

RudgerWolvram wrote:Copy the SQL code and run it as a query in Heidi or MySQL Workbench against the server. It will create the trigger in the database. Refresh the database tree and you'll see it towards the bottom.



Awesome, thank you!

User avatar
Respectful
 
Posts: 8
Joined: 26 Jan 2015, 18:43

Re: [MOD] Set New Char Spawn Point

Post by Respectful » 19 Feb 2015, 08:47

Probably a dumb question I can solve by watching an SQL query tutorial, but would I just copy and paste it as is, or would I have to write more?

EDIT: figured it out, nevermind. Thanks!


Aranax
 
Posts: 13
Joined: 25 Sep 2014, 05:40

Re: [MOD] Set New Char Spawn Point

Post by Aranax » 09 Apr 2015, 08:25

Where do you get the character location from?

edit: problem solved found the info in the character data in the SQL database.
Image

Return to LiF: YO Game mods