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

#16
Quote from: NewK on Jul 21, 2020, 12:29 AMNice work umar. Nice to see more people taking advantage of buildmode to create stuff like this.

There's a 2 things about DecUI internals you should probably know about which will help you improve your editor.

1) The code you're using at the moment will work for all GUIElements but will not work for DecUI components (Grid, Datatable, Circle,  Combobox, etc...). This is because when you do "typeof e" for a DecUI component, it will return "instance" because DecUI components are classes. However, all DecUI components are wrapped in a GUICanvas with the exact same ID as the component. So you just have to check if typeof returns "instance" and if it does, you build the code as if it's a GUICanvas.

2) When printing/copying code to the clipboard, you should avoid additional lookups and use a local variable instead. Avoid doing this:

UI.Label("newLabel").Position3D  = ...
UI.Label("newLabel").Rotation3D = ...
UI.Label("newLabel").Size3D   = ...

and do this instead:
local newLabel = UI.Label("newLabel");
newLabel.Position3D  = ...
newLabel.Rotation3D =  ...
newLabel.Size3D   = ...

This will be faster and is a good optimization to keep in mind when working with DecUI in general, because every time you do UI<Type>(ID) to fetch something, a tree traversal will be made to find the ID you passed, and if you repeat UI.Label("newLabel") 3 times, you will be making 3 unecessary searches. It's better to just do the search once, save it in a variable ( local always, never global). And then just re-use the same variable. This is an optimization which seems small if you dont  have alot of GUIElements created, but once you start having alot of GUIElements this will make a big difference.
Hey mate. Thank you for pointing those things out. I updated  the respository. It now supports DecUI components and does the optimization.
#17
Quote from: habi on Jul 20, 2020, 03:00 PMHow is this 3D Texts created. Suppose one createsHow is this 3D Texts created. Suppose one creates a 3D text at downtown, so does the text is staying at downtown forever or the text comes with player when he move?
As said above, this is not made for servers releases. It is originally made for buildmode so players can easily get the position, rotation and size of the 3D Elements. In Editing mode, when Backspace key is pressed, the element stops moving and with copying to the clipboard, prints out it's values. You can just paste those lines in the code and run it in normal servers. An example is given in the wiki of how you need to load it and explained its usage in the video.


Quote from: habi on Jul 20, 2020, 03:00 PMWhat happens when we shoot the text? ( Nothing. right? )
Yep nothing


Quote from: habi on Jul 20, 2020, 03:00 PMcan you say in laymans terms what is DecUI.
There is already a well detailed topic of DecUI available.
If you ask me, I'll say it's an easy and better way to script gui with less code and more options.
#18
X3DEditor

I've seen VCMP scripters who are working with the GUI are not so familiar with the 3D elements. Since it is a part of my upcoming release, I thought to share it. This script is originally made for scripters who creates GUI in buildmode. Using this snippet, you can easily find the position, rotation and size of a 3D Element.

Note: This only supports DecUI

Understanding controls

It has total 3 types;
  • Position
  • Rotation
  • Size

Position
In order to enter the position changing mode, press 1 from keyboard.

Arrow up - Moves the element forward
Arrow down - Moves the element backward
Arrow left - Moves the element left
Arrow right - Moves the element right
Page up - Moves the element vertically upwards
Page down - Moves the element vertically downwards


Rotation
In order to enter the rotation changing mode, press 2 from keyboard.

Arrow Keys - Change the rotation respectively
Delete - Horizontally rotates to the left (backward)
Page down - Horizontally rotates to the right (forward)



Size
In order to enter the Size changing mode, press 3 from keyboard.

Arrow up - Decreases the size vertically
Arrow down - Increases the size vertically
Arrow left - Decreases the size horizontally
Arrow right - Increases the size horizontally


Saving & Exporting
In order to stop editing the element and export the data, press Backspace key.
This will return print the values and also copy them to the clipboard

Youtube Video

https://www.youtube.com/watch?v=e5k-ZElC55U


Code and example



The code and example is present on the Github Repository.



