General > Developers Corner
Trying to make a command
Bytewave:
--- Quote from: (TG) PotLuck on July 09, 2016, 01:28:45 AM ---
--- Code: ---CATEGORY_NAME = "Custom Commands by Pot"
function ulx.cookie( calling_ply, target_ply, dmg )
local affected_plys = {}
for i=1, #target_ply do
local v = target_ply[ i ]
if v:IsFrozen() then
ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
else
ULib.cookie( v, dmg )
table.insert( affected_plys, v )
end
end
ulx.fancyLogAdmin( calling_ply, "#A gave #T #i cookies!", affected_plys, dmg )
end
local cookie = ulx.command( CATEGORY_NAME, "ulx cookie", ulx.cookie, "!cookie" )
cookie:addParam{ type=ULib.cmds.PlayerArg }
cookie:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="damage", ULib.cmds.optional, ULib.cmds.round }
cookie:defaultAccess( ULib.ACCESS_ADMIN )
cookie:help( "Gives someone cookies!" )
--- End code ---
That is what I have, but it still wont work. I tried to do what Bytewave said but it was confusing for me. I am still a little new to working with ULX
--- End quote ---
Again, I said gut the function save for the call to ulx.fancyLogAdmin.
I tried to break everything down for you. I feel like I did everything but write it for you in that post, but I'll try again based on the code you have now.
Remove everything between function ulx.cookie( calling_ply, target_ply, dmg ) and ulx.fancyLogAdmin( calling_ply, "#A gave #T #i cookies!", affected_plys, dmg ).
Replace all occurrences of dmg with cookies for consistency.
Replace affected_plys in the ulx.fancyLogAdmin call with target_ply --- affected_plys no longer exists and isn't waht you want anyway.
Replace "damage" in the hint section of the second cookie:addParam call with "cookies" for consistency.
Done.
(TG) PotLuck:
--- Quote from: Bytewave on July 09, 2016, 09:17:38 AM ---Again, I said gut the function save for the call to ulx.fancyLogAdmin.
I tried to break everything down for you. I feel like I did everything but write it for you in that post, but I'll try again based on the code you have now.
Remove everything between function ulx.cookie( calling_ply, target_ply, dmg ) and ulx.fancyLogAdmin( calling_ply, "#A gave #T #i cookies!", affected_plys, dmg ).
Replace all occurrences of dmg with cookies for consistency.
Replace affected_plys in the ulx.fancyLogAdmin call with target_ply --- affected_plys no longer exists and isn't waht you want anyway.
Replace "damage" in the hint section of the second cookie:addParam call with "cookies" for consistency.
Done.
--- End quote ---
Um, I did what you said. I thing the #i is messing up the fancy log admin print. Do I need it back? If so, where do I put it.
--- Code: ---CATEGORY_NAME = "Custom Commands by Pot"
function ulx.cookie( calling_ply, target_ply, cookies )
ulx.fancyLogAdmin( calling_ply, "#A gave #T #i cookies!", affected_ply, cookies )
end
local cookie = ulx.command( CATEGORY_NAME, "ulx cookie", ulx.cookie, "!cookie" )
cookie:addParam{ type=ULib.cmds.PlayerArg }
cookie:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="cookies", ULib.cmds.optional, ULib.cmds.round }
cookie:defaultAccess( ULib.ACCESS_ADMIN )
cookie:help( "Gives someone cookies!" )
--- End code ---
An Error Has Occurred!
array_keys(): Argument #1 ($array) must be of type array, null given
[0] Board index
Go to full version