Author Topic: SpeedKart Add-On: Death Timer Upon Leaving Vehicle  (Read 3163 times)

Hey, I've been working on making mods useful for SpeedKart, and one that I swear I have seen before but never found on the forums, is an add-on that kills players if they leave their vehicles for more than ten seconds. So, since I have been running SpeedKart lately, I decided to take the time to recreate it. Harder than expected, but all the kinks seem to be worked out, so it's good to go! Hope it's as useful to you as it is to me.

If you have any questions, or ideas for add-ons, feel free to mention it! I'm open to suggestions.  :cookieMonster:


Sincerely,
Permamiss
« Last Edit: August 16, 2017, 01:06:02 AM by Alpinu »

speedkart mod already do this so whats the point?

no

also dont sign, just, wtf u think u are!

also dont sign, just, wtf u think u are!
obviously permamiss!!

but yea like wasn't this a thing that the gamemode already did? honestly it's been so long since i tried it i can't quite recall
well it's not specific to speedkarts anyways so hey this seems like a pretty useful thing
« Last Edit: August 14, 2017, 05:10:17 AM by gr8dayseth »

I made one of these like 5 years ago but maybe this one is better

http://swololol.com/rd?f=Server_VehicleTimerKill


I made one of these like 5 years ago but maybe this one is better

http://swololol.com/rd?f=Server_VehicleTimerKill

oh my God I looked for this for hours why couldn't I find it
I doubt mine is any better, I just started getting serious about using TorqueScript a few days ago, so the way I did some things is probably frowned upon the way it is now should be just fine

failbin

 :cookieMonster: :cookieMonster: :cookieMonster:
« Last Edit: August 16, 2017, 07:19:12 PM by Alpinu »

Remove that link or fix the functions below. You are using eval which can be easily exploited. I also have a feeling this gives out eval errors with people having spaces in their names. Use stuff like $DeathSchedule::Name[%client.getPlayerName()]

Here is your main problem.
function endDeathTimer(%client)
{
   eval("if (isEventPending($" @ %client.getPlayerName() @ "::DeathSchedule)) { cancel($" @ %client.getPlayerName() @ "::DeathSchedule); }");
   %client.DeathTimer = "";
   %client.bottomPrint("", 0.01); //removes the bottomprint
}

