Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - umar4911

#1
Command Manager


I had this command manager scripted long ago which I used in my old squirrel-based projects. Complete credits go to SLC as this command manager is a replica of the SqMod command manager and has a function of getting argument type made by him.




Installation

function onScriptLoad()
{
    CPlayer.rawnewmember("Authority", 1);
    dofile("CMD_Manager.nut", true);
}


function onPlayerCommand(player, cmd, arguments)
{
    local str = cmd + (arguments == null ? "" : " " + arguments);
    if(cmd != "") CMD_Manager.Run(player, player.Authority, str);
}



The code for CMD_Manager.nut can be found on the Github Repository.




Usage


Creating command

The syntax to create a command is:
CMD_Manager.Create(command, args_type, args_array, min_args, max_args, auth, protected, assoc)
Understanding the parameters

First argument is the command name.

Second are the command masks for each argument. At the moment it supports the following specifiers:

i The argument accepts integer.
f The argument accepts floating point number.
b The argument accepts boolean.
s The argument accepts string.
g This argument is a greedy argument. Anything after this argument is captured as a string and no further parsing is done.

And you can combine them if one argument accepts multiple types of values.

Let's say that your command expects integer or float for the first argument, boolean for the second, uppercase string for the third and integer, float or boolean for the fourth. Then your mask should be like:

"if|b|u|ifb"
That way the command system knows how to parse the parameters and what values to expect.

Third argument is an array of argument names.  For example, let's say I'm creating a register command with 3 arguments. I'll probably specify ["name", "password", "email"].

The fourth and fifth argument is the minimum and maximum arguments that the command needs. When calling the command you only need the minimum and the rest is optional. You can have up to 16 arguments. I believe that's a fair number.

The sixth argument defines the authority/level of the command. It is validated with the newly added player.Authority. So yea, you got yourself an easy admin system in it, just change the player's authority.
player.Authority = 5If the player's authority is equal to more than the command authority, then it is triggered.

The seventh argument defines whether you want to protect the command or validate it to the player's authority. When set to true, it checks whether the player's authority is equal to or more than the command's authority. When set to false, it skips this validation step.

The last argument is Assosicate. It defines whether to get command's  'args' in form of table or array. When set to true, values are received in table form or else in array form.


Once done, you need to bind an environment and a function with 2 parameters (player and arguments) to the command by for example,
CMD_Manager.Create().BindExec(this, function (player, args) {

});



Lets create a command sethealth
CMD_Manager.Create("sethealth", "s|i", ["Target", "HP"], 0, 2, 1, true, false).BindExec(this, function(player, args) {
    if(args.len() >= 2)
    {
        local plr = FindPlayer(args[2]);
        if(plr)
        {
            if(args[1] <= 255 && args[1] >= 0)
            {
                Message(format("%s changed the health of %s to %d", player.Name, plr.Name, args[1]));
                plr.Health = args[1];
            }
            else MessagePlayer("Health must be between 0 to 255.", player);
        }
        else MessagePlayer("Unknown player", player);
    }
    else MessagePlayer("Wrong syntax, use /sethealth <player> <hp>", player)
})
This command is set to work if the arguments passed by the player are in between 0 to 2, having authority 1. Since the Associate is defined as zero, the arguments are in form of an array. Now the same command but which Associate set to true:
CMD_Manager.Create("sethealth", "s|i", ["Target", "HP"], 0, 2, 1, true, true).BindExec(this, function(player, args) {
    if(args.rawin("Target") && args.rawin("HP"))
    {
        local plr = FindPlayer(args.Target);
        if(plr)
        {
            if(args[1] <= 255 && args[1] >= 0)
            {
                Message(format("%s changed the health of %s to %d", player.Name, plr.Name, args.HP));
                plr.Health = args.HP;
            }
            else MessagePlayer("Health must be between 0 to 255.", player);
        }
        else MessagePlayer("Unknown player", player);
    }
    else MessagePlayer("Wrong syntax, use /sethealth <player> <hp>", player)
})
The arguments are now in table form.



Error Handling:

In order to trigger errors for the commands, you need to define a BindFail function.

There are total 5 types of Errors defined in an Enum:
enum CMDErrorTypes {
    UnknownCommand,
    InsufficientAuth,
    UnsupportedArg,
    IncompleteArgs,
    SyntaxError
}

An example of BindFail function:
CMD_Manager.BindFail(this, function (type, player, cmd, msg) {

switch(type)
{
case CMDErrorTypes.UnknownCommand:
MessagePlayer("[#ffffff]Error - Command doesn't exist.", player);
break;
case CMDErrorTypes.InsufficientAuth:
MessagePlayer("[#FF3300]Error - Unauthorized Access.", player);
break;
case CMDErrorTypes.UnsupportedArg:
MessagePlayer(format("[#DDFF33]Error - Wrong type of parameter passed to command %s.", cmd), player);
break;
case CMDErrorTypes.IncompleteArgs:
MessagePlayer(format("[#FFDD33]Error - Incomplete arguments for command %s.", cmd), player);
break;
case CMDErrorTypes.SyntaxError:
MessagePlayer(format("[#ff0000]Error - [#ffffff]Command %s throwed an error: %s", cmd, msg), player);
break;
default:
print("Bind Fail called");
break;
}
})





