This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mercwear's profile picture

Hardcore Quest Mode & Command Computer

Started by mercwear, 26 May 2015 - 12:49 AM
mercwear #1
Posted 26 May 2015 - 02:49 AM
We would like to allow users to push a button to receive more HQM lives on our server and the command computer seems to be the perfect way to do this however, I am having a few issues that I hope the community can help me with.

At the console, as an admin you can run this command to add one life to a player named steve: "/hqm lives add steve 1". I want the closest player to the command computer to get the lives so I put together the following program:


commands.exec("/hqm lives add @p 1")

When I run this I get the following error from HQM:
"Please use only positive numbers and / or a correct Playername."

If I use the player name, rather than @p (as seen below) everything works:


commands.exec("/hqm lives add steve 1")


I believe the problem is the @p but I am at a loss on how to fix it. Any advice is appreciated.

Note: I am trying to stay away from Sensors if I can.
Edited on 26 May 2015 - 12:50 AM
Lyqyd #2
Posted 26 May 2015 - 02:53 AM
Does it make any difference if you take out the preceding slash? It shouldn't really matter, but all the examples on the wiki omit the slash, so maybe it's worth a shot?
mercwear #3
Posted 26 May 2015 - 02:57 AM
Does it make any difference if you take out the preceding slash? It shouldn't really matter, but all the examples on the wiki omit the slash, so maybe it's worth a shot?

Just tried this and go the same error:

commands.exec("hqm lives add @p 1")

Is there any way for me to capture the return of @p as a variable? That may work..

If I can capture @p as a variable, this will work:


local name = @p --(does not work)
commands.exec("/hqm lives add "..name.." 1")
Bomb Bloke #4
Posted 26 May 2015 - 03:22 AM
The slash isn't needed. It's optional, same as when you run commands via actual command blocks.

I would expect @p ("nearest player") to work. I've used it via commands.exec() with other commands. Does it work with "hqm lives" in a real command block?

There's a bit of discussion on getting player names and locations using the tp command via a command computer here. Combine that with commands.getBlockPosition(), and you should be able to target the closest.
mercwear #5
Posted 26 May 2015 - 06:33 AM
Thanks for the replies. I went ahead and use a sensor to get the job done and it's working. I still wonder why the @p is not working.. I'll try it on a command block and get back to you Bomb.
Cranium #6
Posted 26 May 2015 - 06:36 AM
For me, usually when player variables in command blocks don't work, it's usually due to the mod/plugin author's neglect to handle those cases.