AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How do I do things with Entities? (https://forums.alliedmods.net/showthread.php?t=17057)

Batman/Gorlag 08-25-2005 03:28

How do I do things with Entities?
 
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?

Zenith77 08-25-2005 14:07

Plz tell us the EXACT errors...not just where there located..for all we know it could be loose indention :/

XxAvalanchexX 08-25-2005 15:59

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 } //-----------------------------------------------------------------------------------------

Batman/Gorlag 08-25-2005 16:27

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 08-25-2005 23:35

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 } //-----------------------------------------------------------------------------------------

Xanimos 08-25-2005 23:41

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)

XxAvalanchexX 08-25-2005 23:53

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

Batman/Gorlag 08-26-2005 01:14

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?

XxAvalanchexX 08-26-2005 01:19

Yeah. Right now the second one is pretty useless.

Batman/Gorlag 08-26-2005 03:13

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????


All times are GMT -4. The time now is 14:21.

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