Modme Forums

Random Chance for zombie to drop a part?

Game Modding | Call of Duty: Black Ops 3 | Scripting


Zombieslayeraj:

I have most of the scripting for my map's easter egg done, however there is one thing I want which is for zombies to have a random chance to drop a hand that is used for another part of the easter egg. So far for testing and such I have left it in the middle of the room, but if someone could possibly help me to figure out how to make a zombie drop the part that would be incredible!


sharpgamers4you:

Hmmm this is really good, but i have no idea bro sorry, but will get back to you when I have something


MyNameIsNobody:

Maybe would be easier/better to spawn in one specific zombie that drops it that can spawn at random during a span of the next 3 rounds after "x" happens in the EE. But i cant script.


Spiki:

I used this:

in main function:

zm_spawner::register_zombie_death_event_callback(&mario_cap_zom_spawn);

down below:
#precache( "model", "mario_sunshine_cap");
#define CAP_DROP_CHANCE 10
function mario_cap_zom_spawn()
{

if(level.zombie_can_drop_cap == 0) //check if zombie can drop caš
    return;

if(!isdefined(zm_zonemgr::get_zone_from_position(self.origin, true))) //check if zom is in playable area
    return;

if(RandomInt(100) > CAP_DROP_CHANCE) //drop chance
    return;

level.zombie_can_drop_cap = 0;

v_land_pos = util::ground_position( self.origin+(0,0,100), 300 );
cap = Spawn("script_model", v_land_pos);
cap SetModel("mario_sunshine_cap");
cap clientfield::set( "sm64_keyline", 1);

trig = Spawn("trigger_radius_use", cap.origin+(0,0,32), 0, 32, 32);
trig SetCursorHint("HINT_NOICON");
trig SetHintString("Press ^3[{+activate}]^7 to pick up");
trig SetTeamForTrigger("allies");


trig waittill("trigger", player);
trig Delete();
cap Delete();
level notify("mario_cap_pickedup");
}


Zombieslayeraj:

I used this:

in main function:
zm_spawner::register_zombie_death_event_callback(&mario_cap_zom_spawn);

down below:
#precache( "model", "mario_sunshine_cap");
#define CAP_DROP_CHANCE 10
function mario_cap_zom_spawn()
{

if(level.zombie_can_drop_cap == 0) //check if zombie can drop caš
    return;

if(!isdefined(zm_zonemgr::get_zone_from_position(self.origin, true))) //check if zom is in playable area
    return;

if(RandomInt(100) > CAP_DROP_CHANCE) //drop chance
    return;

level.zombie_can_drop_cap = 0;

v_land_pos = util::ground_position( self.origin+(0,0,100), 300 );
cap = Spawn("script_model", v_land_pos);
cap SetModel("mario_sunshine_cap");
cap clientfield::set( "sm64_keyline", 1);

trig = Spawn("trigger_radius_use", cap.origin+(0,0,32), 0, 32, 32);
trig SetCursorHint("HINT_NOICON");
trig SetHintString("Press ^3[{+activate}]^7 to pick up");
trig SetTeamForTrigger("allies");


trig waittill("trigger", player);
trig Delete();
cap Delete();
level notify("mario_cap_pickedup");
}

quick question, what is a level notify? Also thank you I will check if this works

Zombieslayeraj:

I used this:

in main function:
zm_spawner::register_zombie_death_event_callback(&mario_cap_zom_spawn);

down below:
#precache( "model", "mario_sunshine_cap");
#define CAP_DROP_CHANCE 10
function mario_cap_zom_spawn()
{

if(level.zombie_can_drop_cap == 0) //check if zombie can drop caš
    return;

if(!isdefined(zm_zonemgr::get_zone_from_position(self.origin, true))) //check if zom is in playable area
    return;

if(RandomInt(100) > CAP_DROP_CHANCE) //drop chance
    return;

level.zombie_can_drop_cap = 0;

v_land_pos = util::ground_position( self.origin+(0,0,100), 300 );
cap = Spawn("script_model", v_land_pos);
cap SetModel("mario_sunshine_cap");
cap clientfield::set( "sm64_keyline", 1);

trig = Spawn("trigger_radius_use", cap.origin+(0,0,32), 0, 32, 32);
trig SetCursorHint("HINT_NOICON");
trig SetHintString("Press ^3[{+activate}]^7 to pick up");
trig SetTeamForTrigger("allies");


trig waittill("trigger", player);
trig Delete();
cap Delete();
level notify("mario_cap_pickedup");
}

