Jump to content

[SOURCE]Mob spawn


Recommended Posts

Hi guys, I would like to know how can I spawn a mob via source.

Like...I want to spawn a mob (mob2_vnum) when another certain mob(mob1_vnum) reach 90% of his hp...so I tried this...didn' worked...


        if (mob1_vnum->GetHPPct() > 98)
        {
            SpawnMob(mob2_vnum);
        }

Can someone tell me how to do that correctly? Please...

Link to comment
Share on other sites

  • Premium
1 minute ago, RcDragon said:

Hi guys, I would like to know how can I spawn a mob via source.

Like...I want to spawn a mob (mob2_vnum) when another certain mob(mob1_vnum) reach 90% of his hp...so I tried this...didn' worked...


        if (mob1_vnum->GetHPPct() > 98)
        {
            SpawnMob(mob2_vnum);
        }

Can someone tell me how to do that correctly? Please...

Well, this code must be inside some OnUpdate()-like event in order to work, else it's never going to get called.

You could easily do that in LUA, via timer.

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

3 minutes ago, Syreldar said:

Well, this code must be inside some OnUpdate()-like event in order to work, else it's never going to get called.

You could easily do that in LUA, via timer.

But I want the mob to spawn when the main mob reach 90% hp, and I don't know how to do that via quest if you can tell me I would be grateful.

Link to comment
Share on other sites

  • Premium

Only doable inside a dungeon tho, with the functions I can use.

quest spawn_mob begin
	state start begin
		when --[[]] begin
			--
			--** Spawns the first monster and memorizes its vid in a variable.
			local mob1_vid = d.spawn_mob(VNUM, LOCAL_X, LOCAL_Y);
			
			--** Sets the first monster as the 'mob1' unique.
			d.set_unique("mob1", mob1_vid);
			
			--** Starts the first monster''s HP check with a loop timer that will trigger once every 'check_interval_seconds' seconds.
			local check_interval_seconds = 5;
			server_loop_timer("mob1_hp_check", check_interval_seconds, d.get_map_index());
		end -- when
		
		--[[
			Server Loop Timer: Triggers infinitely once every X seconds, until cleared.
			Function:
				Checks the first spawned monster''s HP once every 'check_interval_seconds' seconds.
				If the check is met, it clears the HP check timer and executes the function inside the check. (Spawns the second monster).
		]]
		when mob1_hp_check.server_timer begin
			if (d.unique_get_hp_perc("mob1") <= 90) then
				clear_server_timer("mob1_hp_check", get_server_timer_arg());
				d.spawn_mob(VNUM2, LOCAL_X, LOCAL_Y);
			end -- if
		end -- when
	end -- state
end -- quest

 

  • Confused 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

@Syreldar Holy shit you just gave the worst possible solution regarding performance that I could think of.

In CHARACTER::StateBattle(char_state.cpp) do a check for mob1_vnum and if below the percentage you want, you can spawn the mob2 with CHARACTER_MANAGER::SpawnMob.

For more information look for dwSummonVnum from TMobTable and see how it is implemented, it seems to be closer to what you want to implement

Link to comment
Share on other sites

  • Premium
11 minutes ago, miguelmig said:

@Syreldar Holy shit you just gave the worst possible solution regarding performance that I could think of.

In CHARACTER::Damage do a check for mob1_vnum and if below the percentage you want, you can spawn the mob2 with CHARACTER_MANAGER::SpawnMob.

For more information look for ressurect_vnum from MobTable and see how it is implemented, it seems to be closer to what you want to implement

At least don't comment at all.. if you want to make fun of yourself you can do it somewhere else. Talking of performance in Metin2? About an instanciated server timer? You have like no idea man, just..do us a favor and don't comment anymore.

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

Just now, Syreldar said:

At least don't comment at all.. if you want to make fun of yourself you can do it somewhere else. Talking of performance in metin2? About an instanciated server timer? Just..do us a favor and do not comment anymore.

You're pathetic. Yes, performance is important in Metin2, at least server-side it can be improved or at least not made worse. A single "instanciated" server timer in combination with many other server_timers used when it isn't needed will surely lag out the server. 

Plus, there's no reason to use LUA in this context, it is utterly un-necessary, and needless to say your solution only works on a dungeon AND with a single monster ( you used unique ).

Don't come here saying I'm making fun of myself, I have a lot more experience on this area than you do, I'm sure.

Link to comment
Share on other sites

  • Premium
9 minutes ago, miguelmig said:

You're pathetic. Yes, performance is important in Metin2, at least server-side it can be improved or at least not made worse. A single "instanciated" server timer in combination with many other server_timers used when it isn't needed will surely lag out the server. 

Plus, there's no reason to use LUA in this context, it is utterly un-necessary, and needless to say your solution only works on a dungeon AND with a single monster ( you used unique ).

Don't come here saying I'm making fun of myself, I have a lot more experience on this area than you do, I'm sure.

Game performance can't be affected by a loop_timer.

  • Love 1
Link to comment
Share on other sites

4 minutes ago, Dobrescu Sebastian said:

Game performance can't be affected by a loop_timer.

lmao you can't be serious. You seriously think that? Every loop_timer is a event more for the game to process, not to speak whatever happens inside the timer body itself is code executed by the game core

