AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem whit Plugin Api (https://forums.alliedmods.net/showthread.php?t=148026)

Stylaa 01-17-2011 09:40

Problem whit Plugin Api
 
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 ;)

Arkshine 01-17-2011 09:50

Re: Problem whit Plugin Api
 
Invalid array handle provided (0) , means the handle provided has not been created. Show your actual code.

Stylaa 01-17-2011 10:13

Re: Problem whit Plugin Api
 
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 );



fysiks 01-17-2011 12:47

Re: Problem whit Plugin Api
 
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).

Stylaa 01-17-2011 13:54

Re: Problem whit Plugin Api
 
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

Exolent[jNr] 01-17-2011 14:14

Re: Problem whit Plugin Api
 
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.

Stylaa 01-17-2011 17:42

Re: Problem whit Plugin Api
 
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

Exolent[jNr] 01-17-2011 17:45

Re: Problem whit Plugin Api
 
Show your full code.

Stylaa 01-17-2011 17:53

Re: Problem whit Plugin Api
 
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

Exolent[jNr] 01-17-2011 17:53

Re: Problem whit Plugin Api
 
Quote:

Originally Posted by Exolent[jNr] (Post 1395878)
Show your full code.



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

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