MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750
Plugin Development
«  »
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

  • Wiki Contributor
  • Posts: 909
Re: Plugin Development
« Reply #1,  »
Code: [Select]
/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
Code: [Select]
extern PluginFuncs* api;

Source:
Code: [Select]
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.
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

habi

  • Full Member
  • Posts: 194
Re: Plugin Development
« Reply #2,  »
thanks Xmair for pointing it out.
@MEGAMIND, in our template it is named VCMP
So VCMP->SendClientMessage(......)

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750
Re: Plugin Development
« Reply #3,  »
Quote from Xmair on May 13th, 12:47 PM
Code: [Select]
/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
Code: [Select]
extern PluginFuncs* api;

Source:
Code: [Select]
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

  • Wiki Contributor
  • Posts: 909
Re: Plugin Development
« Reply #4,  »
Quote from MEGAMIND on May 13th, 01:08 PM
Quote from Xmair on May 13th, 12:47 PM
Code: [Select]
/* vcmpErrorNoSuchEntity, vcmpErrorNullArgument, vcmpErrorTooLargeInput */
vcmpError (*SendClientMessage) (int32_t playerId, uint32_t colour, const char* format, ...);

Header:
Code: [Select]
extern PluginFuncs* api;

Source:
Code: [Select]
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.
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750

habi

  • Full Member
  • Posts: 194
Re: Plugin Development
« Reply #6,  »
i just made one, it is working
Code: [Select]
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

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750
Re: Plugin Development
« Reply #7,  »Last edited
Quote from habi on May 13th, 02:04 PM
i just made one, it is working
Code: [Select]
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

  • Wiki Contributor
  • Posts: 909
Re: Plugin Development
« Reply #8,  »Last edited
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 13th, 02:04 PM
i just made one, it is working
Code: [Select]
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");
            }
        }
Code: [Select]
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}
Quote from MEGAMIND on May 13th, 02:19 PM
ok 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.
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750
Re: Plugin Development
« Reply #9,  »
Quote from Xmair on May 13th, 03: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 13th, 02:04 PM
i just made one, it is working
Code: [Select]
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");
            }
        }
Code: [Select]
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}
Quote from MEGAMIND on May 13th, 02:19 PM
ok 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

  • Wiki Contributor
  • Posts: 909
Re: Plugin Development
« Reply #10,  »
Quote from MEGAMIND on May 13th, 04:27 PM
Quote from Xmair on May 13th, 03: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 13th, 02:04 PM
i just made one, it is working
Code: [Select]
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");
            }
        }
Code: [Select]
for (int i = 0; i < VCMP -> GetMaxPlayers(); ++ i) {
   if (VCMP -> IsPlayerConnected(i))
      VCMP -> SendClientMessage(i, 0xFFFFFFFF, "hello");
}
Quote from MEGAMIND on May 13th, 02:19 PM
ok 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
Code: [Select]
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.
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

habi

  • Full Member
  • Posts: 194
Re: Plugin Development
« Reply #11,  »Last edited
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
Code: [Select]
void myFunction( int32_t playerID )
{
//your code
}

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 750