Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Change Image in gui (https://forums.graalonline.com/forums/showthread.php?t=134257040)

sssssssssss 11-24-2009 01:56 AM

Change Image in gui
 
If i have a script with imgctrl in it:

PHP Code:

    new GuiShowImgCtrl("Stan_Window_Image" @ this.guildflag) { 
      
x = 12; 
      
y = 50; 
      
width = 150; 
      
height = 150; 
      
image = this.guildflag; 
    } 

And I need to change that image later, how would I go about it?

I tried doing a triggerserver on created, then get the image from dbnpc, then triggerclient, and set the this.gulidflag clientside, but that isnt working.
Also, on a whim, tried gui.setImage(this.guildflag), but I guess thats not a way to do it, kinda like setText.

cbk1994 11-24-2009 02:07 AM

You can change it like any other variable of an object

PHP Code:

MyImage.image = "block.png";
Stan_Window_Image_0.image = "block.png"; 

if it's a dynamic name, you can do

PHP Code:

(@ "Stan_Window_Image" @ this.guildFlag).image = "block.png"; 

However, you shouldn't be placing the image name in the GUI control's name. Instead, try appending numbers (_0, _1, etc)

sssssssssss 11-24-2009 04:17 AM

Ill post the code its using in pieces. I tried some of those, they didnt work.
The gui weapon:

PHP Code:

function onCreated() {
  
this.db = findnpc("db_registeredguilds");
}

function 
onActionServerSide(action, acton) {
  if (
temp.action == "getImage"){
    
triggerclient("weapon", this.name, "getFlag", this.db.getGuildFlag());
  }
}
//#CLIENTSIDE
function onActionClientSide(cmd, data, data2) {
  if (
cmd == "getFlag"){
    
Stan_Window_Image_.image = temp.data;  
    
this.guildflag = temp.data;
    
player.chat = temp.data;
  }
}
function 
onCreated(){
  
triggerserver("weapon", this.name, "getImage");
}
new 
GuiWindowCtrl("Stan_Window") {
    
profile = "GuiBlueWindowProfile";
    
useOwnProfile = true; 
    
extent = "495 300";
    
x = 50;
    
y = 50;
    
text = "Guild Registration Lobby";
    
visible = true;
    
canResize = false;
    new 
GuiShowImgCtrl("Stan_Window_Image") { 
      
x = 12; 
      
y = 50; 
      
width = 150; 
      
height = 150; 
      
image = ""; 
    } 
} 

PHP Code:

DBNPC
public function getGuildFlag() {
  return 
this.guilds.(@player.guild).flag;
} 

the flag is
PHP Code:

guilds.guildname.flag="block.png" 

also tried the flag w/o quotes.

in the set for the image on the action clientside ive tried:
setImage,
setImg,
and using a variable then putting the variable in the gui image = section.
With the code that is posted, all that shows up is a big "0" (zero) when I use
PHP Code:

this.guildflag 

if i use it blank as shown, it shows up nothing.
i put player.chat and its saying "block.png" when i use so I know it shouldnt be empty, its just not setting.

If im doing this completely wrong, can someone show an example and please explain how it works? really wish graal.net worked. :/

Switch 11-24-2009 04:26 AM

PHP Code:

function onCreated() {
  
this.db = findnpc("db_registeredguilds");
}

function 
onActionServerSide(action, acton) {
  if (
temp.action == "getImage"){
    
triggerclient("weapon", this.name, "getFlag", this.db.guilds.(@player.guild).flag);
  }
}
//#CLIENTSIDE
function onActionClientSide(cmd, data, data2) {
  if (
cmd == "getFlag"){
    
Stan_Window_Image.image = temp.data;  
    
this.guildflag = temp.data;
    
player.chat = temp.data;
  }
}
function 
onCreated(){
  
triggerserver("weapon", this.name, "getImage");
}
new 
GuiWindowCtrl("Stan_Window") {
    
profile = "GuiBlueWindowProfile";
    
useOwnProfile = true; 
    
extent = "495 300";
    
x = 50;
    
y = 50;
    
text = "Guild Registration Lobby";
    
visible = true;
    
canResize = false;
    new 
GuiShowImgCtrl("Stan_Window_Image") { 
      
x = 12; 
      
y = 50; 
      
width = 150; 
      
height = 150; 
      
image = ""; 
    } 
} 

No need for the DBNPC code using this.
Also make sure object names match; you had a "_" at the end of "Stan_Window_Image" in the clientside trigger.

sssssssssss 11-24-2009 04:50 AM

Removed that, and of coarse its still not working. I do need to use the dbnpc for this, because every guild will be able to upload a flag, and that is what Im trying to show up, so the image will be different depending on what guild you are in, being stored in the dbnpc. It also needs to find the dbnpc, which is why the this.db.whatever is in there, everything else searching through the dbnpc to pull up values works except this particular thing.

any ideas on how to fix?

Switch 11-25-2009 02:46 AM

Quote:

Originally Posted by sssssssssss (Post 1539941)
Removed that, and of coarse its still not working. I do need to use the dbnpc for this, because every guild will be able to upload a flag, and that is what Im trying to show up, so the image will be different depending on what guild you are in, being stored in the dbnpc. It also needs to find the dbnpc, which is why the this.db.whatever is in there, everything else searching through the dbnpc to pull up values works except this particular thing.

any ideas on how to fix?

PHP Code:

function onCreated() {
  
this.db = findnpc("db_registeredguilds");
}

function 
onActionServerSide(action, acton) {
  if (
temp.action == "getImage"){
    
triggerclient("weapon", this.name, "getFlag", this.db.guilds.(@player.guild).flag);
  }
} 

If I'm not mistaken, a DBNPC doesn't read the player object, unless using findPlayer(), except in the Control-NPC.

cbk1994 11-25-2009 02:48 AM

Quote:

Originally Posted by Switch (Post 1540266)
If I'm not mistaken, a DBNPC doesn't read the player object, unless using findPlayer(), except in the Control-NPC.

You are mistaken. An NPC can definitely "read" the player object, but only if it's in scope. Some events there will be no 'player' object because no player triggered them.

sssssssssss 11-26-2009 01:37 AM

It shouldnt need findplayer() or anything, all the other functions bring up the attributes just fine working the way I've shown.

Also like I said, when I use player.chat on the action clientside, it shows the block.png text that is set in the flags on the dbnpc, just not showing the image in the gui for some reason.

cbk1994 11-26-2009 02:21 AM

I don't think you have a clear grasp of the way objects work.

PHP Code:

temp.obj = new TStaticVar();

obj.test = "foo";
echo(
obj.test); // echoes foo

obj.test = 1;
echo(
obj.test); // echoes 1

obj.destroy(); // destroys the object 

You can also do it with global names

PHP Code:

temp.obj = new TStaticVar("MyObject");

MyObject.test = "foo";
echo(
MyObject.test); // echoes foo 

The same works for GUI controls

PHP Code:

new GuiShowImgCtrl("MyGuiImage") {
  
image = "block.png";
  
  
x = 32;
  
y = 64;
  
  
width = 32;
  
height = 32;
} 

then in another script you can call

PHP Code:

MyGuiImage.image = "bcalarmclock.png";
MyGuiImage.x = 16; 

or change any other variables, as long as you know the object name; you can also use dynamic object names:

PHP Code:

for (temp.i = 0; i < 5; i ++) { // make 5 images
  
new GuiShowImgCtrl("MyGuiImage_" @ i) {
    
image = "block.png";
    
    
x = 32 + (i * 33);
    
y = 64;
    
    
width = 32;
    
height = 32;
  }
} 

then you could do something like this:

PHP Code:

MyGuiImage_0.image = "bcalarmclock.png"; 

which would change only the first image's image. If you wanted to change all the images, you could do:

PHP Code:

for (temp.i = 0; i < 5; i ++) {
  (@ 
"MyGuiImage_" @ i).image = "bcalarmclock.png";
} 

However, in your case, I don't think you will need to use dynamic objects. I think you mistakenly used them in your initial post, though I could be wrong.

sssssssssss 11-26-2009 02:40 AM

Quote:

Originally Posted by sssssssssss (Post 1539935)
Ill post the code its using in pieces. I tried some of those, they didnt work.
The gui weapon:

PHP Code:

function onCreated() {
  
this.db = findnpc("db_registeredguilds");
}

function 
onActionServerSide(action, acton) {
  if (
temp.action == "getImage"){
    
triggerclient("weapon", this.name, "getFlag", this.db.getGuildFlag());
  }
}
//#CLIENTSIDE
function onActionClientSide(cmd, data, data2) {
  if (
cmd == "getFlag"){
    
Stan_Window_Image.image = temp.data;  
    
player.chat = temp.data;
  }
}
function 
onCreated(){
  
triggerserver("weapon", this.name, "getImage");
}
new 
GuiWindowCtrl("Stan_Window") {
    
profile = "GuiBlueWindowProfile";
    
useOwnProfile = true; 
    
extent = "495 300";
    
x = 50;
    
y = 50;
    
text = "Guild Registration Lobby";
    
visible = true;
    
canResize = false;
    new 
GuiShowImgCtrl("Stan_Window_Image") { 
      
x = 12; 
      
y = 50; 
      
width = 150; 
      
height = 150; 
      
image = ""; 
    } 
} 

PHP Code:

DBNPC
public function getGuildFlag() {
  return 
this.guilds.(@player.guild).flag;
} 

the flag is
PHP Code:

guilds.guildname.flag="block.png" 

also tried the flag w/o quotes.

in the set for the image on the action clientside ive tried:
setImage,
setImg,
and using a variable then putting the variable in the gui image = section.
With the code that is posted, all that shows up is a big "0" (zero) when I use
PHP Code:

this.guildflag 

if i use it blank as shown, it shows up nothing.
i put player.chat and its saying "block.png" when i use so I know it shouldnt be empty, its just not setting.

If im doing this completely wrong, can someone show an example and please explain how it works? really wish graal.net worked. :/

So what am I missing, or not understanding? I obviously have
PHP Code:

    Stan_Window_Image.image = temp.data; 

in there after retrieving it, and player.chat set to check its there. The player.chat says the flag, but no image shows, even with
PHP Code:

    Stan_Window_Image.image = temp.data; 


sssssssssss 12-02-2009 11:44 PM

Different question, same topic.
Is there a way to use something like changeimgpart on a gui image like above?

Chompy 12-02-2009 11:47 PM

Quote:

Originally Posted by sssssssssss (Post 1542010)
Different question, same topic.
Is there a way to use something like changeimgpart on a gui image like above?

Tried the variables partx, party, parth and partw? :- )