To think that loop_timers don't affect Game performance is ludicrous and outright stupid. Not to mention if those loop_timers are never cleared they will run until the game core process gets shutdown or you run out of memory :)

Link to comment
Share on other sites

  • Premium
13 minutes ago, Dobrescu Sebastian said:

Game performance can't be affected by a loop_timer.

 

23 minutes ago, miguelmig said:

You're pathetic. Yes, performance is important in Metin2, at least server-side it can be improved or at least not made worse. A single "instanciated" server timer in combination with many other server_timers used when it isn't needed will surely lag out the server. 

Plus, there's no reason to use LUA in this context, it is utterly un-necessary, and needless to say your solution only works on a dungeon AND with a single monster ( you used unique ).

Don't come here saying I'm making fun of myself, I have a lot more experience on this area than you do, I'm sure.

I don't know you, but if someone who claims to know more than ME thinks he's going to improve the performance of almost HUNDREDS OF THOUSANDS of bad code lines and over 200 SOURCE-SIDED permanently active TIMERS by adding ONE SIMPLE THING to a function that's meant to manage generic things related mainly to the mob_proto which behaves similarly to what I did, which, remember, WAS A SIMPLE EXAMPLE.. then I can easily say that that person can throw everything he/she gained and learned into the trash can.

Remember, there's a reason someone here is acknowledged as a developer and you aren't.

I won't say anything else, nor will I answer your bullshit any further.

Have a good day.

  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

  • Premium
7 minutes ago, miguelmig said:

lmao you can't be serious. You seriously think that? Every loop_timer is a event more for the game to process, not to speak whatever happens inside the timer body itself is code executed by the game core

To think that loop_timers don't affect Game performance is ludicrous and outright stupid. Not to mention if those loop_timers are never cleared they will run until the game core process gets shutdown or you run out of memory :)

Talk about performance when you have a server. ( and ps: It's not normal that a game run out of memory). I have 10 loop_timers to all connected players and the game doesn't even feel them. It's about data you put that loop to read/write. But most loops writes/read just some lines of code. Just stop

  • Love 1
Link to comment
Share on other sites

1 minute ago, Dobrescu Sebastian said:

Talk about performance when you have a server. It's not normal that a game run out of memory. I have 10 loop_timers to all connected players and the game doesn't even feel them. It's about data you put that loop to read/write. But most loops writes/read just some lines of code. Just stop

Who said I don't have one? I don't even know how the conversation got to this point but my idea is pretty simple, loop timers are completely un-necessary to do what OP wanted and most of the times are just worthless when the same thing could be implemented in C++ without the performance overhead.

If you want to continue using loop_timers for simple things feel free, just know that one day it MIGHT bit you in the ass ( remember that for each player in your case it's another 10x loop_timers ), 100 more players is another 1000x loop_timers running. Complexity is a thing, look it up.

 

6 minutes ago, Syreldar said:

 

I don't know you, but if someone who claims to know more than ME, thinks he's going to improve the performance of HUNDRED OF THOUSANDS of bad code lines and over 200 SOURCE-SIDED permanently active TIMERS by adding ONE SIMPLE THING to a function that's meant to manage generic things related mainly to the mob_proto which behaves similarly  to what I did which, remember that WAS A SIMPLE EXAMPLE, then I can easily say that you can throw everything you gained and learned into the trash can, there's a reason someone here is acknowledged as a developer and you aren't.

 

I won't say anything else, nor will I answer further to your bullshit.

Have a good day.

Throw everything I gained into the trash? Guess I'll have to do that since some random told me on the internet, oh boy there goes my Compute Science diplome into the trash can.

I don't need a "Developer" tag to feel superior or to know how good of a developer I am.

Most of the "source-sided permantently active timers" are of high times or only happen once, they're not in a loop.

The worst case that I know of Looped Events/Timers hard-coded on source are the regen events which I've been trying to think of a good way to refactor them.

Link to comment
Share on other sites

  • Premium
3 minutes ago, miguelmig said:

Who said I don't have one? I don't even know how the conversation got to this point but my idea is pretty simple, loop timers are completely un-necessary to do what OP wanted and most of the times are just worthless when the same thing could be implemented in C++ without the performance overhead.

If you want to continue using loop_timers for simple things feel free, just know that one day it MIGHT bit you in the ass ( remember that for each player in your case it's another 10x loop_timers ), 100 more players is another 1000x loop_timers running. Complexity is a thing, look it up.

 

Throw everything I gained into the trash? Guess I'll have to do that since some random told me on the internet, oh boy there goes my Compute Science diplome into the trash can.

I don't need a "Developer" tag to feel superior or to know how good of a developer I am.

Most of the "source-sided permantently active timers" are of high times or only happen once, they're not in a loop.

The worst case that I know of Looped Events/Timers hard-coded on source are the regen events which I've been trying to think of a good way to refactor them.

My server it's 3 old old and have hundreds of players online. A 3 old server has also a huge database right ? so more memory to read/write. And i don't have problems. Just stop telling people that loop timers are bad performance because are not. EVERYTHING ON METIN2 IT'S BASED ON TIMERS.

You want to optimise the game ? Start with python part. 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.