Jump to content

Limit Scripts


McclaudEagle

Recommended Posts

Hi.

 

I'm trying to create a script that gives you certain items, but won't give you anymore than what it already gave you. Below is the script I have already made.

 

scn L4DNVActivateAssaultRifleSCRIPT

 

Begin OnActivate

 

player.additem L4DNVAssaultRifle 1 100

player.equipitem L4DNVAssaultRifle

player.additem L4DNVAmmoRifle 350

 

End

 

How do I make it so that if I already have an Assault Rifle, it will refuse to give me another. Also, how do I make it so that if I have 350 rounds, it won't give me anymore, but if I have less, it will give me enough to get back to 350?

 

McclaudEagle.

 

P.S. Yes, you might be able to guess what this is for when you look at the item prefixes. :P

Link to comment
Share on other sites

Hi.

 

I'm trying to create a script that gives you certain items, but won't give you anymore than what it already gave you. Below is the script I have already made.

How do I make it so that if I already have an Assault Rifle, it will refuse to give me another. Also, how do I make it so that if I have 350 rounds, it won't give me anymore, but if I have less, it will give me enough to get back to 350?

 

scn L4DNVActivateAssaultRifleSCRIPT

Short DoOnce

Begin OnActivate
   If DoOnce == 0
player.additem L4DNVAssaultRifle 1 100
player.equipitem L4DNVAssaultRifle
player.additem L4DNVAmmoRifle 350
       Set DoOnce to 1
   endIf
End

 

You could also make it a quest script, set it priority 55 and attache the script, except instead of the if block a StopQuest at the end. That way the player doesn't have to do anything it just loads up and it's gone.

Edited by devinpatterson
Link to comment
Share on other sites

Here's a list of what it needs to be...

 

  • The activator script must be able to be used an infinite amount of times, regardless of whether it gives you anything or not
  • It must not give you more than one weapon at a time
  • It must not give you more than the specified ammo limit (350), but will give you enough to get back to 350 if you have less than 350 rounds.
  • If the player has another similar weapon, like the Service Rifle, it must remove the Service Rifle, then give the player the Assault Rifle.

 

I hope that's all possible.

Link to comment
Share on other sites

Here's a list of what it needs to be...

I hope that's all possible.

 

I would think so. Activating it a infinite amount of times is ok (take out the doOnce),

  • The activator script must be able to be used an infinite amount of times, regardless of whether it gives you anything or not

I would think so. Activating it a infinite amount of times is ok (take out the doOnce),

 

  • It must not give you more than one weapon at a time

 

Don't think that will be a problem since your script will determine how many weapons to give. Use GetItemCount on the player to see if he already has the assault rifle

 

  • It must not give you more than the specified ammo limit (350), but will give you enough to get back to 350 if you have less than 350 rounds.

 

use GetItemCount set it to a variable subtract it from 350 for your additem

 

  • If the player has another similar weapon, like the Service Rifle, it must remove the Service Rifle, then give the player the Assault Rifle.

 

