Raised This Month: $ Target: $400
 0% 

Problem whit Plugin Api


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 01-17-2011 , 09:40   Problem whit Plugin Api
Reply With Quote #1

Hay i got a Problem i want to add Items from the Main Plugin as Defaults but i always get a runtime error

i used this Code
http://forums.alliedmods.net/showthread.php?t=123445

and the error looks like this

The Inc i have included
the code is a 1 to 1 Copy just whit other func names

Error:
L 01/17/2011 - 15:34:55: Invalid array handle provided (0)
L 01/17/2011 - 15:34:55: [AMXX] Displaying debug trace (plugin "plugin.amxx")
L 01/17/2011 - 15:34:55: [AMXX] Run time error 10: native error (native "ArrayPushArray")
L 01/17/2011 - 15:34:55: [AMXX] [0] plugin.sma::_shop_item_add (line 2023)

Please help me ;)
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-17-2011 , 09:50   Re: Problem whit Plugin Api
Reply With Quote #2

Invalid array handle provided (0) , means the handle provided has not been created. Show your actual code.
__________________
Arkshine is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 01-17-2011 , 10:13   Re: Problem whit Plugin Api
Reply With Quote #3

hmm but when i add the Item via en Sub-Plugin everythink is working Well

Head
PHP Code:
//Shop
enum _:ItemData
{
    
ItemName32 ],
    
ItemCost,
    
ItemPlugin,
    
ItemFuncID
};
new Array:
g_aItems;
new 
g_iTotalItems
Plugin Init
PHP Code:
shop_item_add"Waffenwette",       15,         "gun_gamble" );

g_aItems ArrayCreateItemData ); 
Plugin Natives
PHP Code:
public plugin_natives( )
{
    
// register our custom library
    
register_library"plugin_api" );
    
    
// Native - Create Shop Item
    
register_native"shop_item_add""_shop_item_add" );


Error Part
PHP Code:
public _shop_item_addiPluginiParams )
{
    
// create an array to hold our item data
    
new eItemDataItemData ];
    
    
// get item name from function
    
get_string1eItemDataItemName ], charsmaxeItemDataItemName ] ) );
    
    
// get item cost from function
    
eItemDataItemCost ] = get_param);
    
    
// save the plugin adding the item
    
eItemDataItemPlugin ] = iPlugin;
    
    
// get item callback function
    
new szHandler32 ];
    
get_string3szHandlercharsmaxszHandler ) );
    
eItemDataItemFuncID ] = get_func_idszHandleriPlugin );
    
    
// add item to array and increase size
    
ArrayPushArrayg_aItemseItemData );             // The Error accures HERE but just when lunched from Main Plugin whit Sub Plugin Works
    
g_iTotalItems++;
    
    
// return the index of this item in the array
    // this creates the unique item index
    
return ( g_iTotalItems );

__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-17-2011 , 12:47   Re: Problem whit Plugin Api
Reply With Quote #4

I would make a local function that does the same thing and use that instead of using the native (if, infact, you can't use the native within the plugin which created it).
__________________
fysiks is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 01-17-2011 , 13:54   Re: Problem whit Plugin Api
Reply With Quote #5

yes i tought about the same think but i dont know how because i dont know how callfunc works and i dont know how to change the Code

PHP Code:
callfunc_begin_ieItemDataItemFuncID ], eItemDataItemPlugin ] );
        
callfunc_push_intiPlayer );
        
callfunc_end( ); 
It whould be very nice if someone could give me an example
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-17-2011 , 14:14   Re: Problem whit Plugin Api
Reply With Quote #6