#19
Run a keyboard key checker to see if F6 is stuck or not.
#20
Quote from: EK.IceFlake on Feb 06, 2015, 05:16 AMHi, guys! After a bit of number-quenching and guesswork, I finally came up with my function that takes a random number from rand() and does some maths to make the from and to function work! It supports negative numbers, too. And also a mixture of negative and positive.
Here is the code:
function Random(from, to) return (rand()*(to+1-from)) / (RAND_MAX+1)+from;Purely tested.
Hope you like it!

local n = Random(1000, 2000)
#21
Credits:

VC:MP Icons Font
This font allows to use icons in your GUI Labels. Here is the chart:



Originally it has more than 90 glyphs, try going through character map to view them all (some of them might be repeating).

It has all properties of a normal GUILabel. You can use TextColour, align, padding, flags, or whatever you want.

Download:
https://www.mediafire.com/file/x6068hfb5l7bhs4/FAEditUmar_unp.7z/file

Installation:
Paste the 7z file in store/fonts


Usage:
- Use FontName of a Label as "FAEditUmar"

Note: The size of some of the icons might be varying.
#22
Update: Added enumerations as the start and added in the whole script
#23
Update: Added enumerations
#24
Quote from: Xmair on May 25, 2020, 11:30 AMIt's a lot better to check for the health on the client side each frame than it is to send streams each time health changes from the server. For the streams, you should consider storing the stream identifiers in enumerations. Other than that, good one.
since one of the main objective of the tutorial was to send data from server to client. That's the reason, I'm sending data each time health changes. I wasn't getting any example in my mind so what I got, I made. I was even thinking to send data onPlayerJoin :P (but didn't due to script load delay)

For streams identification, I myself prefer enum. It was just a basic tutorial that's the reason I'm didn't make it. Thanks for your opinion btw.
#25
Ping is not only dependent on your internet connection. I had at first 4mbps connection, I used to get 160 ping. Now I have 30mbps connection but still, the ping is 150-160. The ping also depends on the traceroute.

Your ISP
If your ISP is providing you a bad traceroute to the specific location, you'll be getting high ping. In bad, it can be divided into two parts
1. The traceroute is very long (it means you are very far from the host location)
2. The traceroute is poor, the responding time of the various IPs is very high (obviously done by ISP to reduce their expenses)

Solutions:
- Find a better ISP who provides better traceroute if your ISP can't change your traceroute (try contacting them)
- Travel around the world close to the Host location so the traceroute is shorter and you can get better ping
#26
There are already a lot scripts posted in the subboards:
https://forum.vc-mp.org/?board=11.0
https://forum.vc-mp.org/?board=12.0

You can also go through the alternate wiki for more help
http://wiki.thijn.ovh/

Try reading the scripts and understand how it works + you got wiki to support you
#27
Support / Re: Help me fix problem!
May 25, 2020, 08:05 AM
What is the error? Like the index NPC_ARRAY doesn't exist, etc.
#28
I wrote this guide for a friend who wanted to know how to send data from server to client and how to use DecUI. I thought why not post here too.

The function is taken from here https://forum.vc-mp.org/?topic=4484 Credits: Seby
DecUI is taken from here https://forum.vc-mp.org/?topic=6775 Credits: NewK


P.S: Sorry in advance if it's a little messed up.

Comments are added in each code for more explanation.





okay first example. We are sending kills from the server which should show to the player using a label


In order to record the identifier bytes, we can use enumerations (enum as short) like

[noae][noae][noae][noae]enum ByteInfo {
Kills = 0x02
}
[/noae][/noae][/noae][/noae]

Let's set that as soon as player spawns, it is shown.

[noae][noae][noae][noae][noae]

enum ByteInfo {
Kills = 0x02
};


function onPlayerSpawn(player)
{
// The ByteInfo.Kills will record it's identifier
SendDataToClient(player, ByteInfo.Kills, status[player.ID].kills, status[player.ID].Deaths)

// We send 3 values to the client, in the order, byte, int, int
}

