Notice, cache control is currently disabled, pastes of specific sizes redirect to their source.

viewing paste topic/11509- OnPCPickUpEvent | C

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "map/npc.h"
#include "map/party.h"
#include "map/itemdb.h"
#include "map/script.h"
#include "common/timer.h"
#include "common/nullpo.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
        "OnPCPickUpEvent",
        SERVER_TYPE_MAP,
        "0.1",
        HPM_VERSION,
};
 
enum pickup_type {
        PICKUP_ITEMID = 1,
        PICKUP_AMOUNT,
        PICKUP_IDENTIFY,
        PICKUP_REFINE,
        PICKUP_BROKEN,
        PICKUP_CARD1,
        PICKUP_CARD2,
        PICKUP_CARD3,
        PICKUP_CARD4,
        PICKUP_EXPIRE,
        PICKUP_BOUND,
        PICKUP_UNIQUEID,
        PICKUP_POSX,
        PICKUP_POSY,
};
 
/* STUPID !!! map->clearflooritem(&fitem->bl); clear the item data !!
int pc_takeitem_post( int retVal, struct map_session_data *sd, struct flooritem_data *fitem ) {
        if ( retVal == 0 ) return 0;
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_ITEMID ), (int)fitem->item_data.nameid );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_AMOUNT ), (int)fitem->item_data.amount );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_IDENTIFY ), (int)fitem->item_data.identify );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_REFINE ), (int)fitem->item_data.refine );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_BROKEN ), (int)fitem->item_data.attribute );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD1 ), (int)fitem->item_data.card[0] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD2 ), (int)fitem->item_data.card[1] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD3 ), (int)fitem->item_data.card[2] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD4 ), (int)fitem->item_data.card[3] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_EXPIRE ), (int)fitem->item_data.expire_time );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_BOUND ), (int)fitem->item_data.bound );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_UNIQUEID ), (int)fitem->item_data.unique_id );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_POSX ), (int)fitem->bl.x );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_POSY ), (int)fitem->bl.y );
        npc->event_doall_id( "OnPCPickUpEvent", sd->bl.id );
        return 1;
}
*/
 
int pc_takeitem_overload( struct map_session_data *sd, struct flooritem_data *fitem ) {
        int flag=0;
        int64 tick = timer->gettick();
        struct party_data *p=NULL;
 
        nullpo_ret(sd);
        nullpo_ret(fitem);
 
        if(!check_distance_bl(&fitem->bl, &sd->bl, 2) && sd->ud.skill_id!=BS_GREED)
                return 0; // Distance is too far
 
        if( pc_has_permission(sd,PC_PERM_DISABLE_PICK_UP) )
                return 0;
 
        if (sd->status.party_id)
                p = party->search(sd->status.party_id);
 
        if (fitem->first_get_charid > 0 && fitem->first_get_charid != sd->status.char_id) {
                struct map_session_data *first_sd = map->charid2sd(fitem->first_get_charid);
                if (DIFF_TICK(tick,fitem->first_get_tick) < 0) {
                        if (!(p && p->party.item&1 &&
                                first_sd && first_sd->status.party_id == sd->status.party_id
                        ))
                                return 0;
                } else if (fitem->second_get_charid > 0 && fitem->second_get_charid != sd->status.char_id) {
                        struct map_session_data *second_sd = map->charid2sd(fitem->second_get_charid);
                        if (DIFF_TICK(tick, fitem->second_get_tick) < 0) {
                                if (!(p && p->party.item&1 &&
                                        ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
                                        (second_sd && second_sd->status.party_id == sd->status.party_id))
                                ))
                                        return 0;
                        } else if (fitem->third_get_charid > 0 && fitem->third_get_charid != sd->status.char_id) {
                                struct map_session_data *third_sd = map->charid2sd(fitem->third_get_charid);
                                if (DIFF_TICK(tick,fitem->third_get_tick) < 0) {
                                        if (!(p && p->party.item&1 &&
                                                ((first_sd && first_sd->status.party_id == sd->status.party_id) ||
                                                (second_sd && second_sd->status.party_id == sd->status.party_id) ||
                                                (third_sd && third_sd->status.party_id == sd->status.party_id))
                                        ))
                                                return 0;
                                }
                        }
                }
        }
 
        //This function takes care of giving the item to whoever should have it, considering party-share options.
        if ((flag = party->share_loot(p,sd,&fitem->item_data, fitem->first_get_charid))) {
                clif->additem(sd,0,0,flag);
                return 1;
        }
 
        //Display pickup animation.
        pc_stop_attack(sd);
        clif->takeitem(&sd->bl,&fitem->bl);
 
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_ITEMID ), (int)fitem->item_data.nameid );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_AMOUNT ), (int)fitem->item_data.amount );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_IDENTIFY ), (int)fitem->item_data.identify );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_REFINE ), (int)fitem->item_data.refine );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_BROKEN ), (int)fitem->item_data.attribute );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD1 ), (int)fitem->item_data.card[0] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD2 ), (int)fitem->item_data.card[1] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD3 ), (int)fitem->item_data.card[2] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_CARD4 ), (int)fitem->item_data.card[3] );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_EXPIRE ), (int)fitem->item_data.expire_time );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_BOUND ), (int)fitem->item_data.bound );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_UNIQUEID ), (int)fitem->item_data.unique_id );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_POSX ), (int)fitem->bl.x );
        pc->setreg( sd, reference_uid( script->add_str("@pickup"), PICKUP_POSY ), (int)fitem->bl.y );
        npc->event_doall_id( "OnPCPickUpEvent", sd->bl.id );
 
        map->clearflooritem(&fitem->bl);
        return 1;
}
 
HPExport void plugin_init (void) {
//      addHookPost( "pc->takeitem", pc_takeitem_post );
        pc->takeitem = &pc_takeitem_overload;
 
        script->set_constant("PICKUP_ITEMID",PICKUP_ITEMID,false);
        script->set_constant("PICKUP_AMOUNT",PICKUP_AMOUNT,false);
        script->set_constant("PICKUP_IDENTIFY",PICKUP_IDENTIFY,false);
        script->set_constant("PICKUP_REFINE",PICKUP_REFINE,false);
        script->set_constant("PICKUP_BROKEN",PICKUP_BROKEN,false);
        script->set_constant("PICKUP_CARD1",PICKUP_CARD1,false);
        script->set_constant("PICKUP_CARD2",PICKUP_CARD2,false);
        script->set_constant("PICKUP_CARD3",PICKUP_CARD3,false);
        script->set_constant("PICKUP_CARD4",PICKUP_CARD4,false);
        script->set_constant("PICKUP_EXPIRE",PICKUP_EXPIRE,false);
        script->set_constant("PICKUP_BOUND",PICKUP_BOUND,false);
        script->set_constant("PICKUP_UNIQUEID",PICKUP_UNIQUEID,false);
        script->set_constant("PICKUP_POSX",PICKUP_POSX,false);
        script->set_constant("PICKUP_POSY",PICKUP_POSY,false);
}
Viewed 732 times, submitted by AnnieRuru.