et.gentity_set? Explain Please :)


(mi$i3k:]) #1

Hello, i’ve finally posted here because i need a little help from you guys :wink:

I don’t really know much about c++, so im writing in lua, its easier for me :slight_smile:
Ok back to the topic, i was wondering how can i use lua function:
for ex.

et.gentity_set(clientNum, "ps.ammoclip", WEAPON_ID, AMOUNT)

I know how to change ammoclip and reserve ammo from other scripts i saw but what im asking for is if there is someone who could explain to me from where can i get some new ‘functions’ for this, like this i saw while exploring wolf:et source bg_misc:

	//	MAX			USES	MAX		START	START  RELOAD	FIRE			NEXT	HEAT,	COOL,	MOD,	...
	//	AMMO			AMT.	CLIP		AMMO	CLIP	TIME	DELAY			SHOT

It would be great if its possible to for ex. change fire delay or next shot values of weapons, or change maxclip permanently. As i said i can’t do this in C++, because i don’t have source files of nq mod, only option is to write lua script for it but i need to know how to use this function, wikia say’s

et.gentity_set( entnum, Fieldname, arrayindex, (value) )

    Sets the value of Fieldname from entity entnum in the g_entity struct to (value) 
    arrayindex is used to specify which element of an array entity field to set.

I was looking through whole source for that g_entity file but i can’t find it. I don’t know maybe im not so smart as u guys to understand it well, so i can read it wrong.

Any help will be appreciated :slight_smile:

Thanks in advance!

P.S. Sorry if topic tittle is wrong its my first post here.


(mi$i3k:]) #2

So many views, and 0 replies :/?


(eQuilibrium) #3

If I am not too wrong, the .weap files in NQ define the weapon speeds, ammo etc?


(Scennative) #4

c++? hmmm it is written (or wrotten? fu cking english…) in “C”. not c++ :stuck_out_tongue_winking_eye:

so, open your eyes or use your brain:

These is for example, the one ****ty weapon settings in bg_misc.c:

ammotable_t ammoTableMP[WP_NUM_WEAPONS] = {
	//	MAX				USES	MAX		START	START  RELOAD	FIRE			NEXT	HEAT,	COOL,	MOD,	...
	//	AMMO			AMT.	CLIP	AMMO	CLIP	TIME	DELAY			SHOT
	{	0,				0,		0,		0,		0,		0,		50,				0,		0,		0,		0						},	// WP_NONE					// 0

hmm, the easy way is search the string “ammotable_t”.

ah i found these wonderfull code in bg_public.h…

typedef struct ammotable_s {
	int		maxammo;		// 
	int		uses;			// 
	int		maxclip;		// 
	int		defaultStartingAmmo;	// Mad Doc - TDF
	int		defaultStartingClip;	// Mad Doc - TDF
	int		reloadTime;		// 
	int		fireDelayTime;	// 
	int		nextShotTime;	// 
//----(SA)	added
	int		maxHeat;		// max active firing time before weapon 'overheats' (at which point the weapon will fail)
	int		coolRate;		// how fast the weapon cools down. (per second)
//----(SA)	end
	int		mod;			// means of death
} ammotable_t;

so now you can use your lua code to use these new “commands”.
for example:

et.gentity_set(clientNum, "ps.reloadTime", WEAPON_ID, AMOUNT) 

but plz dont ask my about lua. i hate lua.

greetz scenna

Edit: -.- didnt read the mod… noquarter. yes look at there wiki about the weapon scripting with the .weap files…


(mi$i3k:]) #5

Ahh, thank you very much Scenna :wink:
That will help a lot for sure :slight_smile:


(Soak) #6

Scennative, no need to be so mean - what you posted was wrong as well. You are absolutely correct about the parts of the source, but mistaken about the lua. e.gentity_set is only able to modify wolfenstein entities - the playerState struct within q_shared.h holds some very basic info about weapons etc:

int			ammo[MAX_WEAPONS];		// total amount of ammo
int			ammoclip[MAX_WEAPONS];	// ammo in clip

What yo posted was code to set weapon properties - which cannot be changed at runtime using lua. If you hate lua so much, why attempt to post a solution at all? For those looking for more info on entity properties, go here:
http://wolfwiki.anime.net/index.php/Fieldname


(mi$i3k:]) #7

So there is no chance of changin ‘ReloadTime’ by lua?

And i’ve got one more question how can i make onReload function?
I mean how can i ‘catch’ command send by player in game?
Afaik, ‘+reload’ is command which issues weapon reload, i’ve tried with et_ClientCommand() function to look for +reload command but not worked… :confused:

