Anubhav Posted February 11, 2014 Share Posted February 11, 2014 (edited) Welcome to Anubhav's Tutorials TUTORIAL 1 - Checking money Lets start! First we will start with basic functions which are not complicated. We will do money checking script. Make sure its server in meta.xml 1. We will start with a function named checkMoney. function checkMoney() 2. To check player's money we must use getPlayerMoney and we will add the first argument. function checkMoney() getPlayerMoney(thePlayer) 3. We will make local. function checkMoney() local money = getPlayerMoney(thePlayer) 4. We will need to output the money so we will use. Arguments: 1st is the text you want to take out. i used money.. with it. function checkMoney() local money = getPlayerMoney(thePlayer) outputChatBox("You have $"..money,player) 5. We will end the function function checkMoney() local money = getPlayerMoney(thePlayer) outputChatBox("You have $"..money,player) end 6. Last thing , we need to add the command so we can check anytime we want. function checkMoney() local money = getPlayerMoney(thePlayer) outputChatBox("You have $"..money,player) end addCommandHandler("money",checkMoney) Use /money to get your money! TUTORIAL 2 - Exports What is exports? Export is like selling things to other country but here it is used as functions not goods ( items ). Lets start@! We will make changeAccountPassword script which will change the account password. 1. We will add the function named changeAccountPassword function changeAccountPassword() 2. We will make a end to end the function! function changeAccountPassword() end 3. Now we will make add getPlayerAccount to get what account to set. function changeAccountPassword(account) local account = getPlayerAccount(account) end 4. We will check if got the account. [/lua] function changeAccountPassword(account) local account = getPlayerAccount(account) if account then end [/lua] 5. We will add a end to end if and check if it was guest account , if it was then return and add one more end. function changeAccountPassword(account) local account = getPlayerAccount(account) if account then if (isGuestAccount(account)) then return outputChatBox("changeAccountPassword Error: Bad Argument @ 1",root) end end end 6. We will add else because it was a account and output it that it was succesfully found. function changeAccountPassword(account) local account = getPlayerAccount(account) if account then if (isGuestAccount(account)) then return outputChatBox("changeAccountPassword Error: Bad Argument @ 1",root) end else outputChatBox("changeAccountPassword has got the account!",root) end end 7. Now we will get the account password was entered in second argument! and we will update outputChatBox. NOTE: It must be a number. function changeAccountPassword(account,password) local account = getPlayerAccount(account) if account then if (isGuestAccount(account)) then return outputChatBox("changeAccountPassword Error: Bad Argument @ 1",root) end else local password = tonumber(password) outputChatBox("changeAccountPassword has got the account! Now checking for password",root) end end 8. We will check if he typed the second argument if not then return and say outputChatBox and add one more end. function changeAccountPassword(account,password) local account = getPlayerAccount(account) if account then if (isGuestAccount(account)) then return outputChatBox("changeAccountPassword Error: Bad Argument @ 1",root) end else local password = tonumber(password) outputChatBox("changeAccountPassword has got the account! Now checking for password",root) if not password then return outputChatBox("changeAccountPassword Error: Bad Argument @ 2", root) end end end 9. We will add a else and outputChatBox that it was totaly correct and setted. function changeAccountPassword(account,password) local account = getPlayerAccount(account) if account then if (isGuestAccount(account)) then return outputChatBox("changeAccountPassword Error: Bad Argument @ 1",root) end else local password = tonumber(password) outputChatBox("changeAccountPassword has got the account! Now checking for password",root) if not password then return outputChatBox("changeAccountPassword Error: Bad Argument @ 2", root) end else outputChatBox("changeAccountPassword was sucessfully finished without any errors.", root) setAccountPassword(account,password) end end 10. Last thing you need to update meta. You need to add the line: <export function="changeAccountPassword" type="server"/> Remember to take it as server sided only. Use: exports.yourResourceName:changeAccountPassword(account, password) Thanks anubhav. Edited March 25, 2014 by Guest Link to comment
Saml1er Posted February 11, 2014 Share Posted February 11, 2014 (edited) I don't see any context player or thePlayer in function (). Here: function checkMoney (thePlayer) local money = getPlayerMoney(thePlayer) or 0 outputChatBox("You have $"..money, thePlayer ) end addCommandHandler("money",checkMoney) Edited February 12, 2014 by Guest Link to comment
Castillo Posted February 11, 2014 Share Posted February 11, 2014 It's "outputChatBox" not "outputChatbox". Link to comment
Saml1er Posted February 12, 2014 Share Posted February 12, 2014 It's "outputChatBox" not "outputChatbox". Yes. Link to comment
Anubhav Posted February 12, 2014 Author Share Posted February 12, 2014 Whoops . I will fix it. Link to comment
Noki Posted February 13, 2014 Share Posted February 13, 2014 That's not really a tutorial. You are lacking detail. A fundamental piece of a tutorial, is the 'why' explanation. You didn't explain why you used a local variable, and so forth. I'm taking that your tutorial is made for newer scripters. But, how can this help newer scripters if you don't say why you do things? Good luck next time. Link to comment
Lumia Posted March 23, 2014 Share Posted March 23, 2014 What's the point of this? Your money shows in the top corner anyway. Link to comment
Karuzo Posted March 23, 2014 Share Posted March 23, 2014 It won't work , since you wrote outputChatBox("You have $"money..,) instead of outputChatBox("You have $"..money) -sent from my phone. Link to comment
Anubhav Posted March 25, 2014 Author Share Posted March 25, 2014 Thanks fixed. Soon going to add 2nd tut. Link to comment
Karuzo Posted March 25, 2014 Share Posted March 25, 2014 To the second "tutorial" , you will be just spamming the whole chat since you used root as visibility element. Link to comment
Noki Posted March 25, 2014 Share Posted March 25, 2014 Loops are more efficient. for k, v in pairs (getElementsByType("player")) do outputChatBox("", v, 255, 255, 0) end Link to comment
Karuzo Posted March 25, 2014 Share Posted March 25, 2014 I didn't mean that, i said that if he uses root as the element the chat will be spammed if someone tries to change his password. and btw, why should loops be more efficient if there is a root visibility argument lal. Link to comment
Noki Posted March 25, 2014 Share Posted March 25, 2014 root can be millions of elements, which causes lag. Looping to through players is a lot less than millions of elements lol. Simple performance tweaks. Link to comment
Anubhav Posted March 25, 2014 Author Share Posted March 25, 2014 I know. Some of the new servers will only use it i think and there will be less players because of GTA V . GTA V is rushing up with people.. So maybe its not. Link to comment
Saml1er Posted March 25, 2014 Share Posted March 25, 2014 Thanks fixed. Soon going to add 2nd tut. The code is still incorrect. ------------------------------------------------ function checkMoney() local money = getPlayerMoney(thePlayer) outputChatBox("You have $"..money,player) end addCommandHandler("money",checkMoney) ------------------------------------------------- Should be function checkMoney() local money = getPlayerMoney(thePlayer) outputChatBox("You have $"..money,thePlayer) end addCommandHandler("money",checkMoney) Link to comment
Karuzo Posted March 25, 2014 Share Posted March 25, 2014 Just found this post from IIYAMA, should be that what i tried to say. Root is more efficient, since it only can be send to players. A loop will call the outputChatBox function over and over, which uses much more memory. You can test that with getTickCount(), if you don't believe me. Link to comment
JR10 Posted March 25, 2014 Share Posted March 25, 2014 thePlayer is not defined in the command handler function. Link to comment
Recommended Posts