gui buttons fireman

Started by MEGAMIND, Jun 06, 2018, 06:08 PM

Previous topic - Next topic

MEGAMIND

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 :)

NicusorN5

You need to send a string from the client to the server.

MEGAMIND

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

umar4911

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?
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

MEGAMIND

yes i have senddatatoclient function