• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

[C++]Set CreatureSkullType random every spawn

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
Hi guys, i need a code to set 2 kind of skull to the monsters that are spawned, randomly, it would be nice if someone can help me :d

Thanks in Advance
Kind Regards
 
all monsters?

you can change this line in monster.cpp
[cpp]setSkull(mType->skull);[/cpp]
to this
[cpp]setSkull((Skulls_t) random_range(2, 4));[/cpp]

they'll get a skull with ID between 2 and 4
Code:
SKULL_YELLOW = 1
[B]SKULL_GREEN = [COLOR="red"]2[/COLOR]
SKULL_WHITE = [COLOR="red"]3[/COLOR]
SKULL_RED = [COLOR="red"]4[/COLOR][/B]
SKULL_BLACK = 5
 
the shortest way would be to add this line, but only monster summons are affected
Code:
					if(Monster* summon = Monster::createMonster(it->name))
					{
						addSummon(summon);
						[B][COLOR="red"]summon->setSkull(SKULL_NONE);[/COLOR][/B]
 
summons summoned by me with the command /s and scripts who convice creatures
they get skulls too, i need that only the spawned monsters get the skulls not summoned monsters :c
 
Last edited:
monster.cpp
Code:
bool Monster::convinceCreature(Creature* creature)
{
	Player* player = creature->getPlayer();
	if(player && !player->hasFlag(PlayerFlag_CanConvinceAll) && !mType->isConvinceable)
		return false;

	Creature* oldMaster = NULL;
	if(isSummon())
		oldMaster = getMaster();

	if(oldMaster)
	{
		if(oldMaster->getPlayer() || oldMaster == creature)
			return false;

		oldMaster->removeSummon(this);
	}

	setFollowCreature(NULL);
	setAttackedCreature(NULL);
	destroySummons();

	creature->addSummon(this);
[B][COLOR="red"]	setSkull(SKULL_NONE);
	g_game.updateCreatureSkull(this);[/COLOR][/B]
game.cpp
Code:
ReturnValue Game::placeSummon(Creature* creature, const std::string& name)
{
	Monster* monster = Monster::createMonster(name);
	if(!monster)
		return RET_NOTPOSSIBLE;

	// Place the monster
	creature->addSummon(monster);
	[B][COLOR="red"]monster->setSkull(SKULL_NONE);[/COLOR][/B]
 
Back
Top