Raised This Month: $ Target: $400
 0% 

Creating a decoy (giving it a weapon)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eXist
Member
Join Date: Apr 2005
Old 12-16-2009 , 15:04   Creating a decoy (giving it a weapon)
Reply With Quote #1

My objective is to create a decoy that takes the characteristics from the player who creates it, and copies it on to that decoy.

I'm having a problem attempting to give the decoy a weapon. Is it possible to do this without creating another entity?

My Code: (Most used from UWC3 decoy)

Code:
#include <amxmodx> #include <cstrike> #include <engine> #define MAX_PLAYERS 33          // Max number of players in the game new decoy[MAX_PLAYERS] = 0                      // Decoys stored for each player new Float:decoy_frame[MAX_PLAYERS] = 0.0        // Used in server_frame() new Float:decoy_fstep[MAX_PLAYERS] = 0.0        // Frame step time new Float:last_frame = 0.0                      // Last server_frame saved new decoy_seq[MAX_PLAYERS] = 0                  // Current sequence for each decoy new bool:DoOnce[MAX_PLAYERS] = false            // Used for handling crouch mode new bool:decoyused[MAX_PLAYERS] = false         // Has decoy been used this round new bool:pIsDucking[MAX_PLAYERS] = false        // Is player crouching or not public plugin_init() {     register_plugin("Decoy Test", "1.0", "eXist")     register_clcmd("say /decoy", "make_decoy")     set_task(0.01, "check_duck", 0, "", 0, "b") } public plugin_precache() {    precache_model("models/player/leet/leet.mdl")    precache_model("models/player/arctic/arctic.mdl")    precache_model("models/player/guerilla/guerilla.mdl")    precache_model("models/player/terror/terror.mdl")    precache_model("models/player/gign/gign.mdl")    precache_model("models/player/sas/sas.mdl")    precache_model("models/player/gsg9/gsg9.mdl")    precache_model("models/player/urban/urban.mdl")    precache_model("models/player/vip/vip.mdl")    precache_model("models/guerilla.mdl")        //Weapons    precache_model("models/p_m4a1.mdl")    precache_model("models/p_ak47.mdl")    precache_model("models/p_aug.mdl")    precache_model("models/p_awp.mdl")    precache_model("models/p_c4.mdl")    precache_model("models/p_deagle.mdl")    precache_model("models/p_elite.mdl")    precache_model("models/p_famas.mdl")    precache_model("models/p_fiveseven.mdl")    precache_model("models/p_flashbang.mdl")    precache_model("models/p_g3sg1.mdl")    precache_model("models/p_galil.mdl")    precache_model("models/p_glock18.mdl")    precache_model("models/p_hegrenade.mdl")    precache_model("models/p_knife.mdl")    precache_model("models/p_m3.mdl")    precache_model("models/p_m3super90.mdl")    precache_model("models/p_m249.mdl")    precache_model("models/p_mac10.mdl")    precache_model("models/p_mp5.mdl")    precache_model("models/p_p90.mdl")    precache_model("models/p_p228.mdl")    precache_model("models/p_scout.mdl")    precache_model("models/p_sg550.mdl")    precache_model("models/p_sg552.mdl")    precache_model("models/p_shield.mdl")    precache_model("models/p_smokegrenade.mdl")    precache_model("models/p_tmp.mdl")    precache_model("models/p_ump45.mdl")    precache_model("models/p_usp.mdl")    precache_model("models/p_xm1014.mdl") } public make_decoy(id) {     client_print(id, print_chat, "Making decoy")             //Making Decoy start -- Copied from UWC3 Mod     new arg[64]     new Float:arg2[3]     new vec[3]     new aimvec[3]     new Float:b_orig[3]         get_user_origin(id, vec)     get_user_origin(id, aimvec, 2)         //Fix for people spawning decoys on other players to trap them     new sClass[32], target, body     get_user_aiming(id, target, body)     if ((0 < target <= MAX_PLAYERS))     {       entity_get_string(target, EV_SZ_classname, sClass, 32)       if (equal(sClass, "player")){          client_print(id, print_chat, "[WC3] You cannot create a Decoy on a player.")          return PLUGIN_HANDLED       }     }         b_orig[0] = float(aimvec[0])     b_orig[1] = float(aimvec[1])     b_orig[2] = float(aimvec[2] + 35)     entity_get_string(id, EV_SZ_classname, arg, 63)     new decoyEnt = create_entity("info_target")     entity_set_string(decoyEnt, EV_SZ_classname, "decoy_entity")         entity_set_origin(decoyEnt, b_orig)         entity_set_byte(decoyEnt, EV_BYTE_controller1, 127)         entity_get_vector(id,EV_VEC_absmin,arg2)     entity_set_vector(decoyEnt, EV_VEC_absmin, arg2)     entity_get_vector(id,EV_VEC_absmax,arg2)     entity_set_vector(decoyEnt, EV_VEC_absmax, arg2)     entity_get_vector(id,EV_VEC_mins,arg2)     entity_set_vector(decoyEnt, EV_VEC_mins, arg2)     entity_get_vector(id,EV_VEC_maxs,arg2)     entity_set_vector(decoyEnt, EV_VEC_maxs, arg2)     entity_get_vector(id, EV_VEC_size,arg2)     entity_set_vector(decoyEnt, EV_VEC_size, arg2)             new model[32]     new pmodel[128]         get_user_info(id,"model",model,31)     format(pmodel, 127, "models/player/%s/%s.mdl", model, model)         entity_set_model(decoyEnt, pmodel)     entity_set_float(decoyEnt, EV_FL_health,99999200.0)     entity_set_float(decoyEnt, EV_FL_takedamage, 1.0)     entity_set_float(decoyEnt, EV_FL_dmg_take, 1.0)     entity_set_int(decoyEnt, EV_INT_movetype, 13)     entity_set_int(decoyEnt, EV_INT_solid, 2)     entity_set_int(decoyEnt, EV_INT_spawnflags, 0)     entity_set_int(decoyEnt, EV_INT_sequence, 1)         //Give it a weapon     new weapmodel[256]     entity_get_string(id, EV_SZ_weaponmodel, weapmodel, 255)         new entWeapon = create_entity("info_target")     entity_set_string(entWeapon, EV_SZ_classname, "npc_weapon")     entity_set_int(entWeapon, EV_INT_movetype, MOVETYPE_FOLLOW)     entity_set_int(entWeapon, EV_INT_solid, SOLID_NOT)     entity_set_edict(entWeapon, EV_ENT_aiment, decoyEnt)     entity_set_model(entWeapon, weapmodel)     //------------------         decoy[id] = decoyEnt     decoy_frame[id]=0.0     decoy_seq[id]=0     decoyused[id] = true     //Used to get rid of decoy after ammount of time     new cargs[3]     cargs[0] = id     cargs[1] = decoyEnt     cargs[2] = entWeapon     set_task(15.0, "cleanup_decoy", 866, cargs, 2)     return PLUGIN_CONTINUE } public cleanup_decoy(args[]) {    new id = args[0]    new ent = args[1]    new weap = args[2]        //Remove gun entity    remove_entity(weap)    new Float:orig[3]    entity_get_vector(ent, EV_VEC_origin, orig)    message_begin(MSG_BROADCAST,SVC_TEMPENTITY)    write_byte(11)    write_coord(floatround(orig[0]))    write_coord(floatround(orig[1]))    write_coord(floatround(orig[2]))    message_end()    decoy[id] = 0    remove_entity(ent)    client_print(id, print_chat, "Your decoy has expired") } public check_duck() {    for(new i = 1; i <= MAX_PLAYERS; ++i) {       if (is_user_alive(i)) {          if (decoy[i]) {             //client_print(i, print_chat, "MIH2")             if (get_user_button(i)&IN_DUCK) {                if (!pIsDucking[i]) {                   //client_print(i, print_chat, "You are now ducking")                   pIsDucking[i]=true                   DoOnce[i]=true                 }             }else{                if (pIsDucking[i]) {                   //client_print(i, print_chat, "Stopped ducking")                   pIsDucking[i]=false                   DoOnce[i]=true                }             }          }       }    }    return PLUGIN_CONTINUE } public server_frame() {    new id    new Float:vel[3]    new Float:speed    new Float:new_frame = get_gametime()    new Float:newAngle[3]    new Float:orig[3]    new Float:framerate = 30.0;    new Float:MinBox[3]    new Float:MaxBox[3]    //new aimvec[3]    //new origin[3]    //new Float:temp[3]    //new avgFactor = 3    //new mVelo[3]    //new iNewVelocity[3]    //new ispeed = 300;    //new length, velocityvec[3]    if ( (new_frame - last_frame) < ( 1.0 / framerate) )       return PLUGIN_CONTINUE    last_frame = new_frame    for( id=0; id<MAX_PLAYERS; id++) {       if ( !decoy[id] || !is_user_connected(id) ) continue       //new Float:health = entity_get_float(decoy[id],EV_FL_health)       //client_print(id, print_chat, "decoy health: %f", health)       if (pIsDucking[id]) {          MinBox[0] = 0.0          MinBox[1] = 0.0          MinBox[2] = -20.0 //change to -40 for standing models          MaxBox[0] = 0.0          MaxBox[1] = 0.0          MaxBox[2] = 0.0       }else{          MinBox[0] = 0.0          MinBox[1] = 0.0          MinBox[2] = -40.0 //change to -20 for crouching models          MaxBox[0] = 0.0          MaxBox[1] = 0.0          MaxBox[2] = 0.0       }       entity_set_vector(decoy[id],EV_VEC_mins, MinBox)       new Float:vRetVector[3]       entity_get_vector(id, EV_VEC_v_angle, vRetVector)       vRetVector[0]=float(0)       entity_set_vector(decoy[id], EV_VEC_angles, vRetVector)       entity_get_vector(decoy[id], EV_VEC_velocity, vel)       //client_print(id,print_chat,"Beyonder velocity <%f %f %f> ", vel[0], vel[1], vel[2])       if( vel[0] != 0.0 && vel[1] != 0.0) {          vel[2] = 0.0          vector_to_angle(vel, newAngle);          //entity_set_vector(decoy[id], EV_VEC_angles, newAngle)       }       vel[2] = 0.0       speed = vector_length(vel)       //client_print(id,print_center,"Beyonder speed = %f ",speed)       if (speed <= 5 && pIsDucking[id]){          if (DoOnce[id]) {             entity_get_vector(decoy[id],EV_VEC_origin,orig)             orig[2]=orig[2] - 20             entity_set_vector(decoy[id],EV_VEC_origin,orig)             DoOnce[id]=false          }          decoy_seq[id] = 2          entity_set_int(decoy[id], EV_INT_sequence, 2)          MinBox[0] = -20.0          MinBox[1] = -20.0          MinBox[2] = -20.0          MaxBox[0] = 20.0          MaxBox[1] = 20.0          MaxBox[2] = 40.0          entity_set_vector(decoy[id],EV_VEC_mins, MinBox)          entity_set_vector(decoy[id],EV_VEC_maxs, MaxBox)          new Float:tmpVec[3]          tmpVec[0] = 40.0;   tmpVec[1] = 40.0; tmpVec[2] = 80.0          entity_set_vector(decoy[id],EV_VEC_size,tmpVec)       }else if (speed <= 5 && !pIsDucking[id]){          if (DoOnce[id]) {             entity_get_vector(decoy[id],EV_VEC_origin,orig)             orig[2]=orig[2] + 20             entity_set_vector(decoy[id],EV_VEC_origin,orig)             DoOnce[id]=false          }          decoy_seq[id] = 1          entity_set_int(decoy[id], EV_INT_sequence, 1)          MinBox[0] = -20.0          MinBox[1] = -20.0          MinBox[2] = -40.0          MaxBox[0] = 20.0          MaxBox[1] = 20.0          MaxBox[2] = 40.0          entity_set_vector(decoy[id],EV_VEC_mins, MinBox)          entity_set_vector(decoy[id],EV_VEC_maxs, MaxBox)          new Float:tmpVec[3]          tmpVec[0] = 40.0;   tmpVec[1] = 40.0; tmpVec[2] = 80.0          entity_set_vector(decoy[id],EV_VEC_size,tmpVec)        }       decoy_fstep[id] = 5.0       decoy_frame[id] += decoy_fstep[id]       if( decoy_frame[id] >= 254.0 ) decoy_frame[id] = 0.0       entity_set_float(decoy[id], EV_FL_frame, decoy_frame[id])    }    return PLUGIN_CONTINUE }

