Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Hmmm, shield recharge....
Hmmm, shield recharge....
2003-12-31, 5:51 AM #1
I havn't cogged in quite awhile (heh, so long I had to look at the datamaster to remember the structure of a cog) and I'm trying to make a shield recharge console, like the ones in JO. So far I have this:
Code:
# Jedi Knight Cog Script
#
# CON_SHIELD.COG
#
# Class cog for a shield recharger.
# v 0.1
# [ST]
# Not LEC supported
flags=0x240

symbols

message      activated                                                        
message      pulse                                                            
message      deactivated                                                      

thing        console                            local                         
thing        player                             local                         

sound        beep=helthpu1.wav                  local                         
sound        outsound=Activate01.wav            local                         

int          bin=60                             local                         

flex         max=100                            local                         

end                                                                           

# ========================================================================================

code
activated:
   player = GetSourceRef();
   console = GetSenderRef();

   if (bin < GetInvMax(player, bin))
   {
     if (max <= 100)
     {
       setpulse(0.1);
     }
     else
     {
     return;
     }
   }
Return;
# ........................................................................................
pulse:
   player = GetSourceRef();
   console = GetSenderRef();
   
   Print("pulsing");
   if (bin < GetInvMax(player, bin))
   {
     if(max <= 100)
     {
       PlaySoundThing(beep, console, 1.0, -1, -1, 0);
       ChangeInv(player, bin, 1.0); //set the player's shield up by one
       max = max-1; // set the amount of shields for this recharger down one point
       SetPulse(0); //pulse off for debugging purposes
     }
     else
     {
       PlaySoundThing(outsound, console, 1.0, -1, -1, 0);
       SetPulse(0);
     }
   }
   else
   {
     SetPulse(0);
   }
Return;
# ........................................................................................
deactivated:
   SetPulse(0);
Return;
# ........................................................................................

end

And everytime I activate the console it raises the shield up by one, but it does it regardless of the inventory of the shield bin and max. If you take out the setpulse(0); in the pulse message, it's keep adding shields even after it reaches the bin's max. Any ideas?

------------------
*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"


[This message has been edited by Stormtrooper (edited December 31, 2003).]
2003-12-31, 11:26 AM #2
I'm gonna concenrate on your activated message first.
Quote:
<font face="Verdana, Arial" size="2">
activated:
player = GetSourceRef();
console = GetSenderRef();
if (bin < GetInvMax(player, bin))
{
if (max <= 100)
{
setpulse(0.1);
}
else
{
return;
}
}
Return;
</font>


First of all, your if statement about if( bin < GetInvMax(player, bin) ) doesn't seem right to me. bin is set to 60 in your symbols section. So your if statement asks if 60 is less than the max inv for shields, which is 200, so it is always going to be less than that. I think your if statement should be asking is the player's current inventory value for shields less than the max inventory value for shields.

Now, the next if statment, if( max <= 100 ) won't tell you anything, cuz your pulse message just makes the max value smaller, so this if statement should read if( max > 0 ). This means when your recharger's max value reaches 0 (which is eventually will) it won't call the pulse message.

As for the pulse message, you will need to fix the 1st two if statements in there aswell as i described above. Then you will want to take out that "SetPulse(0);", the one that is there for "debugging purposes". Everything else seems good and it looks like you covered all your bases nicely. I'm not sure how the deactivated message works when you are talking about 3do activation, but hopefully it will work correctly.

Try out the changes i said and let me know what happens dude.
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
2003-12-31, 3:07 PM #3
Thanks, I got it working. Now I just need to make it so that you move a certain distance away from the console it stops recharging your shields and the max gradually returns to 100.
Once again, Thanks.

[EDIT]Oh, and about the deactivated message, I wanted to make it so you had to hold down the activation button for it to keep recharging the shields, but I couldn't get it working so I'm reworking it so it stops if you're too far away from it, like I said above.[/EDIT]

------------------
*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited December 31, 2003).]
2003-12-31, 3:10 PM #4
You have the right idea, but the wrong execution.
Code:
# Jedi Knight Cog Script#
# CON_SHIELD.COG
#
# Cog for a shield recharger.
# v 0.1
# [ST] + [DP]
# Not LEC supported
# DP - Reworked coding to make function if my syntax isn't too rusty :-p
#
#
# note - This is NOT a class cog anymore, its simpler this way, else you'd have to use userdata to make work as intended
#
#
flags=0x240
symbols
message      activated
message      pulse
message      deactivated
thing        console
thing        player                             local
sound        beep=helthpu1.wav                  local
sound        outsound=Activate01.wav            local
int          bin=60                             local
int          left=100                           local
flex         far=0.1                            local
end
# ========================================================================================
code

Activated:
   player = GetSourceRef();
   If(GetInv(player, bin) < GetInvMax(player, bin)) SetPulse(0.1);
   Return;

# ........................................................................................

Pulse:
   player = GetSourceRef();
   // Print("pulsing"); // Debugging
   If(GetInv(player, bin) < GetInvMax(player, bin) && left > 0 && VectorDist(GetThingPos(player), GetThingPos(console)) <= far)
   {
      PlaySoundThing(beep, console, 1.0, -1, -1, 0); // lotta beeping, but you're choice
      ChangeInv(player, bin, 1); // Set the player's shield up by one
       left = left - 1;
   }
   Else
   {
       If(left <= 0) PlaySoundThing(outsound, console, 1.0, -1, -1, 0); // play out sound if out only, nuh?
       SetPulse(0);
   }
   Return;

# ........................................................................................

Deactivated:
   SetPulse(0);
   Return;

end
Any questions on what I changed and/or why?

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

[This message has been edited by Descent_pilot (edited December 31, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-12-31, 3:28 PM #5
Heh, mine works almost as good, but the coding is so much cleaner and easier to understand in yours, thanks, I'm going to use your's as a major base for my next versions. Thanks, both of you guys. Much, much thanks.

------------------
*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

↑ Up to the top!