Code:
public _shop_item_add( iPlugin, iParams ) {     // create an array to hold our item data     new eItemData[ ItemData ];         // get item name from function     get_string( 1, eItemData[ ItemName ], charsmax( eItemData[ ItemName ] ) );         // get item cost from function     eItemData[ ItemCost ] = get_param( 2 );         // save the plugin adding the item     eItemData[ ItemPlugin ] = iPlugin;         // get item callback function     new szHandler[ 32 ];     get_string( 3, szHandler, charsmax( szHandler ) );     eItemData[ ItemFuncID ] = get_func_id( szHandler, iPlugin );         // add item to array and increase size     ArrayPushArray( g_aItems, eItemData );             // The Error accures HERE but just when lunched from Main Plugin whit Sub Plugin Works     g_iTotalItems++;         // return the index of this item in the array     // this creates the unique item index     return ( g_iTotalItems - 1 ); }

If you want to use this native in the main plugin, then just make a function for it to save native calls.

Code:
public _shop_item_add( iPlugin, iParams ) {     new szItemName[ 64 ];     get_string( 1, szItemName, charsmax( szItemName );         new szHandler[ 32 ];     get_string( 3, szHandler, charsmax( szHandler ) );         return AddItem( szItemName, get_param( 2 ), iPlugin, szHandler ); } AddItem( szItemName[ ], iCost, iPlugin, szHandler[ ] ) {     new eItemData[ ItemData ];     copy( eItemData[ ItemName ], charsmax( eItemData[ ItemName ] ), szItemName );     eItemData[ ItemCost ] = iCost;     eItemData[ ItemPlugin ] = iPlugin;     eItemData[ ItemFuncID ] = get_func_id( szHandler, iPlugin );         ArrayPushArray( g_aItems, eItemData );     g_iTotalItems++;         return ( g_iTotalItems - 1 ); }

In AddItem(), you can use -1 for iPlugin if the function is called from the main plugin.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 01-17-2011 , 17:42   Re: Problem whit Plugin Api
Reply With Quote #7

First Thanks for this nice example.

i got one more Problem the Price of the Item always Returns -1

My Code :

Plugin Init
PHP Code:
//               Item Name        Price        Handler            Plugin ID -1 = Lokal
AddShopItem"Gay or Not?",   15,         "gay_check",            -); 
AddShopItem Func

PHP Code:
AddShopItemszItemName[ ], iCostszHandler[ ], iPlugin )

    new 
eItemDataItemData ];
    
copyeItemDataItemName ], charsmaxeItemDataItemName ] ), szItemName );
    
eItemDataItemCost ] = iCost;
    
eItemDataItemFuncID ] = get_func_idszHandleriPlugin );
    
eItemDataItemPlugin ] = iPlugin;
    
    
// Here in Testing Print eItemData[ ItemCost ] also returns   -1

    
ArrayPushArrayg_aItemseItemData );
    
g_iTotalItems++;
    return ( 
g_iTotalItems );

Best Regards
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-17-2011 , 17:45   Re: Problem whit Plugin Api
Reply With Quote #8

Show your full code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Stylaa
Senior Member
Join Date: Oct 2009
Location: Flensburg, Germany
Old 01-17-2011 , 17:53   Re: Problem whit Plugin Api
Reply With Quote #9

Soo

If i Call it whit This Function via a Sub Plugin it works

PHP Code:
public _jb_shop_item_add_terroriPluginiParams )
{
    new 
szItemName64 ];
    
get_string1szItemNamecharsmaxszItemName ) );
    new 
szHandler32 ];
    
get_string3szHandlercharsmaxszHandler ) );
    
    return 
AddShopItemszItemNameget_param), szHandleriPlugin );

but if i call via Plugin Init the Price Returns -1

PHP Code:
//Register SHOP Items
    
g_aItems ArrayCreateItemData );
    
    
//           Item Name        Preis        Handler         Plugin ID -1 = Lokal
    
AddShopItem"Waffenwette",   15,         "gun_gamble",            -); 
PHP Code:
AddShopItemszItemName[ ], iCostszHandler[ ], iPlugin )

    new 
eItemDataItemData ];
    
copyeItemDataItemName ], charsmaxeItemDataItemName ] ), szItemName );
    
eItemDataItemCost ] = iCost;
    
eItemDataItemFuncID ] = get_func_idszHandleriPlugin );
    
eItemDataItemPlugin ] = iPlugin;
    
    
ArrayPushArrayg_aItemseItemData );
    
g_iTotalItems++;
    return ( 
g_iTotalItems );

but i dont find my Mistake in this Part of the Code
__________________

Some People brings Happynes by Coming
Some by Going
Stylaa is offline
Send a message via ICQ to Stylaa
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-17-2011 , 17:53   Re: Problem whit Plugin Api
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
Show your full code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode