Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Radio System (https://forums.graalonline.com/forums/showthread.php?t=73323)

Rapidwolve 04-06-2007 08:05 PM

Radio System
 
NPC: Radio
PHP Code:

/*
Radio System by Rapidwolve
*/

public function doUpdateStation(stationiddjtextsonghead){
  
this.radio.("station_" stationid) = {djtextsonghead};
  
refresh(stationid);
}

public function 
doUpdateSong(stationidsongdjdjhead){
  
temp.text this.radio.("station_" stationid)[1];
  
this.radio.("station_" stationid) = new [4];
  
this.radio.("station_" stationid)[1] = temp.text;
  
this.radio.("station_" stationid)[2] = song;
  
this.radio.("station_" stationid)[0] = dj;
  
this.radio.("station_" stationid)[3] = djhead;
  
refresh(stationid);
}

public function 
doUpdateText(stationidtextdjdjhead){
  
temp.song this.radio.("station_" stationid)[2];
  
this.radio.("station_" stationid) = new [4];
  
this.radio.("station_" stationid)[2] = temp.song;
  
this.radio.("station_" stationid)[1] = text;
  
this.radio.("station_" stationid)[0] = dj;
  
this.radio.("station_" stationid)[3] = djhead;
  
refresh(stationid);
}

public function 
refresh(stationid){
  for (
pallplayers){
    
with (p){
      if (
client.radiochannel == stationid){
      
temp.newdj this.radio.("station_" stationid)[0];
      
temp.newtext this.radio.("station_" stationid)[1];
      
temp.newsong this.radio.("station_" stationid)[2];
      
temp.newhead this.radio.("station_" stationid)[3];
      
p.findWeapon("Radio").updateChannelVars(temp.newdjtemp.newtexttemp.newsongtemp.newhead);
      }
    }
   }


Class: radiostation-control
PHP Code:

//

function onPlayerChats(){
if (
player.chat.starts(":song")) findNPC("Radio").doUpdateSong(this.stationidplayer.chat.substring(6), player.accountplayer.head);
if (
player.chat.starts(":text")) findNPC("Radio").doUpdateText(this.stationidplayer.chat.substring(6), player.accountplayer.head);


Weapon: Radio
PHP Code:

/*
NPC by rapidwolve
*/
function onActionServerside(action){
  switch (
action){
    case 
"updateChannel":
      
findNPC("Radio").refresh(params[1]);
  break;
  }
}

public function 
updateChannelVars(djtextsongdjhead){
  
player.triggerClient("gui"name"recRadioParams"djtextsongdjhead);
}
//#CLIENTSIDE

function onCreated()
  
setVars();


function 
onActionClientside(action){
  switch (
action){
    case 
"recRadioParams":
      
updateChannelVars(params[1], params[2], params[3], params[4]);
  break;
  }
}

function 
onKeyPressed(codekey){
  if (
client.radio true){
    if (
key in serverr.radio.validstations){
     
doChangeStation(key);
    }
  }
}

function 
onWeaponFired()
  
toggleRadio();


function 
setVars(){
  if (
client.radiochannel == nullclient.radiochannel 1;
    
updateChannel(client.radiochannel);
    
client.radio false;
    
this.sx screenwidth - (32 9.5);
    
this.sy 35;
    
this.font "Tahoma";
    
this.fontsize .65;
    
this.textstyle "b";
    
stopmidi();
}

public function 
updateChannelVars(djrtextsongdjhead){
  
this.djhead temp.djhead;
  
this.rtext temp.rtext;
  
this.dj temp.dj;
  
this.song temp.song;
}

public function 
updateChannel(channel)
  
triggerServer("gui"name"updateChannel"channel);


public function 
doChangeStation(channel){
  
updateChannel(channel);
  
client.radiochannel channel;
}

public function 
toggleRadio(){
  if (
client.radio == false){
    
client.radio true;
    
drawRadio();
    
setTimer(.05);
  }
else{
  
destroyRadio();
  
setTimer(0);
  }
}

function 
drawRadio(){
  
updateChannel(client.radiochannel);
  
client.radio true;
  
player.addMessage("System""You turned your radio on.");
  
onTimeout();
}

function 
destroyRadio(){
  
client.radio false;
  
player.addMessage("System""You turned your radio off.");
  
stopmidi();
  
hideimgs(-1,1000);
}

function 
onTimeout(){
  
showimg(202this.djheadthis.sxthis.sy 25);
  
changeimgvis(202,4);
  
changeimgpart(202,3,69,26,23);

  
showText(200this.sx 140this.sy 25"Tahoma""ic"serverr.("radio" client.radiochannel "name"));
  
changeimgvis(2007);
  
changeimgzoom(200this.fontsize .1);
  
showText(201this.sx 140this.sy 10"Tahoma""ic"this.dj);
  
changeimgvis(2017);
  
changeimgzoom(201this.fontsize .1);

  
tokens wraptext2(255this.fontsize" "this.font "@" this.fontstyle "@" this.rtext);
  
hideimgs(250,300);
    for (
this.0this.tokens.size(); this.i++){
      
showText(250 this.ithis.sxthis.sy + (this.15), this.fontthis.textstyletokens[this.i]);
      
changeimgvis(250 this.i7);
      
changeimgzoom(250 this.ithis.fontsize);
  }
    if (
this.song != null)
      
playlooped(this.song);
       else
      
stopmidi();
      
setTimer(.05);


Operation:

Setting up stations
Create a new level with and inside of an NPC add this code in.
PHP Code:

     join("radiostation-control");
this.stationid int// Can be any value from 1-9 Make sure the station id isn't in use 

Create a 'serverr.radio.validstations' flag and add the station id to that array(make sure that the list is in numerical order).

To give the radio station a name create another server flag 'serverr.radio#name' and its value should be the desired name.

Station Operation
While you are inside the station level, use these commands (without the <>'s).
:text <text> | Changes the stations text
:song <file/url> | Changes the stations song

pez307 08-24-2009 03:35 PM

It found 3 errors;


Script compiler output for Radio:
<b>error: function updateChannelVars redefined at line 50: public function updateChannelVars(dj, rtext, song, djhead){
Weapon/GUI-script Radio added/updated by pez307
<b>Script: Function triggerServer not found at line 58 in script of Radio
<b>Script: Function stopmidi not found at line 47 in script of Radio

cbk1994 08-24-2009 09:51 PM

Quote:

Originally Posted by pez307 (Post 1518145)
It found 3 errors;


Script compiler output for Radio:
<b>error: function updateChannelVars redefined at line 50: public function updateChannelVars(dj, rtext, song, djhead){
Weapon/GUI-script Radio added/updated by pez307
<b>Script: Function triggerServer not found at line 58 in script of Radio
<b>Script: Function stopmidi not found at line 47 in script of Radio

Did you place the NPC and weapon in different (and correct) places?

pez307 08-25-2009 01:08 PM

Don't worry, i used your Jukebox Chris, it's nice ;p


All times are GMT +2. The time now is 03:50 PM.

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