And next thing is if i’ve manage to get command that listens comands send by player, what if someone uses complicated binds for ex.
bind X “say XXX;+reload;wait 2;say XXX;-reload” ?


(phisherman) #8

No. But why do you even want to do this? The time must fit the animation, so if you really wanted to change it you would also have to change the animation or the result is going to look really weird.

I mean how can i ‘catch’ command send by player in game?
The function for that is et_ClientCommand(), but unfortunately it’s still not possible to catch “+reload”.


(Shownie) #9

Wolf: ET is written in “C”? Lols, you mean it is written in c++. Or am I missing something here? :slight_smile:


(UJERebel) #10

I think ET is C, mods and the end of the basic game c++ :slight_smile:


(Indloon) #11

.h as header files are C++(not sure tbh,C has too),other are C


(dutchmeat) #12

Just for the sake of argument, there’s no C++ code in the entire wolf source.
The header files are just normal C headers, the fact that .h headers can be used in C++ aswell has nothing to do with this.

Anyway, Phisher has already said what needed to be said.


(Shownie) #13

:confused:

C same as C#?

:slight_smile:


(Dushan) #14

C same as C#?

:)[/QUOTE]

uhm no :slight_smile:

basically differences are that C is structured programming language while C# (cSharp) is Object Oriented programming Languages (like C++).
Think about C++/C# like they are more window oriented programming :slight_smile:

In fact you can easily recognize C++ and cSharp code [one have .cpp and .hpp files (pure C++ files), while other have .cs (C#) and no header files]


(Soak) #15

If this is intended as a fun mode (if you are messing around or something) - there may be other ways to do what you want. Possible solutions:

a) Auto reloading player weapons, on a timer.
b) The reload action cannot be caught, but if you are enabling this for some kind of clan fun pratice,
you could have members bind another command - “bind r specialreload”. You could then catch the special reload command and change ammo appropriately.

These solutions aren’t really suitable for regular play though.

Soak


(mi$i3k:]) #16

At first i wanted to make Increased Ammoclip capacity but after reload it transforms back to the original value for ex. changin thomspon clip to 60 from 30 results in 60 ammo in first clip as i wanted but after reload it becomes again 30… So i started to think bout reload action cos i dunno how to make ps.ammoclip permanent change, and yes this is for ‘fun’ event :slight_smile:


(phisherman) #17

What mod do you use? If you use NQ, you can use weapon scripting to do that.

Note: After clicking the link, replace “**” with “it”.


(Soak) #18

This is extremely easy - from what I understand you basically want player to spawn with 60 rounds in their initial clip? Looks like NQ weapon scripts can do this easily - but if you do want to use lua, just set the ammoclip values inside the spawn function - giving players 60 rounds of thommy and mp40 ammo every time they respawn. The key here is that you don’t actually want a permanent change - it should only take effect for the first clip. Lua scripts are great for problems like this, since they can only hook into game engine function calls anyways.

It looks like you will be able to do this on your own - code should look something like this:

function et_ClientSpawn(player, revived)
et.gentity_set(player, “ps.ammoclip”, 3, 60)
et.gentity_set(player, “ps.ammoclip”, 8, 60)
end

You should be able to copy/paste that directly, let me know if there are problems.

Soak


(mi$i3k:]) #19

"Important: Changing weapon scripts while the server is running is NOT recommended. Your weapons could disappear or behave erratically! "

@Soak
Read my post again please :slight_smile: I said that i know how to make it NOT permanent change, and i want to make it PERMANENT, so i dont need to copy paste it cos i figured it out myself… So there is problem that still i dunno how to make it permanent change for example if someone types !xxx cmd, it changes clip’s size to 60


(Soak) #20

You mean you haven’t figured out how to turn it off and on? Because as it stands, the code I posted will change a player’s first clip to 60 every time they spawn, on every map. This is permanent on a map, but not permanent when the player reloads, which is what you asked for.

I think there is some confusion about the whole permanent thing as well. Seem like you actually want something you can turn off and on:

So there is problem that still i dunno how to make it permanent change for example if someone types !xxx cmd, it changes clip’s size to 60

Pretty much the opposite of permanent lol. There are a couple of ways to have it toggle - the easiest one to start off with for you would be too hook a special clientCommand - like ‘/specialreload’, and then have it turn another variable on or off. Then stick the ammoclip code into an if statement checking the value of that variable. This should also be pretty straight forward, post if you run into problems or need code.

Soak