sssssssssss 12-03-2009 12:22 AM

Ok, now back to the original reason for this topic. It's a large amount of code, but im going to post it all, except some unnecessary text. I'm not the best, obviously, so please, dont comment on my messyness, I already know, and I know a ton of stuff in unnecessary. The player.chat = temp.data2[7] says the right thing, but the image still wont set.
PHP Code:

function onCreated() {
  
this.db = findnpc("db_registeredguilds");
}
function 
onActionServerSide(action, acton) {
  if (
temp.action == "getRegisteredGuilds") {
    
triggerclient("weapon", this.name, "guildList", this.db.getGuildList());
  }
  else if (
temp.action == "getGuildList") {
    
this.g1 = this.db.getGuildRank(player.guild);
    
this.g2 = this.db.getGuildKills(player.guild, 0);
    
this.g3 = this.db.getGuildDeaths(player.guild, 0);
    
this.g4 = this.db.getGuildLevel();
    
this.g5 = this.db.getGuildRupees();
    
this.g6 = this.db.getGuildEc();
    
this.g7 = this.db.getGuildMessage(player.guild);
    
this.g8 = this.db.getGuildFlag();
    
temp.data2 = {this.g1, this.g2, this.g3, this.g4, this.g5, this.g6, this.g7, this.g8};
    
triggerclient("weapon", this.name, "memberList", this.db.getMembersList(), temp.data2);
  }
  else if (
temp.action == "registerGuild") {
    
this.db.RegistersdeServer();
  }
  else if (
temp.action == "sendTheTextMes") {
    
this.db.guilds.(@player.guild).message = temp.acton;
  }
  else if (
temp.action == "sendTheTextAdd") {
    
this.db.AddMemRegGuildServer(temp.acton);   
  }
  else if (
temp.action == "sendTheTextDel") {
    if (
temp.acton != this.db.guilds.(@player.guild)[0]){
      
this.db.DelMemRegGuildServer(temp.acton);
    }
  }
  else if (
temp.action == "getAbyss") {
    
triggerclient("weapon", this.name, "theAbyss", this.db.getTopAbyss());
  }
  else if (
temp.action == "getTop") {
    
triggerclient("weapon", this.name, "getTop", this.db.getTopGuild());
  }
}
//#CLIENTSIDE
function onActionClientSide(cmd, data, data2) {
  if (
cmd == "memberList"){
    
temp.list = "";
    for (
temp.line: temp.data) {
      
temp.list @= temp.line @ "\n";
    }
    
//show up all the myguild stuff here. This code is only showing access
    
temp.newVar = data2;
    
temp.guildAcc = "Members with Access: " @ temp.data;
    
temp.guildName = "Guild: " @ player.guild;
    
temp.guildLeader = "Guild Leader: " @ temp.data[0];
    
temp.guildRating = "Guild Rating: " @ temp.newVar[0];
    
temp.guildWins = "Guild Wins: " @ temp.newVar[1];
    
temp.guildLosses = "Guild Losses: " @ temp.newVar[2];
    
temp.guildControl = "Guild Control: " @ temp.data2[3];
    
temp.guildRupees = "Guild Rupees: " @ temp.data2[4];
    
temp.guildEC = "Guild EC: " @ temp.data2[5];
    
temp.guildFlag = "";
    
temp.guildMessage = "Guild Message: " @ temp.data2[6];
    if (
player.guild != ""){
      
player.chat = temp.data2[7];
      
Stan_Image1.image = temp.data2[7];
      
Stan_WindowText.setText();
    }else{
      
Stan_WindowText.setText("Please put on your guild tag!");
    }

  }
}
function 
onCreated(){
}
public function 
OpenWindow(){
  new 
GuiWindowCtrl("Stan_Window") {
    
profile = "GuiBlueWindowProfile";
    
useOwnProfile = true; 
    
profile.bitmap = "guiarm_window.png"; 
    
extent = "495 300";
    
x = 50;
    
y = 50;
    
text = "Guild Registration Lobby";
    
visible = true;
    
canResize = false;  
    new 
GuiScrollCtrl("Stan_Window_Scroll") {
      
profile = "GuiBlueScrollProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_scroll.png"; 
      
extent = "300 250";
      
x = Stan_Window.width - 2;
      
y = Stan_Window.height - 1;
      
visible = true;
      
hscrollbar = "alwaysOff";
      
vscrollbar = "dynamic";
    }
    new 
GuiButtonCtrl("Stan_Window_Buy") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "5 23";
      
text = "List";
    }
    new 
GuiButtonCtrl("Stan_Window_Sell") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "98 25";
      
position = "101 23";
      
text = "Top 5";
    }
    new 
