(anet) weapon generator

Posted By: Random

(anet) weapon generator - 06/13/12 03:31

I just wanted to ask how to create an object correct with anet.
I tryed:

Code:
action weapon_generator()
{
	set(my,PASSABLE); 
	set(my,INVISIBLE);
	
	wait(1);
	while (my)
	{
		wait(-10);
		ent_create ("deagle.mdl", vector(-600 + random(1200),-600 + random(1200),my.z), deagle); 
		
		wait(1);
	}
}



But that doesn't happen at the same time with all clients...
What do I have to do?
Posted By: Espér

Re: (anet) weapon generator - 06/13/12 07:40

you need to send a trigger (variable, skill or so) to the clients, they need to ask if this trigger is set, and activate the function again local by their own.

like:
server creates model -> server set trigger -> send var to all clients -> client get trigger -> client create model


when a client creates the model, the client needs to send the trigger to the server:
client creates model -> sets trigger -> send var to server -> server creates model -> server set trigger -> send var to all clients -> client get trigger -> client create model (except the start client)
Posted By: MasterQ32

Re: (anet) weapon generator - 06/13/12 08:10

enet_svent_create
enet_clent_create
you need to register the model as a global anet model
look in the manual for examples


offtopic:
ist doch schön, wenn wir deutschen und ans forum anpassen und englisch schreiben grin
Posted By: Espér

Re: (anet) weapon generator - 06/13/12 08:23

i really should update my anet xD
Posted By: MasterQ32

Re: (anet) weapon generator - 06/13/12 09:21

yes, would be helpful laugh
Posted By: Espér

Re: (anet) weapon generator - 06/13/12 09:24

problem is: i'm not using ANet.. cause it is non-commercial only laugh
Posted By: Dark_samurai

Re: (anet) weapon generator - 06/13/12 15:06

When you have ANet Web/Standard/Professional, you can of course use it for commercial projects! Only the demo edition must not be used for commercial projects.
Posted By: Random

Re: (anet) weapon generator - 06/14/12 02:53

off topic.
MasterQ32:
Das ist wirklich unglaublich. Wir deutschen sind sehr anpassungsfahig.
Siehst du? Ich benutze im Moment sogar eine Amerikanische Tastatur ^^

On topic.
Thanks. I will try it out.
And are there any open scoure games made with Anet??
I would really like to tare one appart, mash it back together and run a thousends of test with the mashed pices ^^
Posted By: Dark_samurai

Re: (anet) weapon generator - 06/14/12 15:15

Germanunkol made a small open source shooter example with ANet. You can get it here: http://www.anet-plugin.com/downloads_eng.htm

But the code got a bit messy because of my changes when I adapted it to new ANet versions...
Posted By: exile

Re: (anet) weapon generator - 06/15/12 06:50

Hey feel free to send me a message. Dark_Samurai actually just helped me out on the issue after explaining/reminding me how ANET works! Because of his help, I managed to make a weapon spawner that 100% works flawlessly!
Posted By: Random

Re: (anet) weapon generator - 06/23/12 18:22

Thank you for your offer. I will write you an PM
Posted By: tunisod

Re: (anet) weapon generator - 07/11/12 17:29

Wait!!!! No PM .. how's the rest of the community going to benifit if you guys PM the solution?
Posted By: xbox

Re: (anet) weapon generator - 07/11/12 17:40

@tunisod- I second that. I want to see the solution too.
Posted By: exile

Re: (anet) weapon generator - 07/12/12 02:38

I'll share the solution! What I do is this...

Code:
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...

Code:
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.

Code:
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.

Code:
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.
Posted By: tunisod

Re: (anet) weapon generator - 07/12/12 19:45

It's more than enough to get some really good idea's. Thanks Exile
Posted By: Random

Re: (anet) weapon generator - 08/06/12 16:15

I am finally back in Germany!
That is a amazin pice of code!
Thank you very much!
© 2024 lite-C Forums