100 lines
3.3 KiB
Plaintext
100 lines
3.3 KiB
Plaintext
///////////////////////////////////////////////////////////////////////////
|
|
// Real Time Strategy - NWN - Unit Creation Tool
|
|
//========================================================================
|
|
// By Deva Bryson Winblood. 02/23/2003
|
|
///////////////////////////////////////////////////////////////////////////
|
|
#include "rtsh_multiplay"
|
|
|
|
int fnCountUnits(string sID)
|
|
{ // return how many units this team currently has
|
|
int nRet=0;
|
|
object oMod=GetModule();
|
|
object oNPC;
|
|
int nC=0;
|
|
int nUnitTypes=GetLocalInt(oMod,sID+"_UNITS");
|
|
int nNum=0;
|
|
string sTag;
|
|
while(nC<nUnitTypes)
|
|
{ // count units
|
|
sTag=GetLocalString(oMod,sID+IntToString(nC)+"_tag");
|
|
nNum=0;
|
|
oNPC=GetObjectByTag(sTag,nNum);
|
|
while(oNPC!=OBJECT_INVALID)
|
|
{ // count units
|
|
nNum++;
|
|
nRet++;
|
|
oNPC=GetObjectByTag(sTag,nNum);
|
|
} // count units
|
|
nC++;
|
|
} // count units
|
|
return nRet;
|
|
} // fnCountUnits()
|
|
|
|
int fnNearControlPoint(object oPC)
|
|
{ // near control point
|
|
int nRet=FALSE;
|
|
object oNear;
|
|
object oCP;
|
|
int nC=1;
|
|
float fDist;
|
|
while(nC<5)
|
|
{ // see if near
|
|
oCP=GetNearestObjectByTag("CONTROL_POINT"+IntToString(nC),oPC,1);
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // in same area
|
|
fDist=GetDistanceBetween(oPC,oCP);
|
|
if (fDist<=10.0)
|
|
{ // within distance
|
|
if (GetLocalString(oPC,"sTeamID")==GetLocalString(oCP,"sTeamID")) return TRUE;
|
|
} // within distance
|
|
} // in same area
|
|
nC++;
|
|
} // see if near
|
|
return nRet;
|
|
} // fnNearControlPoint()
|
|
|
|
void main()
|
|
{
|
|
object oPC=GetItemActivator();
|
|
object oMod=GetModule();
|
|
string sID=GetLocalString(oPC,"sTeamID");
|
|
object oDest=GetObjectByTag(sID+"_START");
|
|
string sDummy=IntToString(fnGetTeamMana(oPC));
|
|
object oLead=GetLocalObject(oMod,"oTeamLead"+sID);
|
|
int nCount;
|
|
if (oLead==oPC||GetLocalInt(oPC,"nBuilder")==TRUE)
|
|
{ // builder
|
|
SetLocalInt(oMod,"bHasUsedCreationTool"+sID,TRUE);
|
|
nCount=fnCountUnits(sID);
|
|
SetLocalInt(oMod,sID+"_UnitCount",nCount);
|
|
if (GetLocalInt(oMod,"nMaxUnits")>nCount)
|
|
{ // not at max units
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)==GetArea(oPC)||fnNearControlPoint(oPC)==TRUE))
|
|
{ // in base
|
|
location lLoc=GetItemActivatedTargetLocation();
|
|
oDest=CreateObject(OBJECT_TYPE_PLACEABLE,"creature_create",lLoc,FALSE);
|
|
int nTeamNum=GetLocalInt(oPC,"nTeamNum");
|
|
int nUnitC=GetLocalInt(oMod,"nTeamU"+IntToString(nTeamNum));
|
|
string sTeamN=GetLocalString(oMod,"sTeamN"+IntToString(nTeamNum));
|
|
int nL=0;
|
|
string sName;
|
|
if (oDest==OBJECT_INVALID)
|
|
SendMessageToPC(oPC,"ERROR RTS: Waypoint to create creature not created!!");
|
|
SetLocalObject(oPC,"oCreateUnit",oDest);
|
|
SetLocalInt(oPC,"nTeamU",nUnitC);
|
|
DeleteLocalInt(oPC,"nUCBase");
|
|
AssignCommand(oPC,ActionStartConversation(oPC,"rts_unit_create3",TRUE,FALSE));
|
|
} // in base
|
|
else
|
|
SendMessageToPC(oPC,"You can only create units within your own base or within 10 meters of a control point you control!");
|
|
} // not at max units
|
|
else
|
|
SendMessageToPC(oPC,"You have the maximum number of units allowed! You have "+IntToString(GetLocalInt(oMod,sID+"_UnitCount"))+" units.");
|
|
} // builder
|
|
else
|
|
{ // not allowed to use this item
|
|
SendMessageToPC(oPC,"You are NOT allowed to use this item!");
|
|
DestroyObject(GetItemActivated());
|
|
} // not allowed to use this item
|
|
}
|