AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Creating an entity messes up (https://forums.alliedmods.net/showthread.php?t=49378)

hlstriker 01-02-2007 19:23

Creating an entity messes up
 
Hey everyone, I have a plugin that is supposed to create an entity "info_tfdetect". This entity controls settings for the maps in the game Team Fortress Classic. With this plugin I am trying to remove a current "info_tfdetect" if there is one, then make a new one. After it is created it should set the values to it.

All the plugin seems to do at the moment is spawn every entity in the map at 0,0,0 origin.

Here is the code...
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     new ent = find_ent_by_class(-1, "info_tfdetect");         if(ent)     {         remove_entity_name("info_tfdetect");     }         create_entity("info_tfdetect");     entity_set_string(ent, EV_SZ_classname, "info_tfdetect");     DispatchKeyValue(ent, "origin", "0 0 0");     DispatchKeyValue(ent, "maxammo_shells", "1006");     DispatchKeyValue(ent, "team1_name", "SuRf3rs!");     DispatchKeyValue(ent, "hook_out", "0");     DispatchKeyValue(ent, "ex_skill_max", "3");     DispatchKeyValue(ent, "ex_skill_min", "1"); } public plugin_precache() {     register_forward(FM_KeyValue, "forward_keyvalue") } public forward_keyvalue(ent, kvdid) {     if(ent)     {         new keyname[128];                 get_kvd(kvdid, KV_KeyName, keyname, 127);                 if(equal(keyname, "origin"))         {             set_kvd(kvdid, KV_Value, "0 0 0");         }         else if(equal(keyname, "maxammo_shells"))         {             set_kvd(kvdid, KV_Value, "1006");         }         else if(equal(keyname, "team1_name"))         {             set_kvd(kvdid, KV_Value, "SuRf3rs!");         }         else if(equal(keyname, "hook_out"))         {             set_kvd(kvdid, KV_Value, "0");         }         else if(equal(keyname, "ex_skill_max"))         {             set_kvd(kvdid, KV_Value, "3");         }         else if(equal(keyname, "ex_skill_min"))         {             set_kvd(kvdid, KV_Value, "1");         }     }         return FMRES_IGNORED }

VEN 01-03-2007 01:21

Re: Creating an entity messes up
 
I think you wanted to make it like that:
Quote:

ent = create_entity("info_tfdetect")
Also in keyvalue hook check for entity validity and necessary classname key.

stupok 01-03-2007 02:37

Re: Creating an entity messes up
 
Can't you just do:

switch(keyname)
{
case "blah": do_something(...)
case "blah2": do_someting(...)
}

VEN 01-03-2007 03:05

Re: Creating an entity messes up
 
You can't use switch with arrays.

hlstriker 01-03-2007 14:41

Re: Creating an entity messes up
 
Quote:

Originally Posted by VEN (Post 423040)
I think you wanted to make it like that:

Also in keyvalue hook check for entity validity and necessary classname key.

Hi, I have tried that too and everything still spawns at (0 0 0).

I don't understand why every entity is spawning there anyway? There isn't anywhere in the code that I can see to have everything spawn there, only the "info_tfdetect".

Maybe this code could be causing that, I don't know why it would be though. It's all I can think of.
Code:
public forward_keyvalue(ent2, kvdid) {     if(ent2)     {         new keyname[128];                 get_kvd(kvdid, KV_KeyName, keyname, 127);                 /* ------- This is the cause maybe? ------- */         if(equal(keyname, "origin"))         {             set_kvd(kvdid, KV_Value, "0 0 0");         }         /* ---------------------------------------- */     }         return FMRES_IGNORED }

VEN 01-03-2007 16:08

Re: Creating an entity messes up
 
I already said what you have to do:
Quote:

Also in keyvalue hook check for entity validity and necessary classname key.
Basically what you are doing is set every entity origin to {0, 0, 0}.
You do not want to do that for every entity so you have to check for entity classname: get_kvd(kvdid, KV_ClassName, ...)

But as i said before you better also check for entity validity, this may save the server from crash.

hlstriker 01-03-2007 16:55

Re: Creating an entity messes up
 
Quote:

But as i said before you better also check for entity validity, this may save the server from crash.
Hey VEN, thanks for helping so far. I do not understand what you mean to check for entity valid. How do I know if an entity is valid or not? The entity "info_tfdetect" is a entity you can use when mapping, so I guess it's valid?

Sorry that I don't understand :P

VEN 01-03-2007 17:29

