ID:2708715
 
(See the best response by Ter13.)
Code:
mob
enemy
// when an enemy takes damage, make them target their attacker.
took_damage(damage, mob/attacker, Combat/combat)
..()

if(!target)
target = attacker

// now we'll define a specific enemy
blue_ooze
base_state = "blue-ooze"
icon_state = "blue-ooze-standing"
shadow_state = "ooze-shadow"

power = 4
speed = 5
defense = 5

health = 40
max_health = 40

base_speed = 1

abilities = list(new /Ability/EnemyAttack())

New()
..()
money = rand(1, 10)
if(src.level <= 10)
experience = 1
else
experience = 100

// we override the died proc to give enemies a chance to drop items
died()
noise('splat.wav')

if(prob(50))
new /item/health_potion(src)

if(prob(25))
new /item/sword(src)

..()


Problem description:I'm trying to get less xp when the player get a higher level but the "if condition" doesn't work, the player always get 100 XP

Looks like you are wanting to give the player exp but you are defining all this under New() in the monster.

Also could be that you are setting money randomly from 1 to 10 and then checking level to define experience for them.

So then I would assume you are setting level for base monsters somewhere in the chain to 10 or higher.
In response to Shadowkaroth
Shadowkaroth wrote:
Looks like you are wanting to give the player exp but you are defining all this under New() in the monster.

Also could be that you are setting money randomly from 1 to 10 and then checking level to define experience for them.

So then I would assume you are setting level for base monsters somewhere in the chain to 10 or higher.

ok but if setting this under New() is wrong then where is the right place to do it?

This is the leveling system

mob
var
level = 1
experience = 0
experience_needed = 250
money = 0


proc
description(full_description = 0)
if(full_description)
return "<b>Level [level]</b>"
else
return "Level [level]"

gain_experience(e)
set_experience(experience + e)

set_experience(e)
experience = e

check_level()

if(info_box)
info_box.refresh()

check_level()
while(experience >= experience_needed)
level += 1
level_up()
hp_up()

level_up()
experience_needed += (level)

hp_up()
max_health = src.max_health+5
health = max_health
health_meter.update()

gain_money(m)
set_money(money + m)


set_money(m)
money = m

if(info_box)
info_box.refresh()
None of what you've shown contains the right place to insert this code.

You will want to shim it into the place where you actually call gain_experience() for the killer. It's entirely likely that how this is set up makes how you are attempting this the incorrect approach though, because your base system seems to be set up polymorphically.

I can't say more without seeing the correct spot.
In response to Ter13
Ter13 wrote:
None of what you've shown contains the right place to insert this code.

You will want to shim it into the place where you actually call gain_experience() for the killer. It's entirely likely that how this is set up makes how you are attempting this the incorrect approach though, because your base system seems to be set up polymorphically.

I can't say more without seeing the correct spot.

i dont have a code to set gain experience to the player, the gain experience is called solely when a mob dies. so i ended up with this

        killed(mob/m)

if(quests)
for(var/Quest/q in quests)
q.killed(m)

if(client && m.lootable && src != m)
experience_and_money_gain(m.experience, m.money, m)
gain_experience(m.experience)
gain_money(m.money)


in the npc/mob spot when i put the experience code into the New() instance with the money, the code works well
blue_ooze
base_state = "blue-ooze"
icon_state = "blue-ooze-standing"
shadow_state = "ooze-shadow"

power = 4
speed = 5
defense = 5

health = 40
max_health = 40

base_speed = 1

abilities = list(new /Ability/EnemyAttack())

New()
..()
money = rand(1, 10)
experience = 100


i can get 100 xp from the mob with this code unless i use an if statement. when i use if statement it doesnt work at all. would you have any direction for me?

Run a test and confirm the level of the Ooze, it seemed with your if statement the Experience it granted on death was either 1 or 100 based on level.

So somewhere up the line it is having its level set to some value.. The code you showed last I see uses the experience variable of the monster to grant that as reward exp.

So that doesn't look wrong and confirms that the issue is that the experience variable is being set to 100 and not 1. Which we can tell from the if can only happen if there level is 0||null or higher than 10 on New().. so you may have forgot to set the level all together.

                if(src.level <= 10)
experience = 1
else
experience = 100


If you want the player to receive less exp you may want that to happen in get_exp(). As at the time of the creatures creation it has no idea the level of who is going to kill it.
In response to Shadowkaroth
Shadowkaroth wrote:
Run a test and confirm the level of the Ooze, it seemed with your if statement the Experience it granted on death was either 1 or 100 based on level.

So somewhere up the line it is having its level set to some value.. The code you showed last I see uses the experience variable of the monster to grant that as reward exp.

So that doesn't look wrong and confirms that the issue is that the experience variable is being set to 100 and not 1. Which we can tell from the if can only happen if there level is 0||null or higher than 10 on New().. so you may have forgot to set the level all together.

>
> if(src.level <= 10)
> experience = 1
> else
> experience = 100
>

If you want the player to receive less exp you may want that to happen in get_exp(). As at the time of the creatures creation it has no idea the level of who is going to kill it.

    killed(mob/m)

if(quests)
for(var/Quest/q in quests)
q.killed(m)
if(level < 50 && client && m.lootable && src != m)

experience_and_money_gain(m.experience, m.money, m)
gain_experience(m.experience)
if(level >= 50 && client && m.lootable && src != m)
only_money_gain(m.money, m)
gain_experience(m.experience/10)
gain_money(m.money)


i can set the xp gain using this but how can i set this proc for a specific mob? this proc is actually being called every single time an enemy dies and i want it to happen only to a few of them
In response to 0900
Best response
The reason what you are doing doesn't work, is because when the mob's created, we don't know who is going to kill it. We need to modify the amount of exp given based on who killed the mob, so we need to change how exp is given to the player when they kill a monster. Think this through. This means the relevant place to modify the exp is AFTER killed() has been called, but BEFORE gain_experience() has been called. So we need to target our edits there.

Alright. What you just showed me is where we want to include our code shim. What we need to do, is stop giving experience directly from the mob's experience variable. Instead, we need to get the amount of experience given from a function, and we need to pass that function information about the player who killed them. If we implement this function on /mob, we can override it further down the polymorphic hierarchy so that mob's child types can override this proc in their own way.

        killed(mob/m)

if(quests)
for(var/Quest/q in quests)
q.killed(m)

if(client && m.lootable && src != m)
var/exp = m.get_experience(src) //minor change here
experience_and_money_gain(exp, m.money, m)
gain_experience(exp)
gain_money(m.money)


Now let's define a new proc that will help us to implement this change:

mob
proc
get_experience(mob/killer)
return experience



And last, let's override this proc to add the level limitations to the mob:

mob/enemy/blue_ooze
get_experience(mob/killer)
if(killer.level>10)
return 1
else
return experience


There are better ways to do this, but this should put you on the right track.