Raised This Month: $ Target: $400
 0% 

Creating an entity messes up


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 01-02-2007 , 19:23   Creating an entity messes up
Reply With Quote #1

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 }
hlstriker is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 01-03-2007 , 01:21   Re: Creating an entity messes up
Reply With Quote #2

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.
VEN is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 01-03-2007 , 02:37   Re: Creating an entity messes up
Reply With Quote #3

Can't you just do:

switch(keyname)
{
case "blah": do_something(...)
case "blah2": do_someting(...)
}
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 01-03-2007 , 14:41   Re: Creating an entity messes up
Reply With Quote #4

Quote:
Originally Posted by VEN View Post
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 }
hlstriker is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 01-03-2007 , 03:05   Re: Creating an entity messes up
Reply With Quote #5

You can't use switch with arrays.
VEN is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 01-03-2007 , 16:08   Re: Creating an entity messes up
Reply With Quote #6

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.
VEN is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 01-03-2007 , 16:55   Re: Creating an entity messes up
Reply With Quote #7

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
hlstriker is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 01-03-2007 , 17:29   Re: Creating an entity messes up
Reply With Quote #8

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
}

Last edited by VEN; 01-03-2007 at 17:31.
VEN is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 01-03-2007 , 22:06   Re: Creating an entity messes up
Reply With Quote #9

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 }
hlstriker is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 01-03-2007 , 22:48   Re: Creating an entity messes up
Reply With Quote #10

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 }*/
__________________
|<-- Retired from everything Small/Pawn related -->|
You know when you've been Rango'd

Last edited by Orangutanz; 01-04-2007 at 07:06.
Orangutanz is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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