Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: MEGAMIND on Jun 06, 2018, 06:08 PM

Title: gui buttons fireman
Post by: MEGAMIND on Jun 06, 2018, 06:08 PM
hello everyone i am working on gui for the first time and want to know that how can i solve this problem
my code

 - > store/scripts/main.nut
::fireman_wnd <- null;
::button1 <- null;
::button2 <- null;

then i added this to
function Server::ServerData(stream)
{
local type = stream.ReadString();
local id = stream.ReadInt();

if(type == "NO_fireman")
    {
        ::fireman_wnd = null;
        ::button1 = null;
        ::button2 = null;
    }
    if(type == "fireman")
    {
        GUI.SetMouseEnabled(true);
        ::fireman_wnd = GUIWindow(VectorScreen(sX / 4, sY / 4),VectorScreen(sX / 3, sY / 4),Colour(255,255,255),"You want to fireman job?")
        ::button1 = GUIButton(VectorScreen(50,50),VectorScreen(100,50),Colour(0,255,0),"true");
        ::button2 = GUIButton(VectorScreen(250,50),VectorScreen(100,50),Colour(255,0,0),"false");
        ::fireman_wnd.AddChild(button1);
        ::fireman_wnd.AddChild(button2);
    }

then i added this to
function GUI::ElementClick(element, mousex, mousey)
{
if(element == button1)
    {
        GUI.SetMouseEnabled(false);
        local Data = Stream();
        Data.WriteString("NO_fireman");
        Server.SendData(Data);
    }
    if(element == button2)
    {
        GUI.SetMouseEnabled(false);
        local Data = Stream();
        Data.WriteString("YES_fireman");
        Server.SendData(Data);
        local Data = Stream();
        Data.WriteString("NO_fireman");
        Server.SendData(Data);
    }
basically my aim was that if i do /fireman or just createcheckpoint so a box appears questioning me that do u want a fireman job with buttons yes or no so that when i click yes the skin changes else no so not ckin changed,... im new to this so kindly give some hands plz ty :)
Title: Re: gui buttons fireman
Post by: NicusorN5 on Jun 06, 2018, 06:28 PM
You need to send a string from the client to the server.
Title: Re: gui buttons fireman
Post by: MEGAMIND on Jun 06, 2018, 06:38 PM
like this ?
function onClientScriptData(player) {
    local type = Stream.ReadString();
if(type == "YES_fireman")
{
player.Skin = 6;
}
if(type == "NO_fireman")
{
Stream.StartWrite();
Stream.WriteString(type);
Stream.SendStream(player);
}
if(type == "YES_fireman")
{
Stream.StartWrite();
Stream.WriteString(type);
Stream.SendStream(player);
}
}

and i want to have this as a command

else if ( cmd == "fireman" )
  {
 SendDataToClient( player.ID, 1, "fireman" );
 } // idk if this is they way to do it to send it to cleint or what
Title: Re: gui buttons fireman
Post by: umar4911 on Jun 07, 2018, 05:03 AM
Quote from: MEGAMIND on Jun 06, 2018, 06:38 PMlike this ?
function onClientScriptData(player) {
    local type = Stream.ReadString();
if(type == "YES_fireman")
{
player.Skin = 6;
}
if(type == "NO_fireman")
{
Stream.StartWrite();
Stream.WriteString(type);
Stream.SendStream(player);
}
if(type == "YES_fireman")
{
Stream.StartWrite();
Stream.WriteString(type);
Stream.SendStream(player);
}
}

and i want to have this as a command

else if ( cmd == "fireman" )
  {
 SendDataToClient( player.ID, 1, "fireman" );
 } // idk if this is they way to do it to send it to cleint or what
On receiving data, you send it back to the client again. Why? And do. You have function SendDataToClient?
Title: Re: gui buttons fireman
Post by: MEGAMIND on Jun 07, 2018, 07:41 AM
yes i have senddatatoclient function