Hey there! I'm having a bit of trouble with a mod I'm making. What it does (or is supposed to do) is allow players to challenge each other to duels by typing commands into the chat with the format of /challenge playername #kills to win. The player that is challenged must then type /acceptchallenge or /declinechallenge. If they accept, the first person to get the specified # of kills wins the duel. All it does is keep track of kills and print things to the chat. Here's the code.
function serverCmdChallenge(%client, %targetName, %goal)
{
if(%goal <= 0)
return;
%player = %client.player;
%targetClient = findClientByName(%targetName);
%target = %targetClient.player;
if(isInMinigame(%player))
{
if(isInMinigame(%target))
{
%targetClient.challenged = true;
%targetClient.challenger = %client.name;
%targetClient.challengeGoal = %goal;
messageAll('', '\c2%1 has challenged %2 to a duel of %3 kills! Will he accept?', %client.name, %targetClient.name, %goal);
}
else
{
messageClient(%client, '', '\c2%1 is not in a minigame!', %targetClient.name);
}
}
else
{
messageClient(%client, '', '\c2You are not in a minigame!');
}
}
function serverCmdAcceptChallenge(%client)
{
//keep in mind %client and %target will be switched as opposed to what it was in serverCmdChallenge().
if(%client.challenged == false || %client.challenger == 0)
messageClient(%client, '', '\c2Nobody has challenged you!');
else
{
%client.challenged = false;
%player = %client.player;
%targetClient = %client.challenger;
%target = %targetClient.player;
%player.dueling = %target;
%target.dueling = %player;
%player.wins = 0;
%target.wins = 0;
%player.goal = %client.challengeGoal;
%target.goal = %client.challengeGoal;
messageAll('', '\c2%1 has accepted the duel challenge against %2! The goal is %3 kills!', %client.name, %target.name, %player.goal);
}
}
function serverCmdDeclineChallenge(%client)
{
//keep in mind %client and %target will be switched as opposed to what it was in serverCmdChallenge().
if(%client.challenged == false || %client.challenger == 0)
messageClient(%client, '', '\c2Nobody has challenged you!');
else
{
%client.challenged = false;
%client.challengeGoal = 0;
messageAll('', '\c2The cowardly %1 has declined the duel challenge against the courageous %2!', %client.name, findClientByName(%client.challenger).name);
%client.challenger = 0;
}
}
function Player::isDueling(%player, %target)
{
if(%player.dueling == %target
&& %target.dueling == %player)
return 1;
else return 0;
}
function GameConnection::onDeath(%this, %obj, %killer, %type, %area)
{
Parent::onDeath(%this, %obj, %killer, %type, %area);
%player = %this.player;
%target = %killer.player;
if(isDueling(%player, %target))
{
%target.wins++;
messageAll('', 'Duel Status: %1: %2' TAB '%3: %4', %this.name, %player.wins, %killer.name, %target.wins);
if(%target.wins == %target.goal) //if %target won
{
messageAll('', '%1 has won the duel against %2!', %killer.name, %this.name);
%player.dueling = 0;
%target.dueling = 0;
%player.wins = 0;
%target.wins = 0;
%player.goal = 0;
%target.goal = 0;
}
}
}
function IsInMinigame(%player)
{
if(isobject(%player))
{
if(%player.getclassname() $= "Player")
{
if(%player.client.minigame != 0 && %player.client.minigame != -1)
{
return 1;
}
}
if(%player.getclassname() $= "AiPlayer")
{
if(%player.spawnbrick.getgroup().client.minigame != 0 && %player.spawnbrick.getgroup().client.minigame != -1)
{
return 1;
}
}
return 0;
}
}
The problem that mainly occurs is I can challenge another player successfully, but then when that player types /acceptchallenge or /declinechallenge, it says "Nobody has challenged you!". Please help!
Note: The isInMinigame() function was taken from another mod, I do not take credit for it.