Jump to content

[TUT] Creating a simple script.


zzx

Recommended Posts

Posted

Yo guys, In this tutorial i'm gonna teach you guys how to create a simple script for beginners, so let's start.

1) You have to open a file in C:\Program Files\MTA San Andreas 1.3\server\mods\deathmatch\resources, and then create in it a meta.xml and then create server.lua (optional) where we will build our script.

2) Open meta.xml and copy these lines:

     "YourName" type="gamemode" name="My Server" description="My first MTA server" version="1.0.0" /> 
     

and paste them in the meta file you have created. (these lines will define your script).

3) Open the server.lua (Lua) file.

4)

function playerCount ( ) 

Add this line to the 1st line in Lua file, by the way, this function gives you the players count in the server.

5)

function playerCount ( ) 
    outputChatBox("#ff8800[server]: #ffffffPlayers: #ffffff(" .. getPlayerCount() .. "#ffffff)" , root, 255, 0, 0, true) 

These lines show you players count in the server's chat with a colored words.

for example: [server]: Players: (12).

6)

addEventHandler ( "onPlayerJoin", getRootElement(), playerCount ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount ) 

When a player joins the server he will be counted in the server counter and the counter gives you the entire players number.

and the same happen when the player leaves the server.

Example: [server]: Players: (12 [When he joins]).

[server]: Players: (11 [When he leaves]).

7) Here is the entire code:

function playerCount ( ) 
    outputChatBox("#ff8800[server]: #ffffffPlayers: #ffffff(" .. getPlayerCount() .. "#ffffff)" , root, 255, 0, 0, true) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), playerCount ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount ) 

If you want any help, you can send me a PM.

Peace, Zeldak.

Posted

2) Open meta.xml and copy these lines:

     "YourName" type="gamemode" name="My Server" description="My first MTA server" version="1.0.0" /> 
     

type="gamemode"

._.

Read more:

Meta.xml

Posted

I appreciate the fact that you've tried and posted this tutorial, but, the wiki teaches you the exact same thing. This section needs tutorials that doesn't already exist. But of course, this is only my opinion.

Posted

You have the chatbox item outputting to root (all element's everywhere). You should replace it with 'source', so the responsible element (the player that joined) will see it. Chat box spam never look nice. :)

Posted
You have the chatbox item outputting to root (all element's everywhere). You should replace it with 'source', so the responsible element (the player that joined) will see it. Chat box spam never look nice. :)

well he used onPlayerQuit that means he wanted it to show it to everyone, didn't he?

  • 1 year later...
Posted

eh, that'll just output [server] isn't it? and it's server sided so ehm, #getElementsByType('player') (Client-Sided) will also work

  • Recently Browsing   0 members

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