Jump to content

Help with simple script (SetPlayerTeammate)


Cthorthu

Recommended Posts

Hi!

 

I need a script to make a NPC teammate with player when spawning. I hope someone with scripting knowledge can help me :)

 

NPC is not unique, it may spawn several times. I'm going to add this script to the NPC.

 

I have this (incomplete) script:

 

ScriptName CustomNPCTeammate extends Actor
{This script makes the NPC teammate with player}

Event OnLoad()
xxxxxxx.SetPlayerTeammate()

endEvent


I wonder if there a reference that calls the actor itself (to replace "xxxxxxx") (Along endless searches in google and bing, I have seen "akActor" several times, and I think this may be what I need, but can't find the meaning of "akActor" and if this can be used in this context, I'm probably completely wrong).

Not sure if I need to create this structure (taking in mind it is not a unique NPC):

ScriptName CustomNPCTeammate extends Actor
{This script makes the NPC teammate with player}

ObjectReference property CtCustomNPC auto

Event OnLoad()
CtCustomNPC.SetPlayerTeammate()

endEvent


Any help will be appreciated!

Link to comment
Share on other sites

If you will be adding the script to the custom NPC itself, you can use the special Self variable to indicate the actor holding the script.

ScriptName CustomNPCTeammate extends Actor
{This script makes the NPC teammate with player}

Event OnLoad()
  Self.SetPlayerTeammate()
endEvent

If for some reason that does not want to compile, cast Self into actor first.

(Self as Actor).SetPlayerTeammate()
Link to comment
Share on other sites

Or just

Event OnLoad()
     SetPlayerTeammate()
EndEvent

Since your script extends Actor class, it natively has access to its methods.

 

akActor is typical argument name for functions that get an Actor as parameter.

I.e. if you attach a script to a piece of armor, (Script will extend ObjectReference) so that any NPC equipping it becomes player's teammate:

you can define an event handler:

Event OnEquipped(Actor akActor)
    akActor.SetPlayerTeammate()
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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