6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood),
1,268
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: (anet) weapon generator
[Re: exile]
#403664
06/23/12 18:22
06/23/12 18:22
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
Thank you for your offer. I will write you an PM
|
|
|
Re: (anet) weapon generator
[Re: xbox]
#404629
07/12/12 02:38
07/12/12 02:38
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
User
|
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
I'll share the solution! What I do is this...
enet_reg_ent(HANDGUN_PICKUP, "handgun.mdl", weapon_ground_fnc);
enet_reg_ent(RIFLE_PICKUP, "rifle.mdl", weapon_ground_fnc);
enet_reg_ent(SHOTGUN_PICKUP, "shotgun.mdl", weapon_ground_fnc);
enet_svset_event(UEVENT_REQUESTWEAPON, removeWeapon);
enet_clset_event(UEVENT_SENDPICKUPINFO,ev_recievePickupInfo);
Lets start with the basics, we declare any events we need and any global entities in our MAIN script BEFORE the wait (if you have one). The events, UEVENT_REQUESTWEAPON and UEVENT_SENDPICKUPINFO are the most important things we need. You'll see why in a moment...
function weaponSpawnerEffects() //properties of the weapon spawner model
{
weaponSpawnerFx(); //Particle and light effects
set(my,PASSABLE);
}
action weaponSpawnerFunc()
{
set(my,PASSABLE|INVISIBLE);
ENTITY* spawned_ent;
ent_create("weaponSpawner.mdl",my.x,weaponSpawnerEffects); //Create the weapon spawner model, may not be needed if you are placing your models directly in wed.
while(enet_get_connection() != SERVER_MODE && enet_get_connection() != CLIENT_SERVER_MODE) wait(1); //This prevents multiple version of the same weapon spawner from being created on client/server-client machines
if(enet_get_connection() == CLIENT_SERVER_MODE)
{
while(enet_get_clientid() == ANET_ERROR) wait(1); //Same as above essentially but targeted directly to client-server machines. May not be needed.
}
my.skill2 = 0; //Skill2 is the spawn trigger. When skill2 = 0, it makes the function respawn the weapon defined by skill1.
my.skill3 = 0;
while(1)
{
if(my.skill2 == 0)
{
if(my.skill1 == 0) // Skill1 is used to define the type of weapon to be spawned. In this case, 1=handgun, 2=rifle, and 3=shotgun.
{
spawned_ent = enet_svent_create(HANDGUN_PICKUP, vector(my.x,my.y,my.z+30));
while(enet_ent_globpointer(spawned_ent) == ANET_ERROR) wait(1);
my.skill2 = enet_ent_globpointer(spawned_ent);
}
if(my.skill1 == 1)
{
spawned_ent = enet_svent_create(RIFLE_PICKUP, vector(my.x,my.y,my.z+30));
while(enet_ent_globpointer(spawned_ent) == ANET_ERROR) wait(1);
my.skill2 = enet_ent_globpointer(spawned_ent);
}
if(my.skill1 == 2)
{
spawned_ent = enet_svent_create(SHOTGUN_PICKUP, vector(my.x,my.y,my.z+30));
while(enet_ent_globpointer(spawned_ent) == ANET_ERROR) wait(1);
my.skill2 = enet_ent_globpointer(spawned_ent);
}
}
if(enet_ent_globpointer(spawned_ent) == ANET_ERROR)
{
weaponPickupAction_emitter(); // This recalls
wait(-2); // This is the amount of time it takes for the weapon to respawn
my.skill2 = 0; //Resetting the Skill to 0, thus recalling the spawn function
}
wait(1);
}
}
The code is commented enough for you to be able to tell whats going on, but in short this is the action you give the actual weapon spawner in WED. While in WED, set the models skill1 to the number corresponding to the weapon you want to spawn. See example above for details.
void removeWeapon(var sender, char* msg, var size)
{
memcpy(sendWeaponRequest, msg, size);
if(enet_ent_globpointer(sendWeaponRequest[0]) == ANET_ERROR) // If the weapon isnt available on the server
{
wait(1);
}
if(sendWeaponRequest[2] == 0) // Handgun
{
weaponInfo[0] = 1;// The weapon type to give the player
weaponInfo[1] = 1;// Adds the weapon to the inventory
weaponInfo[2] = 18;// Amount of reserve ammo to give
weaponInfo[3] = 6;// Amount of ammo in weapon
}
if(sendWeaponRequest[2] == 1) // Rifle
{
weaponInfo[0] = 2;// The weapon type to give the player
weaponInfo[1] = 1;// Adds the weapon to the inventory
weaponInfo[2] = 90;// Amount of reserve ammo to give
weaponInfo[3] = 30;// Amount of ammo in weapon
}
if(sendWeaponRequest[2] == 2) // Shotgun
{
weaponInfo[0] = 3;// The weapon type to give the player
weaponInfo[1] = 1;// Adds the weapon to the inventory
weaponInfo[2] = 18;// Amount of reserve ammo to give
weaponInfo[3] = 6;// Amount of ammo in weapon
}
enet_svent_remove(sendWeaponRequest[0]); //Removes the weapon model from the server and the clients.
enet_svsend_event(UEVENT_SENDPICKUPINFO,weaponInfo, sizeof(var)*4, sendWeaponRequest[1]);//This sends the pickup info from the weapon to the person who sent the pickup request
}
This part is a send/recieve method. When the server recieves a pickup request from a client, it checks to see if the weapon is available. If it is, it sets an array with the proper values based on the kind of weapon it is then sends them to the client who requested them, finally the weapon is removed from the server, preventing other players from picking up the same weapon.
void ev_recievePickupInfo(var sender, char* msg, var size)
{
memcpy(weaponInfo, msg, size); //Copy the info recieved from the server
if(weaponSwitched != weaponInfo[0]) //Is the weapon I am currently holding the same as the one I am trying to pick up?
{
weaponSwitched = weaponInfo[0]; //Now it is :)
weaponAmmoCurrent[weaponInfo[0]] = weaponInfo[3]; //Set ammo
weaponAmmoMax[weaponInfo[0]] = weaponInfo[2]; // Set reserve ammo
}
if(weaponInventory[weaponInfo[1]]<1)// If I dont have this weapon in my inventory...
{
weaponInventory[weaponInfo[1]] = 1; //Add it to my inventory
weaponSwitched = weaponInfo[0];//Auto switch, remove if you dont need
snd_play(weaponPickupSound,sfxVolume,0);// Weapon pickup sound
}
else //If I already have this weapon in my inventory
{
weaponAmmoMax[weaponInfo[0]] += weaponInfo[3]; //just add some ammo
snd_play(ammoPickupSound,sfxVolume,0);//Ammo pickup sound
}
weaponInfo[0] = 0; //Reset value
weaponInfo[1] = 0; //Reset value
weaponInfo[2] = 0; //Reset value
weaponInfo[3] = 0; //Reset value
}
As you can see, this code applies the information we received from the server to the client, causing the weapon and ammo to be altered. And thats pretty much all I do. I had this code originally specialized for my own game so it really wont work copy/paste, but its enough to get the idea to you.
|
|
|
Re: (anet) weapon generator
[Re: tunisod]
#405740
08/06/12 16:15
08/06/12 16:15
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
I am finally back in Germany! That is a amazin pice of code! Thank you very much!
|
|
|
|