Author Topic: Radius loop originating from player  (Read 3520 times)

My attempt at a 'noob shield' for super admins.  Respawns players that get too close.  The result: massive console spam with each schedule about unknown function getPosition, and it doesn't even respawn them.  Otherwise the code seems to toggle fine and execute without errors.

Code: [Select]
function serverCmdTNS(%client)
{
serverCmdToggleNoobShield(%client);
}

function serverCmdToggleNoobShield(%client)
{
if(!%client.isSuperAdmin)
return;
if(%client.isNoobShielded)
{
%client.isNoobShielded=0;
cancel(%client.InfiniteNoobShield);
messageClient(%client,'',"\c0You disabled your noob shield.");
}
else
{
%client.isNoobShielded=1;
%client.InfiniteNoobShield = %client.schedule( 100 , InfiniteNoobShield, %client);
messageClient(%client,'',"\c2You enabled your noob shield.");
}


}

function gameconnection::InfiniteNoobShield(%client)
{
initContainerRadiusSearch(%client.getPosition(), 5, $TypeMasks::PlayerObjectType);   

while(%obj = containerSearchNext())
{
if(%obj != %client)
{
if(!%obj.client.isAdmin && !%obj.client.isSuperAdmin)
{
messageclient(%obj.client,'',"You were respawned for getting too close to a shielded super admin.");
%obj.instantrespawn();
}
}
}
%client.InfiniteNoobShield = %client.schedule( 100 , InfiniteNoobShield, %client);
}

Do %client.player.getPosition(); instead.

Also, when you call InfiniteNoobShield you don't need to add that %client arg on there, as it will already be there.

Also, instead of if(%obj != %client) it'd be if(%obj != %client.player) or if(%obj.client != %client).
« Last Edit: February 06, 2015, 12:42:51 AM by jes00 »

beat me to it by 30 seconds, nice jes

I wouldn't use this...
It's well intentioned but it has a lot of potential for frustration, simply walking past someone (could even be with a wall seperating you) or even an admin afking at the spawn area

Also make sure that %obj is defined too.

i intend to make it only usable outside the minigame.  thank you everyone for the help, i will report the results back tomorrow.

I'd just have it push them away
Far less annoying than a complete respawn if it catches someone innocent

I'd just have it push them away
Far less annoying than a complete respawn if it catches someone innocent
how would you do this?

VectorDist VectorSub(pos1,pos2) to get a vector between the two players
VectorNorm vectorNormalize the result of that to get a vector of length 1.
Then scale that with vectorScale

Apply the resulting vector to the player with addVelocity




Another thing is look into is some sort of visual indicator around the shielded player, so approaching players know they can't touch you
« Last Edit: February 07, 2015, 01:44:36 PM by Headcrab Zombie »

VectorDist(obj1,obj2) to get a vector between the two players

Wrong, VectorDist gets the distance between two vectors, a float >= 0, not a vector. Use VectorSub to get the vector difference.

And it is VectorNormalize.

Also, when you call InfiniteNoobShield you don't need to add that %client arg on there, as it will already be there.
At first I thought you were talking about the function declaration and I was like
wat
then I realized you were talking about the schedule.

Wrong, VectorDist gets the distance between two vectors, a float >= 0, not a vector. Use VectorSub to get the vector difference.
Whoops
Funny thing is I thought of vectorSub
But I dismissed it for some reason, don't know why

I don't know how to implement the velocity idea, but here is the finished code that works:

Code: [Select]
package NoobShield
{

function serverCmdJoinMinigame(%client, %minigame)
{
if(%client.isNoobShielded)
{
%client.isNoobShielded=0;
cancel(%client.InfiniteNoobShield);
messageClient(%client,'',"\c0You disabled your noob shield.");
}
parent::serverCmdJoinMinigame(%client, %minigame);
}

function serverCmdTNS(%client)
{
serverCmdToggleNoobShield(%client);
}

function serverCmdToggleNoobShield(%client)
{
if(!%client.isSuperAdmin)
return;
if(isObject(%client.minigame))
return messageClient(%client,'',"\c0You can't use your noob shield in a minigame.");
if(%client.isNoobShielded)
{
%client.isNoobShielded=0;
cancel(%client.InfiniteNoobShield);
messageClient(%client,'',"\c0You disabled your noob shield.");
}
else
{
%client.isNoobShielded=1;
%client.InfiniteNoobShield = %client.schedule( 100 , InfiniteNoobShield, %client);
messageClient(%client,'',"\c2You enabled your noob shield.");
}


}

function gameconnection::InfiniteNoobShield(%client)
{
initContainerRadiusSearch(%client.player.getPosition(), 5, $TypeMasks::PlayerObjectType);   

while(%obj = containerSearchNext())
{
if(%obj != %client.player)
{
if(!%obj.client.isAdmin && !%obj.client.isSuperAdmin)
{
messageclient(%obj.client,'',"You were respawned for getting too close to a shielded super admin.");
%obj.instantrespawn();
}
}
}
%client.InfiniteNoobShield = %client.schedule( 100 , InfiniteNoobShield, %client);
}
};
activatepackage(NoobShield);


Just me being picky but you don't have to do the if(!%obj.client.isAdmin && !%obj.client.isSuperAdmin) due to the fact that if a player is Super Admin they are also Admin, so it could just be if(!%obj.client.isAdmin)

Just me being picky but you don't have to do the if(!%obj.client.isAdmin && !%obj.client.isSuperAdmin) due to the fact that if a player is Super Admin they are also Admin, so it could just be if(!%obj.client.isAdmin)
Not always.  Some admin mods will set isSuperAdmin but not isAdmin.  I think IGSO did that. 

But I also don't want this mod to affect admins either anyways.