UGX-Mods

Call of Duty: Black Ops 3 => Help Desk => Scripting => Topic started by: DeletedUser on September 29, 2016, 05:00:13 pm

Title: [Solved] How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 29, 2016, 05:00:13 pm
So im tryign to give my self weapons from script but everytime i try this i just a a "struct is not an entity" error

(https://i.gyazo.com/2cae53cd815fd8018664f55ba69b3b6c.png)

What i have tried so far

Code Snippet
Plaintext
player GiveWeapon("ray_gun"); // Didnt think this would work
// -----------------------------------------
player GiveWeapon(GetWeapon("ray_gun"));
// -----------------------------------------
weapon = GetWeapon("ray_gun");

player GiveWeapon(weapon);
// -----------------------------------------
#using scripts\zm\_zm_weapons;

weapon = GetWeapon("ray_gun");

player zm_weapons::weapon_give(weapon);
// -----------------------------------------
#using scripts\zm\_zm_weapons;

player zm_weapons::weapon_give("ray_gun");
// -----------------------------------------
// tried all of the above but adding a SEE BELOW before them to make sure everything gets init'ed
level waittill("between_round_over");
Title: Re: How to give a weapon in BLack Ops 3?
Post by: MakeCents on September 30, 2016, 03:26:55 pm
These should work for giving weapons


Code Snippet
Plaintext
player GiveWeapon(GetWeapon("ray_gun"));
// -----------------------------------------
weapon = GetWeapon("ray_gun");

player GiveWeapon(weapon);

But you will also then need to switch to it. Is that the part that is missing? Did you try switching to it?


Code Snippet
Plaintext
player SwitchToWeapon(weapon)
Title: Re: How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 30, 2016, 04:03:33 pm
These should work for giving weapons


Code Snippet
Plaintext
player GiveWeapon(GetWeapon("ray_gun"));
// -----------------------------------------
weapon = GetWeapon("ray_gun");

player GiveWeapon(weapon);

But you will also then need to switch to it. Is that the part that is missing? Did you try switching to it?


Code Snippet
Plaintext
player SwitchToWeapon(weapon)

no im straight up not getting the weapon, when the game tries to give me the weapon it throwss a error "struct is not an entity" even if i add a SwithToWeapon() or swith weapons in game i dont get it
Title: Re: How to give a weapon in BLack Ops 3?
Post by: karelkopp on September 30, 2016, 04:20:52 pm
its will be better to post here your complete script
Title: Re: How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 30, 2016, 04:32:39 pm
its will be better to post here your complete script

see the thing is i dont rly have a complete script just giving a weapon on player connect so ive pretty much given what i have

but yeah hers my script, currtly its all commented out cause none of it works no matter how i type it

Spoiler: click to open...
Code Snippet
Plaintext
#using scripts\codescripts\struct;

#using scripts\shared\array_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\compass;
#using scripts\shared\exploder_shared;
#using scripts\shared\flag_shared;
#using scripts\shared\laststand_shared;
#using scripts\shared\math_shared;
#using scripts\shared\scene_shared;
#using scripts\shared\util_shared;

#insert scripts\shared\shared.gsh;
#insert scripts\shared\version.gsh;

#insert scripts\zm\_zm_utility.gsh;

#using scripts\zm\_zm;
#using scripts\zm\_zm_audio;
#using scripts\zm\_zm_utility;
#using scripts\zm\_zm_score;
#using scripts\zm\_zm_weapons;

#namespace wardog_test_script;

function pre_init()
{
callback::on_connect(&test_player_connect);
}

function test_player_connect()
{
// level waittill("between_round_over");

// weapon = GetWeapon("pistol_standard");
// knife = GetWeapon("knife");
// grenade = GetWeapon("frag_grenade");

// string = "smg_standard";
// weapon = getWeapon(string);
// knife = GetWeapon("knife");
// grenade = GetWeapon("frag_grenade");

// self zm_weapons::weapon_give("smg_standard");
// self zm_weapons::weapon_give(GetWeapon("smg_standard"));
// self giveWeapon(weapon);
// self SwitchToWeapon(weapon);
// self zm_weapons::give_build_kit_weapon(weapon);
// self zm_weapons::weapon_give(weapon, false, false, false, true);
// self SetWeaponAmmoClip(weapon, 1);
// self SetWeaponAmmoStock(weapon, 0);

// self GiveWeapon(knife);

// self zm_utility::set_player_melee_weapon(knife);

// self GiveWeapon(grenade);
// self SetWeaponAmmoClip(grenade, 1);

// self zm_utility::set_player_lethal_grenade(grenade);
}
Title: Re: How to give a weapon in BLack Ops 3?
Post by: karelkopp on September 30, 2016, 04:34:46 pm
so you must give weapon after spawn not after connect i think there is your problem
Title: Re: How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 30, 2016, 04:56:56 pm
so you must give weapon after spawn not after connect i think there is your problem

i thought so to thats why i added level waittill("between_round_over"); to waittill start of round 2 but i still got the error
Title: Re: How to give a weapon in BLack Ops 3?
Post by: karelkopp on September 30, 2016, 05:09:16 pm
use this
Code Snippet
Plaintext
callback::on_spawned( &on_player_spawned );

function on_player_spawned()
{
self endon("disconnect");
        weapon = GetWeapon("ray_gun");
        self GiveWeapon(weapon);
        self SwitchToWeapon(weapon);   
}

Title: Re: How to give a weapon in BLack Ops 3?
Post by: MakeCents on September 30, 2016, 05:14:13 pm
Just do:

Code Snippet
Plaintext
#using scripts\shared\callbacks_shared;
#using scripts\shared\flag_shared;

#namespace wardog_test_script;

function pre_init()
{
callback::on_connect(&test_player_connect);
}

function test_player_connect()
{
    level flag::wait_till( "initial_blackscreen_passed" );
    weapon = getweapon("ray_gun");
    self giveweapon(weapon);
    self switchtoweapon(weapon);
}

That should work.
Title: Re: How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 30, 2016, 05:38:01 pm
Just do:

Code Snippet
Plaintext
#using scripts\shared\callbacks_shared;
#using scripts\shared\flag_shared;

#namespace wardog_test_script;

function pre_init()
{
callback::on_connect(&test_player_connect);
}

function test_player_connect()
{
    level flag::wait_till( "initial_blackscreen_passed" );
    weapon = getweapon("ray_gun");
    self giveweapon(weapon);
    self switchtoweapon(weapon);
}

That should work.

This worked perfectly fine until i decied i wanted to call another function and give my weapon from what function

This does not work but above does

Reason i want to split the functions up is because i want to add my gamemode mod to BO3 and for that to work i need to init the player specfic to the gamemode (calling different functions)
Spoiler: click to open...
Code Snippet
Plaintext
function pre_init()
{
callback::on_connect(&test_player_connect);
}

function test_player_connect()
{
    level flag::wait_till( "initial_blackscreen_passed" );
    self thread new_function();
}

function new_function()
{
    weapon = getweapon("ray_gun");
    self giveweapon(weapon);
    self switchtoweapon(weapon);
}
Title: Re: How to give a weapon in BLack Ops 3?
Post by: MakeCents on September 30, 2016, 05:44:37 pm
what you posted above should work just fine as long as you still have the usings
Title: Re: How to give a weapon in BLack Ops 3?
Post by: DeletedUser on September 30, 2016, 05:54:33 pm
what you posted above should work just fine as long as you still have the usings

well for somereason it doesnt :( if its in the same function it works perfectly fine seperate it and the game throws that struct not entioty error

if it helps i just pushed all of my gamemode script to my GitHub

Where im giving weapons (https://github.com/WARDOGSK93/CoD-BO-Gamemode/blob/BOIII/scripts/zm/wardog/_wardog_gamemode_classic.gsc#L47)
Where im calling player_init (https://github.com/WARDOGSK93/CoD-BO-Gamemode/blob/BOIII/scripts/zm/wardog/_wardog_gamemode.gsc#L276)

youl have to bit of digging to fine where the rest is called from

Double Post Merge: September 30, 2016, 08:38:43 pm
Wow the reason this wasnt workign was cause of a stupid typo i made in my callback system :( im so dumb
See typo (https://github.com/WARDOGSK93/CoD-BO-Gamemode/commit/726eb8401623edaf37c9587b7feda47b27a3e1f5)