Getting more than 100 skills without DLL

Posted By: Lion_Ts

Getting more than 100 skills without DLL - 10/07/05 13:52

I finded question about getting more than 100 SKILLS in one of the forum's thread. It can be done with DLL, fast and efficient. But If you can't deal with C++, you have to think about C-script...
Look at slow C-script version :
Code:

define Skill200, SKILL60; //define skill for handle storing
var GetEntRetVal; //must be global for execute...
entity* GetSetEnt; //pointer for SKILL box entity
string ExecStr; //string for execute command
string TempIntStr; //string for converting int->str
string PsEnt=<ps.mdl>; //create very small MDL5 entity with 4x4 skin (it takes ~296 bytes only)
action PsEntAction{ //action for our SKILL box
my.invisible=on; //invisible passable static
my.passable=on;
my.dynamic=off;
}

function GetSkill200(EntName, SkillNum){ //Get SkillNum value for EntName entity
GetEntRetVal=-1; //Set to ERROR
if (!EntName){return(GetEntRetVal);} //No entity, ERROR
if (SkillNum>100)||(SkillNum<1){return(GetEntRetVal);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200==0){ //No entity for skill storing
GetSetEnt.Skill200=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
str_cpy(ExecStr, "GetEntRetVal=GetSetEnt.SKILL"); //prepare execute command
str_cat(ExecStr, str_for_num(TempIntStr, int(SkillNum)));
str_cat(ExecStr, ";");
execute(ExecStr);
return(GetEntRetVal); //return needed skill
}
function SetSkill200(EntName, SkillNum, SkillVal){ //Set SkillNum to SkillVal for EntName entity
if (!EntName){return(-1);} //No entity, ERROR
if (SkillNum>100)||(SkillNum<1){return(-1);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200==0){ //No entity for skill storing
GetSetEnt.Skill200=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
str_cpy(ExecStr, "GetSetEnt.SKILL"); //prepare execute command
str_cat(ExecStr, str_for_num(TempIntStr, int(SkillNum)));
str_cat(ExecStr, "=");
str_cat(ExecStr, str_for_num(TempIntStr, SkillVal));
str_cat(ExecStr, ";");
execute(ExecStr);
return(0); //no ERROR
}
function RemoveSkill200(EntName){ //remove SKILL box, call this before ent_remove(EntName)
if (!EntName){return(-1);} //No entity, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200!=0){ //No entity for skill storing
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
ent_remove(GetSetEnt); //and remove it
}
return(0); //no ERROR
}


For saving another 100 skills we create invisible passable static entity and use it as "SKILL BOX". Don't forget to remove it before removing 'parent' entity.
Example of usage (without error checking):
Code:

define MySkill6, SKILL6; //define name for skill6
define MySkill106, 6; //define another name for skill6, but this imagine skill106
...
SetSkill200(me, MySkill106, random(50)); //set my.skill106 to random value
me.MySkill6=20; //set my.skill6 to 20
...
your.MySkill6=GetSkill200(me, MySkill106); //set you.skill6 to my.skill106 (random value)
SetSkill200(you, MySkill106, me.MySkill6); //set you.skill106 to my.skill6 (20)
...
RemoveSkill200(me); //remove "skill box" entity before removing parent entity
ent_remove(me);
RemoveSkill200(you);
ent_remove(you);
...


That's all. If you want another 100 skills define one more skill for "skill box" handle and rewrite functions for set/get/remove.
But I don't know for what you may need 300 skills
Posted By: HeelX

Re: Getting more than 100 skills without DLL - 10/07/05 14:19

Yes, you use somekind of a linked list by linking 2 entities together to retrieve a wider range of skills. But your script is a bit too complicated and slow. This is because you use execute and such things.

I use for instance these virtual placeholders to save classified data. For a racing game I defined a virtual track device for a car to save 17 skills. If I had to save them in the original entity's skills it would be too much consuming. By grooping it into one virtual object it is much easier to deal with.

Your approach looks like you want to do a dynamic skills list which automatically appends virtual objects to widen the range. Try dynamic creating with pointer (-> handle!!) connections. It is also recommended to write a new function to read/write skills, because the object with the skills is now relative (because there are now more than the original entity) which are possible to use.

I think until we have no pointers to variables I bet there are some serious users which have to do such a thing when they want some kind of local variables which could be accessed from outside!

(this is a wink, conitec )

ciao
christian
Posted By: Lion_Ts

Re: Getting more than 100 skills without DLL - 10/07/05 14:55

I placed execute() to avoid big case switch(100 cases) (if (Skillnum==1){retval=entity.skill1} else {if(...). About slow, If somone needs 200 skills, TRY IT and report FPS (script time)
Posted By: HeelX

Re: Getting more than 100 skills without DLL - 10/07/05 15:17

I bet, when you write a in-itself structured if then else case decision tree, it is everytime faster than execute.
Posted By: FRAJO

Re: Getting more than 100 skills without DLL - 10/07/05 15:24

function withoutifs(&firstskill,whatskill)
{
return firstskill[whatskill];//whatskill==skill you wnat to receive - 1
}

...
aSkill=withoutifs(my.skill1,5);
//aSkill is now filled with the 6th skill
...
Posted By: Rhuarc

Re: Getting more than 100 skills without DLL - 10/07/05 16:11

It's a lot easier to use arrays....

example:
Code:

define SKILL_SLOT = skill99;
define EXTRA_SKILLS = 100;
define ENTITY_LIMIT = 100;
define SKILLARRAYSIZE = 10000; //EXTRA_SKILLS*ENTITY_LIMIT

var skills[SKILLARRAYSIZE];
var skillslots[ENTITY_LIMIT];

entity* tempSkillEnt;
function init_skills(ent)
{
tempSkillEnt = ent;
var i;
while(i<ENTITY_LIMIT)
{
if(!skillslots[i]){ tempSkillEnt.SKILL_SLOT = i; skillslots[i]=1; return(1); }
i+=1;
}
return(0); // no free slots!
}

function destroy_ent_skills(ent)
{
var i;
tempSkillEnt = ent;
skillslots[i]=1;
while(i<EXTRA_SKILLS)
{
skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+i]=0;
i+=1;
}
tempSkillEnt.SKILL_SLOT = -1;
return(1);
}

// resets all skills (in event of level load!)
function destroy_all_skills()
{
var i;
while(i<ENTITY_LIMIT)
{
skillslots[i]=0;
i+=1;
}
while(i<SKILLARRAYSIZE)
{
skills[i]=0;
i+=1;
}
return(1);
}

function set_skill(ent,skillNum,value)
{
tempSkillEnt = ent;
if(tempSkillEnt.SKILL_SLOT==-1){return(0);}
skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+skillNum]=value;
return(1);
}

function get_skill(ent,skillNum)
{
tempSkillEnt = ent;
if(tempSkillEnt.SKILL_SLOT==-1){return(0);}
return( skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+skillNum] );
}



