AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [TUT] Better Methodmaps tut (https://forums.alliedmods.net/showthread.php?t=260680)

nergal 12-26-2015 12:23

Re: [TUT] Better Methodmaps tut
 
ok there, the examples have real backing fields now.

I also modified the custom example that most plugins would likely use.

CSGOT 02-07-2016 11:07

Re: [TUT] Better Methodmaps tut
 
Nice Tutorial.
This really helped me alot.
Thanks OP

nergal 02-07-2016 12:59

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by CSGOT (Post 2390819)
Nice Tutorial.
This really helped me alot.
Thanks OP

no problem. If you have anymore questions, please don't hesitate to ask.

StSatan 02-09-2016 05:12

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by nergal (Post 2279534)

PHP Code:


int iHealth
[MAXPLAYERS+1];
int iAmmo[MAXPLAYERS+1];
float flSpeed[MAXPLAYERS+1];

methodmap Player
{
    public 
Player(int playerindex//constructor
    
{
        return 
view_as<Player>(playerindex); //make sure you do validity check on players
    
}
     
property int index 
    

        public 
get()                { return view_as<int>(this); } 
    }
    
property int Health
    
{
        public 
get() { return iHealth[this.index]; }
        public 
setint value ) { iHealth[this.index] = value; }
    }
    
property int Ammo
    
{
        public 
get() { return iAmmo[this.index]; }
        public 
setint value ) { iAmmo[this.index] = value; }
    }
    
property float Speed
    
{
        public 
get() { return flSpeed[this.index]; }
        public 
setfloat value ) { flSpeed[this.index] = value; }
    }
    public 
void GiveAmmo(int amount)
    {
        
this.Ammo += amount;
    }
    public 
void RemoveAmmo(int amount)
    {
        
this.Ammo -= amount;
    }
}

public 
void OnClientPutInServer(int client)
{
    
Playur player Player(client);
    if (
player.Health 1player.Health 100;
    if (
player.Ammo 1player.Ammo 50;
    if (
player.Speed 1.0player.Speed 300.0;



So in "normal" situation we can simply increase array:

PHP Code:

iHealth[index]++ 

or decrease

PHP Code:

iHealth[index]-- 

but with using methodmaps we can't type:

PHP Code:

index.Health++ 

am I right?

WildCard65 02-09-2016 08:14

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by StSatan (Post 2391340)
So in "normal" situation we can simply increase array:

PHP Code:

iHealth[index]++ 

or decrease

PHP Code:

iHealth[index]-- 

but with using methodmaps we can't type:

PHP Code:

index.Health++ 

am I right?

Nope.
Basically, what happens is SP will get the return value from the get() method and increment that by one, then it will call the set() method with the new value.
example:
PHP Code:

T.LOL.set(tT.LOL.get(t)++); //T is methodmap, LOL is property(type int), t is variable(type T) 


humbugtheman 02-21-2016 19:19

Re: [TUT] Better Methodmaps tut
 
Thanks for the tut - very clear!

nergal 05-27-2016 13:45

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by humbugtheman (Post 2395489)
Thanks for the tut - very clear!

No problem. If you have any questions, don't hesitate to ask!

sdz 05-27-2016 15:07

Re: [TUT] Better Methodmaps tut
 
Don't understand the tut at all honestly.
See this is why I just stay away from newdecls.

nergal 05-27-2016 18:49

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by EasSidezz (Post 2422550)
Don't understand the tut at all honestly.
See this is why I just stay away from newdecls.

what part do you not understand?

sdz 05-27-2016 23:27

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by nergal (Post 2422616)
what part do you not understand?

It's not you, it's me.


All times are GMT -4. The time now is 22:06.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.