PDA

View Full Version : First Transmute, now this!



Lord_Grismath
04-02-2005, 01:55 AM
HEAVENLY LIGHT:



# spell_heavenly.cog
# Turns night into day.
# [Grismath]
#================================================= =============#
symbols
message activated
message selected
int level local
int bin=35 local
int mana local
int cost=200 local
sound castSound=morning.wav local
int soundChannel=-1 local
int num_surf local
int num_sect local
int player local
int i local
material newsky=sky-blue.mat local
end
#================================================= =============#
code
#------------------------------------------------------
activated:
player=GetSourceRef();
level=GetInv(player, bin);
mana=GetInv(player, 14);
if(level==0) {
Print("Spell Untrained");
Return;
}

if((!IsInvActivated(player, bin)) && (GetThingHealth(player) > 0)) {
mana = GetInv(player, 14);
if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69)) {
if(GetInv(player, 64) != 1) ChangeInv(player, 14, mana-cost);
SetInvActivated(player, bin, 1);
PlayMode(player, 24);
soundChannel = PlaySoundThing(castSound, player, 0.8, -1, -1, 0x80);
SetBinWait(player, bin, 0.2);
num_surf=GetSurfaceCount();
for(i=0; i<num_surf; i=i+1) {
if(GetSurfaceFlags(i)==0x204) {
SetSurfaceMat(i, newsky);
}
}
num_sect=GetSectorCount();
for(i=0; i<num_sect; i=i+1) {
SetSectorLight(i, 0.7, 2);
}
call stop_power;
}
}
return;
#------------------------------------------------------
selected:
Print("Heavenly Light");
return;
#------------------------------------------------------
stop_power:
SetInvActivated(player, bin, 0);
return;
#------------------------------------------------------
end


For some reason, it doesn't do all surfaces and mats.

ZeqMacaw
04-02-2005, 02:16 AM
The line:
if(GetSurfaceFlags(i)==0x204) {

should probably be:
if(GetSurfaceFlags(i) & 0x204) {

:)

Lord_Grismath
04-02-2005, 12:16 PM
Now it changes all surfaces, even ones without 0x204.

ZeqMacaw
04-02-2005, 01:50 PM
Oh, I see, now.

Okay, try this:
surfaceFlags = GetSurfaceFlags(i);
if ((surfaceFlags & 0x200) && (surfaceFlags & 0x4))
{

:)

darthslaw
04-02-2005, 02:39 PM
That'll work. What you were looking for 1st time Zeq was this:
if(GetSurfaceFlags(i) & 0x204 == 0x204)

The '&' will return the flags (bits) that both numbers have. Thus, it could return either 0x200, 0x204, 0x4, or 0x0. 0x204 contains 2 bits, 0x4 and 0x200. The surface flags could contain one, both, or neither of the bits. In JK, 0 is 'false', but any nonzero value counts as 'true'. 'if(GetSurfaceFlags(i) & 0x204)' will return a nonzero value if either 0x4 or 0x200 are contained within the surface flags. Adding '== 0x204' makes the comparison true only if both bits are returned.

Hopefully that made sense. :) I'm not always that good at explaining things.

ZeqMacaw
04-02-2005, 02:55 PM
"What you were looking for 1st time Zeq was this:
if(GetSurfaceFlags(i) & 0x204 == 0x204)"

Yep. (Silly me.)

:)