Request Help defining player

Mollieshane

Banned
Banned
Nov 6, 2018
82
0
18
Hello, i'm trying to make a spell and i've got most of it down however, i cant seem to define the player ive looked through tons of the source but came up empty the piece im trying to define is

PlayerObject player = player;

it says its not set to the instance of an object and im not sure how to define it i have tried

PlayerObject Player = (PlayerObject)ob

but this also doesnt work, any help would be appreciated.
 

Mollieshane

Banned
Banned
Nov 6, 2018
82
0
18
hemorrhage only attacks from behind it checks both players directions here

if (player.Direction == targets.Direction)

but crashes because player isnt defined properly
 
Upvote 0

IceMan

Hero's Act Mir 2
Legendary
Apr 17, 2003
8,544
2
369
350
i dont remember it crashing on the master code? Did you compare to that?
 
Upvote 0

Mollieshane

Banned
Banned
Nov 6, 2018
82
0
18
nah, i mean i changed hemorrhage to make it work only from behind sorta like backstab but when it checks your facing the back of the player it crashes because PlayerObject player = *****; isnt defined because im not sure what to put there.

---------- Post Merged on 13-02-2019 at 02:47 PM ---------- Previous Post was on 12-02-2019 at 11:17 PM ----------

Can any one help with this please no one seems to reply back after the mention of backstab?
Thanks
 
Upvote 0

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
nah, i mean i changed hemorrhage to make it work only from behind sorta like backstab but when it checks your facing the back of the player it crashes because PlayerObject player = *****; isnt defined because im not sure what to put there.

---------- Post Merged on 13-02-2019 at 02:47 PM ---------- Previous Post was on 12-02-2019 at 11:17 PM ----------

Can any one help with this please no one seems to reply back after the mention of backstab?
Thanks

Can't you look at the trading system ? Just do the opposite to what that checks
 
Upvote 0

Chriz

Captain Lurker
VIP
Mar 24, 2003
1,158
277
335
LOMCN
Difficult to help if you don't post code lol which player are you trying to get? Attacker or target?
 
Upvote 0

Mollieshane

Banned
Banned
Nov 6, 2018
82
0
18
Code:
                #region BackStab                magic = GetMagic(Spell.BackStab);
                Direction = Direction;
[COLOR=#ff0000]                PlayerObject player = ;[/COLOR]
                MapObject targets = player.Target;


                if (magic != null)
                {
                    
                    {
                        if (player.Direction == targets.Direction)
                        damageFinal = magic.GetDamage(damageBase);
                         LevelMagic(magic);
                        S.ObjectEffect ef = new S.ObjectEffect { ObjectID = ob.ObjectID, Effect = SpellEffect.BackStab };


                        CurrentMap.Broadcast(ef, ob.CurrentLocation);


                        if (ob == null || ob.Node == null) continue;


                        long calcDuration = magic.Level * 2 + Luck / 6;


                        ob.ApplyPoison(new Poison
                        {
                            Duration = (calcDuration <= 0) ? 1 : calcDuration,
                            Owner = this,
                            PType = PoisonType.Bleeding,
                            TickSpeed = 1000,
                            Value = MaxDC + 1
                        }, this);


                        ob.OperateTime = 0;
                        BackStab = false;
                    }
                }
                #endregion

not able to define player so the script causes crashes, im trying to define the attacker not the target.

Thanks for the help
 
Upvote 0

Chriz

Captain Lurker
VIP
Mar 24, 2003
1,158
277
335
LOMCN
If thats within the PlayerObject class then just use the keyword 'this':

PlayerObject player = this;

or change your variables to exclude player.
 
Upvote 0

Mollieshane

Banned
Banned
Nov 6, 2018
82
0
18
just checked and now it errors on the if (player.Direction == target.Direction) for reason "Object reference not set to an instance of an object."
 
Upvote 0

Chriz

Captain Lurker
VIP
Mar 24, 2003
1,158
277
335
LOMCN
just checked and now it errors on the if (player.Direction == target.Direction) for reason "Object reference not set to an instance of an object."

Whenever you want to reference a property of an object, you should first check that it is not null.

if (player != null && target != null && player.Direction == targets.Direction)

or the short hand version ::

if (player?.Direction == targets?.Direction)

This will return false if either objects are null instead of throwing an exception.
 
Upvote 0