Help me I'm newish.. just a few questions.

Help me I'm newish.. just a few questions.

Postby Leeizazombie » 11 Jun 2013, 00:33

Hey, I'm kinda new but i learn fast, im okay with coding and how it works, but for minecraft id like to know how to:
Make the player use a command when he/she touches something, like another person.... (it might be stupid but its just to give me an idea)
Have a variable like secret = hello, so i want that if a player says in a global message the value of secret, which is hello, to result in a message or a command. if possible make it that the message show as "player said the secret code. so it doesnt globaly show the code, all help is appreciated, even if you give me different examples :)

Topic '/tag or /chasing or /catch, Gamemode' - merged here (below) as your request is similar, the code provided will help in both situations

It would be cool to use this within the freebuild server for admins to make a map based on this game where its basicaly like zombies but only one person can be on, simply like in zombies when the game starts like a 20 seconds waiting thing, someone becomes flipheaded and his/her allias can be set to "I'm on" or "chaser" or whatever, and in contact with a player they get a message that they got caught and they become invisible until the match is over or leaves the map.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Help me I'm newish.. just a few questions.

Postby Conor » 11 Jun 2013, 01:37

Leeizazombie wrote:Hey, I'm kinda new but i learn fast, im okay with coding and how it works, but for minecraft id like to know how to:
Make the player use a command when he/she touches something, like another person.... (it might be stupid but its just to give me an idea)
Have a variable like secret = hello, so i want that if a player says in a global message the value of secret, which is hello, to result in a message or a command. if possible make it that the message show as "player said the secret code. so it doesnt globaly show the code, all help is appreciated, even if you give me different examples :)


To check if players touch, you must run a timer, probably for around every 50ms. Then you must check if their x, y and z position are the same, or within a radius of +-1. For example:

Code: Select all
public void OnTimerElapse(object sender, System.Timers.ElapsedEventArgs e)
{
    // run a loop through every player, where Player A would be the focused player, and Player B would be the changing player throughout the loop:
    if (PlayerA.pos[0] == PlayerB.pos[0] || PlayerA.pos[0] == (PlayerB.pos[0] * 32) + 1 || PlayerA.pos[0] == (PlayerB.pos[0] * 32) -1)
   {
       if (PlayerA.pos[1] == PlayerB.pos[1] || PlayerA.pos[1] == (PlayerB.pos[1] * 32) + 1 || PlayerA.pos[1] == (PlayerB.pos[1] * 32) -1)
        {
            if (PlayerA.pos[2] == PlayerB.pos[2] || PlayerA.pos[2] == (PlayerB.pos[2] * 32) + 1 || PlayerA.pos[2] == (PlayerB.pos[2] * 32) -1)
             {
                 // Intersection of Player A and B in a +-1 radius
                 // I think anyway... I haven't tested this.
             }
        }
   }
}


For the second suggestion, you'd need to look into the player chat event. When the event is raised you would search through the message the player sent, and if it contains the string you're looking for, act upon it. So for example, in the chat event, you'd call the following method:

Code: Select all
public static string secretWord = "banana";

public void CheckForSecretMessage(Player p, string message)
{
   if (message.Contains(secretWord))
   {
       Command.all.Find("say").Use(p, p.PublicName + " is a " + secretWord);
   }
}
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Help me I'm newish.. just a few questions.

Postby Leeizazombie » 11 Jun 2013, 03:36

Okay thanks, but if this:
Code: Select all
public static string secretWord = "banana";

public void CheckForSecretMessage(Player p, string message)
{
   if (message.Contains(secretWord))
   {
       Command.all.Find("say").Use(p, p.PublicName + " is a " + secretWord);
   }
}


Is not a command, how do i put it in the game?
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron