Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Quad), 762 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 7 of 8 1 2 3 4 5 6 7 8
Re: Dropping items from inventory bag [Re: Ruben] #436903
02/05/14 10:46
02/05/14 10:46
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
ok, I see.

I feel 'on_float_end_callback_function_ptr' event a bit useless. It is called when you pick an object from the inventory or when you add an item to the mouse pointer using 'inv_float_item' function.

When you pick an object from the inventory, the 'on_click_callback_function_ptr' function is called with INV_ITEM_REMOVED or INV_ITEM_SWAPPED as first parameter. So there are two different event calls for the same internal game action.

When you add an item to the mouse pointer with 'inv_float_item' you are already executing a function of your own so you can perform whatever you want just after the 'inv_float_item' function call. There is no need of an event call at all.

I go back to the previous question. It has nothing to do with the arrays part. You are probably creating the player weapon this way, isn't it?
Code:
active_weapon = ent_create ( (txtItemModelNames.pstring)[SWORD], vecPos, attach_weapon_action );



Here you have to understand that the 'active_weapon' pointer is filled after executing the entity action. So when the entity action is executed the 'active_weapon' pointer points to the previous weapon, not the newly created one! In the case of the first entity action call 'active_weapon' is NULL because there is no previous weapon.

Let us see what happens when the entity action is called at entity creation.

Code:
action active_weapon_action ()
{
	ENTITY *ent = active_weapon;


You are declaring the ENTITY pointer 'ent' and filling it with the content of the global ENTITY pointer 'active_weapon'. So in the first call 'ent' will be equal to NULL (as I explained you) and in the next calls it will be equal to the previous weapon.

As you can imagine this action start is wrong. In my example 'active_weapon_action' is called after asigning the newly created entity (it was a view entity!) address to the 'active_weapon' pointer so in the action start it has already the correct actual weapon pointer asigned to 'active_weapon'.

Code:
if ( ent )
{



In the first call 'ent' is equal to NULL so the conditioning becomes false and the code inside its brackets is not executed: the weapon will never be positioned at players hand.

The slot event (the function that manages the 'active_weapon' pointer) sets 'active_weapon' to NULL when any of INV_ITEM_REMOVED or INV_ITEM_SWAPPED event types are called so the 'ent_create' function will always be called with the 'active_weapon' pointer previously set to NULL and same as at first call will happen: the weapon will never be positioned at players hand.

I apologize for the mess you've gotten to use 'ent_createlayer' instead of 'ent_create'.

Solution:
Click to reveal..

1. Attach your old 'attach_weapon' action to the newly created weapon (with 'ent_create!). At this point, it will simply run but forever: its ending condition is an empty 'player' pointer! So the player will pile all the armed weapons on its hand; repeated inclusive.

2. Set the 'active_weapon' pointer to 'me' at the beginning of the weapon action. This way when you create a new weapon the global 'active_weapon' pointer will point to the newly created weapon from that time and it can be used into the entity action on its first loop.

3. Add a loop that waits for a correctly filled 'player' pointer before using it.

4. Change the running condition of the weapon action. It should break the loop when the active weapon changes to any other weapon instead of the actual 'player != NULL'. This way the weapon action loop will run while the created entity continues been the active weapon.

5. Remove every weapon when it stops being the active weapon. Tip: Inside its action.

6. Try to imagine the impact of this code line (inside 'attach_weapon')
Code:
vec_set(my.pan,my.pan);




Salud!

Last edited by txesmi; 02/05/14 10:52.
Re: Dropping items from inventory bag [Re: txesmi] #436945
02/06/14 05:22
02/06/14 05:22
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Maybe I am using your new code technique wrong, but when I incorporate it into my program, I am getting weird bugs that I did not have before, and my game is just not working right like it did before.

Going back to my previous code that works, this is the function that works in arming my player with a weapon, when I arm the player using the active weapon slot of the inventory bag:

Code:
function slot_was_clicked ( int occurrence, int bag_id, int slot_id, int placed_item_id, int removed_item_id ) 
{
   if ( ( occurrence == INV_ITEM_REMOVED ) || ( occurrence == INV_ITEM_SWAPPED ) )
   {
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				ent_remove ( active_weapon );
			}
		}   
   }
	if ( ( occurrence == INV_ITEM_PLACED ) || ( occurrence == INV_ITEM_SWAPPED ) )
	{
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				switch ( placed_item_id )
				{
					case SWORD:  active_weapon_mdl = "sword.mdl"; active_weapon = ent_create ( active_weapon_mdl, player.x, attach_weapon );  break;
					case MACE:   active_weapon_mdl = "mace.mdl"; active_weapon = ent_create ( active_weapon_mdl, player.x, attach_weapon );  break;
				}
			}
		}   
	}
}


I am now trying to figure out how to create a function that will drop the weapon or item from the inventory bag that the mouse cursor is currently floating, while the inventory bag is open, as the player clicks outside the bag.

