View Single Post
  #2  
Old 04-28-2014, 12:41 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Hey there!

findimg() basically returns the object of an image displayed at the given index, and there's really no limit to indices, besides the fact that from 0 to 200 will draw images relative to the level (0-64 x and y grid) and above will draw on a screen level (0 to screenwidth and screenheight)

You can also create images using findimg(#), as it will simply return an image object even though you have not created that said image beforehand.

PHP Code:
with(findimg(200)) {
  
image "block.png";
  
width height 42;
  
screenheight/width/2;
  
screenheight/height/2;

When you assign variables inside the with() statement, there's no need to prepend variables with this. as all the variables are in scope with the object you give with()

You can also use it for referencing,

PHP Code:
// say you have a health bar on your GUI and you want to update it

function onCreated() {
  
// create gui, health bar is index 202 for example, assign it a maxwidth on creation
  // for easier updating later on, or you can use the imagewidth function

  
this.healthbar findimg(202);
}

function 
updateHealthBar() {
  
temp.php max(player.health/player.maxhealth1); // player health percentage
  // does not take into account bonuses like extra health or whatever you have in your system
  // this is just an example

  
this.healthbar.width temp.php ? (temp.php this.healthbar.maxwidth) : 0;

And if my memory isn't wrong, showimg() will also return the image object, so you can do something like

NPC Code:
this.healthbar = showimg(200, "healthbar.png", 0, 0, 64, 16);



I didn't have a place to test this on, but if there's something more, just ask
__________________
Reply With Quote