[C++] When I press a key

pai1ne13

Active member
Joined
Jan 2, 2019
Messages
59
Reaction score
4
Hello, i have a problem.I got started with this plugin, I've worked in c ++ before.I want when i press the "HOME" key , this .asi need to type in chat "hello". how can i fix it?
C++:
#include "plugin.h"
using namespace plugin;
class sampproject {
public:
    sampproject() {
        if (KeyPressed(VK_HOME))
        {
            
            Message("/vw 33");
          
    }
    }
}_sampproject;
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
if you use plugin-sdk then you need to add this code to a separate event, the list of events is events.h, examples are in the folder
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
the SDK plugin does not support SAMP, in order to send a message to the chat you will have to write the code manually, as here:


#define SAMP_CHAT_INFO_OFFSET 0x21A0E4
#define SAMP_FUNC_DEBUGLOG 0x64520


typedef int (__cdecl *__DebugLog)(void *g_Chat, char *log, ...);
__DebugLog DebugLog = (__DebugLog)(SAMP + SAMP_FUNC_DEBUGLOG);

//example usage :
DWORD SAMP = (DWORD)GetModuleHandle("samp.dll");
void* g_Chat = (void*)*(DWORD*)(SAMP + SAMP_CHAT_INFO_OFFSET);
DebugLog(g_Chat, "This is a test %d %d %d Hello ugbase!", 1, 2, 3);
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
Ok thx, what plugin is the best for samp?
plugin-sdk is a very convenient sdk, thanks to its events, if you want to work with samp - complete this sdk to work with samp and it will be the best sdk in the world
 
D

Deleted member 46270

Guest
I didn't understand a shit but i thought maybe that can help u...
Code:
void KomutYaz(const char *szMessage, ...)
{
    va_list ap;
    char BotYazi[50];

    char string[256];

    va_start(ap, szMessage);
    vsnprintf(string, sizeof(string), szMessage, ap);
    va_end(ap);
    if (string[0] == '/') // Eğer string'in içinde / varsa --- eng: if string is have /
    {
        // this will work just fine
        // only one thing you have to change is data type of "len" variable
        // BYTE = 1 byte
        // but RPC_ServerCommand takes len in 4 byte format (int)
        // that's why you have to change BYTE len to int len
        /* - DarkNeX */
        int len = strlen(string);

        RakNet::BitStream Params;

        Params.Write(len); // see? now it takes int variable
        Params.Write(string, len);

        g_RakClient->RPC(RPC_ServerCommand, &Params, HIGH_PRIORITY, RELIABLE_ORDERED, 0, false);
    }
}
 

SIGKILL

Active member
Joined
Apr 29, 2020
Messages
37
Reaction score
22
Location
Earth
You're calling if (KeyPressed(VK_HOME)) inside the constructor of a class, which will only run once. So you need to do like StickyAdv said and put that KeyPressed check inside a function that loops.
 
Top