Jump to content

[TUT] Creating a simple script.


zzx

Recommended Posts

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.

Link to comment

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.

Link to comment
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?

Link to comment
  • 1 year later...
  • Recently Browsing   0 members

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