Modme Forums
Menu:

New to scripting, need help!

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


ModmeBot:

Thread By: Wild
Hello, over the past few days I have been learning how to script. I successfully made a script that added little credits in the bottom corner of the screen. I decided to test myself and try and put together something a bit more difficult. I am trying to create a script that allows me to shoot an object, and in return I would get Jugg. Again I am new to scripting and I am just trying to learn so please be nice lol.

Basically since I am trying to learn I don't need people to actually make the script the for me, rather I would like them to help explain to me what I did wrong and what needs to be changed. If it not a problem it would be great if you guys could explain why what I have is wrong and why the other ways are correct. I am not trying to make this script to actually use, it's just simply to help me learn and understand how to script so again, I am looking for explanations, not someone to make a script.

Here is what I did.

1) First I added "#insert scripts\zm\_zm_perks.gsh;" with the other #using lines of text at the top of my mapname.gsc.

2) Underneath "zm_usermap::main();" I added "level shoot_for_jugg();"

3) Finally, this is the script I wrote at the bottom of my mapname.gsc:

function shoot_for_jugg()
{

	trigs = GetEntArray( "trig_for_jugg", "targetname" );
	foreach( trig in trigs )
		trig thread trig_shot();

}

function trig_shot()
{

	self waittill( "trigger", player );
	player PlayLocalSound( "zmb_cha_ching" ); //I don't know the alias name for any other sounds so is simply a placeholder
	self delete_model();

}

function delete_model()
{

	bears = GetEntArray( "give_jug_model", "targetname" );
	foreach( bear in bears )
		bear delete();

	thread give_jugg();

}

function give_jugg()
{

	players = GetPlayers();
	foreach( player in players )
	{
		perk = GetPerks( "PERK_JUGGERNOG" );
		player GivePerks( perk );
	}

}


Before I added the last function (function give_jugg()) I was getting an error that stopped the linking process. After I added in this function the errors got fixed but whenever I launched the map it crashes before it fully loads in (during the blackscreen after you click run).


Once again I am looking for people to explain to me why this script isn't working, as well as explain to me what should be written and why. Thank you guys so much. I really appreciate it!

Remember, I am new to script and I am just trying to learn!

EDIT: I also added a scriptmodel with the targetname "give_jug_model" and surrounded it with a damage trigger with the targetname "trigg_for_jugg" incase you were wondering.

EDIT#2: Also if you're wondering, I wrote this based off of the basic stuff I learned, looking at a script for a shootable door and looking at a script used to give players multiple weapons at the start of the game. I looked at those and used the basics of scripting that I learned and wrote this. So just incase you need to know, that's what i wrote this based off of.


ModmeBot:

Reply By: Abnormal202
The problem is in how you referenced it. You typed:

level shoot_for_jugg();

when you should've threaded it:
level thread shoot_for_jugg();

because you didn't thread it, it would be causing the game to get stuck on that script, before anyone has even loaded in.


ModmeBot:

Reply By: Wild

Abnormal202
The problem is in how you referenced it. You typed: level shoot_for_jugg(); when you should've threaded it: level thread shoot_for_jugg(); because you didn't thread it, it would be causing the game to get stuck on that script, before anyone has even loaded in.

Okay that makes sense, I changed it. Jerri also told me that getperks isnt a thing and to just use setperk so I changed that function to this:
function give_jugg()
{
 
    players = GetPlayers();
    foreach( player in players )
    {
        player SetPerk( "PERK_JUGGERNOG" );
    }
 
}

I tested it in game and the map loads. When I shoot the object a sound plays and the trigger and model disappear which is good. The problem is that it doesn't actually give me Jugg. Any idea why?


EDIT: Jerri fixed the function to say this:
<span class="invisible">https://</span><span class="js-display-url">pastebin.com/FwePbymg</span><span class="tco-ellipsis"><span class="invisible"> </span></span>

The only problem is that when I use zm_perks::give_perk is gives me a linker error that says:
Unresolved external 'zm_perks::give_perk'

Any idea why?


ModmeBot:

Reply By: Wild
FIXED:

Huge thanks to Abnormal and Jerri for helping me to get this working. Looking at it now I kind of understand how it works. Thanks guys