Page 3 of 3

ZingaRandomizer

Posted: October 18th, 2011, 1:20 pm
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!

Re: Post your custom code here

Posted: October 18th, 2011, 9:48 pm
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

Re: Post your custom code here

Posted: October 18th, 2011, 11:35 pm
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.

Re: Post your custom code here

Posted: October 19th, 2011, 12:48 am
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 ;)

Re: Post your custom code here

Posted: October 19th, 2011, 1:16 am
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.

Re: Post your custom code here

Posted: November 6th, 2011, 10:44 am
by BobKare
I have the devbuild version of fCraft 0.610, and how I add these things?

Re: Post your custom code here

Posted: November 6th, 2011, 6:11 pm
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

Re: Post your custom code here

Posted: November 6th, 2011, 8:55 pm
by BobKare
what's the point with all the characters? Like: !, ?, -, v...

Re: Post your custom code here

Posted: November 6th, 2011, 9:01 pm
by Jonty800
I have no idea what you're talking about

Re: Post your custom code here

Posted: November 6th, 2011, 9:07 pm
by Lim-Dul
I think he doesn't either and thus shouldn't be using custom code. :-P

Re: Post your custom code here

Posted: November 6th, 2011, 10:53 pm
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!

Re: Post your custom code here

Posted: November 6th, 2011, 11:51 pm
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 -.-

Re: Post your custom code here

Posted: November 7th, 2011, 7:24 pm
by BobKare
well, I think I solved that problem.

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

Re: Post your custom code here

Posted: November 7th, 2011, 11:20 pm
by fragmer
I split off IPBanInfo.cs into a separate file (because it was getting rather large) in r1209

Re: Post your custom code here

Posted: December 5th, 2011, 4:30 am
by jonnyli1125
Question,

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

Re: Post your custom code here

Posted: December 5th, 2011, 7:17 am
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.

Re: Post your custom code here

Posted: December 6th, 2011, 4:55 pm
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?

Re: Post your custom code here

Posted: December 6th, 2011, 7:04 pm
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.

Re: Post your custom code here

Posted: December 7th, 2011, 12:38 am
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.

Re: Post your custom code here

Posted: December 8th, 2011, 11:09 am
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.

Re: Post your custom code here

Posted: December 12th, 2011, 1:04 am
by ShadowKnight07
How do i add the Door/Remove Door Commands D:

Re: Post your custom code here

Posted: December 12th, 2011, 1:12 am
by Jonty800
/door is not supported by the latest version of fcraft

Re: Post your custom code here

Posted: December 12th, 2011, 1:27 am
by boblol0909
I guess I should update it then.

Re: Post your custom code here

Posted: December 13th, 2011, 3:18 am
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); }
        }


    }
}


Re: Post your custom code here

Posted: December 13th, 2011, 8:55 am
by Jonty800
Thanks for updating Bob, everyone loves /door :D

Re: Post your custom code here

Posted: December 13th, 2011, 11:31 pm
by boblol0909
edit: we cant delete posts anymore?

Re: Post your custom code here

Posted: December 13th, 2011, 11:47 pm
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.