Jump to content

Learning scripts in the CS(E)


Recommended Posts

Learning rudimentary scripting. Help a brother out. What am I doing wrong?

scn WeaponForTheWorthy
short doOnce
short plrFame
short plrInfamy
Begin OnActivate
set plrFame to (GetPCFame)
set plrInfamy to (GetPCInfamy)
	If (doOnce = 0)
		If (getpcfame >= 50) || (GetPCInfamy >=50)
			If (getpcfame > getpcinfamy)
				MessageBox "You are famous enough!"
				player.additem 00090613, 1
				set doOnce to 1
			Else
				MessageBox "You are infamous enough!"
				player.additem 00090613, 1
				set doOnce to 1
			EndIf
		Else
			MessageBox "You are a nobody!"
		Endif
	Else
		MessageBox "You have already received your weapon!"
	Endif
End

CSE is saying I have a syntax error on line 8. I'm not sure why?

It also won't accept any item I attempt to add to the player. What am I doing wrong here?

 

Any and all help is appreciated!

 

Edit: forgive me for the terrible white bars. I don't know what I'm doing.

Edit2: Doh! I see I just forgot to double up on the = signs.

For further clarfication, the error the CSE is giving me regarding the object ids is this: "item XXXXXX not found for parameter object id"

EDIT3: I figured it out. I didn't have the Oblivion.esm selected, so of course it wasn't finding anything. :wallbash:

Edited by Fiore1300
Link to comment
Share on other sites

You can also use the "EditorID" (WeapIronWarAxeRusty) instead of the "FormID" (00090613), should be easier to read for humans.

Edited by mixxa77
Link to comment
Share on other sites

You can also use the "EditorID" (WeapIronWarAxeRusty) instead of the "FormID" (00090613), should be easier to read for humans.

Making things easier to read for humans is always useful. Good tip, thanks.

 

I think I'll just use this thread to post my issues in learning scripting in the future.

 

Now I'm on to my own script. Just organizing my thoughts on how to approach it has been the greatest challenge.

 

So I want to adjust the disposition of all members of a faction towards the player based on that player's infamy. After some deliberation I came to the conclusion that the best way to go about this was to take advantage of the existing faction system and make the player a part of a faction where their rank increases based on how much higher their infamy was over their fame. This is the basic script I came up with. I originally had some bits at the end that would expel the player from the faction if their infamy dipped below their fame, but I cut it for now because I can't get the script to work.

 

I built this from scratch after doing tutorials, so while it passes the CSE sniff test, it doesn't appear to do anything in game when I give my player character infamy. For clarity's sake, FioreInfamousFaction is a six-ranked faction with a -10 disposition modifier with the Chorrol town guard faction. The faction is meant to be invisible to the player and work behind the scenes but I left it visible so that it would be easy to confirm if its working.

scn FioreInfamousScript
short plrfame
short plrinfamy
short plrrank
Begin GameMode
	set plrfame to (GetPCFame)
	set plrinfamy to (GetPCInfamy)
	set plrrank to (player.GetFactionRank FioreInfamousFaction)
	if plrfame < plrinfamy
		player.SetFactionRank FioreInfamousFaction, 0
		if plrinfamy >= (plrfame + 5)
			player.SetFactionRank FioreInfamousFaction, 1
		elseif plrinfamy >= (plrfame + 10)
			player.SetFactionRank FioreInfamousFaction, 2
		elseif plrinfamy >= (plrfame + 15)
			player.SetFactionRank FioreInfamousFaction, 3
		elseif plrinfamy >= (plrfame + 20)
			player.SetFactionRank FioreInfamousFaction, 4
		elseif plrinfamy >= (plrfame + 25)
			player.SetFactionRank FioreInfamousFaction, 5
		endif
	endif
End

 

Like I said, it doesn't appear to have any effect. I'm probably being really sloppy here since its so late, so I don't doubt I am making some obvious mistakes. So let me have it guys.

 

EDIT: Also I don't even know if this is the right approach. I want to (hopefully, eventually) track the number of times a player has been imprisoned, paid off a bounty, whether they have a bounty in another county, and eventually support for Vector where it will handle diseases. Is giving the player a invisible faction needlessly hacky? Will it be useless in addressing future goals?

 

EDIT2: The ultimate goal behind lowering the disposition of the guard faction is to control when they're approach the player (when their disposition is low enough) and throw them out of the city and/or bar them from entering. Its (ultimately) supposed to give guards a way to handle troublesome characters that don't actually have a bounty on their heads to justify arrest/death. Just realized I didn't explain this earlier in the post.

 

