Thread: Radio Example
View Single Post
  #1  
Old 09-04-2006, 02:36 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Radio Example

I made a simple Radio/DJ Weapon which some servers may find useful. I made it for Graal X but I like sharing my work =)

As with any additions I have posted/will post - it is Add and Play. Simply create the Radio weapon (Call it anything) and a DBNPC named RadioDB. Preload with 3 Lemon Jelly songs found off Windows Media. Good stuff to listen to while coding.

This is the weapon
PHP Code:
/* Made by Twinny under Open Source */
/* Must leave this notice in as well as supply */
/* Anyone who asks for the code with the code */
function onActionServerSide()
{
  
/* Player Tunes */
  
if (params[0] == "change")
  {
    
temp.array = RadioDB.Song(params[1]);
    
clientr.radio = {temp.array[0],temp.array[1],temp.array[2],
                     
temp.array[3],temp.array[4]};
    
player.triggerclient(this.name,"change");
  }
  
/* Player Initial Update */
  
else  if (params[0] == "initial")
  {
    
temp.array = RadioDB.Song(params[1]);
    
clientr.radio = {temp.array[0],temp.array[1],temp.array[2],
                      
temp.array[3],temp.array[4]};
    
player.triggerclient(this.name,"update");
  }
  
/* Song Has Changed */
  
else if (params[0] == "setsong")
  {  
    
RadioDB.SetSong(params[1],params[2],params[3],params[4]);
    for (
i=0;i<allplayers.size();i++) {
      
with (allplayers[i]) {
          
player.triggerclient("gui"this.name"fupdate",params[0]);
      }
    }
  }
  
/* Player Changed Message */
  
else if (params[0] == "setchat")
  {
    
RadioDB.SetChat(params[1],params[2],params[3],params[4]);
    for (
i=0;i<allplayers.size();i++) 
    {
      
with (allplayers[i]) 
      {
          
player.triggerclient("gui"this.name"fupdate",params[0]);
        }
      }
    }
   
}
  
//#CLIENTSIDE
function onCreated()
{
  
client.radio = {0,1};
  
CreateGui();
  
this.allowed = {"Twinny","Add Peoples"}; //Leave my name in ;) 
}

function 
onActionClientSide()
{
  if (
params[0] == "update")
  {
  
Radio_Title.setText(clientr.radio[4]);
  
Radio_DJ.setText(clientr.radio[2]);
  
Radio_Text.setText(clientr.radio[1]);
  
Radio_Head.image clientr.radio[3];
  }
  else if (
params[0] == "change")
  {
  
Radio_Title.setText(clientr.radio[4]);
  
Radio_DJ.setText(clientr.radio[2]);
  
Radio_Text.setText(clientr.radio[1]);
  
Radio_Head.image clientr.radio[3];
  
play(clientr.radio[0]);
  }
  else if (
params[0] == "fupdate")
  {
    if (
params[1] == client.radio[1])
    {
      
triggerserver("gui",this.name,"change",client.radio[1]);
    }
  }   
}
function 
CreateGUI()
{
  new 
GuiWindowCtrl(Radio_Window)
  {
    
profile       "GuiBlueWindowProfile";
    
extent        "300 135";
    
x             = (screenwidth Radio_Window.width) -10;
    
y             = (screenheight Radio_Window.height) -10;
    
text          "Radio";
    
destroyonhide true;
    
canmaximize   false;
    
canclose      false;
    
visible       true;
  
    new 
GuiScrollCtrl(Radio_ImageScroll)
    {
      
profile     "GuiBlueScrollProfile";
      
position    "12 25";
      
extent      "40 40";
      
hscrollbar  "dynamic";
      
vscrollbar  "dynamic";
      
      new 
GuiShowImgCtrl(Radio_Head)
      {
        
position "1 1";
        
image    clientr.radio[3];
        
height   "30";
        
width    "35";
        
offsetx  0;
        
offsety  = -62;
      }      
    }
    
     new 
GuiMLTextCtrl(Radio_Title)
     {
       
useownprofile    true;
       
profile          "GuiBlueMLTextProfile";
       
profile.fontsize 16;
       
position         "55 25";
       
extent           "200 30";
       
text             "title";
     }
     new 
GuiTextCtrl(Radio_DJ)
     {
       
useownprofile    true;
       
profile          "GuiBlueMLTextProfile";
       
profile.fontsize 16;
       
position         "55 50";
       
extent           "200 30";
       
text             "DJ";
     }
     new 
GuiTextCtrl(Radio_Text)
     {
       
useownprofile    true;
       
profile          "GuiBlueMLTextProfile";
       
profile.fontsize 16;
       
position         "10 75";
       
extent           "250 30";
       
text             "Text";
     }
     new 
GuiButtonCtrl(Radio_Toggle)
     {
       
profile  "GuiBlueButtonProfile";
       
position "8 100";
       
extent   "75 25";
       
text     "Turn On";
     }
     new 
GuiButtonCtrl(Radio_Up)
     {
       
profile  "GuiBlueButtonProfile";
       
position "110 100";
       
extent   "75 25";
       
text     "Tune Up";
     }
     new 
GuiButtonCtrl(Radio_Down)
     {
       
profile  "GuiBlueButtonProfile";
       
position "210 100";
       
extent   "75 25";
       
text     "Tune Down";
     }      

  }
  
Radio_Window.setText("Radio: Channel" SPC client.radio[1]);
  
Initial();
  
GraalControl.addControl(Radio_Window);
}
function 
Initial()
{
  
triggerserver("gui",this.name,"intial",1);
}

