danielps Posted March 26, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Share Posted March 26, 2018 (edited) Edited October 20, 2020 by danielps Quote Link to comment Share on other sites More sharing options...
0 Playtester Posted March 27, 2018 Group: Developer Topic Count: 37 Topics Per Day: 0.01 Content Count: 897 Reputation: 248 Joined: 01/30/13 Last Seen: Monday at 09:07 AM Share Posted March 27, 2018 An event is player-specific, but here you are in a mob-specific function, so how should that work? You need to put it in a place that is player-specific. Technically, if you want to get from the monster to a list of player, you would do something like "For all players in view range of the monster", but that's fairly complex, nothing I can write down for you. You can search for "map_foreach" in mob.cpp to see similar applications. For example this part: // Scan area for targets if (!tbl && can_move && mode&MD_LOOTER && md->lootitems && DIFF_TICK(tick, md->ud.canact_tick) > 0 && (md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1)) { // Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items. map_foreachinshootrange (mob_ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl); } if ((!tbl && mode&MD_AGGRESSIVE) || md->state.skillstate == MSS_FOLLOW) { map_foreachinallrange (mob_ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode); } else if (mode&MD_CHANGECHASE && (md->state.skillstate == MSS_RUSH || md->state.skillstate == MSS_FOLLOW)) { int search_size; search_size = view_range<md->status.rhw.range ? view_range:md->status.rhw.range; map_foreachinallrange (mob_ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl); } Here is search for all targets in range and calls a function per target found. In that underlying function you will have "bl" of the player from which you can fetch sd. You basically want something similar: "For all players in range -> call new function (you need to define it) -> get sd from bl in new function and then do your function call" 1 Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 27, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 27, 2018 (edited) 45 minutes ago, Playtester said: An event is player-specific, but here you are in a mob-specific function, so how should that work? You need to put it in a place that is player-specific. Technically, if you want to get from the monster to a list of player, you would do something like "For all players in view range of the monster", but that's fairly complex, nothing I can write down for you. You can search for "map_foreach" in mob.cpp to see similar applications. For example this part: // Scan area for targets if (!tbl && can_move && mode&MD_LOOTER && md->lootitems && DIFF_TICK(tick, md->ud.canact_tick) > 0 && (md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1)) { // Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items. map_foreachinshootrange (mob_ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl); } if ((!tbl && mode&MD_AGGRESSIVE) || md->state.skillstate == MSS_FOLLOW) { map_foreachinallrange (mob_ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode); } else if (mode&MD_CHANGECHASE && (md->state.skillstate == MSS_RUSH || md->state.skillstate == MSS_FOLLOW)) { int search_size; search_size = view_range<md->status.rhw.range ? view_range:md->status.rhw.range; map_foreachinallrange (mob_ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl); } Here is search for all targets in range and calls a function per target found. In that underlying function you will have "bl" of the player from which you can fetch sd. You basically want something similar: "For all players in range -> call new function (you need to define it) -> get sd from bl in new function and then do your function call" Thanks a lot bro but what í need is exactly the oposite. I want tô create a label when mob stop attacking and get idle mode. So í think that i put my code in the right place, or not? My problem is: to create á new custom label i need to put sd variable in npc_script_event(SD Right? But in that block of code that turn the mob in idle mode there is no sd. Did you get it? And i want this custom label tô attach to the mob that get idle mode and not his target. Edited March 27, 2018 by danielps Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 27, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 27, 2018 What happens if i declare sd as null? I really need this sd tô attach a custom label in mobs that get in idle mode? Or if i declare sd as null í will get crash? I dont understand the need of sd, actually idk what is this sd.... Thanks for the help bro! Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 27, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 27, 2018 Hi @Playtester, I did this and compiled with sucess. My only question is about this part of my code sd = (TBL_PC*)md->mob_id;. Is this mob_id right? I think that the correct is set in sb, the value of the unique mob id and not the id related with the database (like 1002 = poring) TOnight i will test, but do you guys see any error in my code? that mod_id is right? Is really this value i need to put in sd ? Quote Link to comment Share on other sites More sharing options...
0 Playtester Posted March 28, 2018 Group: Developer Topic Count: 37 Topics Per Day: 0.01 Content Count: 897 Reputation: 248 Joined: 01/30/13 Last Seen: Monday at 09:07 AM Share Posted March 28, 2018 (edited) sd will just get garbage data like that (it will point to whatever memory that mob_id value is saved on and behind that). sd is only for players not for monsters. Monsters are not human beings, there's no point showing them a label. Edited March 28, 2018 by Playtester 1 Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 28, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 28, 2018 1 hour ago, Playtester said: sd will just get garbage data like that (it will point to whatever memory that mob_id value is saved on and behind that). sd is only for players not for monsters. Monsters are not human beings, there's no point showing them a label. Dude, my code -> "sd = (TBL_PC*)md->mob_id" compile successfully, but i get crash ingame when a mob see me. If i'm in @hide there is no problem, mob normaly walk, when i appear using @hide again, map-server crash in the same time! How do i get sd in this function? i need the block_list src, right? but in this function i just have "the mob_data *md", any idea how do i get the sd to call the label? Quote Link to comment Share on other sites More sharing options...
0 Playtester Posted March 28, 2018 Group: Developer Topic Count: 37 Topics Per Day: 0.01 Content Count: 897 Reputation: 248 Joined: 01/30/13 Last Seen: Monday at 09:07 AM Share Posted March 28, 2018 Just because the code compiles doesn't mean it makes any sense. What you're doing is casting mob_id to a pointer (memory address) and then make the sd pointer point to that address. I explained to you how you can get sd -> by fetching all the players in visible range of the monster. 1 Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 28, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 28, 2018 (edited) 34 minutes ago, Playtester said: Just because the code compiles doesn't mean it makes any sense. What you're doing is casting mob_id to a pointer (memory address) and then make the sd pointer point to that address. I explained to you how you can get sd -> by fetching all the players in visible range of the monster. Ah ok, i will try it! Only one question, what if there is no players in visible range of the monster? I mean, my custom label is OnIDLEMob, so mob can get idle mode with no players in visible range, in this case i won't have sd, right? And probably get crash, right? Thanks a lot for your help, i will give like in yours answers and latter i tell you if it worked =D Thanks since now! Edited March 28, 2018 by danielps Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted March 28, 2018 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: April 5 Share Posted March 28, 2018 Don't use npc_script_event; instead look at some session-less events, like OnInit or OnHourXX. 1 Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 28, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 28, 2018 1 minute ago, Nitrous said: Don't use npc_script_event; instead look at some session-less events, like OnInit or OnHourXX. Why? In this session-less events i don't need a SD-> ? I will have a look at that and study more... i'm not so good with src but i'm very interested and studious. Thanks for you tips guys !! Quote Link to comment Share on other sites More sharing options...
0 danielps Posted March 28, 2018 Group: Members Topic Count: 48 Topics Per Day: 0.01 Content Count: 174 Reputation: 18 Joined: 10/09/14 Last Seen: Yesterday at 11:41 PM Author Share Posted March 28, 2018 I tought in use the OnTouchNPC, but in src there is only 3 places that i can see ontouchnpc_event_name: script.h const char* ontouchnpc_event_name; script.c "OnTouchNPC", //ontouchnpc_event_name (run whenever a monster walks into the OnTouch area) npc.c safesnprintf(eventname, ARRAYLENGTH(eventname), "%s::%s", map[m].npc->exname, script_config.ontouchnpc_event_name); Only these 3 lines make the OnTouchNPC work? What if i dont crate a custom label and instead i just call the script from the src? Like, when bot get IDLE mode, i call the script and set as arg(1) the GID of the mob. Is that possible? Its easier i think, right? Quote Link to comment Share on other sites More sharing options...
Question
danielps
Link to comment
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.