Raised This Month: $ Target: $400
 0% 

Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-02-2010 , 02:10   Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #1

Hi all!

I am working on a new plugin: bank_vault. This will have an inventory as a part of the game, where people could buy items. The items would be in separate plugins, could be registrated with a native from the main plugin.

The trouble is, I don't know how I should tell bots to buy items, because every plugin handles it's own items separately. As far as I thinked of:
The money message is being hooked, and as soon as a bot has enough money, then it can buy items. But how to choose which items? How to tell other plugins in the same forward that some othe plugin already spent some of the bot's money.

Any ideas on this? I attached the source code so far...

Thanks in advance for your answers.
Attached Files
File Type: sma Get Plugin or Get Source (bank_vault.sma - 652 views - 13.6 KB)
File Type: sma Get Plugin or Get Source (bv_items.sma - 638 views - 2.4 KB)
File Type: inc bank_vault.inc (1.4 KB, 129 views)
File Type: zip bank_vault.zip (19.3 KB, 63 views)
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-08-2010 , 05:34   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #2

OMG! Not a single answer after a week? Damn...
Lulu the hero is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-08-2010 , 05:48   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #3

Quote:
Originally Posted by Lulu the hero View Post
OMG! Not a single answer after a week? Damn...
People are not familiar with API type plugins. One second for me to read the question and I will answer.
Edit:
Well it is simple. You should make the main plugin (core plugin) handle the item buy! You register the price, etc. and make a native for the buy, that can be used by other plugins and even by the core. You register all the extensions in an array and make the original plugin check if a bot has enough money and after that do a buy. To notify other plugins about money change the best way is with cs_set_user_money.

Edit2:
I released a plugin a night before that does what I have said above.
http://forums.alliedmods.net/showthread.php?t=134691
Check the native/forwards parts and how they are used. Also the inc file should help.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 08-08-2010 at 05:58.
ot_207 is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-18-2010 , 20:24   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #4

Hi there Lulu! I think I've solved your problem using the ideas you gave in your first comment. Step by step here it is:

First of all, there are two type of items defined in your plugin:
1) items that are usable by bots( purse, or any upgrades )
2) items that bots cannot use( crowbar, satchel charges, or any weapons )

Then you need to specify some priority, when can a bot buy an item:
1) immediately, when sufficiant money is gathered( purse upgrade )
2) it can wait, till round start( building upgrades, withdrawing, depositing money from the bank )
3) never( items, that are disabled to bots due to their lack of ability to use it )

Lastly you need to specify the amount, that needs to be bought at a time:
1) buy as much as possible( max out )
2) buy only 1 at a time

Then you can set some properties of the items:
1) Can it be dropped
2) How long does it lasts
3) Who can buy it

All the above are like this:
PHP Code:
// Item Buy Priority - for bots
#define IBP_ASAP        0 //immediately when sufficiant money is gathered
#define IBP_SPAWN        1 //buy on spawn
#define IBP_NEVER        9 //never buy this - eg. cannot be used by a bot

// Item Buy Mode - for bots
#define IBM_MAXOUT        0 //buy as much items as possible
#define IBM_ONE            1 //gonna max out, but buy only 1 now

// Item Flags
#define IF_DROPABLE        (1<<0) //can this item be dropped?
#define IF_STEALABLE        (1<<1) //can be stolen by knifedown?
#define IF_LOOSEONNEWROUND    (1<<2) //only last for a round
#define IF_LOOSEONDEATH     (1<<3) //loose this item on death?
#define IF_LOOSEONTEAMCHANGE    (1<<4) //loose this item on teamchange?
#define IF_FOR_T        (1<<5) //terrorists can buy this(cs & cz)
#define IF_FOR_CT        (1<<6) //ct-s can buy this(cs & cz) 
Gonna continue this, stay tuned...
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-18-2010 , 20:56   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #5

All right Lulu, as you feared, you need to store the above datas all in your main plugin. But that gives you some advantages too, you don't need to send out so many external forwards to check who has a certain item, you can simply use the datas as a lookup table( precache them as nesesery ).

In your main plugin, set up some enums to give your data a structure:
PHP Code:
enum _:ITEM_FLAGS(<<=1){
    
IF_DROPABLE 1,
    
IF_STEALABLE,
    
IF_LOOSEONNEWROUND,
    
IF_LOOSEONDEATH,
    
IF_LOOSEONTEAMCHANGE,
    
IF_FOR_T,
    
IF_FOR_CT,
    
FLAG_SIZE
}

enum _:ITEM_DATA{
    
INAME[30],
    
IPRIZE,
    
IAMOUNT,
    
IPRIORITY,
    
IMODE,
    
IFLAGS
}

#define MAX_ITEMNUM 100

new itemdatas[MAX_ITEMNUM][ITEM_DATA];
new 
itemnum
And then you have your structure.

