PDA

View Full Version : Help me convert an old script


Kamaeru
07-19-2017, 05:19 AM
This script made by Loriel used to make "lava balls" bounce around the level. I'm not certain why it doesn't work anymore and my attempts to convert it failed.

// Lava balls by Loriel
//#CLIENTSIDE
if (playerenters) {
seteffect .1,.05,0,0.03;
this.balls = 50;
setarray this.angle,10;
setarray this.x,10;
setarray this.y,10;
setarray this.radx,10;
setarray this.rady,10;
setarray this.speed,10;
setarray this.dir,10;
for (i=0; i<this.balls; i++)
init(); // First initalizing of all the arrays
while (true) {
for (i=0; i<this.balls; i++) {
if (this.angle[i] in |1.55,4.70|) init(); // Check if under lava (re init),
else loop(); // or above (loop)
}
looplights();
sleep 0.05;
}
}

function init() {
this.x[i] = random(0,60);
this.y[i] = random(0,62);
this.radx[i] = random(0,2);
this.rady[i] = random(2,8);
this.angle[i] = 4.75;
this.speed[i] = random(0.1,0.4);
this.dir[i] = int(random(0,2))*2-1;
}

function loop() {
this.angle[i] += this.speed[i]; // Move ball
this.angle[i] = this.angle[i]%6.3; // Make sure angle stays between 0 and 6.3
showimg i,light2.png,
this.x[i]-this.radx[i]*sin(this.angle[i])*this.dir[i],
this.y[i]-this.rady[i]*cos(this.angle[i]);
changeimgcolors i,0,random(0.1,0.1),.1,0.99;
changeimgzoom i,random(0.15,0.35);
}

function looplights() {
for (i = 0; i < arraylen(this.lpos)/2; i++)
changeimgzoom this.balls+i,random(0.4,0.6);
}

I'm assuming some of the syntax here is just no longer supported but I don't know what it is. Maybe setarray is the problem? A lot of the old gs1 scripts like this on g2k1 perplex me but perhaps they are not hard to fix.

fowlplay4
07-20-2017, 04:33 AM
Changed it from using built-in variables (e.g. this.x, this.y).

Changed it to a regular timeout instead of while true loop.

function looplights doesn't seem to do anything so I removed that as well.

Made showimg use 200+ for the IDs so they aren't displayed globally.

//#CLIENTSIDE

function onPlayerEnters() {
seteffect(0.1, 0.05, 0, 0.03);
this.balls = 50;
this.balls_angle = new[this.balls];
this.balls_x = new[this.balls];
this.balls_y = new[this.balls];
this.balls_radx = new[this.balls];
this.balls_rady = new[this.balls];
this.balls_dir = new[this.balls];
this.balls_speed = new[this.balls];
for (temp.i = 0; temp.i < this.balls; temp.i++) {
init_ball(temp.i);
}
onTimeout();
}

function onTimeout() {
for (temp.i = 0; temp.i < this.balls; temp.i++) {
if (this.balls_angle[temp.i] in |1.55,4.70|) {
init_ball(temp.i);
} else {
this.balls_angle[temp.i] += this.balls_speed[temp.i]; // Move ball
this.balls_angle[temp.i] = this.balls_angle[temp.i] % 6.3; // Make sure angle stays between 0 and 6.3
showimg(200+temp.i,"light2.png",this.balls_x[temp.i]-this.balls_radx[temp.i]*sin(this.balls_angle[temp.i])*this.balls_dir[temp.i],this.balls_y[temp.i]-this.balls_rady[temp.i]*cos(this.balls_angle[temp.i]));
changeimgcolors(200+temp.i,0,random(0.1,0.1),.1,0. 99);
changeimgzoom(200+temp.i,random(0.15,0.35));
}
}
setTimer(0.05);
}

function init_ball(i) {
this.balls_x[i] = random(0,60);
this.balls_y[i] = random(0,62);
this.balls_radx[i] = random(0,2);
this.balls_rady[i] = random(2,8);
this.balls_angle[i] = 4.75;
this.balls_speed[i] = random(0.1,0.4);
this.balls_dir[i] = int(random(0,2))*2-1;
}


note: completely untested, but did verify it compiles successfully in a class script.

Crono
07-20-2017, 09:56 AM
this.balls = 50;

:oo:

Kamaeru
07-20-2017, 09:57 AM
note: completely untested, but did verify it compiles successfully in a class script.

It works perfect man. This will go a long way for nostalgia restoration purposes of classic levels on the server which I don't plan to get rid of. Also studying how you converted it will help me do the same for other scripts.

fowlplay4
07-20-2017, 11:13 PM
o good

Crono
07-21-2017, 01:09 AM
+rep4

edit: You must spread some Reputation around before giving it to fowlplay4 again.

shoot