// here is the special func
function SendDataToClient( player, ... )
{
if( vargv[0] )
{
local   byte = vargv[0], len = vargv.len();
Stream.StartWrite();
Stream.WriteByte( byte );
if( 1 < len )
{
for( local i = 1; i < len; i++ )
{
switch( typeof( vargv[i] ) )
{
case "integer": Stream.WriteInt( vargv[i] ); break;
case "string": Stream.WriteString( vargv[i] ); break;
case "float": Stream.WriteFloat( vargv[i] ); break;
}
}
}
if( player == null ) Stream.SendStream( null );
else if( typeof( player ) == "instance" ) Stream.SendStream( player );
else return;
}
}
[/noae][/noae][/noae][/noae][/noae]



Now we have sent data from the server. Lets get those values in client side
[noae][noae][noae][noae][noae]
enum ByteInfo {
Kills = 0x02
};


function Server::ServerData(Data)
{
// the first parameter we sent for all the data packets will be a byte so lets get it
local byte = Data.ReadByte();
// the local will store it's value

//since we used ByteInfo.Kills for the kills label
switch (byte)
{
case ByteInfo.Kills:
// the next values we sent where kills and deaths in the order and both were int vals
local kills = Data.ReadInt(),
deaths = Data.ReadInt();
// values stored

// I'll use a func to make the labels
CreateKillsGUI(kills, deaths);
break;
default: break;
}
}

function CreateKillsGUI(kills, deaths) {
// you know the drill how to create GUILabels

// In order to help you, I'll use DecUI to Create a Label
local LabelKills = UI.Label({
    id = "KillsLabel" 
    Text = "Kills: " + kills
FontSize = 16
TextColour = Colour(255, 255, 255)
// It helps you do some cool alignments
align = "hud_bottom"
FontFlags = (GUI_FFLAG_BOLD)

// I want the label to move a little more down
move = {down = "10%"}
});


local LabelDeaths = UI.Label({
    id = "LabelDeaths" 
    Text = "Deaths: " + deaths
FontSize = 16
TextColour = Colour(255, 255, 255)
align = "hud_bottom"
FontFlags = (GUI_FFLAG_BOLD)

// deaths should be a bit more down
move = {down = "13%"}
});
}
[/noae][/noae][/noae][/noae][/noae]

Since we created the labels in DecUI, we will be needing the update the labels too.

Let's make like, the player uses the same byte to send the data and the same function to update the labels. We will edit our function

[noae][noae][noae][noae][noae]function CreateKillsGUI(kills, deaths) {
    // We used ID `KillsLabel` to create Label for kills

    if(UI.Label("KillsLabel") != null)
    {
        // if the value is not null, means a label with that ID exists
        UI.Label("KillsLabel").Text = "Kills: " + kills
    }
    else
    {
        // if the condition is null, means the label doesn't exist. Lets create it
        local LabelKills = UI.Label({
            id = "KillsLabel" 
            Text = "Kills: " + kills
            FontSize = 16
            TextColour = Colour(255, 255, 255)
            // It helps you do some cool alignments
            align = "hud_bottom"
            FontFlags = (GUI_FFLAG_BOLD)

            // I want the label to move a little more down
            move = {down = "10%"}
        });
    }
    // similar for the deaths

    if(UI.Label("LabelDeaths") != null)
    {
        UI.Label("LabelDeaths").Text = "Deaths: " + deaths
    }
    else
    {
        local LabelDeaths = UI.Label({
            id = "LabelDeaths" 
            Text = "Deaths: " + deaths
            FontSize = 16
            TextColour = Colour(255, 255, 255)
            align = "hud_bottom"
            FontFlags = (GUI_FFLAG_BOLD)

            // deaths should be a bit more down
            move = {down = "13%"}
        });
    }
}
[/noae][/noae][/noae][/noae][/noae]
Okay let's do some more cool things with DecUI. Let's create a progress bar for health instead of the text


We will be using event onPlayerHeathChange. Also we need to add another identifier in the enum.
Server Side
[noae][noae][noae][noae][noae]enum ByteInfo {
Kills = 0x02
HpBar = 0x03
};

function onPlayerHeathChange(player, oldHp, newHp)
{
//since we need to send the new health only and Health is a float value, we'll convert to integer
SendDataToClient(player, ByteInfo.HpBar, newHp);
}
[/noae][/noae][/noae][/noae][/noae]


