Jump to content

List of predefined variables.


Kenix

Recommended Posts

  • Moderators
Posted (edited)
Server only

client -- the client that called the event

btw what will this be?

a userdata?

can I check with this, if the one that did send it, is still in the server?

Edited by Guest

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 1 month later...
Posted
Server only

client -- the client that called the event

btw what will this be?

a userdata?

can I check with this, if the one that did send it, is still in the server?

Just to answer the question: it will return the client that called the event. If you trigger some server-side event from client-side, the client will be the player who triggered the server-side event. This is useful for checking element data hacks and similiar. Quite a helpful thing with security.

If I helped you, please click the like button on the right ;) Thanks!

  • Moderators
Posted

@ myonlake

thank you very much :)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 6 months later...
  • 1 month later...
  • 2 weeks later...
Posted

Kenix is there any update for the varibles ? or just these ?

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

  • 2 years later...
Posted

You're missing 'arg'.

'arg' is a predefined Lua variable in functions which use '...' as an argument. Example:

crun function a(...) outputChatBox(tostring(arg.n)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

crun function a(...) outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)

  • 3 months later...
Posted
On ٢٧‏/٥‏/٢٠١٧ at 11:52, Arran said:

You're missing 'arg'.

'arg' is a predefined Lua variable in functions which use '...' as an argument. Example:

crun function a(...) outputChatBox(tostring(arg.n)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

crun function a(...) outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)

You'r wrong ..

You Should Define "arg" by yourself to get the results , and
'arg.n' its wrong , the Correct is '#arg'
the examples will be :

function a(...) local arg = { ... }; outputChatBox(tostring(#arg)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

function a(...) local arg = { ... }; outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)


 

  • Confused 1

Experienced MTA developer for 4 years. | MTA خبرة 4 سنين في برمجة

ليس عليك اسعاد الجميع ,
ولكن عليك بإن لا تؤذي أحداً 

=========
You do not have to make everyone happy,
But you should not hurt anyone

 

Want to contact with me?

 

Discord: JustCarry#2616 (Always there)
Skype: Live:JustCarry10 (Not always)

Posted
1 hour ago, iMr.WiFi..! said:

You'r wrong ..

You Should Define "arg" by yourself to get the results , and
'arg.n' its wrong , the Correct is '#arg'
the examples will be :


function a(...) local arg = { ... }; outputChatBox(tostring(#arg)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

function a(...) local arg = { ... }; outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)


 

Actually, arg is indeed predefined, and does contain a key-value pair of n which lists the number of arguments.

Quote

The three dots (...) in the parameter list indicate that the function has a variable number of arguments. When this function is called, all its arguments are collected in a single table, which the function accesses as a hidden parameter named arg. Besides those arguments, the arg table has an extra field, n, with the actual number of arguments collected.

-- https://www.lua.org/pil/5.2.html 

You can check it yourself using the following function (perhaps on HTTP runcode):

function hey(...)
  return inspect(arg)
end

--then call 
hey(553, 674, "test", "foobar")
-- This will return a formatted table containing all the arguments you've inputted, without actually defining the variable "arg", and there's also the "n" key in there.

 

Previously known as MrTasty.

  • qaisjp unpinned this topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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