Jump to content
  • 0

Spawn coins on Zombies


chi

Question

Can someone tell me if im doing something wrong here? Im trying to spawn a random amount of coins on Zombies when they die.

This is my zombie_generate.sqf and im calling it from my custom compiles. Sorry, but im on my phone and cant find a spoiler box button.

#include "\z\addons\dayz_code\loot\Loot.hpp"

private ["_bypass","_position","_unitTypes","_radius","_method","_agent","_maxlocalspawned","_doLoiter","_wildspawns","_maxControlledZombies",
"_cantSee","_isOk","_zPos","__FILE__","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg","_skipFOV","_wildSpawns","_tooClose",
"_type","_loot","_array","_rnd","_lootType","_index","_weights","_loot_count","_favStance","_lootGroup"];

_position = _this select 0;
_doLoiter = _this select 1; // wonder around
_unitTypes = _this select 2; // class of wanted models
//_wildspawns = _this select 3;
_bypass = _this select 3;

_maxlocalspawned = round(dayz_spawnZombies);
//Lets check if we need to divide the amount of zeds
if (r_player_divideinvehicle > 0) then {
    _maxlocalspawned = round(dayz_spawnZombies / r_player_divideinvehicle);
};

_maxControlledZombies = round(dayz_maxLocalZombies);

_cantSee = {
    private "_isOk";

    _isOk = true;
    _zPos = +(_this select 0);
    if (count _zPos < 3) exitWith {
        diag_log format["%1::_cantSee illegal pos %2", __FILE__, _zPos];
        false
    };
    _zPos = ATLtoASL _zPos;
    _fov = _this select 1; // players half field of view
    _safeDistance = _this select 2; // minimum distance. closer is wrong
    _farDistance = _this select 3; // distance further we won't check
    _zPos set [2, (_zPos select 2) + 1.7];
    {
        _xasl = getPosASL _x;
        if (_xasl distance _zPos < _farDistance) then {
            if (_xasl distance _zPos < _safeDistance) then {
                _isOk = false;
            } else {
                _eye = eyePos _x; // ASL
                _ed = eyeDirection _x;
                _ed = (_ed select 0) atan2 (_ed select 1);
                _deg = [_xasl, _zPos] call BIS_fnc_dirTo;
                _deg = (_deg - _ed + 720) % 360;
                if (_deg > 180) then { _deg = _deg - 360; };
                if ((abs(_deg) < _fov) && {( // in right angle sector?
                        (!(terrainIntersectASL [_zPos, _eye]) // no terrain between?
                        && {(!(lineIntersects [_zPos, _eye]))}) // and no object between?
                    )}) then {
                    _isOk = false;
                };
            };
        };
        if (!_isOk) exitWith {false};
    uiSleep 0.001;
    } forEach playableUnits;

    _isOk
};

_skipFOV = false;

