Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 09-04-2006, 03:15 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
While normally I disapprove of serverr. strings for a lot of uses, a radio is a definite use for them. You can access them clientside, which means you don't have to triggerclient() to everyone on the server when you are changing song, and you can only write to them on the serverside for security.

It seems overkill to use a database, and triggerclient in this way.
Reply With Quote
  #3  
Old 09-04-2006, 03:24 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
I hate using serverr strings as well. The script could even be integrated into Control NPC anyways =P

Maybe i'll make a serverr strings version as well =)
Reply With Quote
  #4  
Old 09-04-2006, 03:43 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
I preffer using a database since server and serverr strings are limited in length.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #5  
Old 09-05-2006, 05:35 PM
KuJi KuJi is offline
Banned
Join Date: Apr 2004
Location: Staten Island, New York
Posts: 2,202
KuJi will become famous soon enough
Send a message via ICQ to KuJi Send a message via AIM to KuJi Send a message via MSN to KuJi Send a message via Yahoo to KuJi
Eh, twinny - thats not the updated one on GX atm. =o
Reply With Quote
  #6  
Old 09-06-2006, 12:25 AM
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
I kept working on the GX one -_-
Reply With Quote
  #7  
Old 08-07-2009, 04:23 AM
GULTHEX GULTHEX is offline
Registered User
Join Date: Jul 2008
Posts: 148
GULTHEX can only hope to improve
when i post it in it has errors what do i do
Reply With Quote
  #8  
Old 08-07-2009, 04:32 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by GULTHEX View Post
when i post it in it has errors what do i do
It would be nice if you told us what errors you're receiving.... Also, bravo on bumping a 3-year-old thread.
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #9  
Old 08-07-2009, 11:39 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Programmer View Post
Also, bravo on bumping a 3-year-old thread.
This is the code gallery. If someone use a script, why the hell shouldn't the be able to post about errors in that scripts thread?
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #10  
Old 08-07-2009, 12:08 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
Quote:
Originally Posted by GULTHEX View Post
when i post it in it has errors what do i do
What errors were they?

Also, looking at this code made me laugh...so many things I would have done differently and I love my, "open source" comment at the top
Reply With Quote
  #11  
Old 08-08-2009, 12:48 AM
GULTHEX GULTHEX is offline
Registered User
Join Date: Jul 2008
Posts: 148
GULTHEX can only hope to improve
lets see

Quote:
Originally Posted by Twinny View Post
What errors were they?

Also, looking at this code made me laugh...so many things I would have done differently and I love my, "open source" comment at the top
there is like 10 errors

Script compiler output for radio:
<b>error: unexpected token: * at line 1: * Made by Twinny under Open Source */
<b>error: missing semicolon at line 1: * Made by Twinny under Open Source */
<b>error: unexpected token: / at line 1: * Made by Twinny under Open Source */
Weapon/GUI-script radio added/updated by GULTHEX
<b>Script: Function addcontrol not found at line 102 in script of radio
<b>Script: Function addcontrol not found at line 94 in script of radio
<b>Script: Function addcontrol not found at line 113 in script of radio
<b>Script: Function addcontrol not found at line 122 in script of radio
<b>Script: Function addcontrol not found at line 131 in script of radio
<b>Script: Function addcontrol not found at line 140 in script of radio
<b>Script: Function addcontrol not found at line 147 in script of radio
<b>Script: Function addcontrol not found at line 154 in script of radio
<b>Script: Function addcontrol not found at line 82 in script of radio
<b>Script: Function Radio_Window.setText not found at line 163 in script of radio
<b>Script: Function triggerserver not found at line 169 in script of radio
<b>Script: Function GraalControl.addControl not found at line 165 in script of radio
Reply With Quote
  #12  
Old 08-08-2009, 02:33 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by GULTHEX View Post
Script compiler output for radio:
error: unexpected token: * at line 1: * Made by Twinny under Open Source */
error: missing semicolon at line 1: * Made by Twinny under Open Source */
error: unexpected token: / at line 1: * Made by Twinny under Open Source */
I'm going to take a wild guess and say that you copy+paste'd it wrong. Does your 'radio' WNPC happen to have /* as the first two character?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #13  
Old 08-08-2009, 03:26 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
The "Function addcontrol not found" means you're trying to use the special GUI Control syntax on serverside, which doesn't work obviously because GraalControl is clientside.
__________________
Reply With Quote
  #14  
Old 08-08-2009, 09:25 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Rofl I love the "Leave my Name in " part xD
Reply With Quote
  #15  
Old 08-08-2009, 12:07 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
Quote:
Originally Posted by GULTHEX View Post
there is like 10 errors
errors
And it looks like those 10 errors are mainly because you copied+pasted incorrectly. The fact that the first line was complaining about the comment should have given you some thought. Try some debugging next time

Quote:
Originally Posted by Pelikano View Post
Rofl I love the "Leave my Name in " part xD
Well heck yeah. I'm all for putting my strange music up on random server radios
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.