Re: Creating an entity messes up
 
You have to use pev_valid(ent).
You have to do something like that:
Code:

public forward_keyvalue(ent2, kvdid) {
    if (!pev_valid(ent2)) // if entity isn't valid
        return FMRES_IGNORED // do not perform any action
 
  // do something here
 
    return FMRES_IGNORED // at the end of function
}


hlstriker 01-03-2007 22:06

Re: Creating an entity messes up
 
Alright, I 'think' I did what you said, but it still spawns us all at (0 0 0) and the entity doesn't work that was suppose to be made :(.

Here is all the code i'm using now...
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     new ent = find_ent_by_class(-1, "info_tfdetect");         if(ent)     {         remove_entity_name("info_tfdetect");     }         new ent2 = create_entity("info_tfdetect");     entity_set_string(ent2, EV_SZ_classname, "info_tfdetect");     DispatchKeyValue(ent2, "origin", "0 0 0");     DispatchKeyValue(ent2, "maxammo_shells", "1006");     DispatchKeyValue(ent2, "team1_name", "SuRf3rs!");     DispatchKeyValue(ent2, "hook_out", "0");     DispatchKeyValue(ent2, "ex_skill_max", "3");     DispatchKeyValue(ent2, "ex_skill_min", "1"); } public plugin_precache() {     register_forward(FM_KeyValue, "forward_keyvalue"); } public forward_keyvalue(ent2, kvdid) {     if(!pev_valid(ent2)) {         return FMRES_IGNORED;     }         new keyname[128];         get_kvd(kvdid, KV_KeyName, keyname, 127);         if(equal(keyname, "origin"))     {         set_kvd(kvdid, KV_Value, "0 0 0");     }     else if(equal(keyname, "maxammo_shells"))     {         set_kvd(kvdid, KV_Value, "1006");     }     else if(equal(keyname, "team1_name"))     {         set_kvd(kvdid, KV_Value, "SuRf3rs!");     }     else if(equal(keyname, "hook_out"))     {         set_kvd(kvdid, KV_Value, "0");     }     else if(equal(keyname, "ex_skill_max"))     {         set_kvd(kvdid, KV_Value, "3");     }     else if(equal(keyname, "ex_skill_min"))     {         set_kvd(kvdid, KV_Value, "1");     }     return FMRES_IGNORED // at the end of function }

Orangutanz 01-03-2007 22:48

Re: Creating an entity messes up
 
Code:
new tfdetect public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     new ent = find_ent_by_class(-1, "info_tfdetect");         if(ent)         remove_entity(ent);         tfdetect = create_entity("info_tfdetect");     if(tfdetect)     {         entity_set_string(tfdetect, EV_SZ_classname, "info_tfdetect");         DispatchKeyValue(tfdetect, "origin", "0 0 0");         DispatchKeyValue(tfdetect, "maxammo_shells", "1006");         DispatchKeyValue(tfdetect, "team1_name", "SuRf3rs!");         DispatchKeyValue(tfdetect, "hook_out", "0");         DispatchKeyValue(tfdetect, "ex_skill_max", "3");         DispatchKeyValue(tfdetect, "ex_skill_min", "1");         DispatchSpawn(tfdetect) // you was missing this vital part     } } /* You shouldn't really need any of this below public plugin_precache() {     register_forward(FM_KeyValue, "forward_keyvalue"); } public forward_keyvalue(ent2, kvdid) {     if(!pev_valid(ent2))         return FMRES_IGNORED;     // You should have a classname check here for "info_tfdetect"     // else you're messing with every single entity that calls this function!     new keyname[128];         get_kvd(kvdid, KV_KeyName, keyname, 127);         if(equal(keyname, "origin"))     {         set_kvd(kvdid, KV_Value, "0 0 0");     }     else if(equal(keyname, "maxammo_shells"))     {         set_kvd(kvdid, KV_Value, "1006");     }     else if(equal(keyname, "team1_name"))     {         set_kvd(kvdid, KV_Value, "SuRf3rs!");     }     else if(equal(keyname, "hook_out"))     {         set_kvd(kvdid, KV_Value, "0");     }     else if(equal(keyname, "ex_skill_max"))     {         set_kvd(kvdid, KV_Value, "3");     }     else if(equal(keyname, "ex_skill_min"))     {         set_kvd(kvdid, KV_Value, "1");     }     return FMRES_IGNORED // at the end of function }*/


All times are GMT -4. The time now is 22:28.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.