Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 1,086 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: (anet) weapon generator [Re: exile] #403664
06/23/12 18:22
06/23/12 18:22
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Thank you for your offer. I will write you an PM



Re: (anet) weapon generator [Re: Random] #404608
07/11/12 17:29
07/11/12 17:29
Joined: Aug 2008
Posts: 36
California USA
tunisod Offline
Newbie
tunisod  Offline
Newbie

Joined: Aug 2008
Posts: 36
California USA
Wait!!!! No PM .. how's the rest of the community going to benifit if you guys PM the solution?

Re: (anet) weapon generator [Re: tunisod] #404609
07/11/12 17:40
07/11/12 17:40
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline
Senior Member
xbox  Offline
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
@tunisod- I second that. I want to see the solution too.

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 Offline
User
exile  Offline
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
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.

Re: (anet) weapon generator [Re: exile] #404694
07/12/12 19:45
07/12/12 19:45
Joined: Aug 2008
Posts: 36
California USA
tunisod Offline
Newbie
tunisod  Offline
Newbie

Joined: Aug 2008
Posts: 36
California USA
It's more than enough to get some really good idea's. Thanks Exile

Re: (anet) weapon generator [Re: tunisod] #405740
08/06/12 16:15
08/06/12 16:15
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
I am finally back in Germany!
That is a amazin pice of code!
Thank you very much!



Page 2 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1