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.

Messages - habi
Tutorials / How to detect client side script error. ?
« on November 24th, 12:58 PM »
Just for the record, this is posted. In case someone in future needs this.

I had a client side script main.nut which was not working. Client side scripts not show errors in game.

If there is an error, download this program     sq.exe


Note: You need to copy this sq.exe to your main.nut folder
i don't know how it is calculated, but found a way to make the player shoot npc.
The server sends data to clients aimpos and a three co-ordinates which are "a normalized direction vector " multiplied by 16.0
( Thanks to the reVC codes )
If a RayTrace is created with aimpos as start and range * this vector, then the RayTrace hits npc's head, as my experiments show.
Bugs and Crashes / [Bug] Streams can be send without any target player
« on November 23rd, 07:22 AM »
The Stream class is not throwing error when its function SendStream is called with a null player.


What you were doing when the bug happened
I had a piece of code to send data streams to player and obtain report from them. I restarted server and when the function was called from Server console with FindPlayer function as one of the arguments, nothing happened. Then i understood that no player was connected. So this class is not throwing error.

What you think caused the bug
Stream class not checking inside, if player is not null
Bugs and Crashes / [Bug] Client side PlayerShoot function wrong values
« on November 18th, 08:24 AM »
In first person shoot with Ruger, the hitPosition given by the function mentioned in subject, is found to be inaccurate.


What you were doing when the bug happened
I was shooting player at head to get the co-ordinates of the body part. In third-person aiming, the values are satisfying with player's co-ordinates.
It is suspected that the hitPosition calculated by the client is as if the bullet is passed through the player and the bullet is hit on the wall behind and it is giving position of the wall.

What you think caused the bug
bug caused the bug.

Community Plugins / Re: NPC implementation in VCMP 0.4 Servers
« on November 14th, 11:08 PM »
Working with npcs and sniper rifles,

'habi' in the image is npc and it is shooting me with a weapon 29 (laser sniper)

This function in npc's script
Code: [Select]
FireSniperRifle([integer]wep(28/29), [float]aimPosX, [float]aimPosY, [float]aimPosZ, [float](alpha), [float]Angle ) where alpha is an angle in radians. 0. 0 means complete horizonal, postive means above, negative means below. can be obtained from aimdir.y. Angle - npc's facing angle if faced to target.
which fires a sniper shot from npc to any target.

Need to perfect some codes and will release here.

Version 1.3
npcclient.exe here

