amxmodx/dlls/dod2/dodx/NBase.cpp

388 lines
10 KiB
C++
Raw Normal View History

2004-07-01 21:57:12 +04:00
/*
* DoDX
* Copyright (c) 2004 Lukasz Wlasinski
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*
*/
#include "amxxmodule.h"
#include "dodx.h"
static cell AMX_NATIVE_CALL get_weapon_name(AMX *amx, cell *params){ // from id to name 3 params id, name, len
int id = params[1];
if (id<0 || id>=DODMAX_WEAPONS){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", id);
2004-07-01 21:57:12 +04:00
return 0;
}
return MF_SetAmxString(amx,params[2],weaponData[id].name,params[3]);
}
static cell AMX_NATIVE_CALL wpnlog_to_name(AMX *amx, cell *params){ // from log to name
int iLen;
char *log = MF_GetAmxString(amx,params[1],0,&iLen);
int i;
for ( i=0; i<DODMAX_WEAPONS; i++ ){
if ( strcmp(log,weaponData[i].logname ) == 0 )
return MF_SetAmxString(amx,params[2],weaponData[i].name,params[3]);
}
return 0;
}
static cell AMX_NATIVE_CALL wpnlog_to_id(AMX *amx, cell *params){ // from log to id
int iLen;
char *log = MF_GetAmxString(amx,params[1],0,&iLen);
int i;
for ( i=0; i<DODMAX_WEAPONS; i++ ){
if ( strcmp(log,weaponData[i].logname) == 0 )
return i;
}
return 0;
}
static cell AMX_NATIVE_CALL get_weapon_logname(AMX *amx, cell *params){ // from id to log
int id = params[1];
if (id<0 || id>=DODMAX_WEAPONS){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", id);
2004-07-01 21:57:12 +04:00
return 0;
}
return MF_SetAmxString(amx,params[2],weaponData[id].logname,params[3]);
}
static cell AMX_NATIVE_CALL is_melee(AMX *amx, cell *params){
int id = params[1];
if (id<0 || id>=DODMAX_WEAPONS){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", id);
2004-07-01 21:57:12 +04:00
return 0;
}
return weaponData[id].melee;
}
static cell AMX_NATIVE_CALL get_team_score(AMX *amx, cell *params){
int index = params[1];
switch ( index ){
case 1:
return AlliesScore;
break;
case 2:
return AxisScore;
break;
}
return 0;
}
static cell AMX_NATIVE_CALL get_user_score(AMX *amx, cell *params){
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-07-01 21:57:12 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
return pPlayer->savedScore;
return -1;
}
static cell AMX_NATIVE_CALL get_user_class(AMX *amx, cell *params){
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-07-01 21:57:12 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
return pPlayer->pEdict->v.playerclass;
return 0;
}
static cell AMX_NATIVE_CALL user_kill(AMX *amx, cell *params){
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-07-01 21:57:12 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame && pPlayer->IsAlive() ){
pPlayer->killPlayer();
return 1;
}
return 0;
}
static cell AMX_NATIVE_CALL get_map_info(AMX *amx, cell *params){
switch( params[1] ){
case 0:
return g_map.detect_allies_country;
break;
case 1:
return g_map.detect_allies_paras;
break;
case 2:
return g_map.detect_axis_paras;
break;
default:
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid map info id %d", params[1]);
2004-07-01 21:57:12 +04:00
break;
}
return -1;
}
static cell AMX_NATIVE_CALL get_user_pronestate(AMX *amx, cell *params){
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-07-01 21:57:12 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
return pPlayer->pEdict->v.iuser3;
return 0;
}
static cell AMX_NATIVE_CALL get_user_weapon(AMX *amx, cell *params){
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame){
int wpn = pPlayer->current;
cell *cpTemp = MF_GetAmxAddr(amx,params[2]);
*cpTemp = pPlayer->weapons[wpn].clip;
cpTemp = MF_GetAmxAddr(amx,params[3]);
*cpTemp = pPlayer->weapons[wpn].ammo;
return wpn;
}
return 0;
}
static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params)
{ // forward
#ifdef FORWARD_OLD_SYSTEM
2004-07-01 21:57:12 +04:00
int iFunctionIndex;
2004-10-04 01:33:09 +04:00
int err;
2004-07-01 21:57:12 +04:00
switch( params[1] ){
case 0:
2004-10-04 01:33:09 +04:00
if( (err=MF_AmxFindPublic(amx, "client_damage", &iFunctionIndex)) == AMX_ERR_NONE )
2004-07-01 21:57:12 +04:00
g_damage_info.put( amx , iFunctionIndex );
else
2004-10-04 01:33:09 +04:00
MF_LogError(amx, err, "client_damage not found");
2004-07-01 21:57:12 +04:00
return 0;
break;
case 1:
2004-10-04 01:33:09 +04:00
if( (err=MF_AmxFindPublic(amx, "client_death", &iFunctionIndex)) == AMX_ERR_NONE )
2004-07-01 21:57:12 +04:00
g_death_info.put( amx , iFunctionIndex );
else
2004-10-04 01:33:09 +04:00
MF_LogError(amx, err, "client_Death not found");
2004-07-01 21:57:12 +04:00
return 0;
break;
2004-09-08 22:09:01 +04:00
case 2:
2004-10-04 01:33:09 +04:00
if( (err=MF_AmxFindPublic(amx, "client_score", &iFunctionIndex)) == AMX_ERR_NONE )
2004-09-08 22:09:01 +04:00
g_score_info.put( amx , iFunctionIndex );
else
2004-10-04 01:33:09 +04:00
MF_LogError(amx, err, "client_score not found");
2004-09-08 22:09:01 +04:00
return 0;
break;
2004-07-01 21:57:12 +04:00
default:
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid forward id %d", params[2]);
2004-07-01 21:57:12 +04:00
return 0;
}
#endif
2004-09-08 22:09:01 +04:00
2004-07-01 21:57:12 +04:00
return 1;
}
2004-08-05 16:45:25 +04:00
static cell AMX_NATIVE_CALL register_cwpn(AMX *amx, cell *params){ // name,logname,melee=0
int i;
bool bFree = false;
for ( i=DODMAX_WEAPONS-DODMAX_CUSTOMWPNS;i<DODMAX_WEAPONS;i++){
if ( !weaponData[i].needcheck ){
bFree = true;
break;
}
}
if ( !bFree )
return 0;
int iLen;
char *szName = MF_GetAmxString(amx, params[1], 0, &iLen);
char *szLogName = MF_GetAmxString(amx, params[3], 0, &iLen);
strcpy(weaponData[i].name,szName);
strcpy(weaponData[i].logname,szLogName);
weaponData[i].needcheck = true;
weaponData[i].melee = params[2] ? true:false;
return i;
}
static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params){ // wid,att,vic,dmg,hp=0
int weapon = params[1];
if ( weapon < DODMAX_WEAPONS-DODMAX_CUSTOMWPNS ){ // only for custom weapons
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid custom weapon id %d", weapon);
2004-08-05 16:45:25 +04:00
return 0;
}
int att = params[2];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(params[2]);
2004-08-05 16:45:25 +04:00
int vic = params[3];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(params[3]);
2004-08-05 16:45:25 +04:00
int dmg = params[4];
if ( dmg<1 ){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid damage %d", dmg);
2004-08-05 16:45:25 +04:00
return 0;
}
int aim = params[5];
if ( aim < 0 || aim > 7 ){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid aim %d", aim);
2004-08-05 16:45:25 +04:00
return 0;
}
CPlayer* pAtt = GET_PLAYER_POINTER_I(att);
CPlayer* pVic = GET_PLAYER_POINTER_I(vic);
pVic->pEdict->v.dmg_inflictor = NULL;
2004-08-23 22:10:50 +04:00
if ( pAtt->index != pVic->index )
pAtt->saveHit( pVic , weapon , dmg, aim );
2004-08-05 16:45:25 +04:00
if ( !pAtt ) pAtt = pVic;
int TA = 0;
if ( (pVic->pEdict->v.team == pAtt->pEdict->v.team ) && ( pVic != pAtt) )
TA = 1;
MF_ExecuteForward( iFDamage,pAtt->index, pVic->index, dmg, weapon, aim, TA );
2004-08-05 16:45:25 +04:00
if ( pVic->IsAlive() )
return 1;
pAtt->saveKill(pVic,weapon,( aim == 1 ) ? 1:0 ,TA);
MF_ExecuteForward( iFDeath,pAtt->index, pVic->index, weapon, aim, TA );
return 1;
}
static cell AMX_NATIVE_CALL cwpn_shot(AMX *amx, cell *params){ // player,wid
int index = params[2];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-08-05 16:45:25 +04:00
int weapon = params[1];
if ( weapon < DODMAX_WEAPONS-DODMAX_CUSTOMWPNS ){
2004-10-04 01:33:09 +04:00
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid custom weapon id %d", weapon);
2004-08-05 16:45:25 +04:00
return 0;
}
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
pPlayer->saveShot(weapon);
return 1;
}
2004-08-05 05:02:39 +04:00
static cell AMX_NATIVE_CALL get_maxweapons(AMX *amx, cell *params){
return DODMAX_WEAPONS;
}
static cell AMX_NATIVE_CALL get_stats_size(AMX *amx, cell *params){
return 9;
}
2004-08-05 16:45:25 +04:00
static cell AMX_NATIVE_CALL is_custom(AMX *amx, cell *params){
int weapon = params[1];
if ( weapon < DODMAX_WEAPONS-DODMAX_CUSTOMWPNS ){
return 0;
}
return 1;
}
2004-08-06 17:58:20 +04:00
static cell AMX_NATIVE_CALL dod_get_user_team(AMX *amx, cell *params){ // player,wid
2004-08-23 22:10:50 +04:00
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-08-06 17:58:20 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
return pPlayer->pEdict->v.team;
}
static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params){ // player,wid
2004-08-23 22:10:50 +04:00
int index = params[1];
2004-10-04 01:33:09 +04:00
CHECK_PLAYER(index);
2004-08-06 17:58:20 +04:00
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
int iTeam = pPlayer->pEdict->v.team;
if ( params[3] ){
char *szTeam = "";
switch(iTeam){
case 1:
szTeam = "Allies";
break;
case 2:
szTeam = "Axis";
break;
}
MF_SetAmxString(amx,params[2],szTeam,params[3]);
}
return iTeam;
}
2004-07-01 21:57:12 +04:00
AMX_NATIVE_INFO base_Natives[] = {
2004-08-05 16:45:25 +04:00
{ "dod_wpnlog_to_name", wpnlog_to_name },
{ "dod_wpnlog_to_id", wpnlog_to_id },
2004-07-01 21:57:12 +04:00
2004-08-05 16:45:25 +04:00
{ "dod_get_team_score", get_team_score },
{ "dod_get_user_score", get_user_score },
{ "dod_get_user_class", get_user_class },
{ "dod_get_user_weapon", get_user_weapon },
2004-07-01 21:57:12 +04:00
2004-08-05 16:45:25 +04:00
{ "dod_get_map_info", get_map_info },
{ "dod_user_kill", user_kill },
{ "dod_get_pronestate", get_user_pronestate },
2004-07-01 21:57:12 +04:00
2004-08-05 16:45:25 +04:00
{ "xmod_get_wpnname", get_weapon_name },
{ "xmod_get_wpnlogname", get_weapon_logname },
{ "xmod_is_melee_wpn", is_melee },
{ "xmod_get_maxweapons", get_maxweapons },
{ "xmod_get_stats_size", get_stats_size },
{ "xmod_is_custom_wpn", is_custom },
2004-08-05 05:02:39 +04:00
2004-08-05 16:45:25 +04:00
{ "register_statsfwd",register_forward },
// Custom Weapon Support
{ "custom_weapon_add", register_cwpn }, // name,melee,logname
{ "custom_weapon_dmg", cwpn_dmg },
{ "custom_weapon_shot", cwpn_shot },
2004-07-01 21:57:12 +04:00
2004-08-06 17:58:20 +04:00
//****************************************
{ "get_user_team", get_user_team },
{ "get_weaponname", get_weapon_name },
{ "get_user_weapon", get_user_weapon },
{ "dod_get_user_team", dod_get_user_team },
2004-08-23 22:10:50 +04:00
{ "dod_get_wpnname", get_weapon_name },
{ "dod_get_wpnlogname", get_weapon_logname },
{ "dod_is_melee", is_melee },
2004-08-06 17:58:20 +04:00
2004-08-05 16:45:25 +04:00
///*******************
{ NULL, NULL }
2004-07-01 21:57:12 +04:00
};