Author Topic: Onscreen messages for multiple item pickups  (Read 2427 times)

Galavant Garde

  • Full Member
  • ***
  • Posts: 129
  • Cayelan Mendoza
    • View Profile
    • Galavant Garde - Dark Electro Disco Pop
    • Email
Onscreen messages for multiple item pickups
« on: December 15, 2014, 05:13:46 AM »
Hi there, slowly getting back into this and thought I'd start out sharing a little script I came up with this morning to resolve a problem I've had for a long time.  Say you pick up an item in game and a message is displayed on screen saying what it is...great!  But then say you pick up 3 items within a short succession of one another...if the display text changes as soon as you pick the new item up then the display telling you what the old item was will disappear too fast to read.  The solution is using arrays :-)

So I have one script that controls all of my onscreen messages that looks like this:

Code: [Select]
// DISPLAY MESSAGES CONTROLLER
// By Cayelan Mendoza

script.attachEvent(DIM3_EVENT_SPAWN,'startup');

var displayingMessage=false;
var msgArray=new Array(0);

function startup(obj)
{
    iface.text.show('Alert');
}

// Receive call

function displayMessage(obj,id)
{   
    playSound(obj,id);
    disposableVariable=msgArray.push(id);

    if (!displayingMessage) show(obj);
    else obj.event.chain(10,'show');
}

function show(obj)
{
    displayingMessage=true;
    newVar=msgArray.shift();
    iface.text.setText('Alert',decipherID(obj,newVar));

    if (msgArray.valueOf()==0) obj.event.chain(30,'end');
    else obj.event.chain(20,'show');
}

function end(obj)
{
    displayingMessage=false;
    iface.text.setText('Alert','');
}

// Message sounds

function playSound(obj,idy)
{
    switch (idy) {
   
    case 1:
    case 2:
    case 3:
    case 4:
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
    sound.playGlobalPlayer('Weapon Pickup',1);
    return;
   
    case 5:
    case 6:
    sound.playGlobalPlayer('Laser Charge',1);
    return;
   
    case 19:
    case 22:
    sound.playGlobalPlayer('Select',1);
    return;
   
    case 26:
    sound.playGlobalPlayer('Armor',1);
    return;
    }
}

// Message IDs

function decipherID(obj,idx)
{
    switch (idx) {
   
    case 1:
    return("Picked up some ammo");
   
    case 2:
    return("Picked up some rifle ammo");
   
    case 3:
    return("picked up some grenades");
   
    case 4:
    return("Picked up some rockets");
   
    case 5:
    return("Picked up some laser charge cells");
   
    case 6:
    return("Picked up an LP4 laser pistol");
   
    case 7:
    return("Picked up an UZI 9mm");
   
    case 8:
    return("Picked up an Assault Rifle");
   
    case 9:
    return("Picked up an automatic Sniper Rifle");
   
    case 10:
    return("Picked up an F2000S");
   
    case 11:
    return("Picked up an M1 Bazooka");
   
    case 12:
    sound.playGlobalPlayer('KeyPress',1);
    return("OBJECTIVE 1 COMPLETE");
   
    case 13:
    sound.playGlobalPlayer('KeyPress',1);
    return("OBJECTIVE 1 FAILED");
   
    case 14:
    sound.playGlobalPlayer('KeyPress',1);
    return("OBJECTIVE 2 COMPLETE");
   
    case 15:
    sound.playGlobalPlayer('KeyPress',1);
    return("OBJECTIVE 2 FAILED");
   
    case 16:
    sound.playGlobalPlayer('Select',1);
    return("Rendezvous point located");
   
    case 17:
    return("Dimitri has been killed");
   
    case 18:
    return("Door is locked - keycard required");
   
    case 19:
    return("Picked up a door keycard");
   
    case 20:
    return("ACCESS DENIED");
   
    case 21:
    sound.playGlobalPlayer('Adrenaline',1);
    return("Picked up an adrenaline capsule");
   
    case 22:
    return("Osiris package located");
   
    case 23:
    return("Warning - motorbike severely damaged");
   
    case 24:
    return("Security Centre unlocked");
   
    case 25:
    return("Security Centre locked");
   
    case 26:
    return("Picked up some body armor");
   
    case 27:
    return("Door is locked");
    }
}

So all I do is call the displayMessage function from any other script with the an item ID (see the cases under the decipherID function) and it will add that ID to an array of IDs which will all be displayed in succession using a chained delay so you'll be able to read all of them.

I've also added the playSound function so that some items will make a sound as soon as you pick them up and some will play them only when the relevant onscreen message is displayed.  This is so picking up ammo makes an ammo sound immediately and the message follows on whenever, whereas something like OBJECTIVE 1 COMPLETE will only make a sound when the message displays to make sure it's clear

Anyway, the hardest bit was getting the array to work properly so I hope this is helpful to someone  ;D

Koridar

  • Full Member
  • ***
  • Posts: 12
    • View Profile
    • Email
Re: Onscreen messages for multiple item pickups
« Reply #1 on: December 26, 2014, 12:30:40 PM »
Very impressive! I've been wondering how to do something like this for a long time, I've just not gotten quite that far along for it to be a problem yet. I thank you for now solving a problem that I didn't realize would have been a problem, but now it's not thanks to you!
Be a voice, not an echo


