Deepu Posted February 26, 2014 Share Posted February 26, 2014 (edited) Hello every body..... Long TIme no see Well, I am here to give you a tutorial on how to make a numberID command since if you type a command and if its in abc text, still it gets executed.......(I had this problem when I was a 1 week scripter better to make a client sided script as client side is easy..... first you gotta make a function for the command..... So lets take poops, where if you type /poops (amount) it gives you n amounts of poops We take thePlayer as the player because I feel thats easier than localPlayer thePlayer = getLocalPlayer() function poopaDoopa (cmd, id) -- the id is the parameter for id next we add the functions for id parameter for example : (remember, we need to use getElementData and setElementData as the main things) function poopaDoopa local id = tonumber(id)(cmd, id) if (id) and (id>0) then -- checks if an ID was typed and if id is greater than 0) ama = getElementData(localPlayer, "poops") or 0 ana = setElementData(localPlayer, "poops", tonumber(id)) -- to number verifies that the id is a number else outputChatBox("SYNTAX: /"..cmd.." [id]", thePlayer, 255, 2, 0, false) end end addCommandHandler("poops", poopaDoopa) now that we made the command and we wanna know how much poops you currently have ..... function howMuch () outputChatBox("you have "tostring(ama)"amounts of poops", thePlayer, 255, 2, 0, false) end addCommandHandler("poopa", howMuch) this returns amounts of poops..... Now this may not work but the full script is..... function tapu (cmd, amount) local amount = tonumber(amount) if amount and amount > 0 then local pro = tonumber(getElementData(localPlayer, "poops")) or 0 noob = pro + amount setElementData(localPlayer, "poops", noob) else outputChatBox("SYNTAX: /"..cmd.." amount", thePlayer, true) end end addCommandHandler("poops", tapu) function tapl () local pro = tonumber(getElementData(localPlayer, "poops")) or 0 outputChatBox(tostring(pro), thePlayer, 255, 2, 0, false) end addCommandHandler("poopa", tapl) and this works perfectly Edited February 26, 2014 by Guest Link to comment
BlueBerry Posted February 26, 2014 Share Posted February 26, 2014 The tutorial is filled with errors and doesnt work. How it's done correctly. function poopaDoopa(player, cmd, id) if (id) and (id > 0) then -- checks if an ID was typed and if id is greater than 0) ana = setElementData(player, "poops", tonumber(id)) -- to number verifies that the id is a number else outputChatBox("SYNTAX: /"..cmd.." [id]", player, 255, 2, 0, false) end end addCommandHandler("poops", poopaDoopa) function howMuch (player) outputChatBox("You have ".. getElementData(player, "poops").."amounts of poops", thePlayer, 255, 2, 0, false) end addCommandHandler("poopa", howMuch) What was incorrect to your code was the string insertion from lua, which should be done by placing 2 dots in front and behind when it's completely surrounded by the string( "this " ..value.. " is a value"). When there's a string infront you should place 2 dots infront of the value("This" .. value) same goes for behind the value, ( value .. " is a value"). Also I suggest you not to pass values across functions unless they're delivered by a function, like the value AMA you were calling, you can better just call the getElementData from the code where you want it to be. What was also not really clever was the localPlayer you used, you can better use (player, command, value) instead of using localplayer, as it can be used in both serversided scripting and clientsided scripting. Also, this made very little sense to me; function poopaDoopa local id = tonumber(id)(cmd, id) You're declaring the varible id the value id, which is the same. I know many scripting languages need you to declare the type of a variable before you can use them, but LUA doesnt. LUA's variables are pretty much dynamic, they are all types in one, when they are empty. I suggest you to try and master LUA before you start writing tutorials. Link to comment
Deepu Posted February 26, 2014 Author Share Posted February 26, 2014 Well thing is that I know proper lua but I dint test it sorry I will make a nice tut after 2 weeks Cuz i am busy now and thanks blueberry for ur help but I know those I made the correct one I will be editing the entry now Link to comment
Castillo Posted February 26, 2014 Share Posted February 26, 2014 The tutorial is filled with errors and doesnt work. How it's done correctly. function poopaDoopa(player, cmd, id) if (id) and (id > 0) then -- checks if an ID was typed and if id is greater than 0) ana = setElementData(player, "poops", tonumber(id)) -- to number verifies that the id is a number else outputChatBox("SYNTAX: /"..cmd.." [id]", player, 255, 2, 0, false) end end addCommandHandler("poops", poopaDoopa) function howMuch (player) outputChatBox("You have ".. getElementData(player, "poops").."amounts of poops", thePlayer, 255, 2, 0, false) end addCommandHandler("poopa", howMuch) What was incorrect to your code was the string insertion from lua, which should be done by placing 2 dots in front and behind when it's completely surrounded by the string( "this " ..value.. " is a value"). When there's a string infront you should place 2 dots infront of the value("This" .. value) same goes for behind the value, ( value .. " is a value"). Also I suggest you not to pass values across functions unless they're delivered by a function, like the value AMA you were calling, you can better just call the getElementData from the code where you want it to be. What was also not really clever was the localPlayer you used, you can better use (player, command, value) instead of using localplayer, as it can be used in both serversided scripting and clientsided scripting. Also, this made very little sense to me; function poopaDoopa local id = tonumber(id)(cmd, id) You're declaring the varible id the value id, which is the same. I know many scripting languages need you to declare the type of a variable before you can use them, but LUA doesnt. LUA's variables are pretty much dynamic, they are all types in one, when they are empty. I suggest you to try and master LUA before you start writing tutorials. This is wrong: if (id) and (id > 0) then -- checks if an ID was typed and if id is greater than 0) "id" will be a string, not a number. Link to comment
myonlake Posted February 27, 2014 Share Posted February 27, 2014 And why are you guys mixing thePlayer, player and localPlayer together? Just use one player element for the same one... Link to comment
Recommended Posts