Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Kingware, AndrewAMD, AemStones, RealSerious3D, degenerate_762), 837 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[ANET] Spells #338796
08/21/10 17:47
08/21/10 17:47
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
Hi,

im really thinking about how to create spells. I can code evrything else like movement, dead reckoning and so on. But i really could need some help how to create a spell.

Lets say player push key 1.

Then he´s choosing his enemy. After choosing he casts a fireball (particle animation) this fireball flys to the enemy and kills him.

How can i create such an effect so that every player can see this one?

With enet_ent_create? Creating a fireball model and adding particle animation to it?

Also with those if(MY_CREATOR == MY_CLIENTID)... lines?

Tahnks laugh

Re: [ANET] Spells [Re: Rasch] #338799
08/21/10 17:54
08/21/10 17:54
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
What i use is a custom enet event.

In a struct you can send the caster, target and spell id and other information to the server (when key 1 is pushed).
The server then checks for validity, decreases the casters mana and sends another event that also contains the same information to all clients. He is also responsible for the action of the spell, like draining the targets health now or after the "fireball" has hit the enemy.

The clients then create a local effect for that spell, that isn't networked and saves bandwith.

Re: [ANET] Spells [Re: SchokoKeks] #338802
08/21/10 18:06
08/21/10 18:06
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
Ok das hört sich schonmal logisch an. GLaubst du, du kannst mir mal per PM oder irgendwo eine kleines Script dieser Art zukommen lassen? Weil ich das mit den Structs noch nie so wirklich versucht habe.

Re: [ANET] Spells [Re: Rasch] #338805
08/21/10 18:25
08/21/10 18:25
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline
Senior Member
Razoron  Offline
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
How do you send structs threw events? You can send structs by suing enet_send_data, but how to send it as a string?

Re: [ANET] Spells [Re: Razoron] #338824
08/21/10 20:45
08/21/10 20:45
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
@Razoron: Since ANet Version 1.2.3.4 you can send structs with events, thanks to the "length/size" parameter that is passed. Take a look at the code I'm using for these spells to see how:

The player wants to cast a spell and sends it to the server:
Code:
// struct that contains spell info
typedef struct {
	unsigned short id;  // id of spell
	var ent_targ;   // globpointer of target
} s_sendspell;

s_sendspell d_send_spell; // global variable of the above struct that is automatically initialized, not a pointer.


void cl_send_spell(int spell_id, int spell_level, ENTITY* ent_targ)
{
	//TODO: check if the player is allowed to
	
	d_send_spell.id = spell_id;
	d_send_spell.ent_targ = enet_ent_globpointer(ent_targ);	
	
	enet_clsend_event(EVENT_SPELL, &d_send_spell, sizeof(s_sendspell), SERVER);
}



The server receives the spell and only sends the ID to the clients:

Code:
void sv_e_spell(var sender, STRING* data, var size)
{
	if (size != sizeof(s_sendspell)) {svdiag("\nERROR in sv_e_spell: received invalid data length"); return;}
	
	s_sendspell* sp_data = (s_sendspell*)data->chars; // get a new pointer with correct type, because the data is passed as a STRING*
	
// own code for handling spells, replace it with yours
// I included it to show cheating tests and how to send ok back to player
	ENTITY* ent_caster = enet_ent_locpointer(pl_globpointers[sender]);
	ENTITY* ent_targ = enet_ent_locpointer(sp_data->ent_targ);
	
	
	int sp_level = spellbook_get_level((s_spell_book*)ent_caster->spellbook, sp_data->id);
	if (sp_level == 0) {svdiag("\nCHEATING ATTEMPT in sv_e_spell: player doesn't have send spell"); return;}

	// do spell action
	if (sv_spell_act(ent_caster, sp_data->id, sp_level, ent_targ))
	{
		// send ok back to player, just the id, not the whole struct
		// will start cooldown timer at the player
		enet_svsend_event(EVENT_SPELL, sp_data->id, sizeof(unsigned short), sender);
		
		// TODO: send effect to all players nearby.
	}
}



I've used the type "unsigned short" to save 2 bytes of transferred data. Thats not really necessary for smaller games, but I want to save traffic wherever possible. I'm also not sending the caster, it is implied that the player entity of the sender is always the caster.



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