If you can test against a formlist (don't know, not a scripting guy) you could make one that includes all the items you consider similar, and use that. Otherwise a if/else block with each item you consider similar . I guess you'd have a bunch of if/else statements to remove each item. the first item removed should end the if/else block and the player looses one item.

 

Of course someone that actually knows about scripting may have a much simpler and more elegant aproach than the if else blocks.

Link to comment
Share on other sites

If you can test against a formlist (don't know, not a scripting guy) you could make one that includes all the items you consider similar, and use that. Otherwise a if/else block with each item you consider similar . I guess you'd have a bunch of if/else statements to remove each item. the first item removed should end the if/else block and the player looses one item.

 

Of course someone that actually knows about scripting may have a much simpler and more elegant aproach than the if else blocks.

The AddItem and RemoveItem functions can take a formlist as a parameter, which becomes useful in this case. If you make a formlist (I called it L4DNVWeaponList in the script below) with all the weapons that you consider similar, you can call RemoveItem with your list as a parameter and specify some high number of weapons to remove. I wrote 100 in this case, which should be more than enough. I guess a player might have more than a 100 of a given weapon in his inventory, but I think the probability is near zero unless there's cheating involved. This example also takes care of adding the rifle and the ammo.

 

ScriptName L4DNVActivateAssaultRifleSCRIPT
int iAmmoCount
int iAmmoToGive

BEGIN OnActivate
Player.RemoveItem L4DNVWeaponList 100
If Player.GetItemCount L4DNVAssaultRifle == 0
	Player.AddItem L4DNVAssaultRifle 1 1
	Player.EquipItem L4DNVAssaultRifle
EndIf
Set iAmmoCount to Player.GetItemCount L4DNVAmmoRifle
If iAmmoCount < 350
	Set iAmmoToGive to 350 - Player.GetItemCount iAmmoCount
	Player.AddItem L4DNVAmmoRifle iAmmoToGive
EndIf
END

Of course, as devinpatterson points out, this won't stop players from dropping the rifle and getting a new one.

 

A couple of questions:

  • Are you planning to have a single activator placed with this script, or are you going to have several of them (as a kind of checkpoint system)?
  • If you're going to have more of them, do you really need to be able to activate each one more than one time?
  • What about the weapons condition? If the player has a rifle that is nearly broken, should that not be switched for a new one?

If you're going to have several activators placed, and each only need to be activated once, you could use a doOnce variable as in devinpattersons script.

Each instance of the activator will run its own separate instance of the script, so if one cannot be used anymore, the next can.

 

However, a clever player might still drop the rifle before activating the next checkpoint and end up with 2 that way.

 

As for the condition, you could easily remove the rifle and add a new one if it is in bad shape.

Edited by Ladez
Link to comment
Share on other sites

All weapons in this mod can not be dropped, or removed from the inventory as they are marked as Quest Items. The only way they'll be removable is by activating another weapon's activator, and at the end of the level. Nothing I intend to do with this mod will prevent people from cheating and bypassing stuff, but for the non-cheating user, they will only have two weapons at a time, a primary and secondary.

 

There will be multiple activators throughout each section of the map, some being the same ones, hence why they need to be able to be activated an unlimited amount of times.

 

As for the weapon condition, there's very little RPG elements in this mod, so the player will be given a 100% condition weapon.

 

Thanks for the script, I hope it works. :)

Link to comment
Share on other sites

Unfortunately, it won't save which means something in the script isn't right.

 

scn L4DNVActivateAssaultRifleSCRIPT
int iAmmoCount
int iAmmoToGive

Begin OnActivate
Player.RemoveItem L4DNVTier2WeaponsList 100
If Player.GetItemCount L4DNVAssaultRifle == 0
	Player.AddItem L4DNVAssaultRifle 1 100
	Player.EquipItem L4DNVAssaultRifle
Endif
Set iAmmoCount to Player.GetItemCount L4DNVAmmoRifle
If iAmmoCount < 350
	Set iAmmoToGive to 350 - Player.GetItemCount iAmmoCount
	Player.AddItem L4DNVAmmoRifle iAmmoToGive
Endif
End

 

Any ideas?

Link to comment
Share on other sites

The AddItem and RemoveItem functions can take a formlist as a parameter, which becomes useful in this case.

 

Good deal Ladez, nice to know :thumbsup:

I have a mars mod where I use a formlist of all the pressurized suits/armor the player must wear so he/she doesn't pop like a balloon. This will be much easier.

 

 

Unfortunately, it won't save which means something in the script isn't right.

Any ideas?

 

Did you make the formlist (L4DNVWeaponList)? If so then grab powerup (the newer one that works with 1.4) and it will let you know what line the error is on.

Edited by devinpatterson
Link to comment
Share on other sites

  • Recently Browsing   0 members

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