Jump to content

MTA:SA 1.4


ixjf

Recommended Posts

Hi,

I would appreciate if somebody could answer these two questions:

  • Is there any documentation of the OOP implemented in the 1.4 release (e.g. "class" members signature)?
  • How does a script of type "shared" work? Do we simply mix both server-side and client-side functions? How does it differentiate between the client and server files then? I know you can overload functions in C++, but would it be possible in Lua?

Link to comment

shared = client, server

meaning this:

  
<script src="script.lua" type="shared"/> 
  

is practically translated as

  
<script src="script.lua" type="server"/> 
<script src="script.lua" type="client"/> 

idk about the oop.

Link to comment

OOP-wise, they're still working on it. First they want to implement OOP client-side only and then translate it to server-side. There will be useful classes that will make things easier eg. vectors and matrices for position translation. For instance freecam resource can be shrank down from ~200 lines down to ~30 lines of code, that's because of all the calculations being done with math functions; vectors and matrices makes things simple

The classes will be self explanatory, eg: Ped, Vehicle, etc. and will work the following way:

local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ); -- create a CJ ped at 0,0,3 
myPed:position( 100.0, 100.0, 4.0 ); -- set myPed position to 100, 100, 4 
  
local newPos = Vector3D( -104, 140, 15 ); 
myPed:Position( newPos ); -- set new position by vector 
  
local myVeh = Vehicle( 560, 0, 0, 4 ); -- create Sultan at 0, 0, 4 
myVeh.health = 500; -- set the vehicle's health to 500 
myPed.vehicle = myVeh; -- waprs the myPed to myVeh  (waprs CJ to Sultan); 
  
localPlayer.skin = 3; -- change local player's skin to 3 

There is plenty more to describe about the new OOP but these are just simple examples I can think of.

Link to comment
I am intrestred about the "shared" thing, could anyone explain what it does exactly?
shared = client, server

meaning this:

  
<script src="script.lua" type="shared"/> 
  

is practically translated as

  
<script src="script.lua" type="server"/> 
<script src="script.lua" type="client"/> 

idk about the oop.

OOP-wise, they're still working on it. First they want to implement OOP client-side only and then translate it to server-side. There will be useful classes that will make things easier eg. vectors and matrices for position translation. For instance freecam resource can be shrank down from ~200 lines down to ~30 lines of code, that's because of all the calculations being done with math functions; vectors and matrices makes things simple

The classes will be self explanatory, eg: Ped, Vehicle, etc. and will work the following way:

local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ); -- create a CJ ped at 0,0,3 
myPed:position( 100.0, 100.0, 4.0 ); -- set myPed position to 100, 100, 4 
  
local newPos = Vector3D( -104, 140, 15 ); 
myPed:Position( newPos ); -- set new position by vector 
  
local myVeh = Vehicle( 560, 0, 0, 4 ); -- create Sultan at 0, 0, 4 
myVeh.health = 500; -- set the vehicle's health to 500 
myPed.vehicle = myVeh; -- waprs the myPed to myVeh  (waprs CJ to Sultan); 
  
localPlayer.skin = 3; -- change local player's skin to 3 

There is plenty more to describe about the new OOP but these are just simple examples I can think of.

With object chaining:

local myPed = Ped.create( 0, 0.0, 0.0, 3.0 ):position( 100.0, 100.0, 4.0 ); 

Link to comment
function isServer() return triggerClientEvent ~= nil end 
function isClient() return triggerServerEvent ~= nil end 
function getScriptLocation() return isServer() and "Server" or "Client" end 
  
if getScriptLocation() == "Client" then 
    -- here client 
else 
    -- here server 
end 

I got it from Race resource.

Link to comment

Basically, shared files are used to define functions that can be used on both sides: client and server. For example you may have some math or table functions that work on both sides.

eg:

function table.equal( t1, t2 ) -- check if 2 tables are the same 
    for i, v in pairs( t1 ) do 
        if t2[ i ] ~= v then 
            return false; 
        end 
    end 
    return true; 
end 

This is very simple example, as you can see, this script doesn't use any MTA functions and therefore it can be used on client and server side thus "shared".

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