sending command via client side

Started by MEGAMIND, Oct 30, 2024, 12:07 PM

Previous topic - Next topic

MEGAMIND

Sup everyone actually i am trying to achive send command from client side scripting

what ive tried so far

server side
m <- BindKey(true,0x4D,0,0); //gamemodes

function onClientScriptData(player) {
     local type = Stream.ReadInt();
if (type == 302) {
        Stream.StartWrite();
        Stream.WriteInt(302);
        Stream.SendStream(player);
    }
if (type == 303) {
     Stream.ReadInt(303);
    MessagePlayer("u r in drift", player);
    onPlayerCommand(player , "drift", "");
  }
}

functions
function onKeyDown(player,key)
{
if( key == m )
{
if(player.World == 1)
      {
       Stream.StartWrite();
        Stream.WriteInt(302);
        Stream.SendStream(player);
}
}
}

client side
function Server::ServerData(stream) {
    local StreamReadInt = stream.ReadInt();
    local StreamReadString = stream.ReadString();

    switch (StreamReadInt.tointeger()) {
             case 302:
            GUI.SetMouseEnabled(true);
            ::spritedrift <- GUIButton(VectorScreen(400,380), VectorScreen(200, 22), Colour(75,75,75), "drift", GUI_FLAG_BORDER | GUI_FLAG_VISIBLE);
            //::spritedrift <- GUISprite("drift.png", VectorScreen(1000, 600));
            //::spritedrift.Size = VectorScreen(50, 50);
            break;
           
           
    }
}



function GUI::ElementClick(element, mousex, mousey)
{
  GUI_ServerLogs.ElementClick( element );
  if (element == spritedrift) {
   Console.Print("Hello. welcome to VCMP")
    local message = Stream();
    message.WriteInt(303);
    Server.SendData(message);
    GUI.SetMouseEnabled(false);
    ::spritedrift <- null;

  }
}
aim is to click a sprite that executes drift command

@habi2 @vito

habi2

Hi @MEGAMIND, i did not quite understand what you are trying to achieve.
Quotem <- BindKey(true,0x4D,0,0); //gamemodes

function onClientScriptData(player) {
     local type = Stream.ReadInt();
if (type == 302) {
        Stream.StartWrite();
        Stream.WriteInt(302);
        Stream.SendStream(player);
    }
if (type == 303) {
     Stream.ReadInt(303);
    MessagePlayer("u r in drift", player);
    onPlayerCommand(player , "drift", "");
  }
}
Here you are binding key M (virtual key code 0x4d=77, https://asawicki.info/nosense/doc/devices/keyboard/key_codes.html ).
Then you are checking the integer passed from client equals 302 or 303. If it is 303, /drift is processed and message is send to player You are in drift.
So I think the client press M and drift starts. Is that it?

MEGAMIND

#2
Quote from: habi2 on Oct 30, 2024, 04:41 PMHi @MEGAMIND, i did not quite understand what you are trying to achieve.
Quotem <- BindKey(true,0x4D,0,0); //gamemodes

function onClientScriptData(player) {
     local type = Stream.ReadInt();
if (type == 302) {
        Stream.StartWrite();
        Stream.WriteInt(302);
        Stream.SendStream(player);
    }
if (type == 303) {
     Stream.ReadInt(303);
    MessagePlayer("u r in drift", player);
    onPlayerCommand(player , "drift", "");
  }
}
Here you are binding key M (virtual key code 0x4d=77, https://asawicki.info/nosense/doc/devices/keyboard/key_codes.html ).
Then you are checking the integer passed from client equals 302 or 303. If it is 303, /drift is processed and message is send to player You are in drift.
So I think the client press M and drift starts. Is that it?
actually what i a mdoing is pressing m then a sprite apears with which on sprite click i can execcute a command such as drift, yes that is what it is as u said, but its still not executing the cmd, the client presses m a sprite apears the client presses the sprite adn then the sprite is disappeared and the client goes to drift

MEGAMIND