So yeah, I need help with this script but I also wouldn't mind some general guidance on how I should go from here. And thank you.

Edited by Fiore1300
Link to comment
Share on other sites

Sounds like a reasonable approach. You seem to already know that the faction disposition modifier adds up with each faction rank (-10 at first rank 0, -20 at second rank 1, etc.). If you want to remove the player from the faction you need to use -1 for the rank.

 

About the script not actually doing anything: A script needs something that triggers/runs it. There are three types of scripts: Object, Quest and Magic Effect scripts.

Object scripts need to be attached to an object (Like an NPC, an activator or any other object that can have a script attached to it.

Magic Effect scripts need to be attached to a scripted magic effect in a spell.

Quest scripts need to be attached to a Quest. This is what will be the best to use for this script of yours.

 

Change your script type to a Quest script (there should be a small drop down menu where you can choose between the three types in the same window where you edit the script), then create a new quest using the "Q" icon at the top in the CS, check the "Enabled at game start" (or similar) checkbox and attach your script to the quest.

 

Now your script will be run every five seconds while the game is in GameMode.

If you want to change how often it is run, add the float fQuestDelayTime and set it to the number of seconds you want the script to be run.

 

You can consider moving set plrrank to (player.GetFactionRank FioreInfamousFaction) after the if's where it sets the players rank depending on infamy, that way it will always have the up-to-date rank of the player.

Edited by mixxa77
Link to comment
Share on other sites

Thank you very much, mixxa77. This put me on the path to finishing this particular script. None of the tutorials on scripting that I had done so far had introduced me to the quest scripts, so I didn't know how to handle them. Anyway, there were a few more changes I had to make to get it running correctly (for instance, it initially wouldn't advance the player beyond the second rank) but I ironed everything out and now it works beautifully. This is the final script:

scn FioreInfamousScript
short plrfame
short plrinfamy
short plrrank
Begin GameMode
	set plrfame to (GetPCFame)
	set plrinfamy to (GetPCInfamy)
	if plrfame >= plrinfamy
		player.SetFactionRank FioreInfamousFaction, -1
	elseif plrfame < plrinfamy
		player.SetFactionRank FioreInfamousFaction, 0
		if plrinfamy >= (plrfame + 5) && plrinfamy < (plrfame + 10)
			player.ModFactionRank FioreInfamousFaction, 1
		elseif plrinfamy >= (plrfame + 10) && plrinfamy < (plrfame + 15)
			player.ModFactionRank FioreInfamousFaction, 2
		elseif plrinfamy >= (plrfame + 15) && plrinfamy < (plrfame + 20)
			player.ModFactionRank FioreInfamousFaction, 3
		elseif plrinfamy >= (plrfame + 20) && plrinfamy < (plrfame +25)
			player.ModFactionRank FioreInfamousFaction, 4
		elseif plrinfamy >= (plrfame + 25)
			player.ModFactionRank FioreInfamousFaction, 5
		set plrrank to (player.GetFactionRank FioreInfamousFaction)
		endif
	endif
End

Now I'm moving on to addressing how the guards approach and throw the player out of the city. I figure I'm going to be mimicking the way vanilla Oblivion handles usual crime, and from what I can see in the CS this is mostly handled via a quest rather than scripts. But I don't doubt that I'll be back in this thread again soon.

 

Edit: Ah, the key to avoiding the terrible white bars is to not choose a starting number for the code box.

Edited by Fiore1300
Link to comment
Share on other sites

Glad to have helped.

 

Instead of this at the end

		elseif plrinfamy >= (plrfame + 25)
			player.ModFactionRank FioreInfamousFaction, 5
		set plrrank to (player.GetFactionRank FioreInfamousFaction)
		endif
	endif
End
You should use this, otherwiese the set plrrank is only done when the rank is set to rank 5 as it is in the same (else)if condition.

		elseif plrinfamy >= (plrfame + 25)
			player.ModFactionRank FioreInfamousFaction, 5
		endif
		set plrrank to (player.GetFactionRank FioreInfamousFaction)
	endif
End
Edited by mixxa77
Link to comment
Share on other sites

A bit late to this, but I wrote a giant scripted mod a few months back and am writing another one now, of which I have posted the code for both to GitHub. I commented everything thoroughly with the express intent of others learning from it.

https://github.com/Zephyrum-Alsend/Growth-Items

The sub-directories Dusfergon and Zefiros specifically.

 

I hope it helps.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...