Last edited by eXist; 12-16-2009 at 18:05.
eXist is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-16-2009 , 15:09   Re: Creating a decoy
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=11756
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
eXist
Member
Join Date: Apr 2005
Old 12-16-2009 , 15:15   Re: Creating a decoy (giving it a weapon)
Reply With Quote #3

Very much appreciated.
eXist is offline
eXist
Member
Join Date: Apr 2005
Old 12-16-2009 , 16:28   Re: Creating a decoy (giving it a weapon)
Reply With Quote #4

I edited my original code in the first post.

Ok I can give it a weapon now, but I have another problem. I use the command /decoy to create a decoy where I'm looking.

The first time I use it, everything works fine, the decoy spawns with the gun I'm using. The second time I use it, it spawns with the first gun I was holding, and the new gun I took out.

So for example the first time I use it with a usp out, he spawns fine with a usp. The second time, I have a colt out, he will spawn in with a usp and a colt overlapping on the model.

Maybe I have to delete the weapon entity after I use it? Not sure exactly.

Last edited by eXist; 12-16-2009 at 16:31.
eXist is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-16-2009 , 17:15   Re: Creating a decoy (giving it a weapon)
Reply With Quote #5

Yes, you should remove the weapon ent when you remove the decoy.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
eXist
Member
Join Date: Apr 2005
Old 12-16-2009 , 18:10   Re: Creating a decoy (giving it a weapon)
Reply With Quote #6

I tried removing the entity, but I'm still having the same problem. I've re-edited my first post to include the changes. Very small change, I just additionally send the weapon entity as a parameter to the cleanup_decoy, and have it remove the entity there.

Here's a screen shot that might help to visually see whats happening:

http://img710.**************/img710/6149/92581433.png

The decoy is below me, as you can see he has multiple weapons after attempting to create him more than once.
eXist is offline
eXist
Member
Join Date: Apr 2005
Old 12-19-2009 , 01:39   Re: Creating a decoy (giving it a weapon)
Reply With Quote #7

Any suggestions? I'm tempted to take it back to square 1 and just start with Twilight Sazuka's tutorial on NPC's, but it seems like there should be a fix for this.
eXist is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-19-2009 , 02:57   Re: Creating a decoy (giving it a weapon)
Reply With Quote #8

Code:
set_task(15.0, "cleanup_decoy", 866, cargs, 2)
You are only passing two elements, change the last parameter to 3 to send all 3.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
eXist
Member
Join Date: Apr 2005
Old 12-19-2009 , 21:47   Re: Creating a decoy (giving it a weapon)
Reply With Quote #9

Thanks, can't believe I forgot that.
eXist 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 11:32.


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