Raised This Month: $51 Target: $400
 12% 

How do I do things with Entities?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 08-25-2005 , 03:28   How do I do things with Entities?
Reply With Quote #1

For those of you who have been reading the superhero forum under scripting help, you would know that I can't receive anymore help from the forum because of where I come from. And I know that might sound a lil vague so I'll show you a link: http://forums.alliedmods.net/showthread.php?t=34315

Anyways I need help and plenty of it when it comes to entities. Right now I'm making a hero that has a disk that hurts people!. And you are able to guide where the disk is going just by aiming somewhere else!! Although that part has not been implemented, the test server that I test on keeps crashing when I use it. When I compile it, it gives me 4 warnings, all tag mismatches. They are on line 142, 148, 151, and 175. If anyone knows how to fix those please reply. Here is the code:

Code:
//Cell #include <amxmod.inc> #include <superheromod.inc> #include <engine.inc> #include <Vexd_Utilities.inc> #include <amxmisc.inc> #include <xtrafun.inc> new gHeroName[] = "Cell" new bool:g_hasCellPowers[SH_MAXSLOTS+1] new diskTimer[SH_MAXSLOTS+1] //This variable will represent the disk being made. new NewEnt //------------------------------------------------------------------------------------ public plugin_init() {     register_plugin("SUPERHERO Cell", "1.0", "Gorlag/Batman")     //THE CVARS     register_cvar("cell_level", "4")     register_cvar("cell_damage", "75")     register_cvar("cell_radius", "50")         register_cvar("cell_cooldown", "50")         register_cvar("cell_diskspeed", "750")     register_cvar("cell_disklife", "5")         register_cvar("cell_blastdecal", "1")     //THIS LINE MAKES THE HERO SELECTABLE         shCreateHero(gHeroName, "Energy Disk", "Unleash an energy disk and take control of where it flies!", true, "cell_level")     //INITIAL ACTIONS     register_srvcmd("cell_init", "cell_init")     shRegHeroInit(gHeroName, "cell_init")         //KEY DOWN COMMAND     register_srvcmd("cell_kd", "cell_kd")     shRegKeyDown(gHeroName, "cell_kd")     //SPAWNING EVENT     register_event("ResetHUD", "newSpawn", "b")     //SET THE LIFE OF THE DISK     set_task(1.0, "cell_disklife", 0, "", 0, "b")     for(new id = 1; id <= SH_MAXSLOTS; id++)         diskTimer[id] = -1 } //-------------------------------------------------------------------------------------- public plugin_precache() {     precache_model("models/shmod/friezadisc.mdl")     //boom = precache_model("sprites/zerogxplode.spr") } //--------------------------------------------------------------------------------------- public cell_init() {     new temp[6] //To store temporary information     //First Argument is the id of the player     read_argv(1,temp,5) //Converts the string to a number     new id = str_to_num(temp)     //Second Argument is either 0 or 1 depending on whether the person has the hero or not     read_argv(2,temp,5)     new hasPowers = str_to_num(temp) //Makes the string into a number     g_hasCellPowers[id] = (hasPowers != 0)     if(!hasPowers && diskTimer[id] > 0){         diskTimer[id] = -1         remove_entity(NewEnt)     } } //--------------------------------------------------------------------------------------- public cell_kd() {     if(!hasRoundStarted()) return     new temp[6]     //Get the id of the player     read_argv(1,temp,5)     new id = str_to_num(temp)     if(!is_user_alive(id) || !g_hasCellPowers[id] || gPlayerUltimateUsed[id]) return     if(gPlayerUltimateUsed[id]){         playSoundDenySelect(id)         return     }     diskTimer[id] = get_cvar_num("cell_disklife")     fire_disk(id)     if(get_cvar_float("cell_cooldown") > 0.0)         ultimateTimer(id, get_cvar_float("cell_cooldown")) } //---------------------------------------------------------------------------------------- public newSpawn(id) {     gPlayerUltimateUsed[id] = false  //Makes you able to use power again } //---------------------------------------------------------------------------------------- public cell_disklife(){     for(new id = 1; id <= SH_MAXSLOTS; id++){         if(g_hasCellPowers[id] && is_user_alive(id)){             if(diskTimer[id] > 0){                 diskTimer[id]--             }             else{                 remove_entity(NewEnt)                 diskTimer[id]--             }         }     } } //---------------------------------------------------------------------------------------- public fire_disk(id) {     //Makes an array of origin in the (x,y,z) coordinate system.     new origin[3]     //Makes an array of velocity, specifically in the (x,y,z) coordinate system     new velocity[3]     get_user_origin(id, origin, 0)     create_disk(id, origin, velocity) } //---------------------------------------------------------------------------------------- public create_disk(id, origin[3], velocity[3]) {     NewEnt = CreateEntity("info_target")  //Makes an object     entity_set_string(NewEnt, EV_SZ_classname, "cell_disk_ent")     //This tells what the object will look like     ENT_SetModel(NewEnt, "models/shmod/friezadisc.mdl")     //This will set the origin of the entity     entity_set_vector(NewEnt, EV_VEC_origin, origin)     //This will set the movetype of the entity     entity_set_int(NewEnt,EV_INT_movetype, MOVETYPE_FLY)     //This will set the velocity of the entity     velocity_by_aim(NewEnt, get_cvar_num("cell_maxspeed"), velocity)     //This will set the entity in motion     entity_set_vector(NewEnt, EV_VEC_velocity, velocity) } //----------------------------------------------------------------------------------------- public pfn_touch(ptr, ptd)  //ptr is the toucher, and ptd is the touched! {     //Checks to make sure that the entity is valid!     if(!is_valid_ent(ptr) || !is_valid_ent(ptd))     return PLUGIN_CONTINUE     //Checks to make sure that the victim is alive and connected to the server!     if(!is_user_alive(ptd) || !is_user_connected(ptd))     return PLUGIN_CONTINUE     //Now to deal the damage to the victim (touched) and remove the toucher (the disk)     new resulting_string[41]  //Makes a new empty string that will store 40 characters.     //Allows you to retrieve the entity of the toucher, in this case the disk.     entity_get_string(ptr, EV_SZ_classname, resulting_string, 40)     //Now because the data above is a string, the "==" would not work, when comparing.     //Instead I will use the equal method.     //Makes sure that the toucher entity is the disk.     if(equal(resulting_string, "cell_disk_ent")){         new aimvec[3]  //This is the position where the disk collides         get_user_origin(ptd, aimvec, 0)         RadiusDamage(aimvec, get_cvar_num("cell_damage"), get_cvar_num("cell_radius"))         remove_entity(ptr)  //Makes sure the entity is removed after contact.     }     else{         remove_entity(ptr)     }     return PLUGIN_CONTINUE } //-----------------------------------------------------------------------------------------