All credits go to SLC for this post too as I stole some content of his :P





Some cool things that you can do for example:
[spoiler]
CMD_Manager.Create("cmds", "", [""], 0, 0, 1, true, true).BindExec(this, function (player, args) {
    local msg = "";
    foreach(listener in CMD_Manager.GetArray())
    {
        {
            if(msg != "") msg += ", ";
            msg += listener.Name;
        }
    }
    MessagePlayer(format("Available commands: %s", msg), player);
});

An example of having commands with the same function but different name (like wep, we)


{
    local exec = function (player, args) {
       if(args.rawin("code"))
    {
        try
        {
            local cscr = compilestring(args.code);
            cscr();
        }
        catch (e) MessagePlayer(format("Exection Error %s", e), player);
    }
    else MessagePlayer("/e ( Code )", player);
    }
    CMD_Manager.Create("e", "g", ["code"], 0, 1, 1, true, true).BindExec(this, exec);
    CMD_Manager.Create("exec", "g", ["code"], 0, 1, 1, true, true).BindExec(this, exec);
}
[/spoiler]
#2
VKs Winter Wars is originally the VKs Christmas Jolly Event but this time, the event has been shifted to another server.

New features:
- Event server is scripted in SqMod so you can get a smoother version of the event
- Reduced custom content thus less lag
- Better GUI for the event
- No 50-cap limit

For more info, refer to the forum thread or join our Discord server!


Trailer:

https://www.youtube.com/watch?v=mwR8Mjz2JCc
#3
Quote from: HunTinG on Jan 18, 2021, 10:19 PMthere's word around this summer devs may come back and deal with all issues, but that depends only if they have time...
this word is around for years.
#4
Quote from: ysc3839 on Jan 17, 2021, 05:48 PMI can tell you the 3D arrow was implemented in 0.4.7.
and 0.4.7 never came out
#5


EAD staff are back again presenting to you Season Three of EAD League 2021!
The event that everyone was waiting for to go out there and rock the battlefields with their clan mates!


If you haven't heard about it before, Let's see how it works:
  • Gather your squad and make a team application here.
  • There's a certain amount of rounds to be decided as soon as the teams are decided, in which each team plays one match/round and they don't have to play their matches in order.
  • Each team picks 2 bases from the base list. These bases will stay with them till the league ends.
  • No teams can pick similar bases.
  • The matches are usually 5 v 5, except if both teams agree to play with less than 5, that's okay too.
  • Four bases for each match, with a total of 8 rounds.
  • Team applications has specific requirements this year, Please check it out here before applying.
  • We're very strict about rules, so make sure you check them in the Rules & Regulations.

If you'd like to be part of the staff, Apply as a referee here.!
It's as simple as that. Further information can be found here.
Click here to join EAD League discord
If you have any questions, feel free to ask here and the staff will answer you shortly.

Have a nice one folks, We will be waiting for you.
#6
if you change your skin using player.Skin = skin; your weapon resets. In order to avoid that, add this in your script:

function CPlayer::SetSkin(skin) {
    local slot = this.Slot;
    this.Skin = skin;
    this.Slot = slot;
}

Now use:
player.SetSkin(skinid)


onPlayerSkinChange
If you want this event, use:

function CPlayer::SetSkin(skin) {
    local slot = this.Slot, oldskin = this.Skin;
    this.Skin = skin;
    this.Slot = slot;
  onPlayerSkinChange(this, oldskin, skin)
}

Event:
function onPlayerSkinChange(player, OldSkin, NewSkin) {
}
#7
Quote from: Inferno on Dec 16, 2020, 06:35 PM
Quote from: Mr.Dip 2020 on Dec 16, 2020, 04:41 PMdoes this mean we can host our server in the master list?

You just bumped a 5 years old post to ask that?
._.

Host Time is the uptime to check the time since when the server is up / hosted.

To show your server in masterlist, you need announce plugin and port forwarded internet ( if local hosted ) or VPS
O B V I O U S L Y
#8
Support / Re: can't connect to any server
Nov 19, 2020, 09:35 AM
Updater URL: http://u04.thijn.ovh

Masterlist URL: http://master.vc-mp.org
#10
Servers / Re: [0.4] Arbiter's Official Server
Aug 27, 2020, 05:18 AM
Quote from: Darkninja on Aug 27, 2020, 04:48 AM
Quote from: DarkRaZoR^ on Aug 25, 2020, 09:21 PMI heard rumors that this server leaks account passwords from their echo.
Do you have any proof? You can't blame anyone without any proof.We even don't have echo and tell me how we can check password from Echo?
Get some proof and then talk here.
he said he heard "rumors".
#11
Quote from: SHy^ on Aug 20, 2020, 06:10 PMThat's my boi, stated my name at top! Great work :D
P.S: The first link to link server IP is not working ::)
I mentioned:
Replace ip and port with the server's Ip and port like of EAD, the server's IP and port is: 51.255.102.249:8192. Use:
https://vcmp-info.herokuapp.com/51.255.102.249/8192
#12
VCMP Server Monitor

