Plugin Development

Started by MEGAMIND, May 13, 2020, 11:41 AM

Previous topic - Next topic

MEGAMIND

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?

Xmair

/* 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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

habi

thanks Xmair for pointing it out.
@MEGAMIND, in our template it is named VCMP
So VCMP->SendClientMessage(......)

MEGAMIND

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?

Xmair

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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

MEGAMIND

how do i send to all isntead of a playerid

habi

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");
            }
        }

MEGAMIND

#7
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

Xmair

#8
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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

MEGAMIND

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

Xmair

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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

habi

#11
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


So
void myFunction( int32_t playerID )
{
//your code
}

MEGAMIND

Thanks to @Xmair & @habi Solved, locking topic..