function 
Radio_Toggle.onAction()
{
  if (
client.radio[0] == false)
  {
    
client.radio[0] = true;
    
Radio_Window.setText("Radio: Channel" SPC client.radio[1]);
    
Radio_Toggle.setText("Turn Off");
    
play(clientr.radio[0]);
  }
  else
  {
    
client.radio[0] = false;
    
Radio_Window.setText("Radio: Turned Off");
    
Radio_Toggle.setText("Turn On");
    
stopmidi();
  }
}


function 
Radio_Up.onAction()
{
  if (
client.radio[1] < 10)
  {
    
client.radio[1] ++;
    
triggerserver("gui",this.name,"change",client.radio[1]);
    
Radio_Window.setText("Radio: Channel" SPC client.radio[1]);
    
  }
}

function 
Radio_Down.onAction()
{
  if (
client.radio[1] > 1)
  {
    
client.radio[1] --;
    
triggerserver("gui",this.name,"change",client.radio[1]);
    
Radio_Window.setText("Radio: Channel" SPC client.radio[1]);
  }
}
    
/* Voice Commands */
function onPlayerChats()
{
  if (
this.allowed.index(player.account) => 0)
  {
     if (
player.chat.starts("/setsong"))
     {
       
triggerserver("gui"name"setsong"client.radio[1], player.chat.substring(9,-4), player.nickplayer.headimg);
     }
     if (
player.chat.starts("/setmsg"))
     {
       
triggerserver("gui"name"setchat"client.radio[1], player.chat.substring(8,-4), player.nickplayer.headimg);
    }
  }

And this is the DBNPC

PHP Code:
function onCreated()
{
  
this.radio_1 = {"http://www.wyell.com/musika/Lemon%20Jelly%20-%20Lost%20Horizons%20-%2005%20-%20Nice%20Weather%20For%20Ducks.mp3","Lemon Jelly - Nice Weather For Ducks","Twinny","head983.gif","Lemon Jelly 1"};
  
this.radio_2 = {"http://www.thezapgun.com/blog/mp3/NervousTension.mp3","Lemon Jelly - Nervous Tension","Twinny","head983.gif","Lemon Jelly 2"};
  
this.radio_3 = {"http://www.thezapgun.com/blog/mp3/ATuneForJack.mp3","Lemon Jelly - A Tune for Jack","Twinny","head983.gif","Lemon Jelly 3"};
  for (
temp.4temp.11temp.i++)
  {
  
this.("radio_"@temp.i) = {"No Song","No Song","No DJ",0,"Station " temp.i};

  }
}
    
public function 
Song(st)
{
  if (
this.("radio_"@st) != NULL)
  {
    return 
this.("radio_"@st);
  }
  else return 
false;
}

public function 
SetSong(st,song,nk,hd)
{
  
this.("radio_"@st)[0] = song;
  
this.("radio_"@st)[2] = nk;
  
this.("radio_"@st)[3] = hd;
}

public function 
SetChat(st,msg,nk,hd)
{
  
this.("radio_"@st)[1] = msg;
  
this.("radio_"@st)[2] = nk;
  
this.("radio_"@st)[3] = hd;

Any and all improvements will be greatly appreciated =)
Reply With Quote