Fork me on GitHub

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bytesnake

Pages: [1]
1
Development / Warp
« on: August 29, 2011, 12:51:20 pm »
Hey,

I'm a German student, therefore my english is not so good.
But I think your project ist really cool and I have implemented Warp points to the plugin "commands".
Here's the code:
<plugins/commands/commands.cpp>
Code: [Select]
void warp(std::string user, std::string command, std::deque<std::string> args)
{
    std::string warps;
    std::string line;
    std::ifstream WARPFILE("warp.txt");
    if (WARPFILE.is_open())
    {
while (WARPFILE.good() )
{
 std::getline(WARPFILE, line);
 std::string *warppoint = explode(line, ",");
 if(args.size() == 0)
          {
            std::string str_warppoint = warppoint[0];
            if(str_warppoint != "\n")
            {
              warps += str_warppoint;
              warps += ", ";
            }
          }
          else if(warppoint[0] == args[0])
         {
                mineserver->chat.sendmsgTo(user.c_str(), "Warpe ...." );
           mineserver->user.teleport(user.c_str(), atof(warppoint[1].data()), atof(warppoint[2].data()), atof(warppoint[3].data())/*world: , warppoint[4].data()*/);
          }
}
        if(args.size() == 0) mineserver->chat.sendmsgTo(user.c_str(), warps.c_str() );
WARPFILE.close();
    }
    else mineserver->chat.sendmsgTo(user.c_str(), "No Warp Entries");
}

std::string delwarp(std::string warp)
{
  std::string warps="";
  std::string line;
  std::ifstream iWarp("warp.txt");
  if (iWarp.is_open())
  {
      bool first = true;
      while (iWarp.good() )
      {
        std::getline(iWarp, line);
        std::string *warppoint = explode(line, ",");
        //Copy only the other warppoints
        if(warppoint[0] != warp)
          if(first)
          {
            warps += line;
            first = false;
          }
          else warps += "\n" + line;
      }
      iWarp.close();
  }
  return warps;
}

void setwarp(std::string user, std::string command, std::deque<std::string> args)
{
  if(args.size() == 1)
  {
    double x,y,z;
    int w;
    mineserver->user.getPosition(user.c_str(), &x,&y,&z,NULL,NULL,NULL);
    
    //try to del same entries
    std::string warps = delwarp(args[0]);
    //write data
    std::ofstream oWarp("warp.txt");
    if(oWarp.is_open())
    {
      oWarp << warps << "\n" << args[0] << "," << x << "," << y+2 << "," << z;
      mineserver->chat.sendmsgTo(user.c_str(), "Warp created");
      oWarp.close();
    }
  }
}
    
void delwarp(std::string user, std::string command, std::deque<std::string> args)
{
  if(args.size() == 1)
  {
    //delete warp
    std::string warps = delwarp(args[0]);
    //write data
    std::ofstream oWarp("warp.txt");
    if(oWarp.is_open())
    {
      oWarp << warps;
      mineserver->chat.sendmsgTo(user.c_str(), "Warp deleted");
      oWarp.close();
    }
  }
}
....
....
registerCommand(ComPtr(new Command(parseCmd("warp"), "<warppoint>", "Teleport to warp", warp)));
registerCommand(ComPtr(new Command(parseCmd("setwarp"), "<warppoint>", "Set a warp", setwarp)));
registerCommand(ComPtr(new Command(parseCmd("delwarp"), "<warppoint>", "Delete a warp", delwarp)));

The warps be stored in the file "warps.txt" and the syntax is "name, x, y, z".
Different worlds arent't implemented, because I get the error "886:76: error: too many arguments to function", if I try call the function getposition with eight parameters.

bytesnake

Pages: [1]