if ((_maxlocalspawned < _maxControlledZombies) && (dayz_CurrentNearByZombies < dayz_maxNearByZombies) && (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then {
    if (_bypass) then {  
        _skipFOV = true;
        _position = [_position,3,20,1] call fn_selectRandomLocation;
    };

    if (surfaceIsWater _position) exitWith { diag_log "Location is in Water Abort"; };

    if ((_skipFOV) or {([_position, 15, 10, 70] call _cantSee)}) then {
        _tooClose = {isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0;
        if (_tooClose) exitwith { diag_log "Zombie_Generate: was too close to player."; };
        
        if (count _unitTypes == 0) then {
            _unitTypes = getArray (missionConfigFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass");
        };
        
        // lets create an agent
        _type = _unitTypes call BIS_fnc_selectRandom;
        _radius = 5;
        //_method = if (_doLoiter) then {"CAN_COLLIDE"} else {"NONE"};
        _agent = createAgent [_type, _position, [], _radius, "CAN_COLLIDE"]; 
        uiSleep 0.03;
        
        //add to global counter 
        dayz_spawnZombies = dayz_spawnZombies + 1;
        dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1;
        dayz_currentGlobalZombies = dayz_currentGlobalZombies + 1;
        
        //Add some loot
        if (0.3 > random 1) then {
            _lootGroup = configFile >> "CfgVehicles" >> _type >> "zombieLoot";
            if (isText _lootGroup) then {
                //_lootGroup = dayz_lootGroups find getText (_lootGroup);
                _lootGroup = Loot_GetGroup(getText _lootGroup);
                //[_agent, _lootGroup, 1] call loot_insert;
                Loot_Insert(_agent, _lootGroup, 1);
            };
        };
        
        _agent setVariable["agentObject",_agent];

        if (!isNull _agent) then {
            _agent setDir random 360;
            uiSleep 0.03;
            _position = getPosATL _agent;

            _favStance = (
                switch ceil(random(3^0.5)^2) do {
                    //case 3: {"DOWN"}; // prone
                    case 2: {"middle"}; // Kneel "middle"
                    default {"Up"}; // stand-up
                }
            );
            _agent setUnitPos _favStance;
            _agent setVariable ["stance", _favStance];
            _agent setVariable ["BaseLocation", _position];
            _agent setVariable ["doLoiter", _doLoiter]; // true: Z will be wandering, false: stay still
            
            _coinsRandom = random 1;
            if (_coinsRandom <= 0.5) then {
            _cash = round(random 20) * 5; // number between 0 and 200 Add Coins to Zombie
            _agent setVariable["CashMoney",_cash ,true]; // Add Coins to Zombie
            };
        };
    };
};
 

Link to comment
Share on other sites

19 answers to this question

Recommended Posts

  • 1

dont think this can be done this way.

I do it a bit differently than what you're looking for.

But... It adds coins to players WHEN you kill the zombie.

This is my local_eventkill.sqf

Spoiler

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_zed","_killer","_kills","_array","_type","_humanity","_player_add_wealth"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {
    _kills = _killer getVariable[_type,0];
    _killer setVariable[_type,(_kills + 1),true];
    
    
    
    _player_wealth = _killer getVariable [Z_moneyVariable,0];
    //_player_add_wealth = 50;
    
    
    
    //increase players humanity when zed killed
    _humanity = _killer getVariable["humanity",0];
    _humanity = _humanity + 5;
    
    switch true do {
    case (_humanity <= -50000): {_player_add_wealth = 5};
    case (_humanity <= -5000): {_player_add_wealth = 50};
    case (_humanity >= 50000): {_player_add_wealth = 250};
    case (_humanity >= 10000): {_player_add_wealth = 100};
    default {_player_add_wealth = 50}; // You can use this as a default variable, not sure if it's needed in this situation.
};
    
    
    _killer setVariable["humanity",_humanity,true];    
    _killer setVariable[Z_moneyVariable,(_player_wealth + _player_add_wealth),true];
    
    call player_forceSave;
};

it adds more coins depending on humanity level. You can change to your needs. but keep the structure the same, otherwise it'll break it.

This file is called in your compiles, you will need to change the paths.

GL

Link to comment
Share on other sites

  • 0

I think you need to edit your fn_selfactions.sqf to spawn check-wallet action on zombies.
change
if (_isMan && {!_isAlive} && {!(_cursorTarget isKindOf "Animal")} && {!_isZombie} && {player distance _cursorTarget < 5}) then {
to
if (_isMan && {!_isAlive} && {!(_cursorTarget isKindOf "Animal")} && {player distance _cursorTarget < 5}) then {
(I haven't tested)

Link to comment
Share on other sites

  • 0

Thanks guys.

I got this from Juan last night

 

Spoiler

private["_killer","_coins","_rand"];

_array = _this select 0;
_zed = _array select 0;
_killer = _array select 1;
_type = _this select 1;

if (local _zed) then {
_coins = _zed getVariable [Z_moneyVariable,0];

_a = 1;
_b =2;
_c =3;

_addcoins = [_c,_b,_a] call BIS_fnc_selectRandom; 


_zed setVariable[Z_moneyVariable,_addcoins,true];

_kills = _killer getVariable[_type,0];
_killer setVariable[_type,(_kills + 1),true];

//increase players humanity when zed killed
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 5;
_killer setVariable["humanity",_humanity,true];
};
 

He had the same idea for the local_eventKill.sqf.

I must say that I do like @theduke 's humanity system. 

The zombie_generate.sqf that i posted had the coin section from my old 1.0.5 servers. It worked back then, but no luck in 1.0.6...

Thanks again, and i'm glad you guys are still active here and helping out!! (makes it rain coffee money)

;-)

Link to comment
Share on other sites

  • 0

Let me also just ask, if I wanted to make it more random, like a random amount between 0 and 150 for most zombies, and occasionally a high amount like up to 500, could something like this work?

if _coinsrandom <= .5 then round(random 20) * 5

if _coinsrandom = 1 then round(random 50) * 10

 

If you guys could help me, that would be awesome. Thanks again for helping me to even get coins working.

Link to comment
Share on other sites

  • 0
9 hours ago, JasonTM said:

_chance = random 1;

if (_chance <= .05) then {    //5% chance that player gets 500 coins
    _addcoins = 500;
} else {                     // 95% chance that player gets random amount from 0 to 150        
    _addcoins = round(random 150);
};

@JasonTM I'm trying, but I can't seem to implement it into the local_killEvent.sqf and make it work. Think you could show me what the whole file should look like?

Link to comment
Share on other sites

  • 0
1 hour ago, chi said:

@JasonTM I'm trying, but I can't seem to implement it into the local_killEvent.sqf and make it work. Think you could show me what the whole file should look like?

This should work.

 

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_zed","_killer","_kills","_array","_type","_humanity","_player_add_wealth","_chance"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {
    _kills = _killer getVariable[_type,0];
    _killer setVariable[_type,(_kills + 1),true];
    
    _player_wealth = _killer getVariable [Z_moneyVariable,0];
    
    //increase players humanity when zed killed
    _humanity = _killer getVariable["humanity",0];
    _humanity = _humanity + 5;
	
	_chance = random 1;

	if (_chance <= .05) then {    //5% chance that player gets 500 coins
		_player_add_wealth = 500;
	} else {                     // 95% chance that player gets random amount from 0 to 150        
		_player_add_wealth = round(random 150);
	};

    _killer setVariable["humanity",_humanity,true];    
    _killer setVariable[Z_moneyVariable,(_player_wealth + _player_add_wealth),true];
    
    call player_forceSave;
};

 

Link to comment
Share on other sites

  • 0

@JasonTM That works great to spawn coins on the player. I've tried to get the coins to spawn on the zombie by changing the killer setvariable to zed set variable, but again, I can't get the coins to spawn on the zombie.

I hate to ask more of you on this topic, but can you show me how to make them spawn on the zombies so that players have to use "Check Wallet" to get the coins?

Thanks again!!

 

This is what I had.. im no coder so don't laugh to hard... lol

Spoiler

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_killer","_coins","_chance"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {

    
_coins = _zed getVariable [Z_moneyVariable,0];
    
_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
        _addcoins = round(random 500);
    } else {                     // 90% chance that player gets random amount from 0 to 50        
        _addcoins = round(random 50);
    }; 
    
_zed setVariable[Z_moneyVariable,_addcoins,true];

_kills = _killer getVariable[_type,0];
_killer setVariable[_type,(_kills + 1),true];    

//increase players humanity when zed killed
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 5;
_killer setVariable["humanity",_humanity,true];    
};

 

Link to comment
Share on other sites

  • 0
5 hours ago, chi said:

@JasonTM That works great to spawn coins on the player. I've tried to get the coins to spawn on the zombie by changing the killer setvariable to zed set variable, but again, I can't get the coins to spawn on the zombie.

I hate to ask more of you on this topic, but can you show me how to make them spawn on the zombies so that players have to use "Check Wallet" to get the coins?

Thanks again!!

 

This is what I had.. im no coder so don't laugh to hard... lol

  Reveal hidden contents

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_killer","_coins","_chance"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {

    
_coins = _zed getVariable [Z_moneyVariable,0];
    
_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
        _addcoins = round(random 500);
    } else {                     // 90% chance that player gets random amount from 0 to 50        
        _addcoins = round(random 50);
    }; 
    
_zed setVariable[Z_moneyVariable,_addcoins,true];

_kills = _killer getVariable[_type,0];
_killer setVariable[_type,(_kills + 1),true];    

//increase players humanity when zed killed
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 5;
_killer setVariable["humanity",_humanity,true];    
};

 

