Help me Mcspawn.inc

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
Mallary
Novice Poster
Posts: 40
Joined: Thu Aug 14, 2008 2:54 pm

Help me Mcspawn.inc

Post by Mallary »

Well, I asked if is to help resolve this problem with this script, Mrcpaswn.

Code: Select all

use cfgfile;

var mrcspawn_cfg := ReadConfigFile( "mrcspawn" );


function RestockInventory( merchanttype, inventory )
    foreach productgroup in ProductGroups(merchanttype)
        Restock( inventory, productgroup );
    endforeach
endfunction

function ProductGroups( mtype )
    var mtype_elem := FindConfigElem( mrcspawn_cfg, mtype );
    if (!mtype_elem)
        syslog( "Unable to find config elem " + mtype );
        return 0;
    endif

    return GetConfigStringArray( mtype_elem, "Sells" );
endfunction

function Restock( inventory, productgroup )
    // print( "Restocking " + inventory.name + " with " + productgroup );
    var pg_elem := FindConfigElem( mrcspawn_cfg, productgroup );
    foreach itemstr in GetConfigStringArray( pg_elem, "Item" )
        sleepms(100);
        SpawnItem( inventory, itemstr );
    endforeach
endfunction

function SpawnItem( inventory, itemstr )
    // print( "SpawnItem: " + itemstr );
    var ii := SplitWords( itemstr );
    var objtype := ii[1];
    if (CInt(objtype))
       objtype := CInt(objtype);
    endif
    var i,count := CInt(ii[2]);

// TODO: use stackability to create single items or add to stacks
//       Stacks are always added to, currently.
//       Calling CreateItemInContainer 'count' times would do this
//           automatically, actually

    count := count - CountExisting( inventory, objtype );

    if (count > 0)
        for( i := 1; i <= count; i := i + 1 )
            CreateItemInInventory( inventory, objtype, 1 );
        endfor
    endif
endfunction

// This would be nice, and fast, but this doesn't handle multiple stacks
// In particular, it doesn't handle multiple single nonstackable items.
//    var itemref := FindObjtypeInContainer( inventory, objtype );
//    if (itemref)
//        count := count - itemref.amount;
//    endif

function CountExisting( container, objtype )
    var count := 0;
    foreach item in EnumerateItemsInContainer( container )
        if (item.objtype == objtype)
            count := count + item.amount;
        endif
    endforeach
    return count;
endfunction



function MerchantGroups()
    var mrcgroups_elem := FindConfigElem( mrcspawn_cfg, "MerchantGroups" );
    if (!mrcgroups_elem)
        syslog( "Unable to find 'MerchantGroups' element in mrcspawn.cfg" );
        return 0;
    endif

    return GetConfigStringArray( mrcgroups_elem, "MerchantGroup" );
endfunction

function Merchants( merchantgroup )
    var result := array;
    var mrc := array;
    mrc.+name;
    mrc.+type;

    var group_elem := FindConfigElem( mrcspawn_cfg, merchantgroup );
    var count := GetConfigInt( group_elem, "MerchantCount" );
    var i;
    for( i := 1; i <= count; i := i + 1 )
        mrc.name := GetConfigString( group_elem, "Merchant" + i );
        mrc.type := GetConfigString( group_elem, "MerchantType"+i );
        result[i] := mrc;
    endfor

    return result;
endfunction
Error: Variable EnumerateItemsInContainer has not been declared on line 63.
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Re: Help me Mcspawn.inc

Post by CWO »

Are you trying to compile this INC directly? INC files never have to be compiled. Their code is compiled into the SRC file that includes its code.

if you're not compiling it directly, try changing on line 63 from

Code: Select all

foreach item in EnumerateItemsInContainer( container )
to

Code: Select all

foreach item in ( EnumerateItemsInContainer( container ) )
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Re: Help me Mcspawn.inc

Post by ncrsn »

You will want to add "use uo;" on top of the file, if it isn't stated in the sourcefile or any other includes it has. That's to make sure eCompile found the function you are trying to use.

edit: The function CountExisting is a proper one and compiles without errors when I tried, so the error must be somewhere else.
User avatar
Mallary
Novice Poster
Posts: 40
Joined: Thu Aug 14, 2008 2:54 pm

Re: Help me Mcspawn.inc

Post by Mallary »

Thank you friends could fix

Code: Select all

use cfgfile;
use uo;

var mrcspawn_cfg := ReadConfigFile( "mrcspawn" );


function RestockInventory( merchanttype, inventory )
    foreach productgroup in ProductGroups(merchanttype)
        Restock( inventory, productgroup );
    endforeach
endfunction

function ProductGroups( mtype )
    var mtype_elem := FindConfigElem( mrcspawn_cfg, mtype );
    if (!mtype_elem)
//        syslog( "Unable to find config elem " + mtype );
        return 0;
    endif

    return GetConfigStringArray( mtype_elem, "Sells" );
endfunction

function Restock( inventory, productgroup )
    // print( "Restocking " + inventory.name + " with " + productgroup );
    var pg_elem := FindConfigElem( mrcspawn_cfg, productgroup );
    foreach itemstr in GetConfigStringArray( pg_elem, "Item" )
//        sleepms(100);
        SpawnItem( inventory, itemstr );
    endforeach
endfunction

function SpawnItem( inventory, itemstr )
    // print( "SpawnItem: " + itemstr );
    var ii := SplitWords( itemstr );
    var objtype := ii[1];
    if (CInt(objtype))
       objtype := CInt(objtype);
    endif
    var i,count := CInt(ii[2]);

// TODO: use stackability to create single items or add to stacks
//       Stacks are always added to, currently.
//       Calling CreateItemInContainer 'count' times would do this
//           automatically, actually

    count := count - CountExisting( inventory, objtype );

    if (count > 0)
        for( i := 1; i <= count; i := i + 1 )
            CreateItemInInventory( inventory, objtype, 1 );
        endfor
    endif
endfunction

// This would be nice, and fast, but this doesn't handle multiple stacks
// In particular, it doesn't handle multiple single nonstackable items.
//    var itemref := FindObjtypeInContainer( inventory, objtype );
//    if (itemref)
//        count := count - itemref.amount;
//    endif

function CountExisting( container, objtype )
    var count := 0;
    foreach item in EnumerateItemsInContainer( container )
//    foreach item in ( EnumerateItemsInContainer( container ) )
        if (item.objtype == objtype)
            count := count + item.amount;
        endif
    endforeach
    return count;
endfunction



function MerchantGroups()
    var mrcgroups_elem := FindConfigElem( mrcspawn_cfg, "MerchantGroups" );
    if (!mrcgroups_elem)
//        syslog( "Unable to find 'MerchantGroups' element in mrcspawn.cfg" );
        return 0;
    endif

    return GetConfigStringArray( mrcgroups_elem, "MerchantGroup" );
endfunction

function Merchants( merchantgroup )
    var result := array;
    var mrc := array;
    mrc.+name;
    mrc.+type;

    var group_elem := FindConfigElem( mrcspawn_cfg, merchantgroup );
    var count := GetConfigInt( group_elem, "MerchantCount" );
    var i;
    for( i := 1; i <= count; i := i + 1 )
        mrc.name := GetConfigString( group_elem, "Merchant" + i );
        mrc.type := GetConfigString( group_elem, "MerchantType"+i );
        result[i] := mrc;
    endfor

    return result;
endfunction
Post Reply