Jump to content
RAGE Multiplayer Community

Event - Instance Variables


Recommended Posts

Posted (edited)

Hey there.

 

I've one small question regarding instance-variables, when an event get triggered.

 

I've got this little file called XMarker.cs

using GTANetworkAPI;

public delegate void MyFoo();

public class XMarker : Script {
    public Marker jobStartMarker { get; set; }
    public ColShape jobStartCol { get; set; }
    public MyFoo foo;

    public XMarker()
    {

    }

    public XMarker(MyFoo callback) 
    {      
        this.jobStartMarker = NAPI.Marker.CreateMarker(0, new Vector3(-420.21115, 1133.7943, 325.90845), new Vector3(), new Vector3(), 1f, new Color(255, 0, 0));
        this.jobStartCol = NAPI.ColShape.CreateSphereColShape(new Vector3(-420.21115, 1133.7943, 325.90845), 1f);     
        this.foo = callback;
    }

    [ServerEvent(Event.PlayerEnterColshape)]
    public void OnPlayerColShapeHit(ColShape cl, Player pl) 
    {
        
        // Is Null when the event gets triggered
        this.foo();

        if (cl == jobStartCol) {
            NAPI.Chat.SendChatMessageToPlayer(pl, "Job", "asdasdasdasdasd!");
        }
    }
}

 

And this little file:

public class ScriptTest : Script {
    public ScriptTest() {        
    }

    [ServerEvent(Event.ResourceStart)]
    public void myResourceStart() {
        var call = new MyFoo(this.littleFlowerPot);
        var test = new XMarker(call);

        test.foo();

    }

    public void littleFlowerPot()
    {
        NAPI.Util.ConsoleOutput("Poel :-)");
    }
}

My problem:
On the normal resource-start I get the debug-message: "Poel :-)".

However, I also want to access this callback when I enter the colshape.

Now my question:
 

Is there any way that I can access the variables within the instance when the events get triggered?
Or am I able to register a event to this specific colshape?

I read through several wiki-pages but wasn't able to find a way to create this kind of scenario.

Edited by civele
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...