Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   making roof semi-transparent (https://forums.graalonline.com/forums/showthread.php?t=73935)

Cherrykao 05-11-2007 11:32 PM

making roof semi-transparent
 
I'm having some trouble getting my scripts to work properly online. It works good offline on the editor.

Basically when you enter a house, the roof turns semi-transparent and then when you exit the house through the door, the roof turns back to normal.

Here's my code for the roof NPC:

NPC Code:

//#CLIENTSIDE
//function onCreated() {
if (created) {
setimg roof.gif;
dontblock;
drawoverplayer;
vRoofV();
vUnderRoof = false;
}

//function onPlayerTouchsMe() {
if (playertouchsme) {
vUnderRoof = true;
}

if (vUnderRoof == true) {
vRoofI();
}
if (vUnderRoof == false) {
vRoofV();
}

// Makes roof transparent
function vRoofI() {
setcoloreffect 1,1,1,0.22;
drawaslight;
}

// Puts roof back to normal
function vRoofV() {
setcoloreffect 1,1,1,1;
//drawaslight;
}

timeout = 0.05;



When someone walks out through the door, the "vUnderRoof" flag is set back to false by touching a grass NPC as they walk out through the door:

NPC Code:

if (created) {
setimg vivendi_h10grass.png;
drawunderplayer;
dontblock;
//vUnderRoof = false;
}

if (playertouchsme) {
vUnderRoof = false;
}

timeout = 0.05;


DustyPorViva 05-11-2007 11:36 PM

Well that's a bad way to do it.
You should probably check the players.x/y in a timeout and when the player enters the coordinates of the roof, transparent, otherwise, return to normal.

godofwarares 05-11-2007 11:37 PM

Quote:

Originally Posted by Cherrykao (Post 1307122)
Yadda yadda yadda

Well first of all, You need to define the variable on the client. Something like "client.vUnderRoof = false/true" will work fine.

Next, You need to do a loop to enable the code to detect the variable.

PHP Code:

timeout 0.05;

if (
timeout)
{
if (
client.vUnderRoof == true) {
  
vRoofI();
}
if (
client.vUnderRoof == false) {
  
vRoofV();
}


_______
Quote:

Originally Posted by DustyPorViva
Well that's a bad way to do it.
You should probably check the players.x/y in a timeout and when the player enters the coordinates of the roof, transparent, otherwise, return to normal.

I agree. Cherry, Why not check if the player's X and Y isn't in the NPC to undo it?

PHP Code:

// In timeout code
this.4// How many tiles the roof takes up, Horizontally
this.4// How many tiles the roof takes up, Vertically
if (!(playerx in |this.x, (this.x+this.w)|) && !(playery in |this.y, (this.y+this.h)|)
{
// Code to make roof opaque
} else {
// Code to make roof translucent



Cherrykao 05-12-2007 12:09 AM

thanks. it is better to check the x & y coordinates of the players and i actually started doing that, but i thought it would be easier to use flags.

Rapidwolve 05-12-2007 12:32 AM

The best way to do it, in my opinion, is the way Hikaru is doing it. That's what I do too.


All times are GMT +2. The time now is 04:07 AM.

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