Vice City: Multiplayer

Off-Topic => Off-Topic General => Topic started by: MEGAMIND on May 13, 2020, 11:41 AM

Title: Plugin Development
Post by: MEGAMIND on May 13, 2020, 11:41 AM
Hello, im creating a plugin just learned few stuff from @habi  hello world plugin so i had a question how would we print helloworld inside game?
Title: Re: Plugin Development
Post by: Xmair on May 13, 2020, 11:47 AM
/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
extern PluginFuncs* api;

Source:
PluginFuncs* api;

extern "C" unsigned int VcmpPluginInit(PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo) {
api = pluginFuncs;
return 1;
}

// and to use it:
api -> SendClientMessage(playerID, 0xFFFFFFFF, "stuff");

Refer to the VCMP API for the function calls.
Title: Re: Plugin Development
Post by: habi on May 13, 2020, 11:53 AM
thanks Xmair for pointing it out.
@MEGAMIND, in our template it is named VCMP
So VCMP->SendClientMessage(......)
Title: Re: Plugin Development
Post by: MEGAMIND on May 13, 2020, 12:08 PM
Quote from: Xmair on May 13, 2020, 11:47 AM/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
extern PluginFuncs* api;

Source:
PluginFuncs* api;

extern "C" unsigned int VcmpPluginInit(PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo) {
api = pluginFuncs;
return 1;
}

// and to use it:
api -> SendClientMessage(playerID, 0xFFFFFFFF, "stuff");

Refer to the VCMP API for the function calls.
hey um im getting playerid is undefined.. are there any other headerfiles?
Title: Re: Plugin Development
Post by: Xmair on May 13, 2020, 12:12 PM
Quote from: MEGAMIND on May 13, 2020, 12:08 PM
Quote from: Xmair on May 13, 2020, 11:47 AM/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
extern PluginFuncs* api;

Source:
PluginFuncs* api;

extern "C" unsigned int VcmpPluginInit(PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo) {
api = pluginFuncs;
return 1;
}

// and to use it:
api -> SendClientMessage(playerID, 0xFFFFFFFF, "stuff");

Refer to the VCMP API for the function calls.
hey um im getting playerid is undefined.. are there any other headerfiles?
You need to replace playerID with the player's ID.
Title: Re: Plugin Development
Post by: MEGAMIND on May 13, 2020, 12:51 PM
how do i send to all isntead of a playerid
Title: Re: Plugin Development
Post by: habi on May 13, 2020, 01:04 PM
i just made one, it is working
char buf[10];
        for ( int i = 0; i <  VCMP->GetMaxPlayers(); i++ )
        {
            int b = VCMP->GetPlayerName(i, buf, 10);
            if (b == 0)
            {
                VCMP->SendClientMessage(i, 0xFFFFFFFF, "hello");
            }
        }
Title: Re: Plugin Development
Post by: MEGAMIND on May 13, 2020, 01:19 PM
Quote from: habi on May 13, 2020, 01:04 PMi just made one, it is working
char buf[10];
        for ( int i = 0; i <  VCMP->GetMaxPlayers(); i++ )
        {
            int b = VCMP->GetPlayerName(i, buf, 10);
            if (b == 0)
            {
                VCMP->SendClientMessage(i, 0xFFFFFFFF, "hello");
            }
        }
ok plugins loads successfully but no ingame message
Title: Re: Plugin Development
Post by: Xmair on May 13, 2020, 02:28 PM
I'm not sure about this but in Java, we pass null instead of the ID to message it to everyone. It might or might not work in C++, give it a try.

Quote from: habi on May 13, 2020, 01:04 PMi just made one, it is working
char buf[10];
        for ( int i = 0; i <  VCMP->GetMaxPlayers(); i++ )
        {
            int b = VCMP->GetPlayerName(i, buf, 10);
            if (b == 0)
            {
                VCMP->SendClientMessage(i, 0xFFFFFFFF, "hello");
            }
        }
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}

Quote from: MEGAMIND on May 13, 2020, 01:19 PMok plugins loads successfully but no ingame message
Are you using that code upon the plugin being loaded? If yes then it won't show any message because no players are connected to the server when the plugins are being loaded initially.
Title: Re: Plugin Development
Post by: MEGAMIND on May 13, 2020, 03:27 PM
Quote from: Xmair on May 13, 2020, 02:28 PMI'm not sure about this but in Java, we pass null instead of the ID to message it to everyone. It might or might not work in C++, give it a try.

Quote from: habi on May 13, 2020, 01:04 PMi just made one, it is working
char buf[10];
        for ( int i = 0; i <  VCMP->GetMaxPlayers(); i++ )
        {
            int b = VCMP->GetPlayerName(i, buf, 10);
            if (b == 0)
            {
                VCMP->SendClientMessage(i, 0xFFFFFFFF, "hello");
            }
        }
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}

Quote from: MEGAMIND on May 13, 2020, 01:19 PMok plugins loads successfully but no ingame message
Are you using that code upon the plugin being loaded? If yes then it won't show any message because no players are connected to the server when the plugins are being loaded initially.
so how do i just send a message to a user uppon his join
Title: Re: Plugin Development
Post by: Xmair on May 13, 2020, 03:31 PM
Quote from: MEGAMIND on May 13, 2020, 03:27 PM
Quote from: Xmair on May 13, 2020, 02:28 PMI'm not sure about this but in Java, we pass null instead of the ID to message it to everyone. It might or might not work in C++, give it a try.

Quote from: habi on May 13, 2020, 01:04 PMi just made one, it is working
char buf[10];
        for ( int i = 0; i <  VCMP->GetMaxPlayers(); i++ )
        {
            int b = VCMP->GetPlayerName(i, buf, 10);
            if (b == 0)
            {
                VCMP->SendClientMessage(i, 0xFFFFFFFF, "hello");
            }
        }
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}

Quote from: MEGAMIND on May 13, 2020, 01:19 PMok plugins loads successfully but no ingame message
Are you using that code upon the plugin being loaded? If yes then it won't show any message because no players are connected to the server when the plugins are being loaded initially.
so how do i just send a message to a user uppon his join
void playerCreated(int32_t playerId) {
VCMP -> SendClientMessage(playerId, 0xFFFFFFFF, "hello");
}

unsigned int VcmpPluginInit(PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo) {
pluginCalls -> OnPlayerConnect = playerCreated;
}
You should wrap up player and other entities into classes for better accessibility.
Title: Re: Plugin Development
Post by: habi on May 13, 2020, 03:41 PM
In SQMain.cpp, find VcmpPluginInit function.

You can see a line
pluginCalls->OnServerInitialise = OnServerInitialise

This is attaching the function on Right hand side to server. Right hand side can be renamed as anything you like. But there must be a function with that name.

Also to make the function,  you can see it's details by moving mouse to pluginCalls->onPlayerConnect
(https://i.imgur.com/of1OTEr.png)

So
void myFunction( int32_t playerID )
{
//your code
}
Title: Re: Plugin Development
Post by: MEGAMIND on May 13, 2020, 03:47 PM
Thanks to @Xmair & @habi Solved, locking topic..