P.S. Whats up with this weird indentation, when I post the small file I've been working on?
Batman/Gorlag is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-25-2005 , 14:07  
Reply With Quote #2

Plz tell us the EXACT errors...not just where there located..for all we know it could be loose indention :/
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-25-2005 , 15:59  
Reply With Quote #3

Quote:
Originally Posted by Zenith77
Plz tell us the EXACT errors...not just where there located..for all we know it could be loose indention :/
He told us the warnings, tag mismatch.

This should get rid of the tag mismatches, but I don't know if the server will still crash or not:
Code:
//Cell #include <amxmod.inc> #include <superheromod.inc> #include <engine.inc> #include <Vexd_Utilities.inc> #include <amxmisc.inc> #include <xtrafun.inc> new gHeroName[] = "Cell" new bool:g_hasCellPowers[SH_MAXSLOTS+1] new diskTimer[SH_MAXSLOTS+1] //This variable will represent the disk being made. new NewEnt //------------------------------------------------------------------------------------ public plugin_init() {     register_plugin("SUPERHERO Cell", "1.0", "Gorlag/Batman")     //THE CVARS     register_cvar("cell_level", "4")     register_cvar("cell_damage", "75")     register_cvar("cell_radius", "50")         register_cvar("cell_cooldown", "50")         register_cvar("cell_diskspeed", "750")     register_cvar("cell_disklife", "5")         register_cvar("cell_blastdecal", "1")     //THIS LINE MAKES THE HERO SELECTABLE         shCreateHero(gHeroName, "Energy Disk", "Unleash an energy disk and take control of where it flies!", true, "cell_level")     //INITIAL ACTIONS     register_srvcmd("cell_init", "cell_init")     shRegHeroInit(gHeroName, "cell_init")         //KEY DOWN COMMAND     register_srvcmd("cell_kd", "cell_kd")     shRegKeyDown(gHeroName, "cell_kd")     //SPAWNING EVENT     register_event("ResetHUD", "newSpawn", "b")     //SET THE LIFE OF THE DISK     set_task(1.0, "cell_disklife", 0, "", 0, "b")     for(new id = 1; id <= SH_MAXSLOTS; id++)         diskTimer[id] = -1 } //-------------------------------------------------------------------------------------- public plugin_precache() {     precache_model("models/shmod/friezadisc.mdl")     //boom = precache_model("sprites/zerogxplode.spr") } //--------------------------------------------------------------------------------------- public cell_init() {     new temp[6] //To store temporary information     //First Argument is the id of the player     read_argv(1,temp,5) //Converts the string to a number     new id = str_to_num(temp)     //Second Argument is either 0 or 1 depending on whether the person has the hero or not     read_argv(2,temp,5)     new hasPowers = str_to_num(temp) //Makes the string into a number     g_hasCellPowers[id] = (hasPowers != 0)     if(!hasPowers && diskTimer[id] > 0){         diskTimer[id] = -1         remove_entity(NewEnt)     } } //--------------------------------------------------------------------------------------- public cell_kd() {     if(!hasRoundStarted()) return     new temp[6]     //Get the id of the player     read_argv(1,temp,5)     new id = str_to_num(temp)     if(!is_user_alive(id) || !g_hasCellPowers[id] || gPlayerUltimateUsed[id]) return     if(gPlayerUltimateUsed[id]){         playSoundDenySelect(id)         return     }     diskTimer[id] = get_cvar_num("cell_disklife")     fire_disk(id)     if(get_cvar_float("cell_cooldown") > 0.0)         ultimateTimer(id, get_cvar_float("cell_cooldown")) } //---------------------------------------------------------------------------------------- public newSpawn(id) {     gPlayerUltimateUsed[id] = false  //Makes you able to use power again } //---------------------------------------------------------------------------------------- public cell_disklife(){     for(new id = 1; id <= SH_MAXSLOTS; id++){         if(g_hasCellPowers[id] && is_user_alive(id)){             if(diskTimer[id] > 0){                 diskTimer[id]--             }             else{                 remove_entity(NewEnt)                 diskTimer[id]--             }         }     } } //---------------------------------------------------------------------------------------- public fire_disk(id) {     //Makes an array of origin in the (x,y,z) coordinate system.     new origin[3]     //Makes an array of velocity, specifically in the (x,y,z) coordinate system     new velocity[3]     get_user_origin(id, origin, 0)     create_disk(id, origin, velocity) } //---------------------------------------------------------------------------------------- public create_disk(id, origin[3], velocity[3]) {     new Float:fOrigin[3], Float:fVelocity[3]     IVecFVec(origin, fOrigin)     NewEnt = CreateEntity("info_target")  //Makes an object     entity_set_string(NewEnt, EV_SZ_classname, "cell_disk_ent")     //This tells what the object will look like     ENT_SetModel(NewEnt, "models/shmod/friezadisc.mdl")     //This will set the origin of the entity     entity_set_vector(NewEnt, EV_VEC_origin, fOrigin)     //This will set the movetype of the entity     entity_set_int(NewEnt,EV_INT_movetype, MOVETYPE_FLY)     //This will set the velocity of the entity     velocity_by_aim(NewEnt, get_cvar_num("cell_maxspeed"), fVelocity)     FVecIVec(fVelocity, velocity)     //This will set the entity in motion     entity_set_vector(NewEnt, EV_VEC_velocity, fVelocity) } //----------------------------------------------------------------------------------------- public pfn_touch(ptr, ptd)  //ptr is the toucher, and ptd is the touched! {     //Checks to make sure that the entity is valid!     if(!is_valid_ent(ptr) || !is_valid_ent(ptd))     return PLUGIN_CONTINUE     //Checks to make sure that the victim is alive and connected to the server!     if(!is_user_alive(ptd) || !is_user_connected(ptd))     return PLUGIN_CONTINUE     //Now to deal the damage to the victim (touched) and remove the toucher (the disk)     new resulting_string[41]  //Makes a new empty string that will store 40 characters.     //Allows you to retrieve the entity of the toucher, in this case the disk.     entity_get_string(ptr, EV_SZ_classname, resulting_string, 40)     //Now because the data above is a string, the "==" would not work, when comparing.     //Instead I will use the equal method.     //Makes sure that the toucher entity is the disk.     if(equal(resulting_string, "cell_disk_ent")){         new aimvec[3], Float:fAimvec[3]  //This is the position where the disk collides         get_user_origin(ptd, aimvec, 0)     IVecFVec(aimvec, fAimvec)         RadiusDamage(fAimvec, get_cvar_num("cell_damage"), get_cvar_num("cell_radius"))         remove_entity(ptr)  //Makes sure the entity is removed after contact.     }     else{         remove_entity(ptr)     }     return PLUGIN_CONTINUE } //-----------------------------------------------------------------------------------------
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 08-25-2005 , 16:27  
Reply With Quote #4