function startDeathTimer(%client)
{
   if (%client.player && %client.player.getDamagePercent() < 1) //if player exists and player is not dead, then
   {
      %client.DeathTimer = 10; //initializing
      %client.bottomPrint("\c5Time to re-enter vehicle: " @ %client.DeathTimer);
      eval("%client = " @ %client @ "; if (isEventPending($" @ %client.getPlayerName() @ "::DeathSchedule)) { cancel($" @ %client.getPlayerName( @ "::DeathSchedule); } $" @ %client.getPlayerName() @ "::DeathSchedule = schedule(1000, %client, decrementDeathTimer, %client);"); //we do cancel here because onUnmount actually runs a LOT of times at once, so this makes the schedule not repeat. thanks Blockland.
   }
}

function decrementDeathTimer(%client)
{
   if (%client.player)
   {
      if (%client.DeathTimer > 0 && %client.player.getDamagePercent() < 1) //if player exists, not already mounted, and player is not dead, then
      {
         %client.DeathTimer--; //decrement timer
         %client.bottomPrint("\c5Time to re-enter vehicle: " @ %client.DeathTimer);
         eval("%client = " @ %client @ "; $" @ %client.getPlayerName() @ "::DeathSchedule = schedule(1000, %client, decrementDeathTimer, %client);");
      }
      else
      {
         if (%client.player.getDamagePercent() < 1 && (%client.DeathTimer !$= ""))
         {
            %client.player.kill();
         }
         endDeathTimer(%client);
      }
   }
   else
   {
      endDeathTimer(%client);
   }
}


Tip on using eval: Avoid it unless you REALLY need to use it - there are many ways of doing what you tried to do in eval without using eval
Eval is extremely dangerous if there is a tiny mistake in it
« Last Edit: August 15, 2017, 03:16:41 AM by Kyuande »


wouldnt using local variables in those eval statements crash the server due to local vars in global scope?

wouldnt using local variables in those eval statements crash the server due to local vars in global scope?
No, eval is actually in the local scope. So the "%client = " @ %client @ "; part is completely pointless.

Also the evaling isn't even necessary. Why not tie the schedule to the client object itself?
%client.deathSchedule = schedule(1000,%client,decrementDeathTimer,%client);
Even if for whatever reason you still wanted to use a global var that was tied to the player's name (which will forget up with multiple clients), why not just do
$DeathSchedule[%client.getPlayerName()] so you don't have to eval it? Not that this is important at all, because of the above code.

wouldnt using local variables in those eval statements crash the server due to local vars in global scope?
Only outside of functions

Remove that link or fix the functions below. You are using eval which can be easily exploited. I also have a feeling this gives out eval errors with people having spaces in their names. Use stuff like $DeathSchedule::Name[%client.getPlayerName()]

Here is your main problem.
function endDeathTimer(%client)
{
   eval("if (isEventPending($" @ %client.getPlayerName() @ "::DeathSchedule)) { cancel($" @ %client.getPlayerName() @ "::DeathSchedule); }");
   %client.DeathTimer = "";
   %client.bottomPrint("", 0.01); //removes the bottomprint
}

function startDeathTimer(%client)
{
   if (%client.player && %client.player.getDamagePercent() < 1) //if player exists and player is not dead, then
   {
      %client.DeathTimer = 10; //initializing
      %client.bottomPrint("\c5Time to re-enter vehicle: " @ %client.DeathTimer);
      eval("%client = " @ %client @ "; if (isEventPending($" @ %client.getPlayerName() @ "::DeathSchedule)) { cancel($" @ %client.getPlayerName( @ "::DeathSchedule); } $" @ %client.getPlayerName() @ "::DeathSchedule = schedule(1000, %client, decrementDeathTimer, %client);"); //we do cancel here because onUnmount actually runs a LOT of times at once, so this makes the schedule not repeat. thanks Blockland.
   }
}

function decrementDeathTimer(%client)
{
   if (%client.player)
   {
      if (%client.DeathTimer > 0 && %client.player.getDamagePercent() < 1) //if player exists, not already mounted, and player is not dead, then
      {
         %client.DeathTimer--; //decrement timer
         %client.bottomPrint("\c5Time to re-enter vehicle: " @ %client.DeathTimer);
         eval("%client = " @ %client @ "; $" @ %client.getPlayerName() @ "::DeathSchedule = schedule(1000, %client, decrementDeathTimer, %client);");
      }
      else
      {
         if (%client.player.getDamagePercent() < 1 && (%client.DeathTimer !$= ""))
         {
            %client.player.kill();
         }
         endDeathTimer(%client);
      }
   }
   else
   {
      endDeathTimer(%client);
   }
}


Tip on using eval: Avoid it unless you REALLY need to use it - there are many ways of doing what you tried to do in eval without using eval
Eval is extremely dangerous if there is a tiny mistake in it

Huh, I already updated that. I guess that Dropbox links don't update upon replacing the same file? Sorry about that, I have never used Dropbox before;  I will replace the link with the current version of the add-on (that doesn't use eval at all). Thanks!

I doubt mine is any better, I just started getting serious about using TorqueScript a few days ago, so the way I did some things is probably frowned upon

Hey, it's really cool that you're learning TorqueScript, and you should definitely keep doing it, but it's generally not a good idea to upload your first add-on to the forums.

Here's a great Discord for making content for Blockland.  There are many people on there you could ask if you get stuck on something, or if you just want feedback on what you've made.

Hey, it's really cool that you're learning TorqueScript, and you should definitely keep doing it, but it's generally not a good idea to upload your first add-on to the forums.

Here's a great Discord for making content for Blockland.  There are many people on there you could ask if you get stuck on something, or if you just want feedback on what you've made.

oh wow, thanks! I didn't know there was a Discord for content creation in Blockland. I think this will help a lot. This technically is not my first add-on, but I understand what you mean. I think it is at a point where it can be used by anyone safely though :)