|
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn),
581
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Getting more than 100 skills without DLL
#57218
10/07/05 13:52
10/07/05 13:52
|
Joined: Aug 2005
Posts: 1,185 Ukraine
Lion_Ts
OP
Serious User
|
OP
Serious User
Joined: Aug 2005
Posts: 1,185
Ukraine
|
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 
|
|
|
Re: Getting more than 100 skills without DLL
[Re: Lion_Ts]
#57219
10/07/05 14:19
10/07/05 14:19
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
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
Last edited by HeelX; 10/07/05 14:20.
|
|
|
Re: Getting more than 100 skills without DLL
[Re: Lion_Ts]
#57221
10/07/05 15:17
10/07/05 15:17
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
I bet, when you write a in-itself structured if then else case decision tree, it is everytime faster than execute.
Last edited by HeelX; 10/07/05 15:17.
|
|
|
Re: Getting more than 100 skills without DLL
[Re: HeelX]
#57222
10/07/05 15:24
10/07/05 15:24
|
Joined: Mar 2003
Posts: 569
FRAJO
User
|
User
Joined: Mar 2003
Posts: 569
|
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 ...
-------------------------------------------
ICQ: 242543712
Ich bin nicht hier und bin nicht da.
Wo bin ich dann?
".."
("")
^ ^
This is the evil vampire bunny. Copy and paste him into your signiture to help him achieve world domination. Yeah
|
|
|
Re: Getting more than 100 skills without DLL
[Re: Lion_Ts]
#57223
10/07/05 16:11
10/07/05 16:11
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
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.
|
|
|
Re: Getting more than 100 skills without DLL
[Re: Rhuarc]
#57224
10/07/05 17:43
10/07/05 17:43
|
Anonymous
Unregistered
|
Anonymous
Unregistered
|
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!
|
|
|
Re: Getting more than 100 skills without DLL
[Re: Lion_Ts]
#57227
10/08/05 10:56
10/08/05 10:56
|
Joined: Dec 2003
Posts: 266 Celle
task1
Member
|
Member
Joined: Dec 2003
Posts: 266
Celle
|
|
|
|
|