Even though it is easy to write the packets but I found this very cool npm library which shortens your work. It returns the all the server information so complete credits to the contributors of the library.


GameDig - Game Server Query Library

All the information about this library is present in it's GitHub Repository.

Link: https://github.com/gamedig/node-gamedig

Note: This library is not specifically for vcmp.


Example

I created a sample script using which you can get the information of a server in JSON. I deployed it on Heroku.

Replace ip and port with the server's Ip and port
https://vcmp-info.herokuapp.com/ip/port


Click here to get server information of LW


Click here to get server information of VKs


The source code is present in my Github Repository.

Example of the JSON code:
{
  "msg": "success",
  "state": {
    "name": "VKs official server [VRocker hosting]",
    "map": "",
    "password": false,
    "raw": {
      "version": "04rel006",
      "numplayers": 12,
      "gamemode": "United CA Mode v5.4.1",
      "map": "Vice City"
    },
    "maxplayers": 50,
    "players": [
      {
        "name": "=KF=SHy^LT"
      },
      {
        "name": "[RT]Martyrdom"
      },
      {
        "name": "[RT]ShadowJacK."
      },
      {
        "name": "[F2]MK14"
      },
      {
        "name": "=SdS=SupeR^DaviD*"
      },
      {
        "name": "[WSt]Jhanders"
      },
      {
        "name": "KeNgAhMeD2008"
      },
      {
        "name": "[KFt]Sos^"
      },
      {
        "name": "Jocoka"
      },
      {
        "name": "HUSSIENPRO"
      },
      {
        "name": "Jezza^++"
      },
      {
        "name": "Todor03"
      }
    ],
    "bots": [],
    "connect": "51.38.93.130:8194",
    "ping": 12
  }
}


#13
Quote from: Razor. on Aug 03, 2020, 10:52 PM Vice City Multiplayer Server
 -------------------------------
 v0.4, (c) 2007-2014 VC:MP Team

Warning: parameters for 'password' in config were not as expected

Loaded plugin: announce04rel32

Loaded plugin: sqlite04rel32

Loaded plugin: squirrel04rel32

Loaded plugin: hashing04rel32

[WEAPONS] No custom weapons to load.
** Started VC:MP 0.4 Server **
 Port: 8192
 Max players: 50


[MODULE]  Loaded SQLite3 for VC:MP by S.L.C.

[MODULE]  Loaded SqVCMP 0.4 frontend by Stormeus. (v1.0)
[╠°╔íþ╔·DM] À■╬±ã¸ı²│ú╝ËÈÏ & ã¶Â»═Û▒¤...
[╠°╔íþ╔·DM] Battle Over And Restart, Good job!
[╠°╔íþ╔·DM] NEW Battle Restart: Vehicles=[235], Weapons=[1287], Weather=[Sunny], WTime=[06:22].
Player 'EKNorw' ID 0 connected.
[╠°╔íþ╔·DM] ═µ╝Êú║EKNorw ı²│ú¢°╚Ù┴╦À■╬±ã¸ [0.0.0.0] [03/07/2020 - 19:47:21] [Reserved].
Player 'EKNorw' ID 0 disconnected (kicked).
[╠°╔íþ╔·DM] ═µ╝Êú║EKNorw ı²│ú└Ù┐¬┴╦À■╬±ã¸ [03/07/2020 - 19:47:21].
Kicking connecting player at ID 0, unknown error.
Player 'EKNor' ID 0 connected.

AN ERROR HAS OCCURED [parameter 1 has an invalid type 'null' ; expected: 'userdata']

CALLSTACK
*FUNCTION [AccInfo()] scripts/Main.nut line [544]
*FUNCTION [onPlayerJoin()] scripts/Events.nut line [98]

LOCALS
[e] "parameter 1 has an invalid type 'null' ; expected: 'userdata'"
[q] NULL
[player] INSTANCE
[this] TABLE
[player] INSTANCE
[this] TABLE

AN ERROR HAS OCCURED [parameter 1 has an invalid type 'null' ; expected: 'userdata']

CALLSTACK
*FUNCTION [onPlayerRequestClass()] scripts/Events.nut line [35]

LOCALS
[q] NULL
[AccountCount] 0
[UIDGroup] (UID hidden)
[pName] "eknor"
[skin] 0
[team] 0
[classID] 0
[player] INSTANCE
[this] TABLE

How i can resolve this? I just copied and pasted.
Btw, good work with the script. :)
probably some DB failure. Make sure the dbs are created.
#14
Support / Re: Occasional server crash
Jul 23, 2020, 05:54 AM
Might be some queries or a function on the player's exit which are taking time causing the original player instance not being removed from the server. Just guessing,
#15
I believe it's 1.0