To register your item, use a function like this:
PHP Code:
//in the main plugin:
public native_register_item(name[],prize,max_amount,buy_priority,buy_mode,flags){
    static 
i;
    
    
param_convert(1);
    
    if(
itemnum>=MAX_ITEMNUM){
        
#if defined DEBUG
            
console_print(0,"[BV] Can't add item ^"%s^", because there is no more space!",name);
        
#endif
        
return -1;
    }
    
    if(
itemnum>0){
        for(
0iitemnum;i++){
            if(
equali(itemdatas[i][INAME],name)){
                
#if defined DEBUG
                    
console_print(0,"[BV] Item ^"%s^" already defined as #%d!",itemdatas[i][INAME],i);
                
#endif
                
return itemnum;
            }
        }
    }
    
    
copy(itemdatas[itemnum][INAME],29,name);
    
itemdatas[itemnum][IPRIZE]    = prize;
    
itemdatas[itemnum][IAMOUNT]    = max_amount;
    
itemdatas[itemnum][IPRIORITY]    = buy_priority;
    
itemdatas[itemnum][IMODE]    = buy_mode;
    
itemdatas[itemnum][IFLAGS]    = flags;
    
    
#if defined DEBUG
        
static binflags[32], bitnum;
        
        
bitnum floatround(floatlog(float(FLAG_SIZE),2.0),floatround_floor);
        
        
num_to_binstr(flags,binflags,bitnum);
        
        
console_print(0,"[BV] Added item ^"%s^" as #%d.",name,itemnum);
        
console_print(0,"[BV] (Prize: %d, max amount: %d, buy priority %d, buy mode: %d, flags: %s)",prize,max_amount,buy_priority,buy_mode,binflags);
    
#endif
    
    
itemnum++;
    
    return 
itemnum-1;
}

//use this to print out binary numbers in amxmodx, because %x is not working...
#if defined DEBUG
stock num_to_binstr(num,dest[],len){
    static 
i;
    for(
i=0;i<len;i++){
        
dest[(len-1)-i] = (num>>i)%2=='1' '0';
    }
}
#endif

//in your external plugin:
purse2k bv_register_item("Purse upgrade I.",600,1,IBP_ASAP,IBM_MAXOUT,IF_LOOSEONTEAMCHANGE IF_FOR_T IF_FOR_CT); 
If you want a description to an item, that is being bought, then that is the thing that can be stored in every plugin of it's own( in my opinion ).

For example when someone buys the item purse2k, then you can print out a message( from the purse2k's plugin ): You can now store up to 2000 dollars.

Hope this helps, Lulu.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-18-2010 , 21:01   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #6

Thanks a lot, Lulu, helped me a lot, but there is one more trouble. This plugin will keep growing and growing... How can I maintain it, if it is so big? It will propably run over 3k lines?

All right, I have the answer, no need to this talking to myself thing:
Put the parts of your plugins to separate inline files, that you include when nesesery. Like in pokemod:
You can include anything with this line:
PHP Code:
#include "somewhere/some_file.inl" 
Okay. So I restarted the plugin from crap over 5 times now, and always getting better, so I'm gonna upload the purse upgrade thingy tonight( 3am in Hungary now ), so keep watching if interested...
Lulu the hero is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-19-2010 , 02:57   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #7

Quote:
Originally Posted by Lulu the hero View Post
I restarted the plugin from crap over 5 times now
lol
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 08-19-2010 , 00:36   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #8

I do find it quite amusing that you help yourself. One of the few people.
__________________
Hi.
Kreation is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-19-2010 , 01:03   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #9

If I've found a working solution, then why not share it with you guys?

To be honest, I sat on my ass for a while(2 days), started the whole plugin from scratch, and finally came up with the idea of this:
Am I getting worried, that my plugin will use too much memory? With these new ideas and methods, the plugin is slightly over 60kB, but then again, check the ZombiePlague mod: more than 300k??? I have plenty of space to waste, until I reach ZP's size.( It is funny: ZP. Those are the first letters of a hungarian party place: Zöld Pardon( Green Excuse me :S ), so every time I see ZP, I can only think of that...
Plus I save memory on storing properties of items in bits and not on bytes. And thirdly, who cares? It's the 21th century, dammit...

To be compleately honest, I DO care about memory, because I am used to coding in pascal and assembly, where memory is quite limited( <1MB )

Last edited by Lulu the hero; 08-19-2010 at 01:15.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 08-19-2010 , 03:11   Re: Bank Vault mod - Multiple plugin trouble/Forwards - bot behaviour
Reply With Quote #10

Yep, you know why? I tell you why.

The program is getting bigger and bigger. Working fine. Perfectly. No errors, no warnings. Then I add a few more code. Still works. Then I add something like a menu. Then when I add a bot, the whole hl crashes without an error. Then I remove the things I've edited recently, starting to comment them out, and still has the bug( appeared at the menu ). Then I need to comment out everything almost, and then I realise: I've mistyped a letter in a string, eg. in a forward declaration. 1 flippin' character. That happens lesser then the other version, where I give up the whole thing in the middle of commenting, and just start a new file, and copy paste the working codes from the buggy to the new. It is simpler to me.

Note to self: USE SVN, MORON!( Yep, I should... )

So I am lazy to debug. I hate errors which are not syntactical errors. And I hate debugging them, so I use this method, and I got used to it.
Any idea on how to avoid these kind of problems?


Edit:
I'm doing that right now

Last edited by Lulu the hero; 08-19-2010 at 03:16.
Lulu the hero 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 00:12.


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