[Collection]Adding Ingame Commands

Status
Not open for further replies.
Added /spv command to give vitals to another player:

Needed Files to be changed:
\WarZ Game Server\ServerGameLogic.cpp
\WarZ Game Server\ServerGameLogic.h

ServerGameLogic.h - Line 158:
Add
Code:
int        GetPlayerStruct(peerInfo_s& pr, const char* user);
int        Cmd_SetPlayerVitals(obj_ServerPlayer* plr, const char* cmd);

ServerGameLogic.cpp
Look For:
Code:
    if(strncmp(cmd, "/sv", 3) == 0 && plr->profile_.ProfileData.isDevAccount)
        return Cmd_SetVitals(plr, cmd);
add below
Code:
    if(strncmp(cmd, "/spv", 4) == 0 && plr->profile_.ProfileData.isDevAccount)
        return Cmd_SetPlayerVitals(plr, cmd);

Add Below the ProcessChatCommand
Code:
int ServerGameLogic::GetPlayerStruct(peerInfo_s& pr, const char* user)
{
 for(int i=0; i<MAX_PEERS_COUNT; ++i)
 {
     pr = GetPeer(i);
     if (pr.status_ == PEER_PLAYING && pr.player && (strcmp(pr.player->userName, user) == 0) )
         return 1;
 }
 return 0;
}

int ServerGameLogic::Cmd_SetPlayerVitals(obj_ServerPlayer* plr, const char* cmd)
{
    char buf[128];
    char user[128];
    int v1, v2, v3, v4;
    peerInfo_s pr;


    if(6 != sscanf(cmd, "%s %s %d %d %d %d", buf, user, &v1, &v2, &v3, &v4))
        return 2;
    
    if (GetPlayerStruct(pr, user))
    {
        pr.player->loadout_->Health = (float)v1;
        pr.player->loadout_->Hunger = (float)v2;
        pr.player->loadout_->Thirst = (float)v3;
        pr.player->loadout_->Toxic  = (float)v4;
        r3dOutToLog("Cmd_SetPlayervitals: %s was given %f, %f, %f and %f\n", user, v1, v2, v3, v4);
        return 0;
    }
    r3dOutToLog("Cmd_SetPlayerVitals: Player %s not Found!", user);
    return 2;
}
How-To-Use: /spv username health hunger thirst toxic
Hint: function ServerGameLogic::GetPlayerStruct() can be used for other teleport command to reduce code.

BTW small glitch in Teleport Admin to Player function, here's fix:

Change
Code:
        r3dOutToLog("Cannot fine: %s!\n", user);
    }
    r3dOutToLog("There was an Error while Searching for Players!\n");
  return 2;
To
Code:
     }


    r3dOutToLog("Cmd_TPMTP: Cannot find: %s!\n", user);
    return 2;
 
Last edited:
Added /gpi command to give item (* amount) to another player:

Needed Files to be changed:
\WarZ Game Server\ServerGameLogic.cpp
\WarZ Game Server\ServerGameLogic.h

ServerGameLogic.h - Line 158:
Add
Code:
	int			Cmd_GivePlayerItem(obj_ServerPlayer* plr, const char* cmd);

ServerGameLogic.cpp
Look For:
Code:
	if(strncmp(cmd, "/gi", 3) == 0 && plr->profile_.ProfileData.isDevAccount)
		return Cmd_GiveItem(plr, cmd);
add below
Code:
    if(strncmp(cmd, "/gpi", 4) == 0 && plr->profile_.ProfileData.isDevAccount)
		return Cmd_GivePlayerItem(plr, cmd);

Add Below the ProcessChatCommand
Code:
int ServerGameLogic::Cmd_GivePlayerItem(obj_ServerPlayer* plr, const char* cmd)
{
	char buf[128];
	char user[128];
	int itemid, amount;
	peerInfo_s pr;


	if(4 != sscanf(cmd, "%s %s %d %d", buf, user, &itemid, &amount))
		return 2;


	if (GetPlayerStruct(pr, user))
	{	
		if(g_pWeaponArmory->getConfig(itemid) == NULL) {
			r3dOutToLog("Cmd_GiveItem: no item %d\n", itemid);
			return 3;
		}
		wiInventoryItem wi;
		wi.itemID   = itemid;
		wi.quantity = amount;
		pr.player->BackpackAddItem(wi);
		return 0;
	}
	r3dOutToLog("Cmd_GivePlayerItem: Player %s not Found!", user);
    return 2;
}
How-To-Use: /gpi username itemid amount
Hint: code is using previous added function GetPlayerStruct() (see post above)
 