Client-Side has a function `Script::ScriptLoad()` which runs when all files are downloaded and loaded in the server. Acts like onPlayerJoin

Client Side
[noae][noae][noae][noae][noae]// lets get the func scriptload
enum ByteInfo {
Kills = 0x02
HpBar = 0x03
};

function Script::ScriptLoad() {

    // first of all, we need to remove the player's health from hud
    Hud.RemoveFlags( HUD_FLAG_HEALTH );

    SetHealthBar(); // the function used to create the health bar
}

// to change the values of the progressbar when player's health change
function Server::ServerData(Data)
{
// the first parameter we sent for all the data packets will be a byte so lets get it
local byte = Data.ReadByte();
// the local will store it's value

switch (byte)
{
case ByteInfo.Kills: // kills label
// the next values we sent where kills and deaths in the order and both were int vals
local kills = Data.ReadInt(),
deaths = Data.ReadInt();
// values stored

// I'll use a func to make the labels
CreateKillsGUI(kills, deaths);
break;

        case ByteInfo.HpBar: //GUI Health bar
            // we sent player's health which is in an int value. Lets store that in a variable
            local health = Data.ReadInt();

            // lets create using a func again
            SetHealthBar(health);
        break;
default: break;
}
}

//now the function itself
function SetHealthBar(health = 100) {

    // we will use canvas and add progress bar as its child so we can easily position the label

    // condition to check if the health was already present
    if(UI.Canvas("HealthCanvas") == null)
    {
        local hpcan = UI.Canvas({
            id = "HealthCanvas" 
            // another cool func in DecUI
            RelativeSize = ["7%", "3.5%"] // parameters are width and height, using percent means the part of the screen size of the player
           
            // we want it at the position of old health bar and hud_left doesn't exist :c
            align = "hud_right"
            move = {left = "19.5%", down = "8.5%"}               
           
            // lets add a progressbar but as a child of the canvas
            children = [
                // progressbar
                UI.ProgressBar({
                    id = "HealthBar"
                    RelativeSize = ["100%", "100%"] // it will inherit the size of the canvas since canvas is it's parent


                    // some basic things
                    MaxValue = 100
                    Thickness = 2
                    StartColour = Colour(255, 77, 77)
                    EndColour = Colour(150, 40, 40)
                    selectedColour = Colour(255, 100, 100)
                    Value = health
                })
                // now lets add a label
                UI.Label({
                    id = "HealthLabel" 
                    Text = health + "%"
                    FontSize = 12
                    TextColour = Colour(255, 255, 255)
                    align = "center" // it will align itself according to the canvas since canvas is the parent. center means to the center of the canvas
                })
            ]
        });
    }
    else
    {
        // when we receive the data from the server when player health is changed


        //if the canvas is already present, then obv children will also be. lets change their values
        UI.ProgressBar("HealthBar").Value = health;
        UI.Label("HealthLabel").Text = health + "%";   
    }
}
[/noae][/noae][/noae][/noae][/noae]
#29
Happy Birthday @habi
#30
Quote from: 3416 on May 15, 2020, 09:26 AM
Quote from: umar4911 on May 15, 2020, 08:24 AMExplain a bit more. You create a pickup using the command. If no one enters the pickup within 5 seconds, it is auto removed. Right na?
Yes!
If you are doing with only 1 pickup:
Store the pickup id in an array/table with a false value when creating the pickup. Create a Timer to check the pickup
PickupEntered <- [];
 function onPlayerCommand ( player, cmd, text )
if ( cmd == "pick" )
{
local pic = CreatePickup(368, player.World, 50, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 255, true);
PickupEntered <- [pic.ID, false];
NewTimer("checkpickup", 5000, 1);
}
On the event OnPickupPickedUp, change the value of false to true;
function onPickupPickedUp( player, pickup )
{
if(pickup.ID == PickupEntered[0])
{
PickupEntered[1] <- true;
}
}

The function checkpickup
function checkpickup()
{
 if(PickupEntered[1] == false)
{
local pickup = FindPickup(PickupEntered[0]);
if(pickup) pickup.Remove();
}
}