Jump to content

[TUT] Anubhav's Tutorials


Anubhav

Recommended Posts

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 by Guest
Link to comment

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 by Guest
Link to comment

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
  • 1 month later...
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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...