Jump to content

Modified AmmoHudComponent


Recommended Posts

Posted

ammohudcomponent.png

I created AmmoHudComponent

But it is only GuiStaticImage (performs decorative function)

I want that, this Image should fulfil its calling

I mean when the player's hands Chainsaw, show up Chainsaw modified AmmoHudComponent

My first step

function showClientImage() 
  
   guiCreateStaticImage( 795, 35, 75, 100, "Main/Chainsaw.png", false ) 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage ) 

next step

Switching weapons is changing AmmoHudComponent

who will help change the game interface?

I think that will work with http://development.mtasa.com/index.php?title=BindKey

Posted
guiCreateStaticImage( 795, 35, 75, 100, "Main/Chainsaw.png", false ) -- <-------------- 

That line won't make your script very popular... It will only draw correctly on your current resolution.

Someone with a 800x600 or 1280x960 will probably have a way other view than you have right there. In fact, with 800x600 I think it even draws half inside the right border... :D

You should use relative coordinates, instead of absolute ones. That should make it look about the same for everyone.

Posted

I know that but mostly play in 1024X

but we can do

    local screenWidth, screenHeight = guiGetScreenSize() 
    if screenWidth < 1280 and screenHeight < 1024 then 

Posted

I don't see why you'd want to do that. It's a comparison that does nothing at all.

What MIGHT work is using relative coordinates. Although, the HUD positioning might be different in different resolutions.

Posted

It doesn't matter if "most" people run in 1024x768... There are plenty with other resolutions, and you should also care about them.

About your real problem, you probably don't even WANT to use bindKey, since there's an awefully easier and more effective way onClientPlayerWeaponSwitch.

And one other suggestion: Do guiCreateStaticImage for ALL of the weapon icons you have. Then do guiSetVisible(theImage,false) for the ones you don't need. To check which one you need, it might be useful to use getPlayerWeapon.

This should get you a long way in your script.

And I indeed didn't even think about HUD positioning that might differ...

Posted

...

And one other suggestion: Do guiCreateStaticImage for ALL of the weapon icons you have. Then do guiSetVisible(theImage,false) for the ones you don't need. To check which one you need, it might be useful to use getPlayerWeapon.

This should get you a long way in your script.

If you ever used image functions you'd know there is guiStaticImageLoadImage or if you use my GUI lib then you'd know about it too

image:LoadImage( "newimage.png" ) 

I even made an example in the official topic that swaps an image when you click it.

Posted

Example

function showClientImage ( prevSlot, newSlot ) 
  
        if getPlayerWeapon(getLocalPlayer(),newSlot) == 31 then 
                guiCreateStaticImage( 795, 35, 75, 100, "Main/M4.png", false ) 
        end 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), showClientImage ) 

But i have problem, label dont update... so i get fistly saw second m4 and i have 2 labels runing togetherXD

Posted

How do you want the label to update if you don't even use guiSetText to update it?

BTW, I wonder how it would look.. a function with 40 if statements LOL. You should just make images of all weapons with name of id of the weapon. So you won't have to make tens of if statements to check which image you want to show. Like:

function showClientImage ( prevSlot, newSlot ) 
        local weaponID = getPlayerWeapon( getLocalPlayer(), newSlot); 
        guiStaticImageLoadImage( WEAPON_IMAGE, "Main/".. tostring( weaponID ) ..".png" ); 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), showClientImage ) 

Assuming you have created an image and assigned it to WEAPON_IMAGE.

Posted

Do you think anyone wants to know where you got them from? You have them all in .txd files which are in gta3.img. You can even have them as .png which supports alpha channels and you don't have to edit them in photoshop...

Anyway, get to scripting and tell us any problems you encounter.

Posted

Whot i lost?

label dont create

 function showClientImage ( prevSlot, newSlot ) 
        local weaponID = getPlayerWeapon( getLocalPlayer(), newSlot) 
        guiStaticImageLoadImage( 795, 35, 75, 100, "Hud_ammo/".. tostring( weaponID ) ..".png" ) 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), showClientImage ) 

Posted

Where did you create the label?

And what the hell is this?

  
        guiStaticImageLoadImage( 795, 35, 75, 100, "Hud_ammo/".. tostring( weaponID ) ..".png" ) 
  

Posted

Might be good to read the tutorial and documentation before trying to swing around with guiStaticImageLoadImage...

On resource start, use guiCreateStaticImage to create the image, and then use guiStaticLoadImage to change the pic on weapon switch.

EDIT:

To 50p:

I always thought guiStaticLoadImage could lag a lot when switching weapons quickly for example. That's why I didn't mention it.

And I haven't even looked at your GUI Classes that much yet. GUI is already easy enough to me. :P

Posted

I did not understand

How can show up guiStaticImageLoadImage if you dont indicate (float x, float y, float width, float height)

which differ of youre example

