Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Treasure distribution 2

DouweDabbe
Guest
Quote
2021-08-20 12:22:43

action to distribute game jewels in a circel when triggered from a center position:


/*
<action jsname="action_GemDistCircular" description="Treasure Circ. Dist.">
<property name="iRadius" type="int" default="1000" />
<property name="mCentrNode" type="scenenode" />
<property name="fLibrary" type="scenenode" />
<property name="fTreasure" type="scenenode" />
<property name="sMannaData" type="string" default="GDLG" />
<property name="iMannaHeight" type="int" default="15" />
</action>
*/


action_GemDistCircular = function() {
// version name: v1 GemDistCircular.
// origin : Douwe Dabbe.
// task : distibute gems circular over a terrain from mCentrNode at max iRadius.
// performance :
// issues : may slow down the windows test app.
// inputs:
// iRadius = max goody distance from center.
// mCentrNode = center of circular distribution.
// fLibrary = goody Billboard types grouped in folderNode that will be Clone-ed for use.
// fTreasure = created bGemNodes Parented to this Folder for use.
// sMannaData = string of arbitrary length, out of Capital Letters coding for goody type.
// iMannaHeight = height lift billboard off ground.
// outputs:
"use strict";
};

// more substantial test data:
// var sMannaData ="DLLGGLGLLGGLLLLLGGLDLGDDLDLLLGLLLLLLDDLDLLLGGGGGLDGLDLGGDLLDLGGGGGLDGGLLLLLLLGDGDGGGGGG";

action_GemDistCircular.prototype.execute = function(currentNode) {

// transfer inputs to local vars for performance sake
var iRadius = this.iRadius;
var fLibrary = this.fLibrary;
var fTreasure = this.fTreasure;
var vCentrPos = ccbGetSceneNodeProperty(this.mCentrNode, "Position");
var iGemTypeCount = ccbGetSceneNodeChildCount(this.fLibrary);
var iMannaHeight = this.iMannaHeight;
var sMannaStg = this.sMannaData;

let rRingAngle = 0;
let rRingRad = 0;
var bChildNode, bGemNode, bGunNode, bDollarNode, bLiqNode;
var vGemPos = new vector3d(0,0,0);

for (let i = 0; i < iGemTypeCount; ++i) {
bChildNode = ccbGetChildSceneNode(fLibrary, i);
if (ccbGetSceneNodeProperty(bChildNode, "Name") === "Gun-0") bGunNode = ccbCloneSceneNode(bChildNode);
if (ccbGetSceneNodeProperty(bChildNode, "Name") === "Dollar-0") bDollarNode = ccbCloneSceneNode(bChildNode);
if (ccbGetSceneNodeProperty(bChildNode, "Name") === "Liquor-0") bLiqNode = ccbCloneSceneNode(bChildNode);
}

// distribute MannaData
vGemPos.y = iMannaHeight;
for (let m = 0; m < sMannaStg.length; ++m) {
rRingAngle = 360 * Math.random();
rRingRad = Math.random() * iRadius;
vGemPos.x = vCentrPos.x + rRingRad*Math.cos(rRingAngle);
vGemPos.z = vCentrPos.z + rRingRad*Math.sin(rRingAngle);
if ( sMannaStg[m] === "G" ) bGemNode = ccbCloneSceneNode(bGunNode);
if ( sMannaStg[m] === "D" ) bGemNode = ccbCloneSceneNode(bDollarNode);
if ( sMannaStg[m] === "L" ) bGemNode = ccbCloneSceneNode(bLiqNode);
ccbSetSceneNodeProperty(bGemNode, "Visible", true);
ccbSetSceneNodeProperty(bGemNode, "Position", vGemPos);
ccbSetSceneNodeParent(bGemNode, fTreasure)
}
}
// end



DouweDabbe
Guest
Quote
2021-08-20 12:36:39

Hmm cant post other two scripts:

linear distribution and square distribution?
why
why now
what for


guest
Guest
Quote
2021-08-20 15:39:25

Could you maybe please provide a small demo .ccb?

Thanks for sharing @DouweDabbe!


just_in_case
Moderator
Quote
2021-08-20 16:23:45

Thanks! for sharing these 3 amazing scripts @DouweDabbe.



j6009
Registered User
Quote
2021-08-21 03:46:16

@Just_in_case *hmph


just_in_case
Moderator
Quote
2021-08-21 12:07:08

@DouweDabbe, I tried using the circular script, but I am unable to use it, If you can provide tutorial or CCb files for that.

Please provide Usage instructions at least.


Edit:- have to study the source in order to understand how it works, It seems we have to use folders. But A tutorial or usage instruction will be great so that everybody can use it easily.

Alright after studying and analyzing the source I got it working,
It requires the end user to change or modify the behavior in order to work with this action.
the action uses names like gun-0, dollar-0, and all you might need to change these names in the action with your node names, or has to rename your nodes with the values from this action.
also, you need to create a folder and put the treasure in that folder.

if executed multiple times can freeze or crash the game.

it is good to distribute treasures only once and it will definately requires you to have modify the script.


DouweDabbe
Guest
Quote
2021-08-22 01:29:12

I hoped the code would to be self explanatory.

Developing Games requires tons of testing = boring work.
Therefore made these 3 jewel distribution scripts, to add some event driven randomness.

I am still struggling with debugging, therefore I have begun to use a naming convention:
- node names first letter is nodetype: (m)esh, (o)verlay, etc.
- variable names first letter is var type (g)lobal, s(tring), (i)nt, (f)loat, (o)bject, etc.
I also like to bundle my data into (C-language like structs):

var gPlayer {
name : "",
positionx : 0,
positionz : 0,
positiony : 0,
points : 0
}
PS: cant use ccbcommands in mygame.js files

var Johnny = new gPlayer; // (g)lobal var
var Peter = new gPlayer;

this is beneficial if I need to pass aguments to some function
var route = findPath(Johnny, Peter);
attackPeter(Johnny, route);

@just_in_case
Yess it is very beneficial to create sample ccb files for every
script, so the novice user can visualize and investigate its usage.
will see to upload one.

I did not experience CC crashes,
But long Manna data strings (100 letters) do slowdown the square script quite a bit.

all gems are cloned from prototypes in fLibrary (f)older node
all gems are billboards, you can change that, names should be bGun-0, bLiquor-0, bDollar-0, idea was to use a auto numbering naming routine, not implemented yet.
all gems are parented to fTreasure (f)older node. So we can iterate through fTreasure to keep scores, i.e. 4 of 12 monsters destoyed.

Indeed this script is not just for distributing assets / jewels, but can also be used to place enemies or bad luck and traps as well.

Hope that helps.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact