Post your custom code here

For all mod-related questions and custom code.
BinaryX
Offline
Posts: 8
Joined: October 13th, 2011, 3:52 pm
Location: The Netherlands
Contact:

ZingaRandomizer

Post by BinaryX »

It does just that what the name says, you add a series of words or sentences inside the list items and by using the randomText function it picks a random sentence or word from the list defined by the MessageType enum. It really makes people crazy lol.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*
 *© 2011 - ZingaCraftPlugin.
 *Written for fCraft developed by BinaryX and Phxvyper.
*/
namespace fCraft
{
    public static class ZingaRandomizer
    {
        public enum MessageType
        {
            PLAYER_CONNECT_FIRST,
            PLAYER_CONNECT,
            PLAYER_LEAVE,
            PLAYER_GREETING
        }

        public static List<string> FirstConnectMessages, ConnectMessages, LeaveMessages, GreetingMessages;

        public static void Init()
        {
            ZingaRandomizer.FirstConnectMessages = new List<string>();
            ZingaRandomizer.ConnectMessages = new List<string>();
            ZingaRandomizer.LeaveMessages = new List<string>();
            ZingaRandomizer.GreetingMessages = new List<string>();

            ZingaRandomizer.GreetingMessages.AddRange(new string[]{
                "Hi!",
                "Hello.", 
                "Buy me a drink!",
                "Greetings.",
                "Build!!!!!!!",
                "Hi there.",
                "Hmm.. i think i'm lost."
            });
            ZingaRandomizer.FirstConnectMessages.AddRange(new string[]{
                "Player {0}&S joined for the first time.",
                "Player {0}&S joined for the first time, its a virgin!"
            });
            ZingaRandomizer.ConnectMessages.AddRange(new string[]{
                "Player {0}&S joined, everyone dive into the lava!",
                "Player {0}&S has come to play.",
                "Player {0}&S joined, dig a hole and hide...",
                "Player {0}&S connected again.",
                "Player {0}&S has come back."
            });
            ZingaRandomizer.LeaveMessages.AddRange(new string[]{
                "Player {0}&S got scared and left.",
                "Player {0}&S left for milk and cookies.",
                "Player {0}&S left the server.",
                "Player {0}&S accidentaly pressed ALT+F4.",
                "Player {0}&s died, he wasn't prepared for the awesomeness of minecraft."
            });
        }

        public static string randomText(MessageType type, params object[] format)
        {
            string randomizedMessage = "";
            Random random = new Random();
            int number;
            switch (type)
            {
                case MessageType.PLAYER_GREETING:
                    number = random.Next(0, GreetingMessages.Count);
                    randomizedMessage = GreetingMessages.ElementAt(number);
                    break;
                case MessageType.PLAYER_CONNECT_FIRST:
                    number = random.Next(0, FirstConnectMessages.Count);
                    randomizedMessage = FirstConnectMessages.ElementAt(number);
                    break;
                case MessageType.PLAYER_CONNECT:
                    number = random.Next(0, ConnectMessages.Count);
                    randomizedMessage = ConnectMessages.ElementAt(number);
                    break;
                case MessageType.PLAYER_LEAVE:
                    number = random.Next(0, LeaveMessages.Count);
                    randomizedMessage = LeaveMessages.ElementAt(number);
                    break;
            }
            return String.Format(randomizedMessage, format);
        }
    }
}

Edit: fixed a minor randomizing bug, thanks fragmer!

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

Wow thanks Binary, I never thought about doing this. I did have a plan of allowing a player to change their leaving the server message (similar to IRC)

And LOOOOOOL. How does that bug even happen?

under /door, change the permissions from Permissions.Chat to whatever.

Report all bugs on au70galaxy.com/forums plzzz
You cannot use certain BBCodes: [img].

BinaryX
Offline
Posts: 8
Joined: October 13th, 2011, 3:52 pm
Location: The Netherlands
Contact:

Re: Post your custom code here

Post by BinaryX »

Just some bug... lol.
What is au70? why even have a forum for it, no offence but the code is just written so poorly and it looks so messy.
Edit: its a scripts package right? i saw something at sourceforge.

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

Au70 is a server. "Au70 Galaxy" and the software modifications are written by me.
I recently decided to teach myself C#, hence why the code sucks so much. :P
But /door was never my command ;)
You cannot use certain BBCodes: [img].

