PDA

View Full Version : Radio Example


Twinny
09-04-2006, 02:36 PM
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

/* 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.nick, player.headimg);
}
if (player.chat.starts("/setmsg"))
{
triggerserver("gui", name, "setchat", client.radio[1], player.chat.substring(8,-4), player.nick, player.headimg);
}
}
}


And this is the DBNPC


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.i = 4; temp.i < 11; temp.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 =)

Skyld
09-04-2006, 03:15 PM
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.

Twinny
09-04-2006, 03:24 PM
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 =)

xXziroXx
09-04-2006, 03:43 PM
I preffer using a database since server and serverr strings are limited in length.

KuJi
09-05-2006, 05:35 PM
Eh, twinny - thats not the updated one on GX atm. =o

Twinny
09-06-2006, 12:25 AM
I kept working on the GX one -_-

GULTHEX
08-07-2009, 04:23 AM
when i post it in it has errors what do i do

Programmer
08-07-2009, 04:32 AM
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. :\

xXziroXx
08-07-2009, 11:39 AM
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? :noob:

Twinny
08-07-2009, 12:08 PM
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 :D

GULTHEX
08-08-2009, 12:48 AM
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 :D

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

LoneAngelIbesu
08-08-2009, 02:33 AM
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? :cool:

Inverness
08-08-2009, 03:26 AM
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.

Pelikano
08-08-2009, 09:25 AM
Rofl I love the "Leave my Name in ;)" part xD

Twinny
08-08-2009, 12:07 PM
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 :D

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 :D

cbk1994
08-08-2009, 12:40 PM
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

At least on Mac, client-RC has some problems with copying and pasting; you may want to try using the real RC and see if you have the same problem.

GULTHEX
08-09-2009, 02:55 AM
so how would i copy and paste wrong i coppied everything andpasted everything

so how would i do it right?

Twinny
08-09-2009, 03:20 AM
so how would i copy and paste wrong i coppied everything andpasted everything

so how would i do it right?

Right from the first line,

<b>error: unexpected token: * at line 1: * Made by Twinny under Open Source */

You've missed the first / in the script which turns the first line into a comment. After this, the script broke.....

Please, read the errors that RC gives and solve the problem from there. You have the entire script in front of you so it should become really clear.....