Jump to content

Need to have my script checked.(I believe it's a beginner's mi


HakunoWolf

Recommended Posts

I keep looking over this cursed thing and am trying to figure out why it's not working, is it because I did the reference variables? did I type in something wrong? Is the name too long? I can't save this thing on the Geck, and I prefer to know if I need to scrap the idea of having a weapon giving someone a perk.

 

ScriptName NCRNW44Mageffect

ref rEquipped ; Creates the value of which needs to referenced

ref rHasPerk ; Creates the value of which needs to be referenced

begin OnEquip player ; Begins the script when the weapon is equipped

set rEquipped to GetEquipped ; Sets rEquipped which is the reference value, to the GetEquipped value, which returns on what weapon the actor has equipped

if player.rEquipped == WeapNVNCRNW44Revolver ; Asks if whether or not the 44 Mag is equipped
player.AddPerk NightWolf44Magnum ; Gives the player the 44 Magnum perk if they have it equipped
endif

End

begin OnUnequip

set rHasPerk to HasPerk ; Sets rHasPerk which is the reference value, to the HasPerk value, which returns on if the actor has the perk or not

if player.rHasPerk NightWolf44Magnum ; Asks if the player has the 44 Mag perk
player.RemovePerk NightWolf44Magnum ; Removes the 44 Magnum perk if they have it
endif

End

Link to comment
Share on other sites

I don't know the scripting of Fallout, but some lines in there look very suspicious to me.

You define some 'ref' variables first, set them to an invalid function call without any parameters, and then act as if the 'variable' you defined was a 'function' of the player object? Is this how it's done in Fallout?

 

I for one would rather try it this way round:

 


begin OnEquip player ; Begins the script when the weapon is equipped

set rEquipped to player.GetEquipped ; Sets rEquipped which is the reference value, to the GetEquipped value, which returns on what weapon the actor has equipped

if rEquipped == WeapNVNCRNW44Revolver ; Asks if whether or not the 44 Mag is equipped
player.AddPerk NightWolf44Magnum ; Gives the player the 44 Magnum perk if they have it equipped
endif

End

begin OnUnequip

set rHasPerk to player.HasPerk NightWolf44Magnum; Sets rHasPerk which is the reference value, to the HasPerk value, which returns on if the actor has the perk or not

if rHasPerk ; Asks if the player has the 44 Mag perk
player.RemovePerk NightWolf44Magnum ; Removes the 44 Magnum perk if they have it
endif

End

This way at least variables and functions are used the way I would expect from a scripting language.

However, I cannot tell whether "player.HasPerk XYZ" will return a value fit for a "ref"-type variable rather than something more boolean,

nor do I know the correct usage of the function GetEquipped. I suspect it's rather used like "player.GetEquipped WeapNVNCRNW44Revolver" and returns 1 or 0 according to whether he is or not. In this case my fixed line above still won't work of course.

Link to comment
Share on other sites

This way at least variables and functions are used the way I would expect from a scripting language.


However, I cannot tell whether "player.HasPerk XYZ" will return a value fit for a "ref"-type variable rather than something more boolean,

nor do I know the correct usage of the function GetEquipped. I suspect it's rather used like "player.GetEquipped WeapNVNCRNW44Revolver" and returns 1 or 0 according to whether he is or not. In this case my fixed line above still won't work of course.

 

I tried that too, and then I got the genius idea to actually just try and save the script at multiple points to see exactly where does this issue start.

 

ScriptName NCRNWMageffect

begin OnEquip player ; Begins the script when the weapon is equipped

End

 

Doing this, it allows me to save, but once I add the next line, it doesn't work, but when you talked about how it all seems going from one thing to another doesn't sound right to me, I'll post the link to where I got the idea for that line from.

 

http://geck.bethsoft.com/index.php?title=GetEquipped

 

The reason why I threw in the If statement is because there's a bug where if you try to equip a broken weapon, it counts it as the OnEquip function block, forcing it to start the script, where then if it would give them something(say the perk.) they would have it without actually having the weapon equipped.

 

 

Edit: I just realized that I completely forgot that it returns one, bah, let me see if I can fix it from that information.

 

Edit #2:

 

ScriptName NCRNW44Mageffect

begin OnEquip player ; Begins the script when the weapon is equipped

if player.GetEquipped WeapNVNCRNW44Revolver == 1 ; Asks if whether or not the 44 Mag is equipped
player.AddPerk NightWolf44Magnum ; Gives the player the 44 Magnum perk if they have it equipped
endif

End

 

This script works, however when adding in the reference values the script fails, so maybe I'm doing the reference values wrong? Let me try your way where you replaced the reference value with the entire function script.

 

Edit #3: Tried your way, didn't work either....Maybe I misread it as, "Because the function is pulling from something that is referenced, it NEEDS the reference variable instead of just pulling it from the game because it's returning something that is being called?

 

Or should I be thinking it means that it only needs the reference variable when it is calling from nothing? Forgive me for my bad scripting, but I'm learning this to continue a mod that I had to drop due to a computer bluescreening, and I'm also learning it to give me knowledge of general scripting so I can apply it to a group project I'm working on with some people.

Edited by HakunoWolf
Link to comment
Share on other sites

I think the reference "variables" are entirely unneccessary for this purpose.

 

What they mean likely is you cannot call "GetEquipped" without the 'reference' on who it is equipped like "player.GetEquipped" (player here is a reference, too. You refer the player object to the function so it knows who to check the equipment for, it just isn't a 'variable' you defined yourself). Also you cannot call "player.GetEquipped" either without also adding a reference to 'what' should be equipped like "player.GetEquipped WeapNVNCRNW44Revolver" (WeapNVNCRNW44Revolver also is used as a reference here, it again just isn't a 'variable' defined by you).

 

What I did wasn't "replacing" the reference value with the function script. What you did reads like "variable = function", while mine reads like "variable = return value of a function call", the "=" making an assignment here, value into variable (=storage container, if you like). You actually can do your's in more sophisticated languages like C, Java or PHP, assign an entire function itself into a variable, then use the variable as if you'd call the function stored within it:

 

var myFunction = GetEquipped;

if player.myFunction myItem == something

do somethingelse;

endif

(pseudo-code I just made up)

 

I'm pretty sure it won't work within these simple game scripting environments though.

 

And as for why it doesn't work with the reference variables on the left side of the assignment,

that could perfectly be because of the other thing I mentioned, you trying to insert the "short" (or whatever type the return value of this function is of) returned by the function call into a "ref"-type variable. I could perfectly understand if that wasn't allowed in the scripting language here. For these variable assignments to work the variables likely must be of type "short" or whatever else numeric type can store results 1 and 0, not "ref".

 

As for your last question, those two functions cannot be called 'from nothing'.

 

[Actor].GetEquipped Target:ObjectID

This kind of syntax will always require the two references "Actor" (who is having it equipped?) and "Target" (what is he having equipped?) or they simply can't work.

 

To make things even more confusing (or simpler?) this "player" you're using for "[Actor]" in the script actually is a variable already.

It's a super-global reference variable to the player object, usable in every script right away without a need to be defined first, if I'm making sense here.

 

And to be honest I think "WeapNVNCRNW44Revolver" is something similar as well even, just pointing to a different object.

Link to comment
Share on other sites

This kind of syntax will always require the two references "Actor" (who is having it equipped?) and "Target" (what is he having equipped?) or they simply can't work.

 

To make things even more confusing (or simpler?) this "player" you're using for "[Actor]" in the script actually is a variable already.

It's a super-global reference variable to the player object, usable in every script right away without a need to be defined first, if I'm making sense here.

 

And to be honest I think "WeapNVNCRNW44Revolver" is something similar as well even, just pointing to a different object.

 

All right, thank you, and yeah, the Weap is more or less similar to the player actor(If I'm thinking about it correctly) as they both are things that all ready can be referenced, I kept thinking I would actually need a ref variable for the functions(Idk why I thought that, so that was definitely my bad.)

 

That makes more sense why the Ref variables only cause it to malfunction rather than having without causes it work.

 

 

Get the geck power up, it tells you what's wrong with your script. It may compile scripts that won't actually do anything, but it catches any glaring mistakes

 

I did use it, I'm just very new to scripting(As in, I was using things that probably didn't read off as errors in a way that would cause it not to work.)

Link to comment
Share on other sites

You want to give the player a perk when they equip the gun with the object script and remove it when it is unequipped, correct?

scn NCRNW44OS

short equipped

begin onequip player

    set equipped to 1
    player.addperk NightWolf44Magnum

end ; onequip player

begin gamemode

    if(equipped)
        if(player.getequipped WeapNVNCRNW44Revolver)
        else
            set equipped to 0
            player.removeperk NightWolf44Magnum
        endif
    endif

end ; gamemode

Don't use OnUnequip. It's not completely useless, but it's close. If the player attempts to equip the gun when it's broken and the perk is added by the OnEquip block, the perk will be removed again immediately when they re-enter GameMode.

Link to comment
Share on other sites

You want to give the player a perk when they equip the gun with the object script and remove it when it is unequipped, correct?

Don't use OnUnequip. It's not completely useless, but it's close. If the player attempts to equip the gun when it's broken and the perk is added by the OnEquip block, the perk will be removed again immediately when they re-enter GameMode.

I'm gonna need you to explain this to me, because I understand the perk is removed when the gun is broken, but here's the fun fact, I actually just tested it out in game(I used the console commands and what not to check on everything as a test, I can actually make a video to describe how it works(and it works quite well for me actually), because when the player equips the gun and it's not broken, it gives them the perk, however, when they try to equip the gun when it's broken, the script checks to see if the weapon is actually equipped, if it's not, then it doesn't give them the perk.

The OnUnequip takes away the perk if they have it(Just to prevent the game from trying to do something it doesn't need to do).

 

So, I'm not sure what you're getting at.

 

Edit: Also, when looking at that script, it looks like that if they try to equip the broken weapon, it will give them the perk, which is opposite of what the perk is supposed to do, so again, somewhat confused by what you're getting at.

Edited by HakunoWolf
Link to comment
Share on other sites

It's the check in the GameMode block. It will remove the perk again, if the weapon's not still equipped. So when you equip a broken weapon, you first get the perk, but then it gets taken away from you again only a couple of frames afterwards at latest.

 

However, I prefer your's. Not adding the perk, prevented by an additional check, to begin with is far more clean and less error-prone than having to take it away afterwards again.

 

As for letting a GameMode block handle the removal of the perk as soon as the weapon is no longer equipped, this becomes indeed a viable solution, if OnUnequip really is as unreliable as it's said to be.

 

If you put your additional check if it really is still equipped around the two lines from luthienanarion, you'll even have the benefits from both approaches at once.

 

As for using OnUnequip or GameMode block rather, that is something I cannot decide for a game I don't know. From a functional point of view however the GameMode approach will once the weapon is equipped continue to call the rather performance-heavy function GetEquipped over and over again every single frame until you finally unequip the weapon again. I have yet to stumble across a game that's slowed down by heavy scripting, but I regularly see people 'claim' their game was. And it never hurt to conserve as much performance in script approaches as possible.

Edited by DrakeTheDragon
Link to comment
Share on other sites

I mentioned that because I'm not 100% sure whether or not OnEquip blocks will run if the items isn't actually equipped because it's broken; they shouldn't logically, but you can never take logical things for granted with this game engine.

 

 

The script I posted is a more efficient version of the vanilla script used by the Rebreather to add and remove the waterbreathing effect:

 

 

scn VMS15RebreatherScript

int iEquipped

begin OnEquip player
    player.AddSpell VMS15WaterBreathingActual
    set iEquipped to 1
end

;begin onUnequip player
;    player.RemoveSpell VMS15WaterBreathingActual
;end

begin GameMode
    if iEquipped == 1 && Player.GetEquipped VMS15Rebreather == 0
        player.RemoveSpell VMS15WaterBreathingActual
        set iEquipped to 0
    endif
end

 

The script was changed in one of the game patches to remove the OnUnequip block and move the check to GameMode because of problems with it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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