User avatar
xanderortiz
Offline
Posts: 19
Joined: August 2nd, 2011, 9:27 am

Re: Post your custom code here

Post by xanderortiz »

Jonty800 wrote:Au70 is a server. "Au70 Galaxy" and the software modifications are written by me.
I recently decided to teach myself C#, hence why the code sucks so much. :P
But /door was never my command ;)
Dude, keep doing what you're doing. I appreciate it, and I'm sure others will if they don't already. I only know enough about the code to edit small things to make them do what I'd like them to do.

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Post your custom code here

Post by BobKare »

I have the devbuild version of fCraft 0.610, and how I add these things?

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

This code is very old and shouldnt be used

go to sourceforge.net/projects/jonty800/files and download my latest source, you can pinch stuff out of there
You cannot use certain BBCodes: [img].

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Post your custom code here

Post by BobKare »

what's the point with all the characters? Like: !, ?, -, v...

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

I have no idea what you're talking about
You cannot use certain BBCodes: [img].

User avatar
Lim-Dul
The Necromancer
Offline
Posts: 663
Joined: May 21st, 2011, 10:21 pm

Re: Post your custom code here

Post by Lim-Dul »

I think he doesn't either and thus shouldn't be using custom code. :-P
War does not determine who is right - only who is left. - Bertrand Russell

User avatar
xanderortiz
Offline
Posts: 19
Joined: August 2nd, 2011, 9:27 am

Re: Post your custom code here

Post by xanderortiz »

i would have to agree with you guys. i could be mistaken, but i think he is trying to do a DOS debug command on the compiled files... GTFO!

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: Post your custom code here

Post by boblol0909 »

xanderortiz wrote:i would have to agree with you guys. i could be mistaken, but i think he is trying to do a DOS debug command on the compiled files... GTFO!
Or just trying to read the compiled binaries and insert code there -.-

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Post your custom code here

Post by BobKare »

well, I think I solved that problem.

@Jonty800, you totally removed IPBanInfo.cs? I get an error about that...

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Post your custom code here

Post by fragmer »

I split off IPBanInfo.cs into a separate file (because it was getting rather large) in r1209

User avatar
jonnyli1125
Offline
Posts: 3
Joined: December 5th, 2011, 3:47 am

Re: Post your custom code here

Post by jonnyli1125 »

Question,

I'm new to fCraft so I don't understand this, but how do you put the command into your server? :/

User avatar
PyroPyro
Offline
Posts: 381
Joined: May 25th, 2011, 4:00 pm
Location: #fCraft
Contact:

Re: Post your custom code here

Post by PyroPyro »

jonnyli1125 wrote:Question,

I'm new to fCraft so I don't understand this, but how do you put the command into your server? :/
You will need to compile fCraft for that, you will need a SVN client and MSVS C# 2008.

User avatar
ShadowSkeleton
OP
Offline
Posts: 12
Joined: September 26th, 2011, 4:45 pm
Location: Germany

Re: Post your custom code here

Post by ShadowSkeleton »

i have the same problem, i dont understand something. I have installed Microsoft Visulal C++ 2008 and two svn clients (smartSVN and TortoiseSVN) but i dont understand what i should do to add some mods, like /warn or /door. I guess i must change the fcraft.dll, right? Or what can i do?

User avatar
TheMastBoss
SupOP
Offline
Posts: 208
Joined: May 24th, 2011, 10:09 am
Location: Italy.

Re: Post your custom code here

Post by TheMastBoss »

ShadowSkeleton wrote:i have the same problem, i dont understand something. I have installed Microsoft Visulal C++ 2008 and two svn clients (smartSVN and TortoiseSVN) but i dont understand what i should do to add some mods, like /warn or /door. I guess i must change the fcraft.dll, right? Or what can i do?
First of all, fCraft is written in C# and not in C++, so you have to download Microsoft VS C#.
Second, you have to download the fCraft source code, right click where you want to download the files and use SVN Checkout, then insert this link: http://svn.fcraft.net:8080/svn/fcraft/branch-0.60x/.
Now all the source files are on your computer.

After that open Visual C# and open fCraft with it, now all the source files are ready to be edited.

Modding fCraft requires, obviously, C# knownledge.
* Isotope destructively nudges DreamingInsane with a new frogsleg.
tesfai10: greg79 wanna have sex

