UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

[Tutorial] Spawning A Random Weapon In Your Map

broken avatar :(
Created 11 years ago
by AlecKeaneDUB
0 Members and 1 Guest are viewing this topic.
8,463 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 21 September 2014
Last active: 2 years ago
Posts
191
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Let's all just light up a blunt, and make stuff.
×
AlecKeaneDUB's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
AlecKeaneDUB's Contact & Social LinksAlecKeaneDUBaleckeanedubAlecKeaneDUB
Script Tutorial: Spawning A Random Weapon In Your Map
In this thread, I'll be showing you how to spawn a randomly selected weapon into your map. You can have as many weapons to be possibly selected as you want, as long as you aren't too lazy to change a couple things (but if you suck at scripting, don't stress - for I shall show you how). This isn't a huge, complicated script...because it isn't necessary to be. It's very simple, and shouldn't be too difficult for newbies to add to their maps. Let's get started!

Step 1: Adding The Entity
The first thing you need, is a simple 'trigger_use' placed in your map.

- To create a trigger_use entity, right-click on the 2-D view side of you map and go to --> trigger > use
- The entity must have the following dimensions:      x: 40, y: 40, z: 8
- For newbies, those dimensions mean that the trigger_use should be 40 units in length and width, and 8 units in
  height.

Next, place the trigger flat on the floor (or table, box, shelf, etc.)
PLEASE NOTE: The location that you place this trigger_use is where the weapon will spawn.

- Now save your map and open up your map's .GSC file (nazi_zombie_yourmapname.gsc)

Step 2: Scripting
Now that we have the entity placed in our map, we can get to the fun stuff.

- In your map's .gsc file, find this:
Code Snippet
Plaintext
maps\_zombiemode::main();
and directly underneath, put this:
Code Snippet
Plaintext
thread random_gun();
- Now scroll down to the very bottom and paste this there:
Code Snippet
Plaintext
random_gun()
{
rand = randomintrange( 1, 10 );

// thead pick_up_gun( "weapon model, hint string, weapon file, message" );

if(rand >= 1 && rand <= 6) // 60% chance of this weapon spawning
{
thread pick_up_gun( "weapon_usp", "Press &&1 for weapon", "usp", "You found a USP.45" );
}
else if(rand >= 7 && rand <= 9) // 30% chance of this weapon spawning
{
thread pick_up_gun( "weapon_desert_eagle_silver", "Press &&1 for weapon", "desert_eagle", "You found a Desert Eagle" );
}
else if(rand == 10) // 10% chance of this weapon spawning
{
thread pick_up_gun( "weapon_desert_eagle_gold", "Press &&1 for weapon", "desert_eagle_gold", "You found a Desert Eagle" );
}
}
*BE SURE TO CHANGE THE WEAPON MODEL AND FILE TO THE ONES THAT MATCH YOUR WEAPON*

Now, right under that thread, add this:
Code Snippet
Plaintext
pick_up_gun( model, string, weapon, message )
{
player = undefined;
gun_spawn = getEnt( "gun_spawn" , "targetname" );

r_angle = randomintrange( 1, 361 );
gun_model = Spawn( "script_model" , gun_spawn.origin -(0,0,3) );
gun_model.angles = ( 0,r_angle,90 );
gun_model SetModel( model );
gun_spawn usetriggerrequirelookat();
gun_spawn setCursorHint("HINT_NOICON");
gun_spawn sethintstring( string );

gun_spawn waittill( "trigger" , player );

old_gun = player getcurrentweapon();
weaplist = player GetWeaponsListPrimaries();
for(i=0;i<weaplist.size;i++)
{

}
if(weaplist.size <= 1)
{
player giveweapon( weapon );
player switchtoweapon( weapon );
player playsound( "weap_pickup_plr" );
}
else if(weaplist.size >= 2)
{
player takeweapon( old_gun );
player giveweapon( weapon );
player switchtoweapon( weapon );
player playsound( "weap_pickup_plr" );
}

player iprintlnbold( message );

gun_model delete();
gun_spawn delete();
}
- The purpose of the 'random_gun()' thread is briefly explained in the commented out line at the beginning of the
  thread. The 'weapon model' is the weapon's world model name, which can be found in Asset Viewer. The 'hint
  string' is what will be displayed to players who walk up to the weapon (feel free to customize the hint to your   
  liking). The 'weapon file' is the name of the weapon's file, which contains it's damage settings, camo, clip size, etc.,
  and can be found in mods > your_map_name > weapons > sp. Finally, the 'message' is what the game will display
  on-screen when a player picks up the weapon (this isn't a necessity and can be edited to your liking or removed).

Sub-step 1: Adding More Weapons To Be Randomly Selected
Adding a larger variety of weapons that can possibly be chosen from the script can make your map more fun and add to the replayablilty factor by leaving players eager to see which weapon(s) have spawned for them each time. Doing this may be confusing for those who are new to this, but I will do my best to explain it.

- The two main things we must worry about when adding additional weapons, are these two lines:
Code Snippet
Plaintext
rand = randomintrange( 1, 10 ); <----


if(rand >= 1 && rand <= 6) /* 60% chance of this weapon spawning*/ <----
{
thread pick_up_gun( "weapon_usp", "Press &&1 for weapon", "usp", "You found a USP.45" );
}
To be able to understand this simplicity, you had to have passed atleast 5th grade math. If you have not, then this is not the place for you. Go play some Mario Kart or something.

- What we are looking at is percentages. Now, in case you haven't noticed, I have different weapons set at different
  percentages (or 'chances') of spawning. You know what, nevermind - I'm not going to 9/11 my brain attempting to
  explain this. Here's a brief, simple explanation: change the random_int_range if necessary and adjust the
  percentages to your liking. It isn't difficult once you mess around and get the hang of it. Use the commented out
  template to add more weapons, but be sure to add the correct model and weapon file. Feel free to ask me
  questions.

Overview:
I'm very tired at the moment and may have left out explanations or something. Just be sure to rebuild your mod after adding these scripts and make sure to recompile your map. If anyone suspects something is missing, just comment below, ask me a question, or PM me. I'll check back tomorrow.

Hope this helped!   ;)
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 3 years ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
Signature
Do not take life too seriously. You will never get out of it alive.
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 21 September 2014
Last active: 2 years ago
Posts
191
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Let's all just light up a blunt, and make stuff.
×
AlecKeaneDUB's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
AlecKeaneDUB's Contact & Social LinksAlecKeaneDUBaleckeanedubAlecKeaneDUB
broken avatar :(
×
broken avatar :(
OnionmanVere Bo21
Location: ieu dnt wnt 2 no
Date Registered: 27 September 2013
Last active: 4 months ago
Posts
1,863
Respect
Forum Rank
Zombie Destroyer
Primary Group
Mapper
My Groups
More
Personal Quote
ok
Signature
Aye mate you don't know me so y don't you shut tf up ok buddy :)

×
Scobalula's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Box Mappers Elite
Box Mappers Elite
Mapper Has released one or more maps to the UGX-Mods community.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Scobalula's Contact & Social Links
Cool, probably will use it on my upcoming map. ;)
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 21 September 2014
Last active: 2 years ago
Posts
191
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Let's all just light up a blunt, and make stuff.
×
AlecKeaneDUB's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
AlecKeaneDUB's Contact & Social LinksAlecKeaneDUBaleckeanedubAlecKeaneDUB
Cool, probably will use it on my upcoming map. ;)
Awesome! I'll be sure to keep my eyes open for that :D
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 3 years ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
The purpose of mine is to spawn a random one...
Array list -> "zombie_kar98k" a.k.a. arrayKeys from level.zombie_weapons -> weapon = random(arrayList) -> "weapon_" + weapon

