1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Command radius

Discussion in 'Development' started by Vortix, Aug 1, 2014.

  1. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    I was wondering how I may be able to add a radius to the usage of a command. Currently it works on the player you are looking at, however I don't want it to work for any distance, user must be fairly close to the target. I've reviewed the code for the /charfollow command however I don't see how I would be able to use it for what I want.
    Thanks in advance.
     
  2. Tomo742

    Tomo742 Guest

    You could probably use an if or something to check the distance between the user of the command and the player you wish to use it on, should be relatively easy.
     
  3. Code:
    if (player:GetPos():Distance(target:GetPost()) <= distance) then
        blablabla
    end
    or if you want to be more efficient:
    Code:
    if (player:GetPos():DistToSqr(target:GetPost()) <= math.pow(distance, 2)) then
        blablabla
    end
    Vector:Distance(vector) has to calculate a square root, which costs a lot more than calculating the square of a number. DistToSqr doesn't calculate the root of the distance at the end, so it returns the squared distance with less work even if we add in the math.pow we need to do in the comparison. Just in case you are interested.
     
  4. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Ah, thanks. As I don't really know much about distances in game, could you tell me what value would be about one and a half arm lengths (IC) distance?
     
  5. duck

    duck Phant0m Legend

    1 foot = 16 hammer units
    Average arm length from Google = 25 inches
    25 * 1.5 (one and a half) = 37.5
    37.5 inches = 3.125 feet
    3.125 * 16 = 50

    Use 50.
     
  6. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Great, thanks.
    Next off the infinite list of questions: Is there a way to check if someone is higher up than another player? So if the player is on a building and the target is not.
     
  7. NightAngel

    NightAngel Fuck off Lev

    Get both positions with :GetPos() and then compare the y coordinate. So like...
    Code:
    if (lel:GetPos().y > derp:GetPos().y) then
    Correct me if I'm wrong, but I'm pretty sure that's how it would go.
     
  8. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Thanks. Next question off the list: Can I use a function within a function in the sh_command.lua? I should probably explain better... If I were to have a command that once used will check certain conditions and then if certain conditions are matched call upon another function, in this case PLUGIN:playerSay, to check if the target has responded to the effects set by the command. This would mean that the PLUGIN:playerSay function must be called inside of the COMMAND:OnRun function.
    If I were to put it into a simple example, I should give this:
    I send a friend request, notifying the target that I wish to be his/her friend (Executed by the COMMAND:OnRun() function). That person may then type /accept (To accept my friend request and notify me) or /deny (To deny it and notify me). For this to occur, I would need the PlayerSay inside the OnRun and the conditions I have set. I've completed it and ran it through console without error (well, nothing that wasn't a simple fix, nothing related either), however as my plugin functions with two people and I am restricted to testing on a LAN server I'd like to make sure what I've done is fine before I release it for beta testing.
    So, is it?
     

Previous Readers (Total: 0)