Placing GameObjects in NPC: Difference between revisions
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
Create a Script file in classes. You load the assets the same it was done before in weapons; under '''//#CLIENTSIDE''' | Create a Script file in classes. You load the assets the same it was done before in weapons; under '''//#CLIENTSIDE''' | ||
[[File:Placing GO in | [[File:Placing GO in npcs.png|frameless|1048x1048px]] | ||
function onPlayerChats() { | function onPlayerChats() { | ||
if (player.chat == "/destroy") this.destroy(); | if (player.chat == "/destroy") this.destroy(); | ||
} | } | ||
Line 20: | Line 15: | ||
function onCreated() { | function onCreated() { | ||
this. | Quattro::AssetManagement::LoadAssetBundle("documentationexample"); | ||
this. | this.prefab = GameObject::createfromassetbundle("documentationexample", "assets/example/bomb.prefab"); | ||
this.bomb = Object::Instantiate(Type::GameObject, this.prefab); | |||
this. | this.bomb.transform.parent = this.gameobject.transform; | ||
this.bomb.transform.localposition = Vector3::Create(0,0.5,0); | |||
this. | |||
} | } | ||
Everything is the same when it comes to loading and instantiating the prefabs. | Everything is the same when it comes to loading and instantiating the prefabs. | ||
Line 38: | Line 33: | ||
Now to place the NPC in the scene, in another script and in serverside you use '''''putnpc2()''''' and joining it with the created class: | Now to place the NPC in the scene, in another script and in serverside you use '''''putnpc2()''''' and joining it with the created class: | ||
temp. | findplayer("Graal5918039").addweapon(this.name); | ||
function onActionServerside(cmd,x,y) { | |||
if (cmd == "bomb") { | |||
temp.bombernpc = putnpc2(x,y,""); | |||
temp.bombernpc.join("jimmy_doctest"); | |||
} | |||
} | |||
//#CLIENTSIDE | |||
function onCreated() { | |||
triggerserver("gui", this.name, "bomb", player.x, player.y); | |||
} |
Revision as of 03:26, 15 June 2021
Another way to make GameObjects visible to all the Players is by placing them in NPCs.
However, placing many NPCs may be heavy on the server, so beware of that whenever you're doing so.
Start off by creating the NPC the normal way:
Create a Script file in classes. You load the assets the same it was done before in weapons; under //#CLIENTSIDE
function onPlayerChats() { if (player.chat == "/destroy") this.destroy(); } //#CLIENTSIDE function onCreated() { Quattro::AssetManagement::LoadAssetBundle("documentationexample"); this.prefab = GameObject::createfromassetbundle("documentationexample", "assets/example/bomb.prefab"); this.bomb = Object::Instantiate(Type::GameObject, this.prefab); this.bomb.transform.parent = this.gameobject.transform; this.bomb.transform.localposition = Vector3::Create(0,0.5,0); }
Everything is the same when it comes to loading and instantiating the prefabs.
The only difference is for this line of code:
this.projectile.transform.parent = this.gameobject.transform; |
---|
Here, this.gameobject is the NPC GameObject.
We make the prefabs instantiated children of the NPC GameObject. Destroying the NPC will destroy all the children as well. However, destroying the Children will not destroy the Parent.
Now to place the NPC in the scene, in another script and in serverside you use putnpc2() and joining it with the created class:
findplayer("Graal5918039").addweapon(this.name); function onActionServerside(cmd,x,y) { if (cmd == "bomb") { temp.bombernpc = putnpc2(x,y,""); temp.bombernpc.join("jimmy_doctest"); } } //#CLIENTSIDE function onCreated() { triggerserver("gui", this.name, "bomb", player.x, player.y); }