User avatar
xanderortiz
Offline
Posts: 19
Joined: August 2nd, 2011, 9:27 am

Re: Post your custom code here

Post by xanderortiz »

The mods are code that you add to the appropriate .cs file inside the fCraft.dll file, which (as mentioned above) can be edited via MS Visual C#. Fragmer has conventiently separated the commands by type (example ChatCommands.cs, BuildCommands.cs, etc.) . I highly recommend studying his code and organization of the commands in it. You either need to create your own commands by writing your own C# code or find some already-existing code from someone for the commands you wish to add. If you know what you're doing... You would paste the code into the appropriate .cs file with the same organization in which Fragmer has written the other commands. If you run into errors, PLEASE first read the other posts inside this thread. So many people ask questions that have already been answered here. Good luck.

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

I wouldn't try to add /door, it doesnt work with the latest fCraft due to a change of code in BlockUpdate.

I'll update the code on here for everyone once I get time to fix it.

Pretty much all the commands posted on here by me are very outdated.
You cannot use certain BBCodes: [img].

ShadowKnight07
Offline
Posts: 1
Joined: December 12th, 2011, 12:59 am

Re: Post your custom code here

Post by ShadowKnight07 »

How do i add the Door/Remove Door Commands D:

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

/door is not supported by the latest version of fcraft
You cannot use certain BBCodes: [img].

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: Post your custom code here

Post by boblol0909 »

I guess I should update it then.

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: Post your custom code here

Post by boblol0909 »

Here's door to work with latest fCraft.
EDIT: fixed deleting open doors by placing blocks in it

Code: Select all

using System;
using System.Collections.Generic;
using fCraft.Events;

namespace fCraft
{
    struct DoorInfo
    {
        public readonly Zone Zone;
        public readonly Block[] Buffer;
        public readonly Map WorldMap;
        public DoorInfo(Zone zone, Block[] buffer, Map worldMap)
        {
            Zone = zone;
            Buffer = buffer;
            WorldMap = worldMap;
        }
    }

    static class DoorCommands
    {
        static readonly TimeSpan DoorCloseTimer = TimeSpan.FromMilliseconds(1500);
        static List<Zone> openDoors;
        const int maxDoorBlocks = 15;  //change for max door area             

        internal static void Init()
        {
            CommandManager.RegisterCustomCommand(cdDoor);
            CommandManager.RegisterCustomCommand(cdDoorRemove);
            openDoors = new List<Zone>();
            Player.Clicked += PlayerClickedDoor;
        }

        static readonly CommandDescriptor cdDoor = new CommandDescriptor
        {
            Name = "door",
            Category = CommandCategory.Zone,
            Permissions = new[] { Permission.Build },
            Help = "Creates door zone. Left click to open doors.",
            Handler = Door
        };

        static void Door(Player player, Command cmd)
        {
            if (player.WorldMap.Zones.FindExact(player.Name + "door") != null) {
                player.Message("One door per person.");
                return;
            }

            Zone door = new Zone();
            door.Name = player.Name + "door";
            player.SelectionStart(2, DoorAdd, door, cdDoor.Permissions);
            player.Message("Door: Place a block or type /mark to use your location.");
        }

        static readonly CommandDescriptor cdDoorRemove = new CommandDescriptor
        {
            Name = "removedoor",
            Aliases = new[] { "rd" },
            Category = CommandCategory.Zone,
            Permissions = new[] { Permission.Build },
            Help = "Removes door.",
            Handler = DoorRemove
        };

        static void DoorRemove(Player player, Command cmd)
        {
            Zone zone;
            if ((zone = player.WorldMap.Zones.FindExact(player.Name + "door")) != null) {
                player.WorldMap.Zones.Remove(zone);
                player.Message("Door removed.");
            }
            else {
                player.Message("You do not have a door on this map.");
            }
        }