Current Incarnation: Timeless One

`teh1

  • OOK Dev
  • Global Moderator
  • Full Member
  • *****
  • Posts: 46
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: Onscreen messages for multiple item pickups
« Reply #2 on: December 26, 2014, 05:26:12 PM »
There's a better way to do this..

Still not the BEST way, as there are some other things you should change, but this is a direct conversion from your way to the better way without changing any of the ideas behind things being handled.

Code: [Select]
// DISPLAY MESSAGES CONTROLLER
// By Cayelan Mendoza

script.attachEvent(DIM3_EVENT_SPAWN,'startup');

var displayingMessage=false;
var msgArray=new Array(0);

var soundMapping =
{
    1: { sound: 'Weapon Pickup', description: 'Picked up some ammo' },
    2: { sound: 'Weapon Pickup', description: 'Picked up some rifle ammo' },
    3: { sound: 'Weapon Pickup', description: 'Picked up some grenades' },
    4: { sound: 'Weapon Pickup', description: 'Picked up some rockets' },
    5: { sound: 'Laser Charge', description: 'Picked up some laser charge cells' },
    6: { sound: 'Laser Charge', description: 'Picked up an LP4 laser pistol' },
    7: { sound: 'Weapon Pickup', description: 'Picked up an UZI 9mm' },
    8: { sound: 'Weapon Pickup', description: 'Picked up an Assault Rifle' },
    9: { sound: 'Weapon Pickup', description: 'Picked up an automatic Sniper Rifle' },
    10: { sound: 'Weapon Pickup', description: 'Picked up an F2000S' },
    11: { sound: 'Weapon Pickup', description: 'Picked up an M1 Bazooka' },
    12: { description: 'OBJECTIVE 1 COMPLETE', action: function(){ sound.playGlobalPlayer('KeyPress',1); } },
    13: { description: 'OBJECTIVE 1 FAILED' },
    14: { description: 'OBJECTIVE 2 COMPLETE', action: function(){ sound.playGlobalPlayer('KeyPress',1); } },
    15: { description: 'OBJECTIVE 2 FAILED', action: function(){ sound.playGlobalPlayer('KeyPress',1); } },
    16: { description: 'Rendezvous point located', action: function(){ sound.playGlobalPlayer('Select',1); } },
    17: { description: 'Dimitri has been killed' },
    18: { description: 'Door is locked - keycard required' },
    19: { sound: 'Select', description: 'Picked up a door keycard' },
    20: { description: 'ACCESS DENIED' },
    21: { description: 'Picked up an adrenaline capsule', action: function(){ sound.playGlobalPlayer('Adrenaline',1); } },
    22: { sound: 'Select', description: 'Osiris package located' },
    23: { description: 'Warning - motorbike severely damaged' },
    24: { description: 'Security Center unlocked' },
    25: { description: 'Security Center locked' },
    26: { sound: 'Armor', description: 'Picked up some body armor' },
    27: { description: 'Door is locked' },
}

function startup(obj)
{
    iface.text.show('Alert');
}

// Receive call

function displayMessage(obj,id)
{
    playSound(obj,id);
    disposableVariable=msgArray.push(id);

    if (!displayingMessage) show(obj);
    else obj.event.chain(10,'show');
}

function show(obj)
{
    displayingMessage=true;
    newVar=msgArray.shift();
    iface.text.setText('Alert',decipherID(obj,newVar));

    if (msgArray.valueOf()==0) obj.event.chain(30,'end');
    else obj.event.chain(20,'show');
}

function end(obj)
{
    displayingMessage=false;
    iface.text.setText('Alert','');
}

// Message sounds

function playSound(obj,idy)
{
    if(idy in soundMapping && 'sound' in soundMapping[idy])
    {
        sound.playGlobalPlayer(soundMapping[idy].sound, 1);
    }
}

// Message IDs

function decipherID(obj,idx)
{
    if(idx in soundMapping)
    {
        if('action' in soundMapping[idx])
        {
            soundMapping[idx].action();
        }
       
        if('description' in soundMapping[idx])
        {
            return soundMapping[idx].description;
        }
    }
}
~Ryan

http://spiralnebuladev.com/ || Visit Spiral Nebula Development

Oddity007 wrote:
`teh1: 1) I must go get my chicken wings, like all men with african ancestry 2) I shall blog about dat.

Galavant Garde

  • Full Member
  • ***
  • Posts: 129
  • Cayelan Mendoza
    • View Profile
    • Galavant Garde - Dark Electro Disco Pop
    • Email
Re: Onscreen messages for multiple item pickups
« Reply #3 on: January 05, 2015, 12:01:34 PM »
that IS more efficient, thanks Ryan!  ;D

`teh1

  • OOK Dev
  • Global Moderator
  • Full Member
  • *****
  • Posts: 46
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: Onscreen messages for multiple item pickups
« Reply #4 on: January 05, 2015, 07:38:19 PM »
Definitely. Hash maps are pretty darned quick, and certainly make life easy for many things...
~Ryan

http://spiralnebuladev.com/ || Visit Spiral Nebula Development

Oddity007 wrote:
`teh1: 1) I must go get my chicken wings, like all men with african ancestry 2) I shall blog about dat.