Last edited by Ruben; 02/06/14 05:25.
Re: Dropping items from inventory bag [Re: Ruben] #437030
02/08/14 07:56
02/08/14 07:56
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Is there a way that I can drop items from my inventory bag without using the arrays method? The code I had before worked just fine without any bugs. If I can find a solution using the code I had before the arrays code, that would be easier for me.

Re: Dropping items from inventory bag [Re: Ruben] #437032
02/08/14 08:51
02/08/14 08:51
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
You can find the same code but without arrays in the previous message crazy

Re: Dropping items from inventory bag [Re: txesmi] #437076
02/08/14 21:39
02/08/14 21:39
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Okay, I believe I had part of the functionality I was looking for all along. Its just that my inventory bag GUI was blocking the player, so I could not see what was happening when I drag/clicked an item outside the inventory bag.

It looks like when I drag/click an active weapon outside the inventory bag, the weapon does automatically disappear from the player's hand, since that weapon item icon is no longer in the active weapon slot of the inventory bag. So, I guess I had that functionality all along without realizing it.

My main goal at this point is to make it so that the item icon (from the inventory bag) that I drag/click outside the inventory bag needs to disappear. This should automatically remove it from the player's inventory list.

My goal after that is to make it so that if the item icon disappears after drag/clicking it outside the inventory bag, that same dropped item needs to appear on the ground next to the player.

Last edited by Ruben; 02/08/14 21:41.
Re: Dropping items from inventory bag [Re: Ruben] #437082
02/09/14 00:46
02/09/14 00:46
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
So, I am trying to remove (delete) the floating inventory icon that I click outside the inventory bag. I created a callback function called item_was_dropped() . Here are both of my callback functions so far:

Code:
function slot_was_clicked ( int occurrence, int bag_id, int slot_id, int placed_item_id, int removed_item_id ) 
{
   if ( ( occurrence == INV_ITEM_REMOVED ) || ( occurrence == INV_ITEM_SWAPPED ) )
   {
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				ent_remove ( active_weapon );
			}
		}   
   }
	if ( ( occurrence == INV_ITEM_PLACED ) || ( occurrence == INV_ITEM_SWAPPED ) )
	{
		if (bag_id == MAIN_BAG_ID)
		{
			if (slot_id == ACTIV_WPN_SLOT_ID)
			{
				switch ( placed_item_id )
				{
					case SWORD:  active_weapon_mdl = "sword.mdl"; active_weapon = ent_create ( active_weapon_mdl, player.x, attach_weapon );  break;
					case MACE:   active_weapon_mdl = "mace.mdl"; active_weapon = ent_create ( active_weapon_mdl, player.x, attach_weapon );  break;
				}
			}
		}   
	}
}

function item_was_dropped()
{
	Item* floatingItem;

   if ( !mouse_panel )
	{
		if ( inv_is_floating() )
		{
			if ( mouse_left )
			{
				bmap_remove(floatingItem.floating_icon);
			}
		}
	}
}



In my main function, I make some calls to these callback functions:

Code:
set_on_click_callback("slot_was_clicked");
   set_on_float_end_callback("item_was_dropped");



My "slot_was_clicked" function is used for arming the player with a weapon, if a player places a weapon icon into the active weapon slot of the inventory bag. The "slot_was_clicked" callback function works great.

I am trying to make my "item_was_dropped" function to drop items out of my inventory bag when drag/clicking an item icon outside the inventory bag. I am not sure if I am on the right path with this. Am I using the right command ( bmap_remove ) to delete the floating inventory icon when drag/clicking it outside the inventory bag? I know that the code used above for the "item_was_dropped" callback function is not performing what I want it to do (i.e. it is not performing anything).

Last edited by Ruben; 02/09/14 01:55.
Re: Dropping items from inventory bag [Re: Ruben] #437144
02/10/14 11:32
02/10/14 11:32
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi Ruben,
I divided the 'inv_get_floating_icon_item' function I gived you above into two different functions for better understanding and usage. It was a bit messy.

Code:
function inv_clear_floating_icon ()
{
	if ( inv_floating_flag )
	{
		inv_floating_flag = 0;
		global_floating_item_ptr->item = NULL;		
		bmap_remove(global_floating_item_ptr->floating_item_panel->bmap);
		pan_remove(global_floating_item_ptr->floating_item_panel);
	}
}

var inv_get_floating_icon_item_id ()
{
	if ( inv_floating_flag )
	{
		return global_floating_item_ptr->item->id; 
	}
	else
	{
		error ( "Not existent floating icon on 'inv_get_floating_icon_item_id'.\nValidate the existence of a floating icon before calling 'inv_get_floating_icon_item_id'." );
		return -1;
	}
}



So your 'item_was_dropped' funtion into my example could look as follows:
Code:
#define skill_id   skill20
...
action actObject ()
{
	...
}