        static void DoorAdd(Player player, Vector3I[] marks, object tag)
        {
            int sx = Math.Min(marks[0].X, marks[1].X);
            int ex = Math.Max(marks[0].X, marks[1].X);
            int sy = Math.Min(marks[0].Y, marks[1].Y);
            int ey = Math.Max(marks[0].Y, marks[1].Y);
            int sh = Math.Min(marks[0].Z, marks[1].Z);
            int eh = Math.Max(marks[0].Z, marks[1].Z);

            int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
            if (volume > maxDoorBlocks) {
                player.Message("Doors are only allowed to be {0} blocks", maxDoorBlocks);
                return;
            }

            Zone door = (Zone)tag;
            door.Create(new BoundingBox(marks[0], marks[1]), player.Info);
            player.WorldMap.Zones.Add(door);
            Logger.Log(LogType.UserActivity, "{0} created door {1} (on world {2})", player.Name, door.Name, player.World.Name);
            player.Message("Door created: {0}x{1}x{2}", door.Bounds.Dimensions.X,
                                                        door.Bounds.Dimensions.Y,
                                                        door.Bounds.Dimensions.Z);
        }

        static readonly object openDoorsLock = new object();
        public static void PlayerClickedDoor(object sender, PlayerClickedEventArgs e)
        {

            Zone[] allowed, denied;
            if (e.Player.WorldMap.Zones.CheckDetailed(e.Coords, e.Player, out allowed, out denied)) {
                foreach (Zone zone in allowed) {
                    if (zone.Name.EndsWith("door")) {
                        lock (openDoorsLock) {
                            if (!openDoors.Contains(zone)) {
                                openDoor(zone, e.Player);
                                openDoors.Add(zone);
                            }
                        }
                    }
                }
            }

        }

        static void openDoor(Zone zone, Player player)
        {
            int sx = zone.Bounds.XMin;
            int ex = zone.Bounds.XMax;
            int sy = zone.Bounds.YMin;
            int ey = zone.Bounds.YMax;
            int sz = zone.Bounds.ZMin;
            int ez = zone.Bounds.ZMax;
            
            Block[] buffer = new Block[zone.Bounds.Volume];
            
            int counter = 0;
            for (int x = sx; x <= ex; x++) {
                for (int y = sy; y <= ey; y++) {
                    for (int z = sz; z <= ez; z++) {
                        buffer[counter] = player.WorldMap.GetBlock(x, y, z);
                        player.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), Block.Air));
                        counter++;
                    }
                }
            }

            DoorInfo info = new DoorInfo(zone, buffer, player.WorldMap);

            //not really necessary but...
            Logger.Log(LogType.UserActivity, "{0} opened door {1} (on world {2})", player.Name, zone.Name, player.World.Name);
            //reclose door
            Scheduler.NewTask(doorTimer_Elapsed).RunOnce(info, DoorCloseTimer);
            
        }

        static void doorTimer_Elapsed(SchedulerTask task)
        {
            DoorInfo info = (DoorInfo)task.UserState;
            int counter = 0;
            for (int x = info.Zone.Bounds.XMin; x <= info.Zone.Bounds.XMax; x++) {
                for (int y = info.Zone.Bounds.YMin; y <= info.Zone.Bounds.YMax; y++) {
                    for (int z = info.Zone.Bounds.ZMin; z <= info.Zone.Bounds.ZMax; z++) {
                        info.WorldMap.QueueUpdate(new BlockUpdate(null, new Vector3I(x, y, z), info.Buffer[counter]));
                        counter++;
                    }
                }
            }

            lock (openDoorsLock) { openDoors.Remove(info.Zone); }
        }


    }
}

Last edited by boblol0909 on December 13th, 2011, 11:23 pm, edited 1 time in total.

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Post your custom code here

Post by Jonty800 »

Thanks for updating Bob, everyone loves /door :D
Last edited by Jonty800 on December 14th, 2011, 1:06 am, edited 1 time in total.
You cannot use certain BBCodes: [img].

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: Post your custom code here

Post by boblol0909 »

edit: we cant delete posts anymore?
Last edited by boblol0909 on December 14th, 2011, 1:09 am, edited 1 time in total.

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Post your custom code here

Post by fragmer »

Status update on main fCraft development:

Stable code snapshots, starting with 0.610, are now tagged on SVN. You can get a snapshot here.

Next immediate release will be a minor bugfix release (0.612). It will contain no new features. Next major release will be 0.700. A list of planned additions can be found in the Roadmap article on the fCraft Wiki.

Also I'd like to remind you NOT to use /branch-MySQL/ for the time being. There are many unfinished things and bugs there, and big chunks of that codebase will be rewritten. Development of /branch-MySQL/ is currently stalled by this bug in the MySQL driver.

Also, I put together a little Modding FAQ recently, check it out.

Post Reply