local weaponID = [color=#BF0000]getPlayerWeapon[/color]( getLocalPlayer(), newSlot); 
[color=#00BFFF]guiStaticImageLoadImage[/color]( [color=#0040FF]WEAPON_IMAGE[/color], "direction/".. tostring( [color=#BF0000]weaponID[/color] ) .."[color=#0040FF].png[/color]" ); 
  

and this one

         [color=#BF0000]if getPlayerWeapon[/color](getLocalPlayer(),newSlot) == [color=#BF0000]weaponID[/color] then 
                 [color=#00BFFF]guiCreateStaticImage[/color]([color=#00BFFF] 795, 35, 75, 100,[/color] "direction/[color=#0000FF]Image_name.png[/color]", false ) 

then I must create a image individual at all 38 weapon

Posted

/facepalm

This function allows you to change the image in GUI static image element to another one.

So for instance, you created image1 like...

image=guiCreateStaticImage( 795, 35, 75, 100, "image1.png", false ) 

Then later on you can do...

guiStaticImageLoadImage(image,"image2.png") 

And it'll change to image2! Hard isn't it..? :roll:

Posted

function showClientImage() 
  
   image = guiCreateStaticImage( 795, 35, 75, 100, "image1.png", false ) 
   guiStaticImageLoadImage(image,"2.png") 
   guiStaticImageLoadImage(image,"3.png") 
   guiStaticImageLoadImage(image,"4.png") 
   guiStaticImageLoadImage(image,"5.png") 
   guiStaticImageLoadImage(image,"6.png") 
   guiStaticImageLoadImage(image,"7.png") 
   guiStaticImageLoadImage(image,"8.png") 
   guiStaticImageLoadImage(image,"9.png") 
   guiStaticImageLoadImage(image,"14.png") 
   guiStaticImageLoadImage(image,"16.png") 
   guiStaticImageLoadImage(image,"17.png") 
   guiStaticImageLoadImage(image,"18.png") 
   guiStaticImageLoadImage(image,"22.png") 
   guiStaticImageLoadImage(image,"23.png") 
   guiStaticImageLoadImage(image,"24.png") 
   guiStaticImageLoadImage(image,"25.png") 
   guiStaticImageLoadImage(image,"26.png") 
   guiStaticImageLoadImage(image,"27.png") 
   guiStaticImageLoadImage(image,"28.png") 
   guiStaticImageLoadImage(image,"29.png") 
   guiStaticImageLoadImage(image,"30.png") 
   guiStaticImageLoadImage(image,"31.png") 
   guiStaticImageLoadImage(image,"32.png") 
   guiStaticImageLoadImage(image,"33.png") 
   guiStaticImageLoadImage(image,"34.png") 
   guiStaticImageLoadImage(image,"35.png") 
   guiStaticImageLoadImage(image,"36.png") 
   guiStaticImageLoadImage(image,"37.png") 
   guiStaticImageLoadImage(image,"38.png") 
   guiStaticImageLoadImage(image,"39.png") 
   guiStaticImageLoadImage(image,"41.png") 
   guiStaticImageLoadImage(image,"42.png") 
   guiStaticImageLoadImage(image,"43.png") 
   guiStaticImageLoadImage(image,"44.png") 
   guiStaticImageLoadImage(image,"45.png") 
   guiStaticImageLoadImage(image,"46.png") 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage ) 
  
function showClientImage ( prevSlot, newSlot ) 
        local weaponID = getPlayerWeapon( getLocalPlayer(), newSlot); 
        guiStaticImageLoadImage( image, "Hud_ammo/".. tostring( weaponID ) ..".png" ); 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), showClientImage ) 
  
  

I do that- image name = id of weapon

Label do not Create when i chose weapon

Posted

WHAT THE FUCK!?

I can not handle it anymore. Thanks. I wish you best in the world of scripting!

Posted

Mister,

What you do here is wrong, real wrong. Let me explain;

staticImageLoadImage = This reloads an image that you have created with createStaticImage.

It is real simple:

local image = nil 
  
function showClientImage() 
   -- Image 0 should be the fists (i guess) 
   image = guiCreateStaticImage( 795, 35, 75, 100, "Hud_ammo/0.png", false ) -- This creates the image. Standard 0 cuz that is the fist  
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage ) 

That is onClientResourceStart. You dont need to load every image. That can crash the client i guess.

Now how to change the weapon. That is real simple :)

function showClientImage ( prevSlot, newSlot ) 
        local weaponID = getPlayerWeapon( getLocalPlayer(), newSlot);  
        guiStaticImageLoadImage( image, "Hud_ammo/".. tostring( weaponID ) ..".png" ); 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), showClientImage ) 

Posted

To avoid confusion between images, i think u would wanna to hide standart ones:

function showClientImage() 
   -- Image 0 should be the fists (i guess) 
   image = guiCreateStaticImage( 795, 35, 75, 100, "Hud_ammo/0.png", false ) -- This creates the image. Standard 0 cuz that is the fist 
   [b]showPlayerHudComponent ( 'weapon', false )[/b] 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage ) 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...