Well thanks man for fixing those errors for me =D. If the server still crashes then its probably a runtime error and stuff.....
Batman/Gorlag is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 08-25-2005 , 23:35  
Reply With Quote #5

Well, I see the disk finally appearing, BUT it doesn't move, I don't understand, why is that, I thought i set the velocity. And I modified the coding yet again. So heres the modified code:

Code:
//Cell #include <amxmod.inc> #include <superheromod.inc> #include <engine.inc> #include <Vexd_Utilities.inc> #include <amxmisc.inc> #include <xtrafun.inc> new gHeroName[] = "Cell" new bool:g_hasCellPowers[SH_MAXSLOTS+1] new diskTimer[SH_MAXSLOTS+1] //This variable will represent the disk being made. new NewEnt //------------------------------------------------------------------------------------ public plugin_init() {     register_plugin("SUPERHERO Cell", "1.0", "Gorlag/Batman")     //THE CVARS     register_cvar("cell_level", "4")     register_cvar("cell_damage", "75")     register_cvar("cell_radius", "50")     register_cvar("cell_cooldown", "50")     register_cvar("cell_diskspeed", "750")     register_cvar("cell_disklife", "5")     register_cvar("cell_blastdecal", "1")     //THIS LINE MAKES THE HERO SELECTABLE     shCreateHero(gHeroName, "Energy Disk", "Unleash an energy disk and take control of where it flies!", true, "cell_level")     //INITIAL ACTIONS     register_srvcmd("cell_init", "cell_init")     shRegHeroInit(gHeroName, "cell_init")     //KEY DOWN COMMAND     register_srvcmd("cell_kd", "cell_kd")     shRegKeyDown(gHeroName, "cell_kd")     //SPAWNING EVENT     register_event("ResetHUD", "newSpawn", "b")     //SET THE LIFE OF THE DISK     set_task(1.0, "cell_disklife", 0, "", 0, "b")     for(new id = 1; id <= SH_MAXSLOTS; id++)         diskTimer[id] = -1 } //-------------------------------------------------------------------------------------- public plugin_precache() {     precache_model("models/shmod/friezadisc.mdl")     //boom = precache_model("sprites/zerogxplode.spr") } //--------------------------------------------------------------------------------------- public cell_init() {     new temp[6] //To store temporary information     //First Argument is the id of the player     read_argv(1,temp,5) //Converts the string to a number     new id = str_to_num(temp)     //Second Argument is either 0 or 1 depending on whether the person has the hero or not     read_argv(2,temp,5)     new hasPowers = str_to_num(temp) //Makes the string into a number     g_hasCellPowers[id] = (hasPowers != 0)     if(!hasPowers && diskTimer[id] > 0){         diskTimer[id] = -1         remove_entity(NewEnt)     } } //--------------------------------------------------------------------------------------- public cell_kd() {     if(!hasRoundStarted()) return     new temp[6]     //Get the id of the player     read_argv(1,temp,5)     new id = str_to_num(temp)     if(!is_user_alive(id) || !g_hasCellPowers[id]) return     if(gPlayerUltimateUsed[id]){         playSoundDenySelect(id)         return     }     diskTimer[id] = get_cvar_num("cell_disklife")     fire_disk(id)     if(get_cvar_float("cell_cooldown") > 0.0)         ultimateTimer(id, get_cvar_float("cell_cooldown")) } //---------------------------------------------------------------------------------------- public newSpawn(id) {     gPlayerUltimateUsed[id] = false  //Makes you able to use power again } //---------------------------------------------------------------------------------------- public cell_disklife(){     for(new id = 1; id <= SH_MAXSLOTS; id++){         if(g_hasCellPowers[id] && is_user_alive(id)){             if(diskTimer[id] > 0){                 diskTimer[id]--             }             else{                 remove_entity(NewEnt)                 diskTimer[id]--             }         }     } } //---------------------------------------------------------------------------------------- public fire_disk(id) {     //Makes an array of origin in the (x,y,z) coordinate system.     new origin[3]     //Makes an array of velocity, specifically in the (x,y,z) coordinate system     new velocity[3]     get_user_origin(id, origin, 0)     create_disk(id, origin, velocity) } //---------------------------------------------------------------------------------------- public create_disk(id, origin[3], velocity[3]) {     new Float:fOrigin[3], Float:fVelocity[3]     IVecFVec(origin, fOrigin)     NewEnt = CreateEntity("info_target")  //Makes an object     entity_set_string(NewEnt, EV_SZ_classname, "cell_disk_ent")     //This tells what the object will look like     ENT_SetModel(NewEnt, "models/shmod/friezadisc.mdl")     //This will set the origin of the entity     entity_set_vector(NewEnt, EV_VEC_origin, fOrigin)     //This will set the movetype of the entity     entity_set_int(NewEnt,EV_INT_movetype, MOVETYPE_FLY)     //This will set the velocity of the entity     velocity_by_aim(NewEnt, get_cvar_num("cell_maxspeed"), fVelocity)     FVecIVec(fVelocity, velocity)     //This will set the entity in motion     entity_set_vector(NewEnt, EV_VEC_velocity, fVelocity) } //----------------------------------------------------------------------------------------- public pfn_touch(ptr, ptd)  //ptr is the toucher, and ptd is the touched! {     //Checks to make sure that the entity is valid!     if(!is_valid_ent(ptr) || !is_valid_ent(ptd))     return PLUGIN_CONTINUE     //Checks to make sure that the victim is alive and connected to the server!     if(!is_user_alive(ptd) || !is_user_connected(ptd))     return PLUGIN_CONTINUE     //Now to deal the damage to the victim (touched) and remove the toucher (the disk)     new resulting_string[41]  //Makes a new empty string that will store 40 characters.     //Allows you to retrieve the entity of the toucher, in this case the disk.     entity_get_string(ptr, EV_SZ_classname, resulting_string, 40)     //Now because the data above is a string, the "==" would not work, when comparing.     //Instead I will use the equal method.     //Makes sure that the toucher entity is the disk.     if(equal(resulting_string, "cell_disk_ent")){         new aimvec[3], Float:fAimvec[3]  //This is the position where the disk collides         get_user_origin(ptd, aimvec, 0)         IVecFVec(aimvec, fAimvec)         RadiusDamage(fAimvec, get_cvar_num("cell_damage"), get_cvar_num("cell_radius"))         remove_entity(ptr)  //Makes sure the entity is removed after contact.     }     return PLUGIN_CONTINUE } //-----------------------------------------------------------------------------------------
Batman/Gorlag is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-25-2005 , 23:41  
Reply With Quote #6