New GodMode command (not fully tested, pretty alone atm on my srv, should work for player<->player, tested with zombies):

Added /gm command to give player godmode status on or off (leading to ApplyDamageToPlayer() ineffective and/or Zombies attitude):

Needed Files to be changed:
\WarZ Game Server\sobj_Zombie.cpp
\WarZ Game Server\obj_ServerPlayer.h
\WarZ Game Server\obj_ServerPlayer.cpp
\WarZ Game Server\ServerGameLogic.cpp
\WarZ Game Server\ServerGameLogic.h

sobj_Zombie.cpp:
-----------------
Look for:
Code:
bool obj_Zombie::IsPlayerDetectable(const obj_ServerPlayer* plr, float dist)
{
    if(plr->loadout_->Alive == 0)
        return false;
Add:
Code:
    if (plr->GodMode == 2)
        return false;

Look for:
Code:
bool obj_Zombie::SenseWeaponFire(const obj_ServerPlayer* plr, const ServerWeapon* wpn)
{
    if(ZombieState == EZombieStates::ZState_Dead)
        return false; // no attack while dead.
    if(ZombieState == EZombieStates::ZState_Waking)
        return false; // give him time to wake!
Add:
Code:
    if (plr->GodMode == 2)
        return false;

Look for:
Code:
        case EZombieStates::ZState_Attack:
        {
            obj_ServerPlayer* trg = IsServerPlayer(GameWorld().GetObject(hardObjLock));
Next line should be modified to:
Code:
            if(!trg || trg->loadout_->Alive == 0 || trg->GodMode == 2)


obj_ServerPlayer.h
------------------
Look for:
Code:
    float        deathTime;


    void        DoDeath();
Add
Code:
    int            GodMode;

obj_ServerPlayer.cpp
--------------------
in function obj_ServerPlayer::OnCreate():
Look for:
Code:
    FireHitCount = 0;
Add:
Code:
    GodMode = 0;

ServerGameLogic.h
------------------
Look for:
Code:
    int        ProcessChatCommand(obj_ServerPlayer* plr, const char* cmd);
Add:
Code:
int          Cmd_GodMode(obj_ServerPlayer* plr, const char* cmd);

ServerGameLogic.cpp
--------------------
Look For:
Code:
bool ServerGameLogic::ApplyDamageToPlayer(GameObject* fromObj, obj_ServerPlayer* targetPlr, const r3dPoint3D& 


dmgPos, float damage, int bodyBone, int bodyPart, bool force_damage, STORE_CATEGORIES damageSource, int airState 


)
{
    r3d_assert(fromObj);
    r3d_assert(targetPlr);


    if(targetPlr->loadout_->Alive == 0)
        return false;
Add below:
Code:
    if(targetPlr->GodMode)
        return false;

Look for:
Code:
int ServerGameLogic::ProcessChatCommand(obj_ServerPlayer* plr, const char* cmd)
{
    r3dOutToLog("cmd: %s admin:%d\n", cmd, plr->profile_.ProfileData.isDevAccount);
Add below:
Code:
    if(strncmp(cmd, "/gm", 3) == 0 && plr->profile_.ProfileData.isDevAccount)
        return Cmd_GodMode(plr, cmd);

Add Below the ProcessChatCommand
Code:
int ServerGameLogic::Cmd_GodMode(obj_ServerPlayer* plr, const char* cmd){
    char buf[128];
    int onoff;


    sscanf(cmd, "%s %d", buf, &onoff);


    plr->GodMode = onoff;
    r3dOutToLog("Setting godmode for %s to %d!", plr->userName, onoff);
    return 0;
}
How-To-Use: /gm [status]
where
[status] = 0 -> godmode OFF
[status] = 1 -> godmode ON but detectable by zombies
[status] = 2 -> godmode ON and not detectable by Zombies

Hint: even with GodMode=2, zombie if hit *will* begin to walk toward sound origin but won't attack
 
Last edited:
New GodMode command (not fully tested, pretty alone atm on my srv, should work for player<->player, tested with zombies):

Added /gm command to give player godmode status on or off (leading to ApplyDamageToPlayer() ineffective and/or Zombies attitude):

Needed Files to be changed:
\WarZ Game Server\sobj_Zombie.cpp
\WarZ Game Server\obj_ServerPlayer.h
\WarZ Game Server\obj_ServerPlayer.cpp
\WarZ Game Server\ServerGameLogic.cpp
\WarZ Game Server\ServerGameLogic.h

sobj_Zombie.cpp:
-----------------
Look for:
Code:
bool obj_Zombie::IsPlayerDetectable(const obj_ServerPlayer* plr, float dist)
{
    if(plr->loadout_->Alive == 0)
        return false;
Add:
Code:
    if (plr->GodMode == 2)
        return false;

Look for:
Code:
bool obj_Zombie::SenseWeaponFire(const obj_ServerPlayer* plr, const ServerWeapon* wpn)
{
    if(ZombieState == EZombieStates::ZState_Dead)
        return false; // no attack while dead.
    if(ZombieState == EZombieStates::ZState_Waking)
        return false; // give him time to wake!
Add:
Code:
    if (plr->GodMode == 2)
        return false;
obj_ServerPlayer.h
------------------
Look for:
Code:
    float        deathTime;


    void        DoDeath();
Add
Code:
    int            GodMode;

obj_ServerPlayer.cpp
--------------------
in function obj_ServerPlayer::OnCreate():
Look for:
Code:
    FireHitCount = 0;
Add:
Code:
    GodMode = 0;

ServerGameLogic.h
------------------
Look for:
Code:
    int        ProcessChatCommand(obj_ServerPlayer* plr, const char* cmd);
Add:
Code:
int          Cmd_GodMode(obj_ServerPlayer* plr, const char* cmd);

ServerGameLogic.cpp
Look For:
Code:
bool ServerGameLogic::ApplyDamageToPlayer(GameObject* fromObj, obj_ServerPlayer* targetPlr, const r3dPoint3D& 


dmgPos, float damage, int bodyBone, int bodyPart, bool force_damage, STORE_CATEGORIES damageSource, int airState 


)
{
    r3d_assert(fromObj);
    r3d_assert(targetPlr);


    if(targetPlr->loadout_->Alive == 0)
        return false;
Add below:
Code:
    if(targetPlr->GodMode)
        return false;

Look for:
Code:
int ServerGameLogic::ProcessChatCommand(obj_ServerPlayer* plr, const char* cmd)
{
    r3dOutToLog("cmd: %s admin:%d\n", cmd, plr->profile_.ProfileData.isDevAccount);
Add below:
Code:
    if(strncmp(cmd, "/gm", 3) == 0 && plr->profile_.ProfileData.isDevAccount)
        return Cmd_GodMode(plr, cmd);

Add Below the ProcessChatCommand
Code:
int ServerGameLogic::Cmd_GodMode(obj_ServerPlayer* plr, const char* cmd){
    char buf[128];
    int onoff;


    sscanf(cmd, "%s %d", buf, &onoff);


    plr->GodMode = onoff;
    r3dOutToLog("Setting godmode for %s to %d!", plr->userName, onoff);
    return 0;
}
How-To-Use: /gm [status]
where
[status] = 0 -> godmode OFF
[status] = 1 -> godmode ON but detectable by zombies
[status] = 2 -> godmode ON and not detectable by Zombies

Hint: even with GodMode=2, zombie if hit *will* begin to walk toward sound origin but won't attack

here appears: command executed

but dont works..

zombies still killing me =/

EDIT: I forgot to change sobj_Zombie.cpp, now works fine ^^
 
Last edited:
That means: after the ProcessChatCommand function in ServerGameLogic.cpp file, add this code, which is a new function.
 
Yeh i tipp in /spv Username Not working for me =/ maybe here something wrong.

 
So the same for GPI /gpi username itemid value ?
Edit: tryed it again seem like the same thing like befor execute /SPV Username 1 and the console shows up player reported
 
yes thats because you have to put for example /spv Username 100 0 0 0 (100 is health, and the zeros are hunger, thirst and toxicity. you cant just do one you have to set them all.
 
At the end of my function there was a nice line to read:

How-To-Use: /spv username health hunger thirst toxic

I hope "username" is easy understandable :)
Last 4 values are in percentage, and better put 100 to 'health' :)
As you don't want to be either hunger nor thirsty nor toxic, put 3 times '0'

So:

/spv username 100 0 0 0

 
Status
Not open for further replies.
Back