[SOLVED]Inventory Item not working / First Person Game

Started by Phonoitypal, Wed 03/01/2024 22:36:00

Previous topic - Next topic

Phonoitypal

Hi, I have some problems regarding the usage of inventory items.

I'm making a first person game, and I created my custom inventory.
The items work just fine(they appear on the gui), the gui is set alright with its own window, item appears where its supposed to.
Also, room scripts regarding  "if (player.HasInventory(iItemName))" work !

The problem appears when trying to use the inventory ITEM on a hotspot that has the property
"player.ActiveInventory==iItemName)".

The item of the cursor changes as the one of the item, but it doesent seem to work.


I have the following global script that I think it may cause the problem


Code: ags
// called on every game cycle, except when the game is blocked
function repeatedly_execute()
{
  if (player.ActiveInventory ==null){
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) {
        // Set the variable to true when the mouse is over a hotspot
        if (!isOverHotspot) {
            // Execute global script only when entering a hotspot
            Mouse.ChangeModeGraphic(mouse.Mode, 24);
        }
        isOverHotspot = true;
    } else {
        // If the mouse is not over a hotspot, execute the global script
        if (!isOverHotspot) {
            Mouse.ChangeModeGraphic(mouse.Mode, 22);
        }
        // Reset the variable
        isOverHotspot = false;
    }
}
}

Basically what this script does is to check if im hovering over an object to change the cursor, and re-change it back to 'original' while on 'nothing'. Also the first line is made in that way so it will 'stop executing' while having an inventory item as a cursor.
I also added that stuff to make it 'not execute' while on a specific hotspot (to put back arrows etc in the room)

Furthermore, to make the ItemCursor dissapear while clicking on something(for example, clicking away of any hotspot or on areas that are not designated for its use with the item)I have the following script :

Code: ags
function on_mouse_click(MouseButton button)
{
  if (player.ActiveInventory != null) //An inventory item is selected
{
  player.ActiveInventory = null;
  mouse.Mode = eModeInteract;
}


I don't know why the item would not work while using it on the designated hotspot with the useinv proprety.
I'm sure it's because of some way that I probably messed up the mouse cursor somehow ?

Also, tried to change the above code "mouse.Mode = eModeInteract;" with eModeUseInv but it does not work ! :(

Anyone could help me solve this issue ? I feel so confused !

Phonoitypal

I should also mention i think that I dont use any other 'mouse modes' other than the interact one, since i used a blank template

Phonoitypal

I FIXED IT.
OMG I'M so noobish.
Actually, I didn't need this code at all
Code: ags

function on_mouse_click(MouseButton button)
{
  if (player.ActiveInventory != null) //An inventory item is selected
{
  player.ActiveInventory = null;
  mouse.Mode = eModeInteract;
}




The cursor 'gets back to normal' after executing the useinv propriety.
That code actually prevented the item from being used !

SMF spam blocked by CleanTalk