Jump to content
  • 0

Help to understand Lua


bogdyutzu

Question

Hello, I scripted a long time in Pawn for SA:MP and some days ago I deiced to migrate to MTA:SA.

I need some help to understand the Lua. I already searched tutorials but I not fully understand.

In Pawn I was using this code for an array for player:

enum _:E_MAX_PLAYER_BITS 
{ 
    bitsIsDead = 1, // insted of bool (true and false) 
    ... 
}; 
  
enum _:E_PLAYER_DATA 
{ 
    // the 0 of this array is used for bits 
    intAdminLevel = 1, 
    ... 
} 
  
new g_PlayerFlags[MAX_PLAYERS][E_PLAYER_DATA] 
  
#define BitCheck(%0,%1,%2)  !!  ( ( %0[ %2 ][ 0 ] ) &   ( 1 << %1 ) ) 
#define BitSet(%0,%1,%2,%3)     ( (_:%3) && ( ( %0[ %2 ][ 0 ] ) |=  ( 1 << %1 ) ) || ( ( %0[ %2 ] [ 0 ] ) &= ~( 1 << %1 ) ) ) 
  
public OnPlayerConnect(playerid) 
{ 
    g_PlayerFlags[playerid][intAdminLevel] = 3; 
  
    return 1; 
} 
  
public OnPlayerDeath(playerid, killerid, reason) 
{ 
    BitSet(g_PlayerFlags, bitsIsDead, playerid, true);  // if is posibile to use bit else true or false, is just an example... 
  
    return 1; 
} 
  
public OnPlayerStreamIn(playerid, forplayerid) 
{ 
    static intNumber= 1;        // Static is a constat value that remain evry time we call OnPlayerStreamIn 
    prinf("Player have %d %d", BitCheck(g_PlayerFlags, bitsIsDead, playerid),  intNumber)   // Actualy return int 0/false or 1/true 
} 
  

I need some explications about how to convert this from pawn to lua, if is posible to use bits insted of true or false, explain the client scripting and the server scripting better.

Link to comment

3 answers to this question

Recommended Posts

  • 0
I don't understand pawn, but you are trying to save some players data in array? In Lua, it's better to use setElementData, as it's synced between server and clients.

Visit wiki: https://wiki.multitheftauto.com

Btw. this should be in scripting section.

Lua does not have a function called "setElementData". It's a MTA function, do not connect MTA with Lua, while those two are completely different things.

You can save player data in tables and synchronize them between clients and servers.

Link to comment
  • 0

Client-side functions run in client's MTA:SA process, server-side functions run in the MTA:SA server.

In Lua, you use only the boolean operators "true", "false" and "nil".

Would be better if you explain what you are trying to do and we'll give you tips of how to do it. But I can tell you one thing: Anything you do in SA:MP, you do it faster and simpler in MTA:SA.

Link to comment

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...