• 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!

Monster random level...

Status
Not open for further replies.

crimm

New Member
Joined
Dec 7, 2008
Messages
44
Reaction score
4
Location
Poland
Hi, I want to do 'monster level', but something I did not quit. Here is the screen:



Please help me.

Here is code

C++:
bool Spawn::addMonster(const std::string& _name, const Position& _pos, Direction _dir, uint32_t _interval)
{
    if(!g_game.getTile(_pos))
    {
        std::cout << "[Spawn::addMonster] NULL tile at spawn position (" << _pos << ")" << std::endl;
        return false;
    }

    MonsterType* mType = g_monsters.getMonsterType(_name);
    if(!mType)
    {
        std::cout << "[Spawn::addMonster] Cannot find \"" << _name << "\"" << std::endl;
        return false;
    }

    if(_interval < interval)
        interval = _interval;

    spawnBlock_t sb;
    sb.mType = mType;
    sb.pos = _pos;
    sb.direction = _dir;
    sb.interval = _interval;
    sb.lastSpawn = 0;

    int32_t r = random_range(1,7);
    std::stringstream Msg;
    Msg << r;
    mType->name = mType->name + " [" + Msg.str().c_str() + "]";;
    mType->nameDescription = "a " + mType->name;
    mType->experience = mType->experience + (mType->experience/10 * r);
    mType->health = mType->health + (mType->health/10 * r);
    mType->healthMax = mType->healthMax + (mType->healthMax/10 * r);

    uint32_t spawnId = (int32_t)spawnMap.size() + 1;
    spawnMap[spawnId] = sb;
    return true;
}

I do not know why this is happening.
Sorry for bad english, use translate.
 
Last edited by a moderator:
Nice script, could someone fix it and tell me where can i put it? in dev cpp
 
Try replace this:
C++:
mType->name = mType->name + " [" + Msg.str().c_str() + "]";;[/cpp]
with:
[cpp]for (int i = 0; i < mType->name.length(); ++i) {
    if (isdigit(mType->name[I]))
        mType->name[I] = '\0';
}
mType->name += " [" + Msg.str().c_str() + "]";
[/I][/I]
 
Last edited by a moderator:
How about this?
Code:
std::string level = Msg.str().c_str();
int idx = 0;
for (int i = 0; i < mType->name.length() && idx < level.length(); ++i, ++idx) {
	if (isdigit(mType->name[i])) {
		mType->name[i] = level[idx];
	} else {
		mType->name += " [" + level + "]";
		break;
	}
}
 
Same as first post.

Code:
20:31 You see a Wolf [4] [3] [4] [1] [1] [6] [4] [6] [2] [2] [1] [3] [5] [1] [7] [4] [4] [4] [7] [5] [3] [6] [5] [3] [1] [7] [1] [1] [5] [6] [6].
Health: [318232 / 318232].
Position: [X: 126] [Y: 432] [Z: 7].



Maybe somewhere else is problem? I tryied move it to other function which creating monster in spawn (bool Spawn::spawnMonster) but it only decreases health (and mana I think).

Code:
20:34 You see a Wolf [7] [3] [6] [6] [2] [7] [3] [5] [3] [5] [4] [1] [5] [7] [1] [6] [3] [3] [3] [1] [2] [7] [4] [1] [1] [7] [3] [7] [5] [1] [1].
Health: [438 / 438].
Position: [X: 126] [Y: 432] [Z: 7].
 
Try this, although I don't think it is effective to do monster level system like this..

C++:
std::string level = Msg.str().c_str();
int idx = 0;
bool hadLevel = false;
for (int i = 0; i < mType->name.length() && idx < level.length(); ++i, ++idx) {
    if (isdigit(mType->name[I])) {
        mType->name[I] = level[idx];
        hadLevel = true;
    } 
}
if (!hadLevel)
    mType->name += " [" + level + "]";
[/I][/I]
 
Last edited by a moderator:
Same.


Yea I also think its not effective. I think that is better to create new "attribute" to monster which will we can edit in monster file something like this:

Code:
experience="0" speed="200" [COLOR="#FF0000"]minLevel="12" maxLevel="15"[/COLOR] manacost="250">

And then random_range and also add code to increases monster health and mana.
 
I managed to do something like that, but now the problem is that, for example: Each 'Rat' has the same 'random level'. I think the problem lies in the function 'loadMonster' because it loads only once or only once draws 'level'. Could someone help me? Here's the code:
http://paste.org/pastebin/view/36466

Screen:

 
Last edited:
bump

bump

bump

where the f* are the pro programmers? :C
bump*
 
Last edited by a moderator:
yeah, you can simply use a onSpawn function and use my function to set the monster name, it should work with no problems
 
Status
Not open for further replies.
Back
Top