function item_was_dropped ()
{
	if ( !mouse_panel ) // Is the mouse pointer out of a panel?
	{
		if ( inv_is_floating() ) // Does a floating icon exists?
		{
			if ( mouse_left ) // Is the mouse left button pressed?
			{
				var item_id = inv_get_floating_icon_item_id (); // Get the floating icon item id.
				inv_clear_floating_icon (); // Clear the floating icon.
				switch ( item_id ) // Create the new scenery object.
				{
					case SNIPERGUN: 
						ENTITY *entObject = ent_create ( "snipergun.mdl", player.x, actObject );
						entObject.skill_id = item_id;
						break;
					case SHOTGUN: 
						ENTITY *entObject = ent_create ( "shotgun.mdl", player.x, actObject );
						entObject.skill_id = item_id;
						break;
					case SHOTGUN: 
						ENTITY *entObject = ent_create ( "machinegun.mdl", player.x, actObject );
						entObject.skill_id = item_id;
						break;
				}
			}
		}
	}
}



Salud!

Re: Dropping items from inventory bag [Re: txesmi] #437210
02/12/14 09:24
02/12/14 09:24
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Interesting.

I put your top code into the inventory.c program.

I tried using the logic of your second code in my OrcStronghold.c program. Here is what I have in OrcStronghold.c :

Code:
...

action dropObject ()
{
	// Code to place weapon on ground next to player, when it is dropped.
}

...

function item_was_dropped ()
{
	Bag *bagPanel;
	if ( !mouse_panel ) // Is the mouse pointer out of a panel?
	{
		if ( inv_is_floating() ) // Does a floating icon exists?
		{
			if ( mouse_left ) // Is the mouse left button pressed?
			{
				var item_id = inv_get_floating_icon_item_id (); // Get the floating icon item id.
				inv_clear_floating_icon (); // Clear the floating icon.
				switch ( item_id ) // Create the new scenery object.
				{
					case SWORD: 
						ENTITY *entObject = ent_create ( "sword.mdl", player.x, dropObject );
						entObject.skill_id = item_id;
						break;
					case MACE: 
						ENTITY *entObject = ent_create ( "mace.mdl", player.x, dropObject );
						entObject.skill_id = item_id;
						break;
				}
			}
		}
	}
}



The code still does not work when I click on an inventory icon saved in the inventory bag, drag it outside the inventory bag, and click that same item icon outside the inventory bag. The inventory icon does not disappear.

I wonder, am I still clicking on some hidden panel when trying to drop an item from my inventory bag?

Last edited by Ruben; 02/12/14 09:26.
Re: Dropping items from inventory bag [Re: Ruben] #437215
02/12/14 11:10
02/12/14 11:10
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
You should use a sound or a log entry and isolate the not working code line:

Code:
#define PRAGMA_PATH "%EXE_DIR%\\templates\\sounds"
SOUND *sndBeep = "beep.wav";



Play it to the beginning of your function
Code:
function item_was_dropped ()
{
	snd_play ( sndBeep, 100, 0 ); // Is 'item_was_dropped' properly called?
	...



In the case it sounds, move it to the next flux control:
Code:
function item_was_dropped ()
{
	if ( !mouse_panel ) // Is the mouse pointer out of a panel?
	{
		snd_play ( sndBeep, 100, 0 ); // is it?



Anyway it is a mistery for us the way you call your 'item_was_dropped' function and it can come from there.

Salud!

Last edited by txesmi; 02/12/14 11:13.
Re: Dropping items from inventory bag [Re: txesmi] #437252
02/13/14 04:21
02/13/14 04:21
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thanks txesmi.

I tried your idea. This is what I created:

Code:
function item_was_dropped ()
{
	Bag *bagPanel;
	
	
	snd_play ( sndDebugger, 100, 0 );
	
	if ( !mouse_panel ) // Is the mouse pointer out of a panel?
	{
		snd_play ( sndDebugger, 100, 0 );
		
		if ( inv_is_floating() ) // Does a floating icon exists?
		{
			snd_play ( sndDebugger, 100, 0 );
			
			if ( mouse_left ) // Is the mouse left button pressed?
			{
				snd_play ( sndDebugger, 100, 0 );
				
				var item_id = inv_get_floating_icon_item_id (); // Get the floating icon item id.
				inv_clear_floating_icon (); // Clear the floating icon.
				switch ( item_id ) // Create the new scenery object.
				{
					case SWORD: 
						ENTITY *entObject = ent_create ( "sword.mdl", player.x, dropObject );
						entObject.skill_id = item_id;
						break;
					case MACE: 
						ENTITY *entObject = ent_create ( "mace.mdl", player.x, dropObject );
						entObject.skill_id = item_id;
						break;
				}
			}
		}
	}
}



When I move an inventory icon from one slot of the inventory bag into a different slot, I hear the DEBUGGER sound, which is an explosion. If I click/drag an inventory icon from being saved in the inventory bag, to a location outside the bag, and left-click, I am not hearing the debugger exploding sound, and nothing happens. So, for some reason, "!mousepanel" does not seem to be registering the clicking outside the inventory bag.

Page 7 of 8 1 2 3 4 5 6 7 8

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1