Jump to content
  • 0

Variable declaration in src


Question

11 answers to this question

Recommended Posts

  • 0
Posted

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"

  • Upvote 1
  • 0
Posted (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 by danielps
  • 0
Posted

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!

  • 0
Posted

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 ?

Untitled.png

  • 0
Posted (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 by Playtester
  • Upvote 1
  • 0
Posted
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?

  • 0
Posted

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.

  • Upvote 1
  • 0
Posted (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 by danielps
  • 0
Posted
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 !!

  • 0
Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...