Normalize all the line endings
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -11,278 +11,278 @@
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
#include "ns_const.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
|
||||
#include "FastDelegate.h"
|
||||
#include "GameManager.h"
|
||||
|
||||
extern int IsValidBuilding[AVH_USER3_MAX + 1];
|
||||
|
||||
using namespace fastdelegate::detail;
|
||||
|
||||
|
||||
void *GameRules=NULL;
|
||||
|
||||
|
||||
mBOOL dlclose_handle_invalid; // Linking errors with metamod
|
||||
|
||||
// void AvHBaseBuildable::StartRecycle()
|
||||
static void (GenericClass::*MFP_Recycle)();
|
||||
|
||||
// void AvHWeldable::AddBuildTime(float)
|
||||
static void (GenericClass::*MFP_WeldFinished)(float);
|
||||
|
||||
// AvHGameRules *GetGameRules(void)
|
||||
static void *(*FP_GetGameRules)();
|
||||
|
||||
|
||||
char *FuncBase;
|
||||
|
||||
/**
|
||||
* sizeof(void (detail::GenericClass::*fptr)())
|
||||
* is 8 in GCC. Add an empty void * pointer at
|
||||
* the end to compensate.
|
||||
* Layout in GCC:
|
||||
* union {
|
||||
* void *address; // When this is an address it will always be positive
|
||||
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
|
||||
* };
|
||||
* int delta;
|
||||
* -
|
||||
* Delta is the adjustment to the this pointer
|
||||
* For my implementations I will only need it to 0
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *in[2];
|
||||
OutType out;
|
||||
} mfpu;
|
||||
|
||||
mfpu.in[0]=in;
|
||||
mfpu.in[1]=NULL;
|
||||
out=mfpu.out;
|
||||
};
|
||||
#else
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
out=horrible_cast<OutType>(in);
|
||||
};
|
||||
#endif
|
||||
|
||||
void MFuncs_Initialize(void)
|
||||
{
|
||||
char FileName[256];
|
||||
DLHANDLE DLLBase;
|
||||
#ifdef __linux__
|
||||
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
|
||||
#else
|
||||
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
|
||||
#endif
|
||||
|
||||
DLLBase=DLOPEN(FileName);
|
||||
FuncBase=(char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
|
||||
DLCLOSE(DLLBase);
|
||||
|
||||
#define MFP(Offs) (((void *)(((char *)FuncBase)+MAKE_OFFSET(Offs))))
|
||||
|
||||
set_mfp(MFP_Recycle,MFP(MEMBER_RECYCLE));
|
||||
|
||||
set_mfp(MFP_WeldFinished,MFP(MEMBER_TRIGGER_WELDABLE));
|
||||
|
||||
// This is not a member function pointer, but use MFP since it
|
||||
// uses the same address conversion as MFPs do
|
||||
FP_GetGameRules=horrible_cast<void *(*)()>(MFP(GETGAMERULES));
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_recycle(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free || Entity->pvPrivateData==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (IsValidBuilding[Entity->v.iuser3]!=1) // Not a marine structure?
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Make sure it's a marine building, undefined stuff happens on alien structures
|
||||
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_Recycle))();
|
||||
|
||||
|
||||
return 1;
|
||||
};
|
||||
static cell AMX_NATIVE_CALL ns_finish_weldable(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free || Entity->pvPrivateData==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// verify the classname since this will crash if it's the wrong class!
|
||||
if (strcmp(STRING(Entity->v.classname),"avhweldable")!=0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// First need to set the weldable to 100% complete
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
|
||||
|
||||
// Now make NS think the weldable has been welded again
|
||||
// This has to call AvHWeldable::AddBuildTime(float)
|
||||
// because AvHWeldable::TriggerFinished() does not work properly
|
||||
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_WeldFinished))(100.0);
|
||||
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES));
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES));
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_get_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)=amx_ctof2(params[2]);
|
||||
return 1;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)=amx_ctof2(params[2]);
|
||||
return 1;
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_set_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)+=amx_ctof2(params[2]));
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)+=amx_ctof2(params[2]));
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_add_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEVELOPER_BUILD
|
||||
static cell AMX_NATIVE_CALL findgameinfo(AMX *amx, cell *params)
|
||||
{
|
||||
void *Ret=(*(FP_GetGameRules))();
|
||||
union
|
||||
{
|
||||
void *v;
|
||||
int i;
|
||||
}vi;
|
||||
vi.v=Ret;
|
||||
|
||||
printf("GameRules=%d\n",vi.i);
|
||||
return 1;
|
||||
};
|
||||
#endif
|
||||
AMX_NATIVE_INFO memberfunc_natives[] = {
|
||||
#ifdef DEVELOPER_BUILD
|
||||
{ "getgameinfo", findgameinfo },
|
||||
#endif
|
||||
{ "ns_recycle", ns_recycle },
|
||||
{ "ns_finish_weldable", ns_finish_weldable },
|
||||
{ "ns_get_teamres", ns_get_teamres },
|
||||
{ "ns_set_teamres", ns_set_teamres },
|
||||
{ "ns_add_teamres", ns_add_teamres },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
void AddNatives_MemberFunc()
|
||||
{
|
||||
MF_AddNatives(memberfunc_natives);
|
||||
};
|
||||
#include <string.h>
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
#include "ns_const.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
|
||||
#include "FastDelegate.h"
|
||||
#include "GameManager.h"
|
||||
|
||||
extern int IsValidBuilding[AVH_USER3_MAX + 1];
|
||||
|
||||
using namespace fastdelegate::detail;
|
||||
|
||||
|
||||
void *GameRules=NULL;
|
||||
|
||||
|
||||
mBOOL dlclose_handle_invalid; // Linking errors with metamod
|
||||
|
||||
// void AvHBaseBuildable::StartRecycle()
|
||||
static void (GenericClass::*MFP_Recycle)();
|
||||
|
||||
// void AvHWeldable::AddBuildTime(float)
|
||||
static void (GenericClass::*MFP_WeldFinished)(float);
|
||||
|
||||
// AvHGameRules *GetGameRules(void)
|
||||
static void *(*FP_GetGameRules)();
|
||||
|
||||
|
||||
char *FuncBase;
|
||||
|
||||
/**
|
||||
* sizeof(void (detail::GenericClass::*fptr)())
|
||||
* is 8 in GCC. Add an empty void * pointer at
|
||||
* the end to compensate.
|
||||
* Layout in GCC:
|
||||
* union {
|
||||
* void *address; // When this is an address it will always be positive
|
||||
* int vtable_index; // When it is a vtable index it will always be odd = (vindex*2)+1
|
||||
* };
|
||||
* int delta;
|
||||
* -
|
||||
* Delta is the adjustment to the this pointer
|
||||
* For my implementations I will only need it to 0
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *in[2];
|
||||
OutType out;
|
||||
} mfpu;
|
||||
|
||||
mfpu.in[0]=in;
|
||||
mfpu.in[1]=NULL;
|
||||
out=mfpu.out;
|
||||
};
|
||||
#else
|
||||
template <typename OutType>
|
||||
inline void set_mfp(OutType &out, void *in)
|
||||
{
|
||||
out=horrible_cast<OutType>(in);
|
||||
};
|
||||
#endif
|
||||
|
||||
void MFuncs_Initialize(void)
|
||||
{
|
||||
char FileName[256];
|
||||
DLHANDLE DLLBase;
|
||||
#ifdef __linux__
|
||||
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
|
||||
#else
|
||||
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
|
||||
#endif
|
||||
|
||||
DLLBase=DLOPEN(FileName);
|
||||
FuncBase=(char *)DLSYM(DLLBase, MAKE_OFFSET(BASE));
|
||||
DLCLOSE(DLLBase);
|
||||
|
||||
#define MFP(Offs) (((void *)(((char *)FuncBase)+MAKE_OFFSET(Offs))))
|
||||
|
||||
set_mfp(MFP_Recycle,MFP(MEMBER_RECYCLE));
|
||||
|
||||
set_mfp(MFP_WeldFinished,MFP(MEMBER_TRIGGER_WELDABLE));
|
||||
|
||||
// This is not a member function pointer, but use MFP since it
|
||||
// uses the same address conversion as MFPs do
|
||||
FP_GetGameRules=horrible_cast<void *(*)()>(MFP(GETGAMERULES));
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_recycle(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free || Entity->pvPrivateData==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (IsValidBuilding[Entity->v.iuser3]!=1) // Not a marine structure?
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Make sure it's a marine building, undefined stuff happens on alien structures
|
||||
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_Recycle))();
|
||||
|
||||
|
||||
return 1;
|
||||
};
|
||||
static cell AMX_NATIVE_CALL ns_finish_weldable(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free || Entity->pvPrivateData==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// verify the classname since this will crash if it's the wrong class!
|
||||
if (strcmp(STRING(Entity->v.classname),"avhweldable")!=0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// First need to set the weldable to 100% complete
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
|
||||
|
||||
// Now make NS think the weldable has been welded again
|
||||
// This has to call AvHWeldable::AddBuildTime(float)
|
||||
// because AvHWeldable::TriggerFinished() does not work properly
|
||||
(reinterpret_cast<GenericClass *>(Entity->pvPrivateData)->*(MFP_WeldFinished))(100.0);
|
||||
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES));
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES));
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_get_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)=amx_ctof2(params[2]);
|
||||
return 1;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)=amx_ctof2(params[2]);
|
||||
return 1;
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_set_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_teamres(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (GameRules==NULL) // GameRules not initialized yet
|
||||
{
|
||||
GameRules=(*(FP_GetGameRules))();
|
||||
}
|
||||
if (GameRules==NULL) // Still null? Get out of here
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
switch(params[1])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMA_RESOURCES)+=amx_ctof2(params[2]));
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return amx_ftoc2(*(REAL *)((char *)GameRules+GAMERULES_TEAMB_RESOURCES)+=amx_ctof2(params[2]));
|
||||
}
|
||||
default:
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "ns_add_teamres: Expected 1 for team a or 2 for team b, got %d", params[1]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEVELOPER_BUILD
|
||||
static cell AMX_NATIVE_CALL findgameinfo(AMX *amx, cell *params)
|
||||
{
|
||||
void *Ret=(*(FP_GetGameRules))();
|
||||
union
|
||||
{
|
||||
void *v;
|
||||
int i;
|
||||
}vi;
|
||||
vi.v=Ret;
|
||||
|
||||
printf("GameRules=%d\n",vi.i);
|
||||
return 1;
|
||||
};
|
||||
#endif
|
||||
AMX_NATIVE_INFO memberfunc_natives[] = {
|
||||
#ifdef DEVELOPER_BUILD
|
||||
{ "getgameinfo", findgameinfo },
|
||||
#endif
|
||||
{ "ns_recycle", ns_recycle },
|
||||
{ "ns_finish_weldable", ns_finish_weldable },
|
||||
{ "ns_get_teamres", ns_get_teamres },
|
||||
{ "ns_set_teamres", ns_set_teamres },
|
||||
{ "ns_add_teamres", ns_add_teamres },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
void AddNatives_MemberFunc()
|
||||
{
|
||||
MF_AddNatives(memberfunc_natives);
|
||||
};
|
||||
|
@ -10,246 +10,246 @@
|
||||
//
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
#include "ParticleManager.h"
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
|
||||
#define KVI(__KEY) PSKeyValueI(__KEY,amx,params)
|
||||
#define KVF(__KEY) PSKeyValueF(__KEY,amx,params)
|
||||
#define KVS(__KEY) PSKeyValueS(__KEY,amx,params)
|
||||
#define NEXT params[__pcount++]
|
||||
|
||||
typedef enum partsystype_e
|
||||
{
|
||||
PSYS_TYPE_INT,
|
||||
PSYS_TYPE_FLOAT,
|
||||
PSYS_TYPE_STRING
|
||||
}partsystype;
|
||||
typedef struct partsyskey_s
|
||||
{
|
||||
const char *Name;
|
||||
partsystype type;
|
||||
}partsyskey;
|
||||
|
||||
cell PSKeyValueI(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
char StrData[1024];
|
||||
|
||||
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]);
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=&StrData[0];
|
||||
kvd.fHandled=0;
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
cell PSKeyValueF(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
char StrData[1024];
|
||||
|
||||
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=&StrData[0];
|
||||
kvd.fHandled=0;
|
||||
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
cell PSKeyValueS(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=MF_GetAmxString(amx,params[2],0,NULL);
|
||||
kvd.fHandled=0;
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_name(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("targetname");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_sprite(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pSprite");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genrate(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pGenRate");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genshape(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pGenShape");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genshape_params(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pGenShapeParams");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_spriteframes(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pSpriteNumFrames");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_numparticles(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pNumParticles");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_size(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pSize");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_vel_params(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pVelParams");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_vel_shape(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pVelShape");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_sys_life(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pSystemLifetime");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_particle_life(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pLifetime");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_rendermode(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pRenderMode");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_to_gen(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pPSToGen");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_anim_speed(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pAnimationSpeed");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_spawn_flags(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("spawnflags");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_base_color(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pBaseColor");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_scale(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pScale");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_max_alpha(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pMaxAlpha");
|
||||
}
|
||||
// ns_create_partsys(const name[], pGenShape, const pGenShapeParams[], pGenRate, const pSprite[],
|
||||
// pSpriteFrames, pNumParticles, Float:pSize, const pVelParams[], pVelShape,
|
||||
// Float:pSystemLifetime, Float:pParticleLifetime, pRenderMode, const pPSToGen[], pAnimationSpeed, pSpawnFlags)
|
||||
static cell AMX_NATIVE_CALL ns_create_partsys(AMX *amx, cell *params)
|
||||
{
|
||||
return (cell)CREATE_NAMED_ENTITY(MAKE_STRING("env_particles_custom"));
|
||||
};
|
||||
static cell AMX_NATIVE_CALL ns_spawn_ps(AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid particle system handle");
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *Ent=reinterpret_cast<edict_t *>(params[1]);
|
||||
MDLL_Spawn(Ent);
|
||||
|
||||
if (!Ent->free)
|
||||
{
|
||||
REMOVE_ENTITY(Ent);
|
||||
}
|
||||
return ParticleMan.Add(STRING(Ent->v.targetname),0);
|
||||
}
|
||||
// ns_fire_ps(Particle:id,Float:origin[3],Float:angles[3],flags=0)
|
||||
static cell AMX_NATIVE_CALL ns_fire_partsys(AMX *amx, cell *params)
|
||||
{
|
||||
float *origin=(float*)MF_GetAmxAddr(amx,params[2]);
|
||||
float *angles=(float*)MF_GetAmxAddr(amx,params[3]);
|
||||
|
||||
ParticleMan.FireSystem(static_cast<int>(params[1]),origin,angles,static_cast<int>(params[4]));
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_partsys_id(AMX *amx, cell *params)
|
||||
{
|
||||
return ParticleMan.Find(MF_GetAmxString(amx,params[1],0,NULL));;
|
||||
};
|
||||
|
||||
AMX_NATIVE_INFO particle_natives[] = {
|
||||
{ "ns_create_ps", ns_create_partsys },
|
||||
{ "ns_set_ps_name", ns_set_ps_name },
|
||||
{ "ns_set_ps_sprite", ns_set_ps_sprite },
|
||||
{ "ns_set_ps_genrate", ns_set_ps_genrate },
|
||||
{ "ns_set_ps_genshape", ns_set_ps_genshape },
|
||||
{ "ns_set_ps_genshape_params", ns_set_ps_genshape_params },
|
||||
{ "ns_set_ps_spriteframes", ns_set_ps_spriteframes },
|
||||
{ "ns_set_ps_numparticles", ns_set_ps_numparticles },
|
||||
{ "ns_set_ps_size", ns_set_ps_size },
|
||||
{ "ns_set_ps_vel_params", ns_set_ps_vel_params },
|
||||
{ "ns_set_ps_vel_shape", ns_set_ps_vel_shape },
|
||||
{ "ns_set_ps_sys_life", ns_set_ps_sys_life },
|
||||
{ "ns_set_ps_particle_life", ns_set_ps_particle_life },
|
||||
{ "ns_set_ps_rendermode", ns_set_ps_rendermode },
|
||||
{ "ns_set_ps_to_gen", ns_set_ps_to_gen },
|
||||
{ "ns_set_ps_anim_speed", ns_set_ps_anim_speed },
|
||||
{ "ns_set_ps_spawn_flags", ns_set_ps_spawn_flags },
|
||||
{ "ns_set_ps_base_color", ns_set_ps_base_color },
|
||||
{ "ns_set_ps_scale", ns_set_ps_scale },
|
||||
{ "ns_set_ps_max_alpha", ns_set_ps_max_alpha },
|
||||
{ "ns_spawn_ps", ns_spawn_ps },
|
||||
|
||||
{ "ns_fire_ps", ns_fire_partsys },
|
||||
{ "ns_get_ps_id", ns_get_partsys_id },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Particles()
|
||||
{
|
||||
MF_AddNatives(particle_natives);
|
||||
}
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
#include "ParticleManager.h"
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
|
||||
#define KVI(__KEY) PSKeyValueI(__KEY,amx,params)
|
||||
#define KVF(__KEY) PSKeyValueF(__KEY,amx,params)
|
||||
#define KVS(__KEY) PSKeyValueS(__KEY,amx,params)
|
||||
#define NEXT params[__pcount++]
|
||||
|
||||
typedef enum partsystype_e
|
||||
{
|
||||
PSYS_TYPE_INT,
|
||||
PSYS_TYPE_FLOAT,
|
||||
PSYS_TYPE_STRING
|
||||
}partsystype;
|
||||
typedef struct partsyskey_s
|
||||
{
|
||||
const char *Name;
|
||||
partsystype type;
|
||||
}partsyskey;
|
||||
|
||||
cell PSKeyValueI(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
char StrData[1024];
|
||||
|
||||
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]);
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=&StrData[0];
|
||||
kvd.fHandled=0;
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
cell PSKeyValueF(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
char StrData[1024];
|
||||
|
||||
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=&StrData[0];
|
||||
kvd.fHandled=0;
|
||||
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
cell PSKeyValueS(const char *name, AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
|
||||
return 0;
|
||||
}
|
||||
KeyValueData kvd;
|
||||
|
||||
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
|
||||
kvd.szKeyName=name;
|
||||
kvd.szValue=MF_GetAmxString(amx,params[2],0,NULL);
|
||||
kvd.fHandled=0;
|
||||
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
|
||||
|
||||
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_name(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("targetname");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_sprite(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pSprite");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genrate(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pGenRate");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genshape(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pGenShape");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_genshape_params(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pGenShapeParams");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_spriteframes(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pSpriteNumFrames");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_numparticles(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pNumParticles");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_size(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pSize");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_vel_params(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pVelParams");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_vel_shape(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pVelShape");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_sys_life(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pSystemLifetime");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_particle_life(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pLifetime");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_rendermode(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pRenderMode");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_to_gen(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pPSToGen");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_anim_speed(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("pAnimationSpeed");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_spawn_flags(AMX *amx, cell *params)
|
||||
{
|
||||
return KVI("spawnflags");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_base_color(AMX *amx, cell *params)
|
||||
{
|
||||
return KVS("pBaseColor");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_scale(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pScale");
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_ps_max_alpha(AMX *amx, cell *params)
|
||||
{
|
||||
return KVF("pMaxAlpha");
|
||||
}
|
||||
// ns_create_partsys(const name[], pGenShape, const pGenShapeParams[], pGenRate, const pSprite[],
|
||||
// pSpriteFrames, pNumParticles, Float:pSize, const pVelParams[], pVelShape,
|
||||
// Float:pSystemLifetime, Float:pParticleLifetime, pRenderMode, const pPSToGen[], pAnimationSpeed, pSpawnFlags)
|
||||
static cell AMX_NATIVE_CALL ns_create_partsys(AMX *amx, cell *params)
|
||||
{
|
||||
return (cell)CREATE_NAMED_ENTITY(MAKE_STRING("env_particles_custom"));
|
||||
};
|
||||
static cell AMX_NATIVE_CALL ns_spawn_ps(AMX *amx, cell *params)
|
||||
{
|
||||
if (params[1]==0)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid particle system handle");
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *Ent=reinterpret_cast<edict_t *>(params[1]);
|
||||
MDLL_Spawn(Ent);
|
||||
|
||||
if (!Ent->free)
|
||||
{
|
||||
REMOVE_ENTITY(Ent);
|
||||
}
|
||||
return ParticleMan.Add(STRING(Ent->v.targetname),0);
|
||||
}
|
||||
// ns_fire_ps(Particle:id,Float:origin[3],Float:angles[3],flags=0)
|
||||
static cell AMX_NATIVE_CALL ns_fire_partsys(AMX *amx, cell *params)
|
||||
{
|
||||
float *origin=(float*)MF_GetAmxAddr(amx,params[2]);
|
||||
float *angles=(float*)MF_GetAmxAddr(amx,params[3]);
|
||||
|
||||
ParticleMan.FireSystem(static_cast<int>(params[1]),origin,angles,static_cast<int>(params[4]));
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_partsys_id(AMX *amx, cell *params)
|
||||
{
|
||||
return ParticleMan.Find(MF_GetAmxString(amx,params[1],0,NULL));;
|
||||
};
|
||||
|
||||
AMX_NATIVE_INFO particle_natives[] = {
|
||||
{ "ns_create_ps", ns_create_partsys },
|
||||
{ "ns_set_ps_name", ns_set_ps_name },
|
||||
{ "ns_set_ps_sprite", ns_set_ps_sprite },
|
||||
{ "ns_set_ps_genrate", ns_set_ps_genrate },
|
||||
{ "ns_set_ps_genshape", ns_set_ps_genshape },
|
||||
{ "ns_set_ps_genshape_params", ns_set_ps_genshape_params },
|
||||
{ "ns_set_ps_spriteframes", ns_set_ps_spriteframes },
|
||||
{ "ns_set_ps_numparticles", ns_set_ps_numparticles },
|
||||
{ "ns_set_ps_size", ns_set_ps_size },
|
||||
{ "ns_set_ps_vel_params", ns_set_ps_vel_params },
|
||||
{ "ns_set_ps_vel_shape", ns_set_ps_vel_shape },
|
||||
{ "ns_set_ps_sys_life", ns_set_ps_sys_life },
|
||||
{ "ns_set_ps_particle_life", ns_set_ps_particle_life },
|
||||
{ "ns_set_ps_rendermode", ns_set_ps_rendermode },
|
||||
{ "ns_set_ps_to_gen", ns_set_ps_to_gen },
|
||||
{ "ns_set_ps_anim_speed", ns_set_ps_anim_speed },
|
||||
{ "ns_set_ps_spawn_flags", ns_set_ps_spawn_flags },
|
||||
{ "ns_set_ps_base_color", ns_set_ps_base_color },
|
||||
{ "ns_set_ps_scale", ns_set_ps_scale },
|
||||
{ "ns_set_ps_max_alpha", ns_set_ps_max_alpha },
|
||||
{ "ns_spawn_ps", ns_spawn_ps },
|
||||
|
||||
{ "ns_fire_ps", ns_fire_partsys },
|
||||
{ "ns_get_ps_id", ns_get_partsys_id },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Particles()
|
||||
{
|
||||
MF_AddNatives(particle_natives);
|
||||
}
|
||||
|
@ -10,261 +10,261 @@
|
||||
//
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
#include "AllocString.h"
|
||||
|
||||
StringManager AllocStringList;
|
||||
|
||||
// ns_set_player_model(id,const Model[]="")
|
||||
static cell AMX_NATIVE_CALL ns_set_player_model(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetModel(MF_GetAmxString(amx,params[2],0,NULL));
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ns_set_player_skin(id,skin=-1)
|
||||
static cell AMX_NATIVE_CALL ns_set_player_skin(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetSkin(params[2]);
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
// ns_set_player_body(id,body=-1)
|
||||
static cell AMX_NATIVE_CALL ns_set_player_body(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetBody(params[2]);
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
// ns_get_class(id)
|
||||
static cell AMX_NATIVE_CALL ns_get_class(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetClass();
|
||||
}
|
||||
// ns_get_jpfuel(id)
|
||||
static cell AMX_NATIVE_CALL ns_get_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL ret=(player->GetPev()->fuser3) / 10.0;
|
||||
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
// ns_set_jpfuel(id,Float:fuelpercent)
|
||||
static cell AMX_NATIVE_CALL ns_set_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL fuel = amx_ctof2(params[2]);
|
||||
if (fuel > 100.0)
|
||||
{
|
||||
fuel = 100.0;
|
||||
}
|
||||
if (fuel < 0.0)
|
||||
{
|
||||
fuel = 0.0;
|
||||
}
|
||||
|
||||
player->GetPev()->fuser3 = fuel * 10.0;
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL fuel = clamp(amx_ctof2(params[2]),0.0,100.0);
|
||||
|
||||
return amx_ftoc2(player->GetPev()->fuser3 = clamp(static_cast<float>(player->GetPev()->fuser3 + (fuel * 10.0)),static_cast<float>(0.0)));
|
||||
};
|
||||
// ns_get_speedchange(index)
|
||||
static cell AMX_NATIVE_CALL ns_get_speedchange(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetSpeedChange();
|
||||
}
|
||||
|
||||
// ns_set_speedchange(index,speedchange=0)
|
||||
static cell AMX_NATIVE_CALL ns_set_speedchange(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetSpeedChange(params[2]);
|
||||
|
||||
// Update PreThink_Post if we need to
|
||||
GameMan.HookPreThink_Post();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ns_get_maxspeed(index) (returns the max speed of the player BEFORE speed change is factored in.)
|
||||
static cell AMX_NATIVE_CALL ns_get_maxspeed(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetMaxSpeed();
|
||||
}
|
||||
// ns_set_fov(id,Float:fov);
|
||||
static cell AMX_NATIVE_CALL ns_set_fov(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->SetFOV(amx_ctof3(¶ms[2]));
|
||||
}
|
||||
// ns_giveiteM(id,"item");
|
||||
static cell AMX_NATIVE_CALL ns_giveitem(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
char *classname = MF_GetAmxString(amx,params[2],0,NULL);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (player->GetPev()->deadflag > 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *object=CREATE_NAMED_ENTITY(ALLOC_STRING2(classname));
|
||||
|
||||
if (!object)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Error creating entity \"%s\"", classname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SET_ORIGIN(object,player->GetPev()->origin); // move to player
|
||||
gpGamedllFuncs->dllapi_table->pfnSpawn(object); // emulate spawn
|
||||
object->v.flags |= FL_ONGROUND; // make it think it's touched the ground
|
||||
gpGamedllFuncs->dllapi_table->pfnThink(object); //
|
||||
gpGamedllFuncs->dllapi_table->pfnTouch(object,player->GetEdict()); // give it to the player
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_user_team(AMX* amx, cell* params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int team = player->GetPev()->team;
|
||||
|
||||
if (team > 4 || team < 0)
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (team)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// iuser1 means readyroom (I think!)
|
||||
if (player->GetPev()->iuser1 == 0)
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "marine1team", params[3]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "alien1team", params[3]);
|
||||
|
||||
return 2;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "marine2team", params[3]);
|
||||
|
||||
return 3;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "alien2team", params[3]);
|
||||
|
||||
return 4;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO player_natives[] = {
|
||||
|
||||
{ "ns_set_player_model", ns_set_player_model },
|
||||
{ "ns_set_player_skin", ns_set_player_skin },
|
||||
{ "ns_set_player_body", ns_set_player_body },
|
||||
|
||||
{ "ns_get_class", ns_get_class },
|
||||
|
||||
{ "ns_get_jpfuel", ns_get_jpfuel },
|
||||
{ "ns_set_jpfuel", ns_set_jpfuel },
|
||||
{ "ns_add_jpfuel", ns_add_jpfuel },
|
||||
|
||||
{ "ns_get_energy", ns_get_jpfuel }, // They do the same thing...
|
||||
{ "ns_set_energy", ns_set_jpfuel }, //
|
||||
{ "ns_add_energy", ns_add_jpfuel },
|
||||
|
||||
{ "ns_get_speedchange", ns_get_speedchange },
|
||||
{ "ns_set_speedchange", ns_set_speedchange },
|
||||
{ "ns_get_maxspeed", ns_get_maxspeed },
|
||||
|
||||
{ "ns_set_fov", ns_set_fov },
|
||||
|
||||
{ "ns_give_item", ns_giveitem },
|
||||
|
||||
{ "ns_get_user_team", ns_get_user_team },
|
||||
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Player()
|
||||
{
|
||||
MF_AddNatives(player_natives);
|
||||
}
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
#include "AllocString.h"
|
||||
|
||||
StringManager AllocStringList;
|
||||
|
||||
// ns_set_player_model(id,const Model[]="")
|
||||
static cell AMX_NATIVE_CALL ns_set_player_model(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetModel(MF_GetAmxString(amx,params[2],0,NULL));
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ns_set_player_skin(id,skin=-1)
|
||||
static cell AMX_NATIVE_CALL ns_set_player_skin(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetSkin(params[2]);
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
// ns_set_player_body(id,body=-1)
|
||||
static cell AMX_NATIVE_CALL ns_set_player_body(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetBody(params[2]);
|
||||
|
||||
GameMan.HookPostThink_Post();
|
||||
|
||||
return 1;
|
||||
}
|
||||
// ns_get_class(id)
|
||||
static cell AMX_NATIVE_CALL ns_get_class(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetClass();
|
||||
}
|
||||
// ns_get_jpfuel(id)
|
||||
static cell AMX_NATIVE_CALL ns_get_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL ret=(player->GetPev()->fuser3) / 10.0;
|
||||
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
// ns_set_jpfuel(id,Float:fuelpercent)
|
||||
static cell AMX_NATIVE_CALL ns_set_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL fuel = amx_ctof2(params[2]);
|
||||
if (fuel > 100.0)
|
||||
{
|
||||
fuel = 100.0;
|
||||
}
|
||||
if (fuel < 0.0)
|
||||
{
|
||||
fuel = 0.0;
|
||||
}
|
||||
|
||||
player->GetPev()->fuser3 = fuel * 10.0;
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_jpfuel(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
REAL fuel = clamp(amx_ctof2(params[2]),0.0,100.0);
|
||||
|
||||
return amx_ftoc2(player->GetPev()->fuser3 = clamp(static_cast<float>(player->GetPev()->fuser3 + (fuel * 10.0)),static_cast<float>(0.0)));
|
||||
};
|
||||
// ns_get_speedchange(index)
|
||||
static cell AMX_NATIVE_CALL ns_get_speedchange(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetSpeedChange();
|
||||
}
|
||||
|
||||
// ns_set_speedchange(index,speedchange=0)
|
||||
static cell AMX_NATIVE_CALL ns_set_speedchange(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
player->SetSpeedChange(params[2]);
|
||||
|
||||
// Update PreThink_Post if we need to
|
||||
GameMan.HookPreThink_Post();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ns_get_maxspeed(index) (returns the max speed of the player BEFORE speed change is factored in.)
|
||||
static cell AMX_NATIVE_CALL ns_get_maxspeed(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->GetMaxSpeed();
|
||||
}
|
||||
// ns_set_fov(id,Float:fov);
|
||||
static cell AMX_NATIVE_CALL ns_set_fov(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
return player->SetFOV(amx_ctof3(¶ms[2]));
|
||||
}
|
||||
// ns_giveiteM(id,"item");
|
||||
static cell AMX_NATIVE_CALL ns_giveitem(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
char *classname = MF_GetAmxString(amx,params[2],0,NULL);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (player->GetPev()->deadflag > 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *object=CREATE_NAMED_ENTITY(ALLOC_STRING2(classname));
|
||||
|
||||
if (!object)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Error creating entity \"%s\"", classname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SET_ORIGIN(object,player->GetPev()->origin); // move to player
|
||||
gpGamedllFuncs->dllapi_table->pfnSpawn(object); // emulate spawn
|
||||
object->v.flags |= FL_ONGROUND; // make it think it's touched the ground
|
||||
gpGamedllFuncs->dllapi_table->pfnThink(object); //
|
||||
gpGamedllFuncs->dllapi_table->pfnTouch(object,player->GetEdict()); // give it to the player
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_user_team(AMX* amx, cell* params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int team = player->GetPev()->team;
|
||||
|
||||
if (team > 4 || team < 0)
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (team)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// iuser1 means readyroom (I think!)
|
||||
if (player->GetPev()->iuser1 == 0)
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "undefinedteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "marine1team", params[3]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "alien1team", params[3]);
|
||||
|
||||
return 2;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "marine2team", params[3]);
|
||||
|
||||
return 3;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
MF_SetAmxString(amx, params[2], "alien2team", params[3]);
|
||||
|
||||
return 4;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
MF_SetAmxString(amx, params[2], "spectatorteam", params[3]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO player_natives[] = {
|
||||
|
||||
{ "ns_set_player_model", ns_set_player_model },
|
||||
{ "ns_set_player_skin", ns_set_player_skin },
|
||||
{ "ns_set_player_body", ns_set_player_body },
|
||||
|
||||
{ "ns_get_class", ns_get_class },
|
||||
|
||||
{ "ns_get_jpfuel", ns_get_jpfuel },
|
||||
{ "ns_set_jpfuel", ns_set_jpfuel },
|
||||
{ "ns_add_jpfuel", ns_add_jpfuel },
|
||||
|
||||
{ "ns_get_energy", ns_get_jpfuel }, // They do the same thing...
|
||||
{ "ns_set_energy", ns_set_jpfuel }, //
|
||||
{ "ns_add_energy", ns_add_jpfuel },
|
||||
|
||||
{ "ns_get_speedchange", ns_get_speedchange },
|
||||
{ "ns_set_speedchange", ns_set_speedchange },
|
||||
{ "ns_get_maxspeed", ns_get_maxspeed },
|
||||
|
||||
{ "ns_set_fov", ns_set_fov },
|
||||
|
||||
{ "ns_give_item", ns_giveitem },
|
||||
|
||||
{ "ns_get_user_team", ns_get_user_team },
|
||||
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Player()
|
||||
{
|
||||
MF_AddNatives(player_natives);
|
||||
}
|
||||
|
@ -10,418 +10,418 @@
|
||||
//
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
// Float:ns_get_res(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES)));
|
||||
}
|
||||
|
||||
// ns_set_res(Player,Float:res)
|
||||
static cell AMX_NATIVE_CALL ns_set_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_add_res(Player,Float:res)
|
||||
static cell AMX_NATIVE_CALL ns_add_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]),0.0,100.0));
|
||||
}
|
||||
// Float:ns_get_exp(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(EXP)));
|
||||
}
|
||||
|
||||
// ns_set_exp(Player,Float:exp)
|
||||
static cell AMX_NATIVE_CALL ns_set_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_add_exp(Player,Float:exp)
|
||||
static cell AMX_NATIVE_CALL ns_add_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]),0.0));
|
||||
}
|
||||
|
||||
// ns_get_points(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(POINTS));
|
||||
}
|
||||
|
||||
// ns_set_points(Player,points)
|
||||
static cell AMX_NATIVE_CALL ns_set_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
// ns_add_points(Player,points)
|
||||
static cell AMX_NATIVE_CALL ns_add_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]),0,9);
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(SCORE));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(DEATHS));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_hive_ability(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
int result = get_private(player->GetEdict(), MAKE_OFFSET(HIVEABILITY));
|
||||
|
||||
return (params[2] > 0) ? (result >= params[2] - 1) : result;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_remove_upgrade(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Upgrades are stored in a std::vector<int> in the player's private data
|
||||
// The integer value represents the impulse for the offset
|
||||
// std::vector's memory layout is:
|
||||
// void *start
|
||||
// void *lastobject
|
||||
// void *lastreserved
|
||||
struct upgradevector
|
||||
{
|
||||
int *start;
|
||||
int *end;
|
||||
int *allocated;
|
||||
|
||||
inline int size() { return static_cast<int>((reinterpret_cast<unsigned int>(end) - reinterpret_cast<unsigned int>(start)) / sizeof(int)); }
|
||||
inline int at(int which) { return start[which]; }
|
||||
inline void set(int which, int val) { start[which] = val; }
|
||||
inline bool remove(int val)
|
||||
{
|
||||
|
||||
for (int i = 0; i < this->size(); i++)
|
||||
{
|
||||
if (this->at(i) == val)
|
||||
{
|
||||
|
||||
int last = this->size() - 1;
|
||||
while (i < last)
|
||||
{
|
||||
this->set(i, this->at(i + 1));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
this->end--;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
inline void print()
|
||||
{
|
||||
printf("size: %d values: ", this->size());
|
||||
for (int i = 0; i < this->size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
printf(", ");
|
||||
|
||||
printf("%d", this->at(i));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
upgradevector *bought = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_BOUGHT));
|
||||
upgradevector *active = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_ACTIVE));
|
||||
|
||||
|
||||
//bought->print();
|
||||
//active->print();
|
||||
|
||||
bool bfound = bought->remove(params[2]);
|
||||
bool afound = active->remove(params[2]);
|
||||
|
||||
if (bfound)
|
||||
{
|
||||
if (afound)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (afound)
|
||||
{
|
||||
// shouldn't happen, but just incase
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
AMX_NATIVE_INFO player_memory_natives[] = {
|
||||
|
||||
{ "ns_get_res", ns_get_res },
|
||||
{ "ns_set_res", ns_set_res },
|
||||
{ "ns_add_res", ns_add_res },
|
||||
|
||||
{ "ns_get_exp", ns_get_exp },
|
||||
{ "ns_set_exp", ns_set_exp },
|
||||
{ "ns_add_exp", ns_add_exp },
|
||||
|
||||
{ "ns_get_points", ns_get_points },
|
||||
{ "ns_set_points", ns_set_points },
|
||||
{ "ns_add_points", ns_add_points },
|
||||
|
||||
{ "ns_set_score", ns_set_score },
|
||||
{ "ns_get_score", ns_get_score },
|
||||
{ "ns_add_score", ns_add_score },
|
||||
|
||||
{ "ns_get_deaths", ns_get_deaths },
|
||||
{ "ns_set_deaths", ns_set_deaths },
|
||||
{ "ns_add_deaths", ns_add_deaths },
|
||||
|
||||
{ "ns_get_hive_ability", ns_get_hive_ability },
|
||||
|
||||
{ "ns_remove_upgrade", ns_remove_upgrade },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_PlayerMemory()
|
||||
{
|
||||
MF_AddNatives(player_memory_natives);
|
||||
}
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
// Float:ns_get_res(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES)));
|
||||
}
|
||||
|
||||
// ns_set_res(Player,Float:res)
|
||||
static cell AMX_NATIVE_CALL ns_set_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_add_res(Player,Float:res)
|
||||
static cell AMX_NATIVE_CALL ns_add_res(AMX *amx, cell *params)
|
||||
{
|
||||
if (GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(RESOURCES),amx_ctof2(params[2]),0.0,100.0));
|
||||
}
|
||||
// Float:ns_get_exp(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(player->GetEdict(),MAKE_OFFSET(EXP)));
|
||||
}
|
||||
|
||||
// ns_set_exp(Player,Float:exp)
|
||||
static cell AMX_NATIVE_CALL ns_set_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_add_exp(Player,Float:exp)
|
||||
static cell AMX_NATIVE_CALL ns_add_exp(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(player->GetEdict(),MAKE_OFFSET(EXP),amx_ctof2(params[2]),0.0));
|
||||
}
|
||||
|
||||
// ns_get_points(Player)
|
||||
static cell AMX_NATIVE_CALL ns_get_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(POINTS));
|
||||
}
|
||||
|
||||
// ns_set_points(Player,points)
|
||||
static cell AMX_NATIVE_CALL ns_set_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
// ns_add_points(Player,points)
|
||||
static cell AMX_NATIVE_CALL ns_add_points(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(POINTS),static_cast<int>(params[2]),0,9);
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(SCORE));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_score(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(SCORE),static_cast<int>(params[2]));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(DEATHS));
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_deaths(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(DEATHS),static_cast<int>(params[2]));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_hive_ability(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
int result = get_private(player->GetEdict(), MAKE_OFFSET(HIVEABILITY));
|
||||
|
||||
return (params[2] > 0) ? (result >= params[2] - 1) : result;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_remove_upgrade(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx, params[1]);
|
||||
|
||||
if (!GameMan.IsCombat())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Upgrades are stored in a std::vector<int> in the player's private data
|
||||
// The integer value represents the impulse for the offset
|
||||
// std::vector's memory layout is:
|
||||
// void *start
|
||||
// void *lastobject
|
||||
// void *lastreserved
|
||||
struct upgradevector
|
||||
{
|
||||
int *start;
|
||||
int *end;
|
||||
int *allocated;
|
||||
|
||||
inline int size() { return static_cast<int>((reinterpret_cast<unsigned int>(end) - reinterpret_cast<unsigned int>(start)) / sizeof(int)); }
|
||||
inline int at(int which) { return start[which]; }
|
||||
inline void set(int which, int val) { start[which] = val; }
|
||||
inline bool remove(int val)
|
||||
{
|
||||
|
||||
for (int i = 0; i < this->size(); i++)
|
||||
{
|
||||
if (this->at(i) == val)
|
||||
{
|
||||
|
||||
int last = this->size() - 1;
|
||||
while (i < last)
|
||||
{
|
||||
this->set(i, this->at(i + 1));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
this->end--;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
inline void print()
|
||||
{
|
||||
printf("size: %d values: ", this->size());
|
||||
for (int i = 0; i < this->size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
printf(", ");
|
||||
|
||||
printf("%d", this->at(i));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
upgradevector *bought = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_BOUGHT));
|
||||
upgradevector *active = reinterpret_cast<upgradevector *>(reinterpret_cast<char *>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(UPGRADES_ACTIVE));
|
||||
|
||||
|
||||
//bought->print();
|
||||
//active->print();
|
||||
|
||||
bool bfound = bought->remove(params[2]);
|
||||
bool afound = active->remove(params[2]);
|
||||
|
||||
if (bfound)
|
||||
{
|
||||
if (afound)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (afound)
|
||||
{
|
||||
// shouldn't happen, but just incase
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
AMX_NATIVE_INFO player_memory_natives[] = {
|
||||
|
||||
{ "ns_get_res", ns_get_res },
|
||||
{ "ns_set_res", ns_set_res },
|
||||
{ "ns_add_res", ns_add_res },
|
||||
|
||||
{ "ns_get_exp", ns_get_exp },
|
||||
{ "ns_set_exp", ns_set_exp },
|
||||
{ "ns_add_exp", ns_add_exp },
|
||||
|
||||
{ "ns_get_points", ns_get_points },
|
||||
{ "ns_set_points", ns_set_points },
|
||||
{ "ns_add_points", ns_add_points },
|
||||
|
||||
{ "ns_set_score", ns_set_score },
|
||||
{ "ns_get_score", ns_get_score },
|
||||
{ "ns_add_score", ns_add_score },
|
||||
|
||||
{ "ns_get_deaths", ns_get_deaths },
|
||||
{ "ns_set_deaths", ns_set_deaths },
|
||||
{ "ns_add_deaths", ns_add_deaths },
|
||||
|
||||
{ "ns_get_hive_ability", ns_get_hive_ability },
|
||||
|
||||
{ "ns_remove_upgrade", ns_remove_upgrade },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_PlayerMemory()
|
||||
{
|
||||
MF_AddNatives(player_memory_natives);
|
||||
}
|
||||
|
@ -10,376 +10,376 @@
|
||||
//
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
int IsValidBuilding[AVH_USER3_MAX + 1] = {
|
||||
0, // AVH_USER3_NONE = 0,
|
||||
0, // AVH_USER3_MARINE_PLAYER,
|
||||
0, // AVH_USER3_COMMANDER_PLAYER,
|
||||
0, // AVH_USER3_ALIEN_PLAYER1,
|
||||
0, // AVH_USER3_ALIEN_PLAYER2,
|
||||
0, // AVH_USER3_ALIEN_PLAYER3,
|
||||
0, // AVH_USER3_ALIEN_PLAYER4,
|
||||
0, // AVH_USER3_ALIEN_PLAYER5,
|
||||
0, // AVH_USER3_ALIEN_EMBRYO,
|
||||
0, // AVH_USER3_SPAWN_TEAMONE,
|
||||
0, // AVH_USER3_SPAWN_TEAMTWO,
|
||||
0, // AVH_USER3_PARTICLE_ON, // only valid for AvHParticleEntity: entindex as int in fuser1, template index stored in fuser2
|
||||
0, // AVH_USER3_PARTICLE_OFF, // only valid for AvHParticleEntity: particle system handle in fuser1
|
||||
0, // AVH_USER3_WELD, // float progress (0 - 100) stored in fuser1
|
||||
0, // AVH_USER3_ALPHA, // fuser1 indicates how much alpha this entity toggles to in commander mode, fuser2 for players
|
||||
0, // AVH_USER3_MARINEITEM, // Something a friendly marine can pick up
|
||||
0, // AVH_USER3_WAYPOINT,
|
||||
2, // AVH_USER3_HIVE,
|
||||
0, // AVH_USER3_NOBUILD,
|
||||
0, // AVH_USER3_USEABLE,
|
||||
0, // AVH_USER3_AUDIO_ON,
|
||||
0, // AVH_USER3_AUDIO_OFF,
|
||||
0, // AVH_USER3_FUNC_RESOURCE,
|
||||
1, // AVH_USER3_COMMANDER_STATION,
|
||||
1, // AVH_USER3_TURRET_FACTORY,
|
||||
1, // AVH_USER3_ARMORY,
|
||||
1, // AVH_USER3_ADVANCED_ARMORY,
|
||||
1, // AVH_USER3_ARMSLAB,
|
||||
1, // AVH_USER3_PROTOTYPE_LAB,
|
||||
1, // AVH_USER3_OBSERVATORY,
|
||||
0, // AVH_USER3_CHEMLAB,
|
||||
0, // AVH_USER3_MEDLAB,
|
||||
0, // AVH_USER3_NUKEPLANT,
|
||||
1, // AVH_USER3_TURRET,
|
||||
1, // AVH_USER3_SIEGETURRET,
|
||||
1, // AVH_USER3_RESTOWER,
|
||||
0, // AVH_USER3_PLACEHOLDER,
|
||||
1, // AVH_USER3_INFANTRYPORTAL,
|
||||
0, // AVH_USER3_NUKE,
|
||||
0, // AVH_USER3_BREAKABLE,
|
||||
0, // AVH_USER3_UMBRA,
|
||||
1, // AVH_USER3_PHASEGATE,
|
||||
2, // AVH_USER3_DEFENSE_CHAMBER,
|
||||
2, // AVH_USER3_MOVEMENT_CHAMBER,
|
||||
2, // AVH_USER3_OFFENSE_CHAMBER,
|
||||
2, // AVH_USER3_SENSORY_CHAMBER,
|
||||
2, // AVH_USER3_ALIENRESTOWER,
|
||||
0, // AVH_USER3_HEAVY,
|
||||
0, // AVH_USER3_JETPACK,
|
||||
1, // AVH_USER3_ADVANCED_TURRET_FACTORY,
|
||||
0, // AVH_USER3_SPAWN_READYROOM,
|
||||
0, // AVH_USER3_CLIENT_COMMAND,
|
||||
0, // AVH_USER3_FUNC_ILLUSIONARY,
|
||||
0, // AVH_USER3_MENU_BUILD,
|
||||
0, // AVH_USER3_MENU_BUILD_ADVANCED,
|
||||
0, // AVH_USER3_MENU_ASSIST,
|
||||
0, // AVH_USER3_MENU_EQUIP,
|
||||
0, // AVH_USER3_MINE,
|
||||
0 // AVH_USER3_MAX
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ns_build_structure(idStructure);
|
||||
static cell AMX_NATIVE_CALL ns_build_structure(AMX *amx, cell *params)
|
||||
{
|
||||
// Trick NS into thinking that this structure is being spawned from the map
|
||||
// set the "startbuilt" setting to 1, then remove it.
|
||||
// "startbuilt" is set as "spawnflag" "1" in the ns.fgd
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int StructureType=IsValidBuilding[Entity->v.iuser3];
|
||||
if (StructureType==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->v.iuser3==AVH_USER3_HIVE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Already set?
|
||||
if (Entity->v.spawnflags & 1)
|
||||
{
|
||||
MDLL_Spawn(Entity);
|
||||
|
||||
goto undo_ghost;
|
||||
}
|
||||
|
||||
Entity->v.spawnflags |= 1;
|
||||
|
||||
MDLL_Spawn(Entity);
|
||||
|
||||
Entity->v.spawnflags &= ~1;
|
||||
|
||||
undo_ghost:
|
||||
if (StructureType==1) // marine, remove "ghost" appearance
|
||||
{
|
||||
if (get_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE))!=0)
|
||||
{
|
||||
set_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE),0);
|
||||
|
||||
Entity->v.rendermode=kRenderNormal;
|
||||
Entity->v.renderamt=100.0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
#define MASK_ELECTRICITY 8192
|
||||
static cell AMX_NATIVE_CALL ns_get_build(AMX *amx, cell *params)
|
||||
{
|
||||
int iLength;
|
||||
char *buildtype = MF_GetAmxString(amx,params[1],0,&iLength);
|
||||
int iBuiltOnly = params[2];
|
||||
int iNumber = params[3];
|
||||
edict_t* pBuild = NULL;
|
||||
int iCount=0;
|
||||
|
||||
while ((pBuild = UTIL_FindEntityByString(pBuild,"classname",buildtype)) != NULL)
|
||||
{
|
||||
if (iBuiltOnly > 0)
|
||||
{
|
||||
if (FStrEq("team_advarmory",buildtype) || FStrEq("team_advturretfactory",buildtype))
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBuild->v.fuser1 >= 1000 || pBuild->v.iuser4 & MASK_ELECTRICITY)
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
if (iNumber > 0 && iCount == iNumber)
|
||||
return ENTINDEX_NEW(pBuild);
|
||||
}
|
||||
return iCount++;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_hive_trait(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(Entity,MAKE_OFFSET(HIVE_TRAIT),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_hive_trait(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(HIVE_TRAIT));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_struct_owner(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(STRUCTOWNER));
|
||||
}
|
||||
// ns_set_struct_owner(idStructure,idPlayer) - -1 means no owner
|
||||
static cell AMX_NATIVE_CALL ns_set_struct_owner(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (params[2] > gpGlobals->maxClients || params[2] < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
set_private(Entity,MAKE_OFFSET(STRUCTOWNER),params[2]);
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_get_obs_energy(id);
|
||||
static cell AMX_NATIVE_CALL ns_get_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private(Entity,MAKE_OFFSET(OBS_ENERGY)));
|
||||
};
|
||||
// Float:ns_set_obs_energy(id,Float:energy);
|
||||
static cell AMX_NATIVE_CALL ns_set_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]));
|
||||
return 1;
|
||||
};
|
||||
|
||||
// Float:ns_add_obs_energy(id,Float:energy);
|
||||
static cell AMX_NATIVE_CALL ns_add_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]),0.0,100.0));
|
||||
};
|
||||
|
||||
// Float:ns_get_weld_time(idWeldable);
|
||||
static cell AMX_NATIVE_CALL ns_get_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
|
||||
};
|
||||
// ns_set_weld_time(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_set_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
};
|
||||
// Float:ns_add_weld_time(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_add_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]),0.0));
|
||||
};
|
||||
// Float:ns_get_weld_done(idWeldable);
|
||||
static cell AMX_NATIVE_CALL ns_get_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_DONE)));
|
||||
};
|
||||
// ns_set_weld_done(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_set_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
};
|
||||
// Float:ns_add_weld_done(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_add_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]),0.0));
|
||||
};
|
||||
|
||||
|
||||
AMX_NATIVE_INFO structure_natives[] = {
|
||||
{ "ns_build_structure", ns_build_structure },
|
||||
|
||||
{ "ns_get_build", ns_get_build },
|
||||
|
||||
{ "ns_get_hive_trait", ns_get_hive_trait },
|
||||
{ "ns_set_hive_trait", ns_set_hive_trait },
|
||||
|
||||
{ "ns_get_struct_owner", ns_get_struct_owner },
|
||||
{ "ns_set_struct_owner", ns_set_struct_owner },
|
||||
|
||||
{ "ns_get_obs_energy", ns_get_obs_energy },
|
||||
{ "ns_set_obs_energy", ns_set_obs_energy },
|
||||
{ "ns_add_obs_energy", ns_add_obs_energy },
|
||||
|
||||
{ "ns_get_weld_time", ns_get_weld_time },
|
||||
{ "ns_set_weld_time", ns_set_weld_time },
|
||||
{ "ns_add_weld_time", ns_add_weld_time },
|
||||
|
||||
{ "ns_get_weld_done", ns_get_weld_done },
|
||||
{ "ns_set_weld_done", ns_set_weld_done },
|
||||
{ "ns_add_weld_done", ns_add_weld_done },
|
||||
|
||||
/* prototypes for natives i have planned */
|
||||
//{ "ns_get_phase_target", ns_get_phase_target },
|
||||
//{ "ns_set_phase_target", ns_set_phase_target },
|
||||
|
||||
//{ "ns_set_phase_nextuse", ns_set_phase_nextuse },
|
||||
//{ "ns_get_phase_nextuse", ns_get_phase_nextuse },
|
||||
//{ "ns_add_phase_nextuse", ns_add_phase_nextuse },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Structure()
|
||||
{
|
||||
MF_AddNatives(structure_natives);
|
||||
}
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
int IsValidBuilding[AVH_USER3_MAX + 1] = {
|
||||
0, // AVH_USER3_NONE = 0,
|
||||
0, // AVH_USER3_MARINE_PLAYER,
|
||||
0, // AVH_USER3_COMMANDER_PLAYER,
|
||||
0, // AVH_USER3_ALIEN_PLAYER1,
|
||||
0, // AVH_USER3_ALIEN_PLAYER2,
|
||||
0, // AVH_USER3_ALIEN_PLAYER3,
|
||||
0, // AVH_USER3_ALIEN_PLAYER4,
|
||||
0, // AVH_USER3_ALIEN_PLAYER5,
|
||||
0, // AVH_USER3_ALIEN_EMBRYO,
|
||||
0, // AVH_USER3_SPAWN_TEAMONE,
|
||||
0, // AVH_USER3_SPAWN_TEAMTWO,
|
||||
0, // AVH_USER3_PARTICLE_ON, // only valid for AvHParticleEntity: entindex as int in fuser1, template index stored in fuser2
|
||||
0, // AVH_USER3_PARTICLE_OFF, // only valid for AvHParticleEntity: particle system handle in fuser1
|
||||
0, // AVH_USER3_WELD, // float progress (0 - 100) stored in fuser1
|
||||
0, // AVH_USER3_ALPHA, // fuser1 indicates how much alpha this entity toggles to in commander mode, fuser2 for players
|
||||
0, // AVH_USER3_MARINEITEM, // Something a friendly marine can pick up
|
||||
0, // AVH_USER3_WAYPOINT,
|
||||
2, // AVH_USER3_HIVE,
|
||||
0, // AVH_USER3_NOBUILD,
|
||||
0, // AVH_USER3_USEABLE,
|
||||
0, // AVH_USER3_AUDIO_ON,
|
||||
0, // AVH_USER3_AUDIO_OFF,
|
||||
0, // AVH_USER3_FUNC_RESOURCE,
|
||||
1, // AVH_USER3_COMMANDER_STATION,
|
||||
1, // AVH_USER3_TURRET_FACTORY,
|
||||
1, // AVH_USER3_ARMORY,
|
||||
1, // AVH_USER3_ADVANCED_ARMORY,
|
||||
1, // AVH_USER3_ARMSLAB,
|
||||
1, // AVH_USER3_PROTOTYPE_LAB,
|
||||
1, // AVH_USER3_OBSERVATORY,
|
||||
0, // AVH_USER3_CHEMLAB,
|
||||
0, // AVH_USER3_MEDLAB,
|
||||
0, // AVH_USER3_NUKEPLANT,
|
||||
1, // AVH_USER3_TURRET,
|
||||
1, // AVH_USER3_SIEGETURRET,
|
||||
1, // AVH_USER3_RESTOWER,
|
||||
0, // AVH_USER3_PLACEHOLDER,
|
||||
1, // AVH_USER3_INFANTRYPORTAL,
|
||||
0, // AVH_USER3_NUKE,
|
||||
0, // AVH_USER3_BREAKABLE,
|
||||
0, // AVH_USER3_UMBRA,
|
||||
1, // AVH_USER3_PHASEGATE,
|
||||
2, // AVH_USER3_DEFENSE_CHAMBER,
|
||||
2, // AVH_USER3_MOVEMENT_CHAMBER,
|
||||
2, // AVH_USER3_OFFENSE_CHAMBER,
|
||||
2, // AVH_USER3_SENSORY_CHAMBER,
|
||||
2, // AVH_USER3_ALIENRESTOWER,
|
||||
0, // AVH_USER3_HEAVY,
|
||||
0, // AVH_USER3_JETPACK,
|
||||
1, // AVH_USER3_ADVANCED_TURRET_FACTORY,
|
||||
0, // AVH_USER3_SPAWN_READYROOM,
|
||||
0, // AVH_USER3_CLIENT_COMMAND,
|
||||
0, // AVH_USER3_FUNC_ILLUSIONARY,
|
||||
0, // AVH_USER3_MENU_BUILD,
|
||||
0, // AVH_USER3_MENU_BUILD_ADVANCED,
|
||||
0, // AVH_USER3_MENU_ASSIST,
|
||||
0, // AVH_USER3_MENU_EQUIP,
|
||||
0, // AVH_USER3_MINE,
|
||||
0 // AVH_USER3_MAX
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ns_build_structure(idStructure);
|
||||
static cell AMX_NATIVE_CALL ns_build_structure(AMX *amx, cell *params)
|
||||
{
|
||||
// Trick NS into thinking that this structure is being spawned from the map
|
||||
// set the "startbuilt" setting to 1, then remove it.
|
||||
// "startbuilt" is set as "spawnflag" "1" in the ns.fgd
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->free)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
if (Entity->v.iuser3 <= AVH_USER3_NONE || Entity->v.iuser3 >= AVH_USER3_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int StructureType=IsValidBuilding[Entity->v.iuser3];
|
||||
if (StructureType==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->v.iuser3==AVH_USER3_HIVE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Already set?
|
||||
if (Entity->v.spawnflags & 1)
|
||||
{
|
||||
MDLL_Spawn(Entity);
|
||||
|
||||
goto undo_ghost;
|
||||
}
|
||||
|
||||
Entity->v.spawnflags |= 1;
|
||||
|
||||
MDLL_Spawn(Entity);
|
||||
|
||||
Entity->v.spawnflags &= ~1;
|
||||
|
||||
undo_ghost:
|
||||
if (StructureType==1) // marine, remove "ghost" appearance
|
||||
{
|
||||
if (get_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE))!=0)
|
||||
{
|
||||
set_private(Entity,MAKE_OFFSET(GHOST_STRUCTURE),0);
|
||||
|
||||
Entity->v.rendermode=kRenderNormal;
|
||||
Entity->v.renderamt=100.0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
#define MASK_ELECTRICITY 8192
|
||||
static cell AMX_NATIVE_CALL ns_get_build(AMX *amx, cell *params)
|
||||
{
|
||||
int iLength;
|
||||
char *buildtype = MF_GetAmxString(amx,params[1],0,&iLength);
|
||||
int iBuiltOnly = params[2];
|
||||
int iNumber = params[3];
|
||||
edict_t* pBuild = NULL;
|
||||
int iCount=0;
|
||||
|
||||
while ((pBuild = UTIL_FindEntityByString(pBuild,"classname",buildtype)) != NULL)
|
||||
{
|
||||
if (iBuiltOnly > 0)
|
||||
{
|
||||
if (FStrEq("team_advarmory",buildtype) || FStrEq("team_advturretfactory",buildtype))
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBuild->v.fuser1 >= 1000 || pBuild->v.iuser4 & MASK_ELECTRICITY)
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
iCount++;
|
||||
}
|
||||
if (iNumber > 0 && iCount == iNumber)
|
||||
return ENTINDEX_NEW(pBuild);
|
||||
}
|
||||
return iCount++;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_hive_trait(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(Entity,MAKE_OFFSET(HIVE_TRAIT),static_cast<int>(params[2]));
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_get_hive_trait(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(HIVE_TRAIT));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL ns_get_struct_owner(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(STRUCTOWNER));
|
||||
}
|
||||
// ns_set_struct_owner(idStructure,idPlayer) - -1 means no owner
|
||||
static cell AMX_NATIVE_CALL ns_set_struct_owner(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (params[2] > gpGlobals->maxClients || params[2] < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
set_private(Entity,MAKE_OFFSET(STRUCTOWNER),params[2]);
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_get_obs_energy(id);
|
||||
static cell AMX_NATIVE_CALL ns_get_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private(Entity,MAKE_OFFSET(OBS_ENERGY)));
|
||||
};
|
||||
// Float:ns_set_obs_energy(id,Float:energy);
|
||||
static cell AMX_NATIVE_CALL ns_set_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]));
|
||||
return 1;
|
||||
};
|
||||
|
||||
// Float:ns_add_obs_energy(id,Float:energy);
|
||||
static cell AMX_NATIVE_CALL ns_add_obs_energy(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(OBS_ENERGY),amx_ctof2(params[2]),0.0,100.0));
|
||||
};
|
||||
|
||||
// Float:ns_get_weld_time(idWeldable);
|
||||
static cell AMX_NATIVE_CALL ns_get_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_TIME)));
|
||||
};
|
||||
// ns_set_weld_time(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_set_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
};
|
||||
// Float:ns_add_weld_time(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_add_weld_time(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_TIME),amx_ctof2(params[2]),0.0));
|
||||
};
|
||||
// Float:ns_get_weld_done(idWeldable);
|
||||
static cell AMX_NATIVE_CALL ns_get_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(get_private_f(Entity,MAKE_OFFSET(WELD_DONE)));
|
||||
};
|
||||
// ns_set_weld_done(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_set_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
};
|
||||
// Float:ns_add_weld_done(idWeldable,Float:value);
|
||||
static cell AMX_NATIVE_CALL ns_add_weld_done(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amx_ftoc2(inc_private_f(Entity,MAKE_OFFSET(WELD_DONE),amx_ctof2(params[2]),0.0));
|
||||
};
|
||||
|
||||
|
||||
AMX_NATIVE_INFO structure_natives[] = {
|
||||
{ "ns_build_structure", ns_build_structure },
|
||||
|
||||
{ "ns_get_build", ns_get_build },
|
||||
|
||||
{ "ns_get_hive_trait", ns_get_hive_trait },
|
||||
{ "ns_set_hive_trait", ns_set_hive_trait },
|
||||
|
||||
{ "ns_get_struct_owner", ns_get_struct_owner },
|
||||
{ "ns_set_struct_owner", ns_set_struct_owner },
|
||||
|
||||
{ "ns_get_obs_energy", ns_get_obs_energy },
|
||||
{ "ns_set_obs_energy", ns_set_obs_energy },
|
||||
{ "ns_add_obs_energy", ns_add_obs_energy },
|
||||
|
||||
{ "ns_get_weld_time", ns_get_weld_time },
|
||||
{ "ns_set_weld_time", ns_set_weld_time },
|
||||
{ "ns_add_weld_time", ns_add_weld_time },
|
||||
|
||||
{ "ns_get_weld_done", ns_get_weld_done },
|
||||
{ "ns_set_weld_done", ns_set_weld_done },
|
||||
{ "ns_add_weld_done", ns_add_weld_done },
|
||||
|
||||
/* prototypes for natives i have planned */
|
||||
//{ "ns_get_phase_target", ns_get_phase_target },
|
||||
//{ "ns_set_phase_target", ns_set_phase_target },
|
||||
|
||||
//{ "ns_set_phase_nextuse", ns_set_phase_nextuse },
|
||||
//{ "ns_get_phase_nextuse", ns_get_phase_nextuse },
|
||||
//{ "ns_add_phase_nextuse", ns_add_phase_nextuse },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Structure()
|
||||
{
|
||||
MF_AddNatives(structure_natives);
|
||||
}
|
||||
|
@ -10,450 +10,450 @@
|
||||
//
|
||||
// Natural Selection Module
|
||||
//
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
// ns_has_weapon(idPlayer,NsWeapon,set=0)
|
||||
static cell AMX_NATIVE_CALL ns_has_weapon(AMX *amx,cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (params[3] == -1)
|
||||
{
|
||||
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
|
||||
{
|
||||
if (params[3] == 0)
|
||||
{
|
||||
player->GetPev()->weapons &= ~(1<<params[2]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (params[3] == 1)
|
||||
{
|
||||
player->GetPev()->weapons |= (1<<params[2]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// ns_set_weap_dmg(WeaponID,Float:damage)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_dmg(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WEAPDMG),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Float:ns_get_weap_dmg(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_dmg(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPDMG));
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
|
||||
// ns_set_weap_range(WeaponID,Float:range)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_range(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WEAPRANGE),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_get_weap_range(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_range(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPRANGE));
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
// ns_get_weap_ammo(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(WEAPCLIP));
|
||||
}
|
||||
// ns_set_weap_ammo(WeaponID,ammo)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(Entity,MAKE_OFFSET(WEAPCLIP),params[2]);
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(Entity,MAKE_OFFSET(WEAPCLIP),static_cast<int>(params[2]),0);
|
||||
}
|
||||
// ns_get_weap_reserve(PlayerID,WeaponType)
|
||||
static cell AMX_NATIVE_CALL ns_get_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL));
|
||||
case WEAPON_LMG:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG));
|
||||
case WEAPON_SHOTGUN:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN));
|
||||
case WEAPON_HMG:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG));
|
||||
case WEAPON_GRENADE_GUN:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL));
|
||||
case WEAPON_GRENADE:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3]);
|
||||
return 1;
|
||||
case WEAPON_LMG:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_SHOTGUN:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_HMG:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_GRENADE_GUN:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_GRENADE:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3]);
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3],0);
|
||||
case WEAPON_LMG:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3],0);
|
||||
case WEAPON_SHOTGUN:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3],0);
|
||||
case WEAPON_HMG:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3],0);
|
||||
case WEAPON_GRENADE_GUN:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3],0);
|
||||
case WEAPON_GRENADE:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3],0);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// ns_get_weapon(idPlayer,weaponid,&weapontype=0)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon(AMX *amx, cell *params)
|
||||
{
|
||||
// Peachy did it like this:
|
||||
// if weapontype is 0, return the primary weapon index of the player
|
||||
// if weapontype is < 0, return the last inventory weapon index of the player
|
||||
// otherwise, scan the player's inventory and look for a weapon of the given type
|
||||
// such as WEAPON_KNIFE, etc, etc
|
||||
// I added the last parameter, which will byref the weapontype of the weapon found
|
||||
// returns 0 on failure
|
||||
// last param default value added to not conflict with his version
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (params[2]<0) // find lastinv weapon
|
||||
{
|
||||
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(LAST_WEAPON)));
|
||||
|
||||
if (Weapon==NULL) // no weapon
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
|
||||
{
|
||||
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
|
||||
}
|
||||
|
||||
return ENTINDEX_NEW(Weapon);
|
||||
|
||||
}
|
||||
if (params[2]==0) // find current weapon
|
||||
{
|
||||
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(CURRENT_WEAPON)));
|
||||
|
||||
if (Weapon==NULL) // no weapon
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
|
||||
{
|
||||
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
|
||||
}
|
||||
|
||||
return ENTINDEX_NEW(Weapon);
|
||||
}
|
||||
|
||||
// Finding weapon by ID
|
||||
|
||||
char **pPlayerItems = reinterpret_cast<char**>(static_cast<char*>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(PLAYER_ITEMS));
|
||||
char *pItem;
|
||||
int weapon=params[2];
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
pItem = pPlayerItems[i];
|
||||
while (pItem)
|
||||
{
|
||||
if (*(int *)(pItem + MAKE_OFFSET(WEAPID)) == weapon)
|
||||
{
|
||||
return ENTINDEX_NEW(private_to_edict(pItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem = *(char **)(pItem + MAKE_OFFSET(WEAP_NEXT));
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#ifdef DEVELOPER_BUILD
|
||||
// ns_find_weapon_offset(idPlayer,"primweapon","lastinvweapon")
|
||||
static cell AMX_NATIVE_CALL ns_find_weapon_offset(AMX *amx, cell *params)
|
||||
{
|
||||
char *SPrimWeapon=MF_GetAmxString(amx,params[2],0,NULL);
|
||||
char *SLastInv=MF_GetAmxString(amx,params[3],1,NULL);
|
||||
edict_t *ePlayer=INDEXENT_NEW(params[1]);
|
||||
|
||||
// Locate entities by name
|
||||
edict_t *PrimWeapon=NULL;
|
||||
edict_t *LastInv=NULL;
|
||||
|
||||
edict_t *Temp=NULL;
|
||||
|
||||
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SPrimWeapon))!=NULL)
|
||||
{
|
||||
if (Temp->v.owner==ePlayer)
|
||||
{
|
||||
PrimWeapon=Temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Temp=NULL;
|
||||
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SLastInv))!=NULL)
|
||||
{
|
||||
if (Temp->v.owner==ePlayer)
|
||||
{
|
||||
LastInv=Temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (LastInv == NULL || PrimWeapon == NULL)
|
||||
{
|
||||
if (LastInv==NULL)
|
||||
{
|
||||
MF_Log("LastInv==NULL");
|
||||
}
|
||||
if (PrimWeapon==NULL)
|
||||
{
|
||||
MF_Log("PrimWeapon=NULL");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// now iterate through the client's private data until we find the pointer to PrimWeapon/LastInv's offset
|
||||
unsigned int *Ptr=(unsigned int*)ePlayer->pvPrivateData;
|
||||
|
||||
int FoundLastInv=0;
|
||||
int FoundPrim=0;
|
||||
size_t count=0;
|
||||
unsigned int iPrim;
|
||||
unsigned int iLast;
|
||||
|
||||
// so nasty D: this is basically horrible_cast
|
||||
union bleh
|
||||
{
|
||||
void *ptr;
|
||||
unsigned int ival;
|
||||
}blah;
|
||||
|
||||
blah.ptr=PrimWeapon->pvPrivateData;
|
||||
iPrim=blah.ival;
|
||||
|
||||
blah.ptr=LastInv->pvPrivateData;
|
||||
iLast=blah.ival;
|
||||
|
||||
while (count<4000)
|
||||
{
|
||||
if (*Ptr==iLast)
|
||||
{
|
||||
MF_Log("Found LastInv: %d",count);
|
||||
FoundLastInv=1;
|
||||
}
|
||||
if (*Ptr==iPrim)
|
||||
{
|
||||
MF_Log("Found Primary: %d",count);
|
||||
FoundPrim=1;
|
||||
}
|
||||
|
||||
if (FoundLastInv && FoundPrim)
|
||||
{
|
||||
//break;
|
||||
}
|
||||
count+=4;
|
||||
Ptr++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
AMX_NATIVE_INFO weapon_natives[] = {
|
||||
|
||||
{ "ns_has_weapon", ns_has_weapon },
|
||||
|
||||
{ "ns_set_weap_dmg", ns_set_weapon_dmg },
|
||||
{ "ns_get_weap_dmg", ns_get_weapon_dmg },
|
||||
|
||||
{ "ns_set_weap_range", ns_set_weapon_range },
|
||||
{ "ns_get_weap_range", ns_get_weapon_range },
|
||||
|
||||
{ "ns_set_weap_clip", ns_set_weapon_clip },
|
||||
{ "ns_get_weap_clip", ns_get_weapon_clip },
|
||||
{ "ns_add_weap_clip", ns_add_weapon_clip },
|
||||
|
||||
{ "ns_set_weap_reserve", ns_set_weap_reserve },
|
||||
{ "ns_get_weap_reserve", ns_get_weap_reserve },
|
||||
{ "ns_add_weap_reserve", ns_add_weap_reserve },
|
||||
|
||||
{ "ns_get_weapon", ns_get_weapon},
|
||||
|
||||
#ifdef DEVELOPER_BUILD
|
||||
{ "ns_find_weapon_offset", ns_find_weapon_offset},
|
||||
#endif
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Weapons()
|
||||
{
|
||||
MF_AddNatives(weapon_natives);
|
||||
}
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#include "ns.h"
|
||||
|
||||
#include "utilfunctions.h"
|
||||
#include "NEW_Util.h"
|
||||
|
||||
#include "GameManager.h"
|
||||
#include "CPlayer.h"
|
||||
|
||||
// ns_has_weapon(idPlayer,NsWeapon,set=0)
|
||||
static cell AMX_NATIVE_CALL ns_has_weapon(AMX *amx,cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (params[3] == -1)
|
||||
{
|
||||
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((player->GetPev()->weapons & (1<<params[2])) > 0)
|
||||
{
|
||||
if (params[3] == 0)
|
||||
{
|
||||
player->GetPev()->weapons &= ~(1<<params[2]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (params[3] == 1)
|
||||
{
|
||||
player->GetPev()->weapons |= (1<<params[2]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// ns_set_weap_dmg(WeaponID,Float:damage)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_dmg(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WEAPDMG),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Float:ns_get_weap_dmg(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_dmg(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPDMG));
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
|
||||
// ns_set_weap_range(WeaponID,Float:range)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_range(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private_f(Entity,MAKE_OFFSET(WEAPRANGE),amx_ctof2(params[2]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
// Float:ns_get_weap_range(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_range(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
REAL ret=get_private_f(Entity,MAKE_OFFSET(WEAPRANGE));
|
||||
return amx_ftoc2(ret);
|
||||
}
|
||||
// ns_get_weap_ammo(WeaponID)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_private(Entity,MAKE_OFFSET(WEAPCLIP));
|
||||
}
|
||||
// ns_set_weap_ammo(WeaponID,ammo)
|
||||
static cell AMX_NATIVE_CALL ns_set_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
set_private(Entity,MAKE_OFFSET(WEAPCLIP),params[2]);
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_weapon_clip(AMX *amx, cell *params)
|
||||
{
|
||||
|
||||
CreateNonPlayerEdict(amx,params[1]);
|
||||
|
||||
if (Entity->pvPrivateData == NULL || Entity->free)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inc_private(Entity,MAKE_OFFSET(WEAPCLIP),static_cast<int>(params[2]),0);
|
||||
}
|
||||
// ns_get_weap_reserve(PlayerID,WeaponType)
|
||||
static cell AMX_NATIVE_CALL ns_get_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL));
|
||||
case WEAPON_LMG:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG));
|
||||
case WEAPON_SHOTGUN:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN));
|
||||
case WEAPON_HMG:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG));
|
||||
case WEAPON_GRENADE_GUN:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL));
|
||||
case WEAPON_GRENADE:
|
||||
return get_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_set_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3]);
|
||||
return 1;
|
||||
case WEAPON_LMG:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_SHOTGUN:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_HMG:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_GRENADE_GUN:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3]);
|
||||
return 1;
|
||||
case WEAPON_GRENADE:
|
||||
set_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3]);
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL ns_add_weap_reserve(AMX *amx, cell *params)
|
||||
{
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected() || !player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case WEAPON_PISTOL:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_PISTOL),params[3],0);
|
||||
case WEAPON_LMG:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_LMG),(int)params[3],0);
|
||||
case WEAPON_SHOTGUN:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_SHOTGUN),(int)params[3],0);
|
||||
case WEAPON_HMG:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HMG),(int)params[3],0);
|
||||
case WEAPON_GRENADE_GUN:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_GL),(int)params[3],0);
|
||||
case WEAPON_GRENADE:
|
||||
return inc_private(player->GetEdict(),MAKE_OFFSET(AMMO_HG),(int)params[3],0);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// ns_get_weapon(idPlayer,weaponid,&weapontype=0)
|
||||
static cell AMX_NATIVE_CALL ns_get_weapon(AMX *amx, cell *params)
|
||||
{
|
||||
// Peachy did it like this:
|
||||
// if weapontype is 0, return the primary weapon index of the player
|
||||
// if weapontype is < 0, return the last inventory weapon index of the player
|
||||
// otherwise, scan the player's inventory and look for a weapon of the given type
|
||||
// such as WEAPON_KNIFE, etc, etc
|
||||
// I added the last parameter, which will byref the weapontype of the weapon found
|
||||
// returns 0 on failure
|
||||
// last param default value added to not conflict with his version
|
||||
|
||||
CreatePlayerPointer(amx,params[1]);
|
||||
|
||||
if (!player->IsConnected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!player->HasPrivateData())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (params[2]<0) // find lastinv weapon
|
||||
{
|
||||
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(LAST_WEAPON)));
|
||||
|
||||
if (Weapon==NULL) // no weapon
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
|
||||
{
|
||||
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
|
||||
}
|
||||
|
||||
return ENTINDEX_NEW(Weapon);
|
||||
|
||||
}
|
||||
if (params[2]==0) // find current weapon
|
||||
{
|
||||
edict_t *Weapon=private_to_edict(get_private_p<void *>(player->GetEdict(),MAKE_OFFSET(CURRENT_WEAPON)));
|
||||
|
||||
if (Weapon==NULL) // no weapon
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((params[0] / sizeof(cell))>2) // If this plugin was compiled with peachy's .inc then don't byref
|
||||
{
|
||||
*MF_GetAmxAddr_NEW(amx,params[3])=get_private(Weapon,MAKE_OFFSET(WEAPID));
|
||||
}
|
||||
|
||||
return ENTINDEX_NEW(Weapon);
|
||||
}
|
||||
|
||||
// Finding weapon by ID
|
||||
|
||||
char **pPlayerItems = reinterpret_cast<char**>(static_cast<char*>(player->GetEdict()->pvPrivateData) + MAKE_OFFSET(PLAYER_ITEMS));
|
||||
char *pItem;
|
||||
int weapon=params[2];
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
pItem = pPlayerItems[i];
|
||||
while (pItem)
|
||||
{
|
||||
if (*(int *)(pItem + MAKE_OFFSET(WEAPID)) == weapon)
|
||||
{
|
||||
return ENTINDEX_NEW(private_to_edict(pItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem = *(char **)(pItem + MAKE_OFFSET(WEAP_NEXT));
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#ifdef DEVELOPER_BUILD
|
||||
// ns_find_weapon_offset(idPlayer,"primweapon","lastinvweapon")
|
||||
static cell AMX_NATIVE_CALL ns_find_weapon_offset(AMX *amx, cell *params)
|
||||
{
|
||||
char *SPrimWeapon=MF_GetAmxString(amx,params[2],0,NULL);
|
||||
char *SLastInv=MF_GetAmxString(amx,params[3],1,NULL);
|
||||
edict_t *ePlayer=INDEXENT_NEW(params[1]);
|
||||
|
||||
// Locate entities by name
|
||||
edict_t *PrimWeapon=NULL;
|
||||
edict_t *LastInv=NULL;
|
||||
|
||||
edict_t *Temp=NULL;
|
||||
|
||||
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SPrimWeapon))!=NULL)
|
||||
{
|
||||
if (Temp->v.owner==ePlayer)
|
||||
{
|
||||
PrimWeapon=Temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Temp=NULL;
|
||||
while ((Temp=UTIL_FindEntityByString(Temp,"classname",SLastInv))!=NULL)
|
||||
{
|
||||
if (Temp->v.owner==ePlayer)
|
||||
{
|
||||
LastInv=Temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (LastInv == NULL || PrimWeapon == NULL)
|
||||
{
|
||||
if (LastInv==NULL)
|
||||
{
|
||||
MF_Log("LastInv==NULL");
|
||||
}
|
||||
if (PrimWeapon==NULL)
|
||||
{
|
||||
MF_Log("PrimWeapon=NULL");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// now iterate through the client's private data until we find the pointer to PrimWeapon/LastInv's offset
|
||||
unsigned int *Ptr=(unsigned int*)ePlayer->pvPrivateData;
|
||||
|
||||
int FoundLastInv=0;
|
||||
int FoundPrim=0;
|
||||
size_t count=0;
|
||||
unsigned int iPrim;
|
||||
unsigned int iLast;
|
||||
|
||||
// so nasty D: this is basically horrible_cast
|
||||
union bleh
|
||||
{
|
||||
void *ptr;
|
||||
unsigned int ival;
|
||||
}blah;
|
||||
|
||||
blah.ptr=PrimWeapon->pvPrivateData;
|
||||
iPrim=blah.ival;
|
||||
|
||||
blah.ptr=LastInv->pvPrivateData;
|
||||
iLast=blah.ival;
|
||||
|
||||
while (count<4000)
|
||||
{
|
||||
if (*Ptr==iLast)
|
||||
{
|
||||
MF_Log("Found LastInv: %d",count);
|
||||
FoundLastInv=1;
|
||||
}
|
||||
if (*Ptr==iPrim)
|
||||
{
|
||||
MF_Log("Found Primary: %d",count);
|
||||
FoundPrim=1;
|
||||
}
|
||||
|
||||
if (FoundLastInv && FoundPrim)
|
||||
{
|
||||
//break;
|
||||
}
|
||||
count+=4;
|
||||
Ptr++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
AMX_NATIVE_INFO weapon_natives[] = {
|
||||
|
||||
{ "ns_has_weapon", ns_has_weapon },
|
||||
|
||||
{ "ns_set_weap_dmg", ns_set_weapon_dmg },
|
||||
{ "ns_get_weap_dmg", ns_get_weapon_dmg },
|
||||
|
||||
{ "ns_set_weap_range", ns_set_weapon_range },
|
||||
{ "ns_get_weap_range", ns_get_weapon_range },
|
||||
|
||||
{ "ns_set_weap_clip", ns_set_weapon_clip },
|
||||
{ "ns_get_weap_clip", ns_get_weapon_clip },
|
||||
{ "ns_add_weap_clip", ns_add_weapon_clip },
|
||||
|
||||
{ "ns_set_weap_reserve", ns_set_weap_reserve },
|
||||
{ "ns_get_weap_reserve", ns_get_weap_reserve },
|
||||
{ "ns_add_weap_reserve", ns_add_weap_reserve },
|
||||
|
||||
{ "ns_get_weapon", ns_get_weapon},
|
||||
|
||||
#ifdef DEVELOPER_BUILD
|
||||
{ "ns_find_weapon_offset", ns_find_weapon_offset},
|
||||
#endif
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
void AddNatives_Weapons()
|
||||
{
|
||||
MF_AddNatives(weapon_natives);
|
||||
}
|
||||
|
Reference in New Issue
Block a user