GuiButtonCtrl("Stan_Window_Leave") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "198 23";
      
text = "The Abyss";
    }
    new 
GuiButtonCtrl("Stan_Window_Register") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "294 23";
      
text = "Register Guild";
    }
    new 
GuiButtonCtrl("Stan_Window_Addm") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "200 245";
      
text = "Add Access";
    }
    new 
GuiButtonCtrl("Stan_Window_Delm") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "307 245";
      
text = "Remove Access";
    }
    new 
GuiButtonCtrl("Stan_Window_Myg") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "97 25";
      
position = "390 23";
      
text = "MyGuild";
    }
    new 
GuiButtonCtrl("Stan_Window_GMessage") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "105 25";
      
position = "85 245";
      
text = "Change Message";
    }  
    new 
GuiButtonCtrl("Stan_Window_RegisterDone") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "105 25";
      
position = "85 245";
      
text = "Register";
    } 
    new 
GuiButtonCtrl("Stan_Window_DelAcc") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "105 25";
      
position = "85 245";
      
text = "Remove Access";
    } 
    new 
GuiButtonCtrl("Stan_Window_AddAcc") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "105 25";
      
position = "85 245";
      
text = "Add Access";
    } 
    new 
GuiButtonCtrl("Stan_Window_SubMes") {
      
profile = "GuiBlueButtonProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_button.png"; 
      
extent = "105 25";
      
position = "85 245";
      
text = "Submit Message";
    } 
    new 
