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.