Jump to content

Calling Server/Client Functions in OOP


adamix

Recommended Posts

Objective: To realize the object on the server with which you can call functions of the client.

Example:

client = Client.new (clientElem);
client.setGarageOpen (1, true);

and the object on the client, with which you can call the server functions.

Example:

server.createPed (1, 1024, 1024, 1024);

Waiting for your ideas and examples. Sorry for my english.

Link to comment

It's an intentional part of mta's design that the client can't do too much that will affect other players. Directly exposing server side functions to clients opens things up for cheaters even more. Remember it's not practical really to have server functions being called from the client and returning values due to the latency.

Link to comment
I'm not sure that making client and server objects is the most useful way an OO interface for MTA could be made.

If you wanted to make that kind of interface, I believe it'd be fairly easy with metatables.

It would be easy with metatables but there are main 2 situations where you don't want to use OOP.

1. Calling timers fails, if calling a method from an instance of a class.

local a = Class:new();
setTimer( a:method, 100, 1 ); -- this doesn't work
setTimer( Class.method, 100, 1, a ); -- AFAIR, this fails too

2. You can't really export classes from resource and that makes no use of OOP in Lua for MTA. MTA has new calling exported functions system (accessing exported functions from "exports" table).

exports.myresource:Class:new(); -- Class is a table(class) not exported function and that's why it fails

It would be nice. Even though, I use OOP as often as I can since this is good to get used to.

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