GUI Buttons

What I’m trying to do:
When the player clicks the button, I’d like that player to say Activated!
(setplayerprop #c,Activated!;). Although I don’t know how to make the game detect it’s clicking the Activate image…
If anyone can help with this, please post below! Thanks.

(THE MOUSE MUST BE CLICKING ON THE IMAGE NOT ANYWHERE)

Script:

//Npc made by Ace
if (playerenters){
   if (!isweapon)toweapons -activate;
  setstring this.img,ace_activate.png;
  timeout = 0.05;
}
if (timeout && isweapon){
  showimg 300,#s(this.img),screenwidth/2-60,screenheight-50;
  changeimgpart 300,0,0,152,40;
  changeimgvis 300,4;
  }
  timeout = 0.05;
}

Image:
[ATTACH=CONFIG]3249[/ATTACH]

You will need:

[COLOR="#0000FF"]Mouse Flags		True When[/COLOR]
leftmousebutton		the left mouse button has been pushed

[COLOR="#0000FF"]Mouse Variables			Value[/COLOR]
mousescreenx 			x position of the mouse on the game screen. (in pixels)
mousescreeny 			y position of the mouse on the game screen. (in pixels)

[COLOR="#0000FF"]Special Symbols	Meaning[/COLOR]
in		tests if an array/range contains a variable (e.g. 2 in {1,2,3}; x,y in |0,64|)

a few other things as well :3 But yerr those ones are I M P O R T A N T :o

Learn to look before posting please.

[QUOTE=tricxta;97982]
Other useful showimg operations associated with creation of guis:
In addition to showimg index,image,x,y;
-Crop pictures:changeimgpart index,startX,startY,width,height
-Show an animation:showani index,x,y,direction,gani,params;
–params can then be referred to within the gani(parameter numbers can range from 0-4)
—gani script:#p(0)
—in the gani editor:PARAM0
-overlay/change image layering:changeimgvis index,layer;4
–4+ use screen-coordinates, 0-3 are tile coordinates

Mouse operations:
-If (mousedown){
–will be true if the user clicks any button on their mouse, no loop of any sort is required
-if (mousewheel){
–this function is coupled with mousewheeldelta and is very useful for scrolling

This is for all future scripters not sure on how to create a gui
An example gui is:

if (playerenters){
  showimg 300,plant.png,screenwidth/2,screenheight/2;
  changeimgvis 300,4;
}

if (mousedown && mousescreenx in |screenwidth/2,screenwidth/2+32| && mousescreeny in |screenheight/2,screenheight/2+32|){
  message you clicked it!;
}

[/QUOTE]

@twiggy
leftmousebutton requires constant checking in a loop and isn’t exactly ideal for guis. Although if you were to make custom commands like mouseReleased you’d definately use that.

A thing I failed to mention is mousedown also provides with it information in #p(0) which says exactly what button was pressed.
Example:

if (mousedown){
  if (strequals(#p(0),left)){

  }
}

That’s awesome :smiley: I had no idea about the parameter in mousedown XD
I’ll have to mess with dem commands when I get the chance :3!

Yeah. keydown, mousedown, and a couple other functions use #p for params.