GuiTextEditCtrl("Stan_Window_TextEdit1") {
      
profile = "GuiBlueTextEditProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_textedit.png";
      
height = 20;
      
width = 300;
      
x = 100;
      
y = 150;
    }
    new 
GuiTextEditCtrl("Stan_Window_TextEdit2") {
      
profile = "GuiBlueTextEditProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_textedit.png";
      
height = 20;
      
width = 300;
      
x = 100;
      
y = 150;
    }
    new 
GuiTextEditCtrl("Stan_Window_TextEdit3") {
      
profile = "GuiBlueTextEditProfile";
      
useOwnProfile = true; 
      
profile.bitmap = "guiarm_textedit.png";
      
height = 20;
      
width = 300;
      
x = 100;
      
y = 150;
    }
    new 
GuiMLTextCtrl("Stan_WindowText") {
      
profile = "GuiBlueMLTextProfile";
      
useOwnProfile = true; 
      
extent = "300 250";
      
x = Stan_Window.width - 400;
      
y = Stan_Window.height - 250;
      
text = "battlefield.";
    } 
    new 
GuiShowImgCtrl("Stan_Image1") { 
      
x = 12; 
      
y = 50; 
      
width = 150; 
      
height = 150; 
      
image = ""; 
    } 
  }
}
public function 
Stan_Window_Buy.onAction(){
  
Stan_WindowText.setText("Guild List:");
  
triggerserver("weapon", this.name, "getRegisteredGuilds");
}
public function 
Stan_Window_Sell.onAction(){
  
Stan_WindowText.setText("The top 5 guilds on Armageddon:");
  
onCreated();
  
triggerserver("weapon", this.name, "getTop");
}
public function 
Stan_Window_Leave.onAction(){
  
Stan_WindowText.setText("Top 5 in The Abyss: ");
  
onCreated();
  
triggerserver("weapon", this.name, "getAbyss");
}
public function 
Stan_Window_Register.onAction(){
  
Stan_WindowText.setText("register.");
  
onCreated();
  
Stan_Window_RegisterDone.show();
}
public function 
Stan_Window_Addm.onAction(){
  
Stan_WindowText.setText("wars. ");
  
onCreated();
  
Stan_Window_TextEdit1.show();
  
Stan_Window_AddAcc.show();
}
public function 
Stan_Window_Delm.onAction(){
  
Stan_WindowText.setText("removed.");
  
onCreated();
  
Stan_Window_TextEdit2.show();
  
Stan_Window_DelAcc.show();
}
public function 
Stan_Window_Myg.onAction(){
  
Stan_WindowText.setText("Loading...");
  
onCreated();
  
Stan_Image1.show();
  
triggerserver("weapon", this.name, "getGuildList");
}
public function 
Stan_Window_GMessage.onAction(){
  
Stan_WindowText.setText("submit.");
  
onCreated();
  
Stan_Window_TextEdit3.show();
  
Stan_Window_SubMes.show();
}
public function 
Stan_Window_RegisterDone.onAction(){
  
triggerserver("weapon", this.name, "registerGuild");
  
onCreated();
}
public function 
Stan_Window_DelAcc.onAction(){
  
onCreated();
  
temp.submittext = Stan_Window_TextEdit2.text;
  
triggerserver("weapon", this.name, "sendTheTextDel", temp.submittext);
}
public function 
Stan_Window_AddAcc.onAction(){
  
onCreated();
  
temp.submittext = Stan_Window_TextEdit1.text;
  
triggerserver("weapon", this.name, "sendTheTextAdd", temp.submittext);  
}
public function 
Stan_Window_SubMes.onAction(){
  
onCreated();
  
temp.submittext = Stan_Window_TextEdit3.text;
  
triggerserver("weapon", this.name, "sendTheTextMes", temp.submittext);
} 


sssssssssss 12-03-2009 05:59 AM

That was probably a bit too much to post. sorry. Its the showimg control towards the end of the gui setup. It sends serverside, grabs it, sends clientside, and shows up in the second clientside command, the player.chat says what it should, but it doesnt set in the gui. I used this command in a few other gui's and it worked find, so wondering what is wrong.

sssssssssss 12-06-2009 08:46 PM

Still no idea why its not working. Tried many different things and have went through the wiki numerous times. :(


All times are GMT +2. The time now is 10:56 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.