So I tried this, and I changed it to my model name right and I got


UNRECOVERABLE ERROR:


^1SCRIPT ERROR: No generated data for 'scripts/zm/zm_test.gsc'


ERR(6E) scripts/zm/zm_test.gsc (121,1) : Compiler Internal Error : Unresolved external 'zm_spawner::register_zombie_death_event_callback'

KillJoy:

you need this

#using scripts\zm\_zm_spawner;

also your model needs to be called in your zone file


Zombieslayeraj:

you need this

#using scripts\zm\_zm_spawner;

also your model needs to be called in your zone file

Thanks KillJoy

Zombieslayeraj:

[USER=64]@Spiki[/USER] , what is the purpose of this part?

hand clientfield::set( "sm64_keyline", 1);


Spiki:

[USER=64]@Spiki[/USER] , what is the purpose of this part?

hand clientfield::set( "sm64_keyline", 1);

nothing to you. i made it visible through walls

Zombieslayeraj:

nothing to you. i made it visible through walls

gotcha thanks!

sharpgamers4you:

so did this worked out?


FrostIceforge:

I noticed a (fairly minor) error in your code, which could cause glitches if someone else used it with different values and didn't notice.

if(RandomInt(100) > CAP_DROP_CHANCE) //drop chance
RandomInt(100) makes a number between 0 and 99, not 1 and 100, and you used >, not >=.
So with #define CAP_DROP_CHANCE 10, the numbers 0-10 are all not > 10, and all work.
The way it is right now, the cap on your map has an 11% chance to spawn, not 10% like you wanted.
You might not care, but in fringe cases like percentages below 5 it can feel like a much bigger difference. Hell, if someone set it to be 0% temporarily, it'd actually be 1%.
What you'd want is
if(RandomInt(100) >= CAP_DROP_CHANCE) //drop chance
or
if(RandomInt(100) + 1 > CAP_DROP_CHANCE) //drop chance


Harry Bo21:

I noticed a (fairly minor) error in your code, which could cause glitches if someone else used it with different values and didn't notice.
if(RandomInt(100) > CAP_DROP_CHANCE) //drop chance
RandomInt(100) makes a number between 0 and 99, not 1 and 100, and you used >, not >=.
So with #define CAP_DROP_CHANCE 10, the numbers 0-10 are all not > 10, and all work.
The way it is right now, the cap on your map has an 11% chance to spawn, not 10% like you wanted.
You might not care, but in fringe cases like percentages below 5 it can feel like a much bigger difference. Hell, if someone set it to be 0% temporarily, it'd actually be 1%.
What you'd want is
if(RandomInt(100) >= CAP_DROP_CHANCE) //drop chance
or
if(RandomInt(100) + 1 > CAP_DROP_CHANCE) //drop chance

randomInt( 100 )

would pick from 0 - 99, so no it wouldnt

FrostIceforge:

randomInt( 100 )

would pick from 0 - 99, so no it wouldnt

Thats exactly what I said. That's where the problem comes from. The code acts like it's 1-100.

FrostIceforge:

Consider the 0% case.
if(0>0) returns false. if(1>0) through if(99>0) return true. To be really 0%, it needs to always return true.


Harry Bo21:

Thats exactly what I said. That's where the problem comes from. The code acts like it's 1-100.

That’s only coz you have the =

FrostIceforge:

That’s only coz you have the =

What do you mean? I didn't use an =. The original code as he had it is bugged.

Harry Bo21:

yea i misread

although instead of


RandomInt(100) + 1

could just do

randomIntRange( 1, 100 )

looking back i was wrong earlier anyway

randomInt( 1 )

would return 0 or 1


FrostIceforge:

randomInt( 1 )

would return 0 or 1

But the script docs says the range is 0 to the paramater -1? So shouldn't randomInt(1) always return 0?

Harry Bo21:

But the script docs says the range is 0 to the paramater -1? So shouldn't randomInt(1) always return 0?

Nah it definitely gets 0 / 1

feel free to test, put it in a loop and I print it