Changelog below
(click to show/hide)
Version 1.3 Changes (15.11.2022)
Extended Timer implemented SetTimerEx (
Fixed npc running unwantedly just after sending some packet.
Added boolean parameter for crouching in SendOnFootSyncData
Client side PlayerShoot event is not getting called with sniper rifle if the player is not local.


What you were doing when the bug happened
My client side script has a code to print something on Console if somebody shoots somebody making use of the Player::PlayerShoot function. On working with npcs, i found that the function is not getting called if weapon is sniper rifle.

Later i confirmed it by opening two game windows and making one player shoot another. It showed output only on one window where it was supposed to perform on both windows. At the same time, if the weapon is 27 (Ruger), outputs are shown in both windows.

What you think caused the bug
Client side PlayerShoot was not getting called for sniper rifles and shotguns for any players earlier. So the problem might be related to this previous issue.
General Discussion / Re: Making npcs shoot x y z
« on November 10th, 11:33 AM »
Like we use streams to pass data, 'ClientMessage' function of server side can be used.

Code: [Select]
//Let's choose a number, say 100. And suppose we want to place player to angle 0.57;
ClientMessage("SetMyFacingAngle( 0.57 );", npc, 100, 100, 100 );

And on npc script,
Code: [Select]
function OnClientMessage(r,g,b,message)
if(r==100 && g==100 && b== 100)
local script = compilestring(message );

This will make the npc change its angle!
Do anybody know how exactly aimdirection is calculated?
I have tried for two days:
Code: [Select]
function GetAimDir(aimPos, targetPos)
local x,y,z;
local angle = atan2( -(targetPos.x-aimPos.x), targetPos.y-aimPos.y ); //vcmp angle
local alpha=atan2( targetPos.z - aimPos.z, sqrt( pow( targetPos.y - aimPos.y, 2 ) + pow( targetPos.x - aimPos.x , 2 ) ) );
if(angle >0 ) //angle 0 to 3.14
//Quadrant can be North West or South West
if(angle <PI/2)
//Quadrant is North West
if( alpha > 0 )
y= -PI + alpha;
y= PI + alpha;
//Quadrant is South West
y= alpha;
//Quadrant can be North East or South East
if( angle > -PI/2 )
//Quadrant is North East
z= angle;
x= 0.0;
if( alpha > 0 )
y= -PI + alpha;
y= PI + alpha;
//Quadrant is South East
z= -PI-angle;
x= PI;
y= alpha;
return Vector(x,y,z);

But this is not exact. The bullet misses the point.

AimPos seems to be independent of player's Position. By altering packets, i found out that the player shoots a particular point if (AimPos, AimDir) are specified. Then changing position with former variables i.e. aimpos and aimdir same, still the player shoots the point.
However, if the position is too 'out of range', the player shoots somewhere else.

So the question is how is aim direction calculated, given the position to hit?

Update- Using aiming weapons like 27, using my code hits the target perfectly, the directions being calculated as above. But it hit somewhere when in normal firing (without aiming or right click). It hits near, but not exact.
Community Plugins / Re: Lua Plugin
« on November 6th, 02:35 PM »
Nice work.
General Discussion / Making npcs shoot x y z
« on November 5th, 08:02 PM »
I was standing infront of the Vercetti estate alone. Suddenly i thought, if there was an npc beside me and were it able to shoot !

So i digged into my old NPC project. Reluctant to change the carefully written codes but still quickly want to add two functions.

This is what i got

See the npc is shooting at certain x y z. The one function i made looks like this:
Code: [Select]
SendOnFootSyncData(576,-286.98, -592.451, 12.8423,2.29,100, 0, 17, 0.0, 0.0, 0.0,-284.302, -590.105, 14.4482,-3.14174, -0.222718, 0.851276);
SendOnFootSyncData(576(keys on foot fire),x, y, z, angle, 100(health), 0(armour), 17(colt), 0.0, 0.0, 0.0,-284.302, -590.105, 14.4482,-3.14174, -0.222718, 0.851276);
//The last values are aimpos and aimdir.
Code: [Select]
SendOnFootSyncData([integer] keys, [float] posX, [float] posY, [float] posZ, [float] angle, [integer] health, [integer] armour, [integer] weapon, [float]speedX, [float]speedY, [float]speedZ, [float]aimPosX, [float]aimPosY, [float]aimPosZ, [float]aimDirX, [float]aimDirY, [float]aimDirZ, isCrouching(from v1.3 only) );
Took 5 hours.

You can watch full video of npc shooting here(youtube)

You can also download the compiled program 'npcclient.exe'( See 'NPC implementation in VCMP 0.4 Servers' in Community Plugins for details ) here (version--call it 1.2 )

Changes(additions) to the source code of the project.
Code: [Select]

void SendNPCSyncData(ONFOOT_SYNC_DATA* m_pOfSyncData);
SQInteger fn_SendOnFootSyncData(HSQUIRRELVM v)
    if (!npc) {
        return 0;
    //i fff f i i i fff fff fff
    SQInteger dwKeys;
    sq_getinteger(v, 2, &dwKeys);
    SQFloat x, y, z;
    sq_getfloat(v, 3, &x);
    sq_getfloat(v, 4, &y);
    sq_getfloat(v, 5, &z);
    SQFloat fAngle;
    sq_getfloat(v, 6, &fAngle);

    SQInteger byteHealth;
    sq_getinteger(v, 7, &byteHealth);

    SQInteger byteArmour;
    sq_getinteger(v, 8, &byteArmour);

    SQInteger byteCurrentWeapon;
    sq_getinteger(v, 9, &byteCurrentWeapon);

    SQFloat vx, vy, vz;
    sq_getfloat(v, 10, &vx);
    sq_getfloat(v, 11, &vy);
    sq_getfloat(v, 12, &vz);

    //Aim Position
    SQFloat s, t, u;
    sq_getfloat(v, 13, &s);
    sq_getfloat(v, 14, &t);
    sq_getfloat(v, 15, &u);

    //Aim Direction
    SQFloat p, q, r;
    sq_getfloat(v, 16, &p);
    sq_getfloat(v, 17, &q);
    sq_getfloat(v, 18, &r);
    ONFOOT_SYNC_DATA m_pOfSyncData;
    m_pOfSyncData.byteArmour = (uint8_t)byteArmour;
    m_pOfSyncData.byteCurrentWeapon = (uint8_t)byteCurrentWeapon;
    m_pOfSyncData.byteHealth = (uint8_t)byteHealth;
    m_pOfSyncData.dwKeys = (uint32_t)dwKeys;
    m_pOfSyncData.fAngle = fAngle;
    m_pOfSyncData.IsAiming = ((dwKeys & 1)||(dwKeys &576) == 576);
    m_pOfSyncData.IsCrouching = (dwKeys & 288)==288;
    m_pOfSyncData.vecAimDir.X = p;
    m_pOfSyncData.vecAimDir.Y = q;
    m_pOfSyncData.vecAimDir.Z = r;

    m_pOfSyncData.vecAimPos.X = s;
    m_pOfSyncData.vecAimPos.Y = t;
    m_pOfSyncData.vecAimPos.Z = u;

    m_pOfSyncData.vecPos.X = x;
    m_pOfSyncData.vecPos.Y = y;
    m_pOfSyncData.vecPos.Z = z;

    m_pOfSyncData.vecSpeed.X = vx;
    m_pOfSyncData.vecSpeed.Y = vy;
    m_pOfSyncData.vecSpeed.Z = vz;
    return 0;//0 because we are returning nothing!
Code: [Select]
//In function RegisterNPCFunctions
register_global_func(v, ::fn_SendOnFootSyncData, "SendOnFootSyncData", 18, "tiffffiiifffffffff");

Code: [Select]
//minor change in main.cpp regarding version
CmdLine cmd("VCMP-Non Player Characters", ' ', "1.2",false);

Note: In the functions, using integers (eg. 0, 1, 2 ) in the places of [float] may not work. So if an angle is zero, giving it as '0' will not work.
Tutorials / [Tutorial] Re: The first VC-MP Server built as plugin
« on October 22nd, 06:12 PM »
How is everybody doing..

Added Tommy Golf Skin and Tommy Cuban Skin.

Tommy Golf Skin has Baseball bat, Python and a Snipper.

Tommy Cuban has Grenade, Shotgun and Katana. :)
Support / Re: Adding discord in server
« on June 20th, 05:07 PM »
Put :: before ClientMessageToAll.
Code: [Select]
::ClientMessageToAll( );
Support / Re: Adding discord in server
« on June 20th, 03:46 PM »
Put comma ( , ) after text
Code: [Select]
ClientMessageToAll(...+": "+text, 255, 0, 255);
General Discussion / Re: Help Regard Hosting
« on June 20th, 02:02 PM »
Hi hanya,
VC-MP needed to be port forwarded on windows VPS. I can't figure out what is the problem.
Like the first row in your second screenshot,  you could try by changing protocol to UDP, change Source from Internet to Any and Destination also Any
Save it and restart your server.  If that does not solve we have to check the Outbound Rules.  Add such a rule - from port 8192 to Any.
If this also not solve your problem, working with Load Balancing may be needed.
Support / Re: Adding discord in server
« on June 20th, 01:37 PM »
By normal player, you have meant those discord users in the server on whom no roles are assigned.

In that case using else part of the if statement
Code: [Select]
is not correct,  because normal player has no roles.

In that case member.Roles will be an empty array.

Therefore this loop will not be executed:
Code: [Select]
foreach(roleID in member.Roles) {
      local role=session.GetRoleName(serverID, roleID);
       print("[Discord]"+member.User.Username+": "+text);
So just after the loop (after the closing brace of loop) add this:
Code: [Select]
// here code for user with no roles

This code is not tested yet.

how do I send this message to the server? I mean its printing on the console only
Hint: Use Message function of squirrel
Using print statement will print to console and using Message statement will output in game.