random.
broken avatar :(
×
broken avatar :(
Location: es
Date Registered: 15 August 2013
Last active: 7 years ago
Posts
161
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Mapper
My Groups
More
Signature
Enjoy my work? Feel free to donate here to support me

Wanna become a Patron? Try my Patreon Page
×
sethnorris's Groups
Mapper Has released one or more maps to the UGX-Mods community.
sethnorris's Contact & Social Links
No video, no party
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Array list -> "zombie_kar98k" a.k.a. arrayKeys from level.zombie_weapons -> weapon = random(arrayList) -> "weapon_" + weapon

random.

Surprised you didn't mention everything else with the script.

The script is only good for one use because it deletes the one and only trigger it uses(gun_spawn) and it has a random unnecessary for() loop:

Code Snippet
Plaintext
	for(i=0;i<weaplist.size;i++)
{

}


Last Edit: September 14, 2015, 09:21:00 pm by daedra descent
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 3 years ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Surprised you didn't mention everything else with the script.

The script is only good for one use because it deletes the one and only trigger it uses(gun_spawn) and it has a random unnecessary for() loop:

Code Snippet
Plaintext
	for(i=0;i<weaplist.size;i++)
{

}
Wasn't really checking out the functions just did a quick one-take and didn't look at it again.
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 21 September 2014
Last active: 2 years ago
Posts
191
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Let's all just light up a blunt, and make stuff.
×
AlecKeaneDUB's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
AlecKeaneDUB's Contact & Social LinksAlecKeaneDUBaleckeanedubAlecKeaneDUB
Surprised you didn't mention everything else with the script.

The script is only good for one use because it deletes the one and only trigger it uses(gun_spawn) and it has a random unnecessary for() loop:

Code Snippet
Plaintext
	for(i=0;i<weaplist.size;i++)
{

}



I'm not great at scripting, dude. I've been trying my best lately, and I intentionally made it a one-time use because i dont think weapons spawn out of thin air in real life after you have picked one up. I know you and DUKIP can make this look much better and function better, but the scriot still works perfectly. I respect you guys, but I'm still learning
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 3 years ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
I tried to show you how it could be done better, sorry if it came out wrong.
broken avatar :(
×
broken avatar :(
drago
Location: mx
Date Registered: 5 July 2013
Last active: 6 years ago
Posts
941
Respect
Forum Rank
The Decider
Primary Group
Member
My Contact & Social Links
More
×
jjbradman's Groups
jjbradman's Contact & Social Linksjjbradmanjjbradmanjjbradman
I know "YOU" and DUKIP can make this look much better and function better
lol you must not know daedra's work  :troll: :lol:
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
lol you must not know daedra's work  :troll: :lol:

Probably better anything you could make.  :please:

Quote
I'm not great at scripting, dude. I've been trying my best lately, and I intentionally made it a one-time use because i dont think weapons spawn out of thin air in real life after you have picked one up. I know you and DUKIP can make this look much better and function better, but the scriot still works perfectly. I respect you guys, but I'm still learning

I was just pointing  things out so you can improve it. Sorry if i was a bit harsh.
Last Edit: September 15, 2015, 02:13:33 am by daedra descent
broken avatar :(
×
broken avatar :(
drago
Location: mx
Date Registered: 5 July 2013
Last active: 6 years ago
Posts
941
Respect
Forum Rank
The Decider
Primary Group
Member
My Contact & Social Links
More
×
jjbradman's Groups
jjbradman's Contact & Social Linksjjbradmanjjbradmanjjbradman
Probably better anything you could make.  :please:
indeed

 
Loading ...