Tag OnPlayerTouchesObject

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
weerwolf
Posts: 603
Joined: 15 Jun 2010, 21:21
Location: Wijchen, Netherlands
Contact:

Tag OnPlayerTouchesObject

Post by weerwolf »

Moin,

I placed a rocket item on the map. I figured out to catch the event. Now i want to show a bigmessage with the objects tag, which is "Rocket"
However the script returns a error with null object or parameter not in array

Code: Select all

	else if (Event.Type == CSmModeEvent::EType::OnPlayerTouchesObject)
	{
		if (Event.Landmark.Tag == "Rocket")
		{
			declare Message = Event.Landmark.Tag;
			Message::SendBigMessage(Message, 5000, 1);
		}	
	}
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: Tag OnPlayerTouchesObject

Post by steeffeen »

the Landmark property is only filled for events that depend on landmarks
the PlayerTouchesObject event depends on an object so you could access the property CSmModeEvent::Object
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    User avatar
    weerwolf
    Posts: 603
    Joined: 15 Jun 2010, 21:21
    Location: Wijchen, Netherlands
    Contact:

    Re: Tag OnPlayerTouchesObject

    Post by weerwolf »

    tnx steeffeen

    Unfortunally this is the point i guess where i get lost.

    So after this event happens (the player touches the object), i should read the properties of the object
    with that? Or is the object the event itself?

    Code: Select all

       else if (Event.Type == CSmModeEvent::EType::Object)
       {
          if (Event.Landmark.Tag == "Rocket")
          {
             declare Message = Event.Landmark.Tag;
             Message::SendBigMessage(Message, 5000, 1);
          }   
       }
    or someting like this

    Code: Select all

       else if (Event.Type == CSmModeEvent::EType::OnPlayerTouchesObject)
       {
          declare Object <=> CSmModeEvent::EType::Object;
          if (Object.Landmark.Tag == "Rocket")
          {
             declare Message = Object.Landmark.Tag;
             Message::SendBigMessage(Message, 5000, 1);
          }   
       }
    User avatar
    Eole
    Nadeo
    Nadeo
    Posts: 1265
    Joined: 26 Apr 2011, 21:08

    Re: Tag OnPlayerTouchesObject

    Post by Eole »

    What Steeffeen wants to say is that not all properties of the Event are filled. Some stay Null because they are not pertinent. For example Event.Victim is null on an OnShoot event because there can't be a victim in this case, only an Event.Shooter.

    It's the same thing for the OnPlayerTouchesObject event. Event.Landmark is Null because touching an object doesn't necessarily mean that the player touched a landmark. However Event.Object will contains the informations about the object the player just touched. And from there you can access the landmark the object is linked to (if any) : Event.Object.AnchorLandmark.
    Contribute to the ManiaPlanet documentation on GitHub
    A question about ManiaScript? Ask it here!
    User avatar
    weerwolf
    Posts: 603
    Joined: 15 Jun 2010, 21:21
    Location: Wijchen, Netherlands
    Contact:

    Re: Tag OnPlayerTouchesObject

    Post by weerwolf »

    as a unexpierienced coder fun and frustration come as waves on water :XD
    Basically i think i dont yet fully understand wat information is getting back at me when i call someting and how its presented.
    In php i usually can provide myself more information by using a var_dump :roflol:

    In this case i am trying to do an action when someone touches a item. For example the item called rocket. And then do something with it. Either send a message, change weapon, spawn a bot etc

    Code: Select all

    Event.Type == CSmModeEvent::EType::OnPlayerTouchesObject
    I understand that this line is correct cause it will see that im touching a object (any object)

    Code: Select all

    declare CSmObject Object <=> Event.Object;
    I think this will store the specifications of the touched object in Object
    But what is stored? Im i correct if im looking at this page: http://maniascript.team-devota.com/stru ... bject.html

    :idea:
    User avatar
    Eole
    Nadeo
    Nadeo
    Posts: 1265
    Joined: 26 Apr 2011, 21:08

    Re: Tag OnPlayerTouchesObject

    Post by Eole »

    Oups, looking at the doc you linked I see that you don't have access yet to the new "AnchorLandmark" property on CSmObject. It's only available in our dev build for now. Sorry for the confusion. :?

    However the documentation you linked is also not updated to the latest release of Maniaplanet. Check this topic, people link their doc there when they update it.

    So you have two solutions. If you are using a different 3d model for each of your pick up you can use Event.Object.ModelId to find out which kind of object was picked.

    Otherwise you can take a look at the combo game mode script where we are doing something pretty similar. The interesting parts are the Combo_SpawnObjects() function, the OnPlayerTouch event and the PickUpObject() function.
    Each time I spawn an object on an anchor I save the anchor name in the object with a "declare for" variable. Then when the object is picked up I just access this variable to find the anchor.
    weerwolf wrote:

    Code: Select all

    Event.Type == CSmModeEvent::EType::OnPlayerTouchesObject
    I understand that this line is correct cause it will see that im touching a object (any object)
    Exact.
    weerwolf wrote:

    Code: Select all

    declare CSmObject Object <=> Event.Object;
    I think this will store the specifications of the touched object in Object
    But what is stored? Im i correct if im looking at this page: http://maniascript.team-devota.com/stru ... bject.html
    :idea:
    That's also right.
    Contribute to the ManiaPlanet documentation on GitHub
    A question about ManiaScript? Ask it here!
    User avatar
    weerwolf
    Posts: 603
    Joined: 15 Jun 2010, 21:21
    Location: Wijchen, Netherlands
    Contact:

    Re: Tag OnPlayerTouchesObject

    Post by weerwolf »

    Eole wrote:Oups, looking at the doc you linked I see that you don't have access yet to the new "AnchorLandmark" property on CSmObject. It's only available in our dev build for now. Sorry for the confusion.
    :evil: :roflol:
    Thanks Eole, i will take a look at the combo script
    User avatar
    weerwolf
    Posts: 603
    Joined: 15 Jun 2010, 21:21
    Location: Wijchen, Netherlands
    Contact:

    Re: Tag OnPlayerTouchesObject

    Post by weerwolf »

    Image
    not only my brain ....
    I'm becoming a star at crashing maniaplanet .....
    Post Reply

    Return to “ManiaScript”

    Who is online

    Users browsing this forum: No registered users and 1 guest