background charaters hotspots

Started by shaungaryevans, Sun 19/10/2008 20:56:37

Previous topic - Next topic

shaungaryevans

can characters that you're not controlling but moving, activate hotspots; if yes how?

Khris

Are you talking about regions or actual hotspots? What do you mean by "activate" them?
I'd say yes, but we'll need more info, what are you trying to achieve?

RickJ

This can be done by maiing custom event handlers similar to the example below.  The repeatedly execute handler is a standard AGS event.  To create this you need to do a "room edit" and click on the lightning bolt icon in the properties panel of the editor.  You can edit your room script and enter the rest 9of the script.

The example is untested so you may have to clear any compile errors etc before you use it but it should give you some idea of what needs to be done. 

The room_RepExec() function will poll to see if a character is on a hotspot or whatever. 
Code: ags

// Custom Hotspot interactions
function NpcHotspotInteraction(Character *chr, Hotspot *ptr) {
        if (ptr==hThisHotspot) {
                // Do "This" stuff
        }
        else if (ptr==hThatHotspot) {
                // Do "That" stuff
        }
        else if (ptr==hTheOtherHotspot) {
                // Do "TheOther" stuff
        }
}

// Custom Inventory Interactions
function NpcInventoryInteraction(Character *chr, InventoryItem *ptr) {
        if (ptr==iThisInventoryItem) {
                // Do "This" stuff
        }
        else if(ptr==iThatInventoryItem) {
                // Do "That" stuff
        }
        else if(ptr==iTheOtherInventoryItem) {
                // Do "TheOther" stuff
        }
}

// Custom Object Interactions
function NpcObjectInteraction(Character *chr, Object *ptr) {
        if (ptr==oThisObject) {
                // Do "This" stuff
        }
        else if(ptr==oThatObject {
                // Do "That" stuff
        }
        else if(ptr==oTheOtherObject) {
                // Do "TheOther" stuff
        }
}

// Custom Region Interactions
function NpcRegionInteraction(Character *chr, Region *ptr) {
        if (ptr==oThisObject) {
                // Do "This" stuff
        }
        else if(ptr==oThatObject {
                // Do "That" stuff
        }
        else if(ptr==oTheOtherObject) {
                // Do "TheOther" stuff
        }
}

//  Custom NPC event handler
function NpcEventHandler(Character *chr) {
        int   x, y;

        // Translate character's room coordinates to screen coordinates
        x = chr.X-GetViewportX();
        y = chr.Y-GetViewportY();
        
        // Call custom  hotspot interaction handler
        if (Hotspot.GetAtScreenXY(x,y)!=null)  {
                NpcHotspotInteraction(Hotspot.GetAtScreenXY(x,y), chr);
        }
        // Call custom  inventory interaction handler
        else if (InventoryItem.GetAtScreenXY(x,y)!=null)  {
                NpcInventoryInteraction(InventoryItem.GetAtScreenXY(x,y), chr);
        }
        else if (Object.GetAtScreenXY(x,y)!=null)  {
                NpcObjectInteraction(Object.GetAtScreenXY(x,y), chr);
        }
        else if Region.GetAtScreenXY(chr.X,chr.y)!=null) {
                NpcRegionInteraction(Region.GetAtScreenXY(chr.X,chr.y), chr);
        }
}

// AGS Standard interaction handler - need to create this with lightning bolt icon
function room_RepExec() {

       NpcEventhandler(cSomeCharacter);
}

SMF spam blocked by CleanTalk