Example usage:
Code:

action my_extra_skills_entity
{
init_skills(my);
set_skill(my,50,100); //sets extra skill #50 to 100
get_skill(my,50); // returns 100
}



Untested, but should work.
Posted By: Anonymous

Re: Getting more than 100 skills without DLL - 10/07/05 17:43

Wow, thanks, I need more than a thousand skills for the animation capabilities I'm putting in my light/sound correlation program as I ran out of 100 skills quickly. Variables will not work locally when I'm dynamically creating many of them with the same function, they have a very small max local array count. Do you have the dll code? Thanks again! Your contributions are very helpful LionTs!
Posted By: Lion_Ts

Re: Getting more than 100 skills without DLL - 10/07/05 21:44

Thank you, espesially to RHUARC
Guys, you are creative, why didn't you post it ?
Posted By: Lion_Ts

Re: Getting more than 100 skills without DLL - 10/08/05 09:38

Frajo, good idea to cast skills as array. Thank you. I'll try to overwrite this 'slow' code.
@WING: I haven't DLL, but i'm thinking about it. When finished I'll post code and compiled DLL here.
Posted By: task1

Re: Getting more than 100 skills without DLL - 10/08/05 10:56

thanx.itīs very helpfuly
Posted By: HeelX

Re: Getting more than 100 skills without DLL - 10/08/05 12:15

I dont want to make it bad, but remember: arrays are limited! So you cant have a real dynamic system with this.
Posted By: profmakx

Re: Getting more than 100 skills without DLL - 10/08/05 13:39

Quote:

Wow, thanks, I need more than a thousand skills for the animation capabilities I'm putting in my light/sound correlation program as I ran out of 100 skills quickly. Variables will not work locally when I'm dynamically creating many of them with the same function, they have a very small max local array count. Do you have the dll code? Thanks again! Your contributions are very helpful LionTs!




I do think you have a different problem if you need 1000 skills...

What exactly are you trying to do?

profmakx
Posted By: Lion_Ts

'Unlimited' number of SKILLS without DLL - 10/08/05 22:59

Proudly present, the 'fast' finalized version, thanks to FRAJO
*DELETED* old code for 100 skills *DELETED*
Fot those who care about script time execution
I'm using in this version some kind of 'linked list'
Code:

define Skills, SKILL60; //define skill for handle storing
entity* GetSetEnt; //pointer for SKILL box entity
string PsEnt=<ps.mdl>; //create very small MDL5 entity (it takes 296 bytes only)
action PsEntAction{ //action for our SKILL box
my.invisible=on; //invisible passable static
my.passable=on;
my.dynamic=off;
}

function GetArr(&Arr, SkillNum){ //helper function to get skill by index
return(Arr[SkillNum]);
}
function SetArr(&Arr, SkillNum, SkillVal){ //helper function to set skill by index
Arr[SkillNum]=SkillVal;
}
function GetSkill(EntName, SkillNum){ //Get SkillNum value for EntName entity
if (!EntName){return(-1);} //No entity, ERROR
if (SkillNum<1){return(-1);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
SkillNum=int(SkillNum); //for a case
if (SkillNum>100){
if (GetSetEnt.Skills==0){ //No entity for skill storing
GetSetEnt.Skills=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skills); //set pointer to next entity
GetSkill(GetSetEnt, SkillNum - 100); //and get skill for next entity
}else{
return(GetArr(GetSetEnt.Skill1, int(SkillNum))); //skill < 100, get it
}
}
function SetSkill(EntName, SkillNum, SkillVal){ //Set SkillNum to SkillVal for EntName entity
if (!EntName){return(-1);} //No entity, ERROR
if (SkillNum<1){return(-1);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
SkillNum=int(SkillNum); //for a case
if (SkillNum>100){
if (GetSetEnt.Skills==0){ //No entity for skill storing
GetSetEnt.Skills=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skills); //set pointer to next entity
SetSkill(GetSetEnt, SkillNum-100, SkillVal); //and set skill for next entity
}else{
SetArr(GetSetEnt.Skill1, SkillNum, SkillVal); //skill < 100, set it
}
return(0); //no ERROR
}
function EntRemoveSkills(EntName){ //remove SKILL box, call this to remove entity, not ent_remove(EntName)
var TempEntHandle=0; //handle for current entity

if (!EntName){return(-1);} //No entity, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skills!=0){ //No entity for skill storing
TempEntHandle=handle(GetSetEnt); //store current entity
RemoveSkills(ptr_for_handle(GetSetEnt.Skills)); //remove next entity
}
ent_remove(ptr_for_handle(TempEntHandle)); //remove current entity
return(0); //no ERROR
}


Sorry for posting as answer, edit disabled for me
usage example:
Code:

define MySkill456, 456; //define name for skill456 (56th skill on 4th entity in list)
define MySkill301, 301; //define name for skill301 (1st skill on 3 entity in list)
...
SetSkill(you,MySkill456,1024); //you.skill456=1024
SomeVar=GetSkill(my,MySkill301); //SomeVar=my.skill301
...
SetSkill(my,6,100); //my.skill6=100 :) this and next are useless just for fun
SomeVar=GetSkill(my,6); //SomeVar=my.skill6
...
EntRemoveSkills(me); //ent_remove(me);
...


Feel free to use this stuff.
Posted By: Lion_Ts

Re: 'Unlimited' number of SKILLS without DLL - 10/09/05 22:58

And thank you guys for pointing me in the right way with skills.
Posted By: Anonymous

Re: Getting more than 100 skills without DLL - 10/16/05 19:31

Quote:

What exactly are you trying to do?



-profmakx




I have about 20 paramaters for each created entity (which makes it hard to use global arrays since I'm creating them dynamically), which include scale_x, scale_y, scale_z, pan, tilt, roll, .x, .y, .z, red, green, blue, etc. and I am allowing the user to animate them according to how they want over many frames! That means for each frame, the skill will store the value for each parameter so each object can be animated separately (like in a 3d animation program) but I can only have 2 frames right now because of the low amount of skills I can have. But I can change the animation speed between these two frames so its not so bad. In a .dll tutorial (Grimber's?) it says something about unlimited skills so I'm hoping I won't have to try to use arrays (because it will be much more difficult to program) like you guys are mentioning.
Posted By: Lion_Ts

Re: Getting more than 100 skills without DLL - 10/18/05 00:53

WING, look closer at my code. No arrays except skills one. It's like a linked list. If you need 201st skill, you'll get 2 entities, 526 - 5. It's a dynamic solution, slower than arrays, but more flexible, i think.
Posted By: PrenceOfDarkness

Re: Getting more than 100 skills without DLL - 01/08/07 09:01

although this was over a year ago i decided to leave a comment, because I'm sure new comers will find this very useful, and I went nuts looking for this. Next step will be implementing this for multiplayer use. If anyone really wants to see it work for multiplayer leave a comment or else I wont bother until it's time.
© 2024 lite-C Forums