using the check wallet on zombies will not work. Ill have time to work on this in a bit for you

Link to comment
Share on other sites

  • 0
On 12/26/2017 at 6:30 PM, Schalldampfer said:

I think you need to edit your fn_selfactions.sqf to spawn check-wallet action on zombies.
change
if (_isMan && {!_isAlive} && {!(_cursorTarget isKindOf "Animal")} && {!_isZombie} && {player distance _cursorTarget < 5}) then {
to
if (_isMan && {!_isAlive} && {!(_cursorTarget isKindOf "Animal")} && {player distance _cursorTarget < 5}) then {
(I haven't tested)

I checked my server and  confirmed this works well

I have added coins to zeds in local_eventkill.sqf

Spoiler

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private["_array","_zed","_killer","_type","_kills","_humanity"];

_array = _this select 0;
_zed = _array select 0;
_killer = _array select 1;
_type = _this select 1;

[_zed,"spotted",0,false] call dayz_zombieSpeak;

if (local _zed) then {
    _kills = _killer getVariable[_type,0];
    _killer setVariable[_type,(_kills + 1),true];

    //increase players humanity when zed killed
    _humanity = _killer getVariable["humanity",0];
    _humanity = _humanity + 5;
    _killer setVariable["humanity",_humanity,true];

    //Credit to Zupa for original "add money to ai" code.
    if (Z_singleCurrency) then {
        _zed setVariable[Z_MoneyVariable,round(random 50)*10 ,true];
    };

};

 

Link to comment
Share on other sites

  • 0
8 hours ago, theduke said:

using the check wallet on zombies will not work. Ill have time to work on this in a bit for you

I actually have check wallet working on zombies and a working local_eventKill that spawns coins on them. Its in array format though, and I really prefer the round random configuration. I'll attach the array version thats working with check wallet on zombies (provided to me by @juandayz)

Spoiler

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
 private["_killer","_coins","_rand"];

_array = _this select 0;
_zed = _array select 0;
_killer = _array select 1;
_type = _this select 1;

if (local _zed) then {
_coins = _zed getVariable [Z_moneyVariable,0];

_a =17;
_b =29;
_c =34;
_d =48;
_e =54;
_addcoins = [_e,_d,_c,_b,_a] call BIS_fnc_selectRandom; 


_zed setVariable[Z_moneyVariable,_addcoins,true];

_kills = _killer getVariable[_type,0];
_killer setVariable[_type,(_kills + 1),true];

//increase players humanity when zed killed
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 5;
_killer setVariable["humanity",_humanity,true];
};

Thanks again to all of you for helping me out!

Link to comment
Share on other sites

  • 0
46 minutes ago, chi said:

I actually have check wallet working on zombies and a working local_eventKill that spawns coins on them. Its in array format though, and I really prefer the round random configuration. I'll attach the array version thats working with check wallet on zombies (provided to me by @juandayz)

  Reveal hidden contents

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
 private["_killer","_coins","_rand"];

_array = _this select 0;
_zed = _array select 0;
_killer = _array select 1;
_type = _this select 1;

if (local _zed) then {
_coins = _zed getVariable [Z_moneyVariable,0];

_a =17;
_b =29;
_c =34;
_d =48;
_e =54;
_addcoins = [_e,_d,_c,_b,_a] call BIS_fnc_selectRandom; 


_zed setVariable[Z_moneyVariable,_addcoins,true];

_kills = _killer getVariable[_type,0];
_killer setVariable[_type,(_kills + 1),true];

//increase players humanity when zed killed
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 5;
_killer setVariable["humanity",_humanity,true];
};

Thanks again to all of you for helping me out!

I should have phrased that better. lol it will work, but for the performance of what it does, with check wallet it adds alot more "actions" for the server.

Hence hurting the FPS.

But...every server owner does things differently. Thanks for sharing :)

Link to comment
Share on other sites

  • 0

So do you think you can help me swap the array for the "round(random)" chance config i posted before?

@juandayz @JasonTM maybe you can help with it. I want to use this in local_killEvent to spawn coins on zombies.

_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
        _addcoins = round(random 500);
    } else {                     // 90% chance that player gets random amount from 0 to 50        
        _addcoins = round(random 50);
    }; 

Link to comment
Share on other sites

  • 0
13 hours ago, chi said:

So do you think you can help me swap the array for the "round(random)" chance config i posted before?

@juandayz @JasonTM maybe you can help with it. I want to use this in local_killEvent to spawn coins on zombies.

_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
        _addcoins = round(random 500);
    } else {                     // 90% chance that player gets random amount from 0 to 50        
        _addcoins = round(random 50);
    }; 

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_zed","_killer","_kills","_array","_type","_humanity","_addcoins","_chance"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {
    _kills = _killer getVariable[_type,0];
    _killer setVariable[_type,(_kills + 1),true];
    
    //increase players humanity when zed killed
    _humanity = _killer getVariable["humanity",0];
    _humanity = _humanity + 5;
	
	_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
		_addcoins = round(random 500);
	} else {                     // 90% chance that player gets random amount from 0 to 50        
		_addcoins = round(random 50);
	};  

    _killer setVariable["humanity",_humanity,true];
	
	_zed setVariable[Z_MoneyVariable,_addcoins ,true];
};

 

Edited by JasonTM
Edited out the player force save
Link to comment
Share on other sites

  • 0
56 minutes ago, JasonTM said:

//[unit, selectionName, damage, source, projectile]
//will only run when local to the created object
//record any key hits to the required selection
private ["_zed","_killer","_kills","_array","_type","_humanity","_addcoins","_chance"];

_array =         _this select 0;
_zed =             _array select 0;
_killer =         _array select 1;
_type =         _this select 1;

if (local _zed) then {
    _kills = _killer getVariable[_type,0];
    _killer setVariable[_type,(_kills + 1),true];
    
    //increase players humanity when zed killed
    _humanity = _killer getVariable["humanity",0];
    _humanity = _humanity + 5;
	
	_chance = random 1;

    if (_chance <= .1) then {    //10% chance that player gets up to 500 coins
		_addcoins = round(random 500);
	} else {                     // 90% chance that player gets random amount from 0 to 50        
		_addcoins = round(random 50);
	};  

    _killer setVariable["humanity",_humanity,true];
	
	_zed setVariable[Z_MoneyVariable,_addcoins ,true];
};

 

Thanks alot for the response. Going to test it as soon as i get home.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Discord

×
×
  • Create New...