I actually saw this error when you first posted(I didnt know it was an error then)
Quote:
Originally Posted by Batman/Gorlag
Code:
public fire_disk(id) {     //Makes an array of origin in the (x,y,z) coordinate system.     new origin[3]     //Makes an array of velocity, specifically in the (x,y,z) coordinate system     new velocity[3]     get_user_origin(id, origin, 0)     create_disk(id, origin, velocity) }
Notice anything fishy?

You make a new velocity then dont set it to anything and just send it off (its still set to nothing)
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-25-2005 , 23:53  
Reply With Quote #7

Yeah, I have no idea what that part of the function is for, but he gets a velocity inside the function with velocity_by_aim
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 08-26-2005 , 01:14  
Reply With Quote #8

Yeah well I'm planning to make use of the velocity a lil later in that function, thats why its blank in the fire_disk function. Thanks for pointing that out, BTW. Yeah maybe thats why my disk aren't moving lol. And also what does IVecFvec and those functions do? just convert an int to a float?
Batman/Gorlag is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-26-2005 , 01:19  
Reply With Quote #9

Yeah. Right now the second one is pretty useless.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 08-26-2005 , 03:13  
Reply With Quote #10

Aww man my disc still isn't moving, what the heck is up with that?? Maybe I need to move the velocity_by_aim function up to the fire_disk(id) function????
__________________
GRR If only the amxmod programming were in Java.....
Java and C used to be two different languages, now Java is turning into another C. My logevent plugin
Batman/Gorlag 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 07:18.


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