home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


Tweaks in the source code

by chark on 09/29/2013 00:35, 29 messages, last message: 01/27/2014 18:29, 8477 views, last view: 05/02/2024 17:48

Hello. i wanna share a few source code tweaks.. i'm very noob when it comes to programming so these are just copy-paste from other parts of sauer
to fulfill a role and they concern ctf sounds and a few changes to rifle trail. also i'm not gonna include some sauerbraten.exe cause i messed
my source at some point and water rendering is messed up in my game and i dont remember what i messed up :P oh you must compile the game
for these to work. if you're on windows download (if you're on linux or mac.. good luck :P no idea)
code::blocks (http://www.codeblocks.org/downloads) no idea which one is needed, i got mingw-setup.exe
and tdm64-gcc (http://tdm-gcc.tdragon.net/download)
once u install both open code::blocks and click settings->compiler. go to the Toolchain executables tab and point the Compiler's installation directory
to wherever u installed tdm64-gcc, e.g C:Program FilesMinGW64. Below that delete the prefixes of (mingw32-) was it? dont remember.. so you're left with gcc.exe g++.exe, g++.exe. (not sure if you have to do this last part, i just read it in some tutorial). then open sauerbraten directorysrcvcppsauerbraten.cbp with code blocks
and you're set!

Now to the tweaks.. the ctf sounds. i added different sounds for red and blue flag drops, returns, captures, and stolen. (personally i stole the ones from xonotic
cuz i like them :)) but you can use whatever you want. i'm not gonna give some link for you to download them cuz i've seen some folks in quadropolis
very uptight about licences and stuff, and since i couldnt care less about licences i just wont bother.

go to srcfpsgamegame.h at around line 170 you'll find
enum
{
S_JUMP = 0, S_LAND, S_RIFLE, S_PUNCH1, S_SG, S_CG,
...
}
scroll down to where it says
S_FLAGPICKUP,
S_FLAGDROP,
S_FLAGRETURN,
S_FLAGSCORE,
S_FLAGRESET,
now, you either add 4 (or 5 if you want different FLAG_RESET) more lines underneath them or above them like this (random names you can pick whatever you want (no spaces))
S_FLAGPICKUP,
S_FLAGDROP,
S_FLAGRETURN,
S_FLAGSCORE,
S_FLAGRESET,
S_REDPICKUP, // this is gonna be the sound pointer to the red flag stolen announcement
S_REDDROP, // this to red flag dropped.. etc
S_REDRETURN,
S_REDSCORE,
S_REDRESET,
obviously the already existing ones are gonna be used for the BLUE announcements respectively.
Then go to fpsentctf.h at around line 464 where it says
static const int sounds[] = { S_FLAGPICKUP, S_FLAGDROP, S_FLAGRETURN, S_FLAGSCORE, S_FLAGRESET, S_FLAGFAIL };
and fill it with the ones you added in game.h like this:
static const int sounds[] = { S_FLAGPICKUP, S_FLAGDROP, S_FLAGRETURN, S_FLAGSCORE, S_FLAGRESET, S_FLAGFAIL, S_REDPICKUP,S_REDDROP,S_REDRETURN,S_REDSCORE,S_REDRESET};
Next search for "playsound" without quotes in code::blocks to get a general list about the lines we'll need to change in ctf.h
the first hit is:
playsound(S_FLAGDROP);
which is the sound that plays when a flag drops! now you can either comment this line like this
//playsound(S_FLAGDROP);
and write the new one below or above it, or replace it with the new one which is:

playsound(flags[i].team==ctfteamflag(player1->team) ? S_FLAGDROP : S_REDDROP);

Trivia: if the statement-comparison in parentheses before the question mark is true, then it plays the sound S_FLAGDROP which we assigned (in our heads) to be for
the blue flag, otherwise it plays the sound S_REDDROP.

You're gonna do the same with all playsound lines in ctf.h except for the line 869:
playsound(team==ctfteamflag(player1->team) ? S_FLAGSCORE : S_FLAGFAIL);

in which you're just gonna change the corresponsing sounds. (S_FLAGSCORE for blue score and the other for red score).


Your sounds are stored in your sauerbraten directorypackagessounds
that is where sounds.cfg reads the location of sounds.. eg registersound "ctf/flagpickup" means there is a sound named flagpickup.wav in sauerbraten directorypackagessoundsctf
Next you open your sauerbraten directorydatasounds.cfg and scroll down to where it says:

registersound "ctf/flagpickup" //sound for blue flag pickup
registersound "ctf/flagdrop" //sound for blue flag drop.. etc
registersound "ctf/flagreturn"
registersound "ctf/flagscore"
registersound "ctf/flagreturn"

Then you replace the "flagpickup, flagdrop, flagreturn..." part with the name of the new sound file.
Afterwards you add these lines right below it (IF you added them in the order i mention before in game.h)
assuming you have sounds named redpickup.wav, reddrop.wav, etc... in your sauerbraten directorypackagessoundsctf otherwise replace accordingly.

registersound "ctf/redpickup" //sound for red flag pickup
registersound "ctf/reddrop" //sound for red flag drop.. etc
registersound "ctf/redreturn"
registersound "ctf/redscore"
registersound "ctf/redreturn"

And thats all about the sounds! Now about the rifle trail tweaks...

open srcfpsgameweapons.cpp and go to line 627:

particle_trail(PART_SMOKE, 500, hudgunorigin(gun, from, to, d), to, 0x404040, 0.6f, 20);

Here you can change some qualities of the particle trail of the rifle (smoke trail). Now i'll explain a few things:
--the first slot (PART_SMOKE) i'm not sure what it is.. i think it points to a smoke.png where it is spiraled around the axis of your gun->target. Maybe you can change it to something like PART_FLAME or PART_SNOW if you like.
--the second slot (500) is the duration of the smoke before it dissapears from the moment you fire in milliseconds, tweak to your liking!
--the third and fourth slots (hudgunorigin(gun, from, to, d)), to) we'll ignore cuz i dunno what they do and i dont think there is anything to tweak here :P
--the fifth slot is the color of the smoke! 0x[RED][GREEN][BLUE] 2 digits per color(0-9 and then A=10,B=11,C=12,D=13,E=14,F=15) google for "hex colors" to find something you like or.. stay tuned for random!
--the sixth slot is the diameter of the smoke and you can tweak it in this format: x.yf where x,y numbers of your choice.
and the last is the gravity.. dunno if anyone noticed (i hadnt until i changed it) for positive numbers the trail goes down, 0 = no gravity and negative numbers smoke goes up.

if you want random colors (yay!) you add this code below the "case GUN_RIFLE:" line 625

char bufferrr[15];
long kk = rnd(16777216);
itoa(kk, bufferrr, 16); //i think this converts integers from decimal form to their hexademical

Not sure what this does programmatically speaking.. but it gives us random colors! so replace the fifth slot (the one with the 0xFFFFFF with the variable kk
and you and everyone else gets random colors with every shot!

of course you, like me, may want just different smoke colors for your team and the enemy team.
add this code below the "case GUN_RIFLE:" line 625

int teamsmoke;
(isteam(d->team, player1->team)) ? popo=0x0789FC : popo=0xFC0907;

Comment out the previous code (for random colors) and replace in the fifth slot the variable teamsmoke

Want 3 smokes, one in middle one going up and one going down? copy the particle_trail.... line and paste it below it 2 times. change the last slot (gravity) to
-20, 0, 20 one in each line.
Maybe you like to shoot lightnings? we borrow the pistol ray trail and tweak it.
Comment out the particle_trail line.
copy paste right above or below it this line:

particle_flare(hudgunorigin(gun, from, to, d), to, 600, PART_STREAK, 0xFFC864, 0.28f);

you can tweak it just like the particle_trail if you want. and if you want the lightning replace the PART_STREAK with PART_LIGHTNING and remove the last slot like this
0xFFC864, 0.28f); ----> 0xFFC864); because it messes things up if you use the lightning.

Thats all folks maybe some day i search how to make these changeable by GUI but i'm probably lazy. cheers
oh and get the sauerfr mod it rox.

Go to first 20 messagesGo to previous 20 messages    Board Index   

#10: more stuff

by chark on 11/06/2013 03:07

Hello again, i added more options and polished the menu. windows download, screenshots and source code links at the end.
i managed to squeeze everything in one tab (in the menu)
notes: removed xcode folder from source because its 70 mb, no idea if its needed for mac people.
if you download the zip, you start the game from sauerbraten_colors.bat. also, i set the sound.cfg to load from someMod/sound.cfg folder to minimize overwritting stuff (in main.cpp)
if you use the code in the zip, search in the project for "extra code begins here" and/or "extra code ends here"
also you need to get your own sounds for flag drops, returns etc. they're set to default sounds in someMod/sounds.cfg
if you already have an autoexec.cfg dont overwrite it, just copy the contents to yours... but if you have, you probably already know that :P

known bugs/problems: when playing with bots and the flag is picked by one of them, the game sometimes crashes, nothing in the log, just closes the game
if anyone figures out why please share :)
when you open the menu for first time all sliders for colors are at 0 and because of that an error is spammed: unknown alias lookup: bla.
so move all color sliders to something other than zero and restart game.. or dont, just dont play with bots until you do :P

the friend notifier i mention in the code is disabled in the zip cause you must put the name of your friend in the source, maybe if i learn
stuff about strings.. i might make a better one. by the way it notifies if friend enters/is on the same server as you.
tbh i dont know why there isnt such a thing in the official ;/

as i said feel free to do whatever you want with it

source code: http://pastebin.com/Jh9bRDpe
menu screenshots: http://postimg.org/image/r0v2ul4jr/
download: http://www.filedropper.com/colorsnstuffsauerbraten

forgot to mention somewhere, that to install it just unzip in your sauerbraten installation folder
enjoy!

reply to this message

#11: ..

by raz on 11/06/2013 20:40

If i had to guess, you probably completely forgot to initialise the variables you're getting the error spam with. Anything that tries to access them when they don't exist yet will just report errors.

That is also some horrible cubescript, but you probably don't care, and i also don't feel like helping with that, so there.

reply to this message

#12: ..

by chark on 11/07/2013 21:02

What i dont know is how to initialize the variables ONCE. The way it is now they are initialized when you move the slider and they're saved in config.cfg. but the contents of autoexec are executed every time you start the game (or thousands of times if initialized in newgui [ ], while the menu is open) resetting the values to the initialized ones.

I realised i use a variable in 2 places when its intended for one. Here's a fixed version: http://pastebin.com/pH1kCkAS

to raz:
Whatever "horrible" may mean, you're right i dont give a http://www.gadgetsandgear.com/flying-fuck.html so long as it works. Also if i could write "non horrible code" wouldnt i?
With this attitude i dont want YOU to help me. Now gtfo from here troll, i didnt ask for unconstructive criticism.
Lastly you forgot this is open source, I may not care but others might.

reply to this message

#13: Re: ..

by Zamwa on 11/08/2013 03:44, refers to #12

Raz is a veteran cubescripter and is well known to be overtoned sometimes with a choice of words amongst the cube community, but Raz is not trolling only trying to help with bug reporting! ;3

reply to this message

#14: ..

by Zamwa on 11/08/2013 03:45

Oh and cool mod by the way!

reply to this message

#15: Re: ..

by raz on 11/09/2013 11:08, refers to #12

Well gee, aren't you a person made of matches and lighters.

When i meant i didn't want to help with that, i meant i'm not interested in making it all prettier since you said yourself that it works and from experience most people do not really want to improve on something that just works, so that was it.

So for your variables to be initialised, you'll just run them all through a check, see if they're null, and if they are, give them a starting value. Pretty simple, no?

And oh, non-constructive criticism? Maybe, some days i don't feel like helping people unless asked to. But trolling? Far from it, you should know better.

reply to this message

#16: Re: ..

by suicizer01 on 11/09/2013 12:42, refers to #15

We will alwaysbe asking about cubescript to our script-shaman Razgriz.

Whoops, that's a troll, sorry my bad!

reply to this message

#17: ..

by chark on 11/09/2013 17:22

This forum has no post count, i see Raz's post and for all i know he just registered to say that. What am i supposed to think? Anyway i take it back.

Now for what you said.. i have no idea how to do that :)

and thx zamwa

reply to this message

#18: Re: ..

by raz on 11/09/2013 17:55, refers to #17

Actually i had another account but i lost my password and i had to make a dupe since no one would help me get access back to my old one. That's my sad little story :P

And it's rather simple

if (=s (getalias VAR_NAME) "") [ VAR_NAME = VALUE_OF_SOME_SORT ]

You can also use looplist if you feel like it. Oh, and take a peek at this if you want: https://github.com/Hirato/lamiae/wiki/CubeScript

reply to this message

#19: ..

by chark on 11/10/2013 14:01

Heh coincidence, i meant the contents of the post. I wouldnt know you as razgrir either cause I'm the new guy.

Didnt know you can compare strings wow, actually i didnt know half of whats in that page thx!
updated http://pastebin.com/VrK4qgg0

reply to this message

#20: Re: ..

by raz on 11/10/2013 14:39, refers to #19

forgot to close the " at the first guitext :P

reply to this message

#21: ..

by chark on 11/10/2013 17:21

buuuut.. it works :/

reply to this message

#22: Re: ..

by raz on 11/10/2013 18:21, refers to #21

Yea it does, it just messes up highlighting in editors, and that's not nice :P

Doesn't matter much now, you can do more stuff first instead of releasing again for a missing quote.

reply to this message

#23: ..

by chark on 11/10/2013 19:49

Yes and that time is now cause i assigned the particle variables to the opposite team :P

Particle choice for smoke is now assigned to the correct team (according to the menu) http://pastebin.com/dgeJJVfU

reply to this message

#25: ..

by chark on 12/19/2013 18:14

I realised this is a stupid and messy way to share code. I doubt i would look at it if someone shared it like this so until i learn to use git i'll lay it out
here just in case.

The purpose i release these is the hope that someone may find them useful, they may be included in some more feature-full mods, or even better the official! Yea, yea hold your horses realists
i know the chances are small but a man can dream.

If you include this in some closed source thingy you must explicitly point to the source code of these features so others who dont want your client can
add them themselfs.
I say this because i discovered some closed source clients with cool features and thought -i want that! -nope :S

These lines are in the included source not yours.

fpsgame/client.cpp
-added lines 5-7 toggle < /friendnotify 0-1 > sound when a friend joins or leaves, < /chatsounds 0-1 > sounds when you receive chat and < /friendoperations 0-1 >
sounds when you use commands to interact with friendlist. I put them in /fhelp because why not.
-added lines 1168-1448 friendlist functions and commands type < /fhelp > (you'll need to check full console if you set console to show less than 13 lines)
-added line 1552 different sound when someone speaks in all chat and when friend speaks
-added line 1568 different sound when someone speaks in team chat and when friend speaks
-changed/added lines 1627-1631 message and sound when someone renames to a friend
-changed/added lines 1636-1640 message and sound when a friend joins/is online


fpsgame/fps.cpp
-added line 5 command to toggle teamkill sound < /tksound 0-1 >
-added line 436 sound when you get teamkilled
-added line 507 to use same variable for join and leave condition sounds. Or in other words use one command to disable both join and leave sounds
-changed/added lines 521-529 add message and sound when friend leaves


fpsgame/game.h
-added lines 216-226 sound declarations
-added line 760 prototype isFriend function (to use in other files too)
--didnt add prototypes for the friendlist functions cause someone might not like the friendlist command names and wanna change them


fpsgame/scoreboard.cpp
-added lines 14-15 commands to choose highlight colors of yourself and your friends in scoreboard < /highlightcolor 0x000000-0xFFFFFF > and < /fhighlightcolor 0x000000-0xFFFFFF >
-commented line 234 to enable frags in scoreboard for us frag whores :D
-added lines 209-211 determine if player is friend
-added lines 325-327 determine if spectator is friend (not sure which circumstances this and the one below cover)
-added lines 362-363 determine if spectator is friend
-changed lines 212+220, 329+335, 365+371 to highlight your friends as well
-changed lines 332, 368 choose highlight color for you and your friends

engine/rendertext.cpp
-added lines 222-230 more chat/gui colors copy paste from sauerfr cause that's where i coded friendlist notification colors

A known bug is if you write a name more than 15 characters long it will store the extra characters as a new friend. Too lazy to search for solution,
wanted to post :)

Some things i noticed: some of the included sounds are in wav format, and when played in game, they are distorted IF 44100 sample rate ISNT chosen in sound options.
and secondly i noticed that for the friend SOUNDS to work (and probably all?), you must have joined a game.

The sounds i included for flag captures, drops, friend operations etc. are just placeholder ie they suck. you should find your own. i would include some good ones
but.. fuk licences

Here's a pastebin with just the updated autoexec.cfg (highlight color chooser and sound toggles)
the new stuff is from <guitab "Scoreboard colors"> to the end.
http://pastebin.com/wqhB9Buw
And here's the link to try it (if on windows): http://www.filedropper.com/amodsauerbraten
The source is in the aMod folder.

reply to this message

#26: ..

by chark on 12/19/2013 19:22

Once again i forgot something :S
you'll need to make a file named friendlist.cfg in aMod folder or use /fadd name or /faddcn cn ingame to create the file.
If you dont do any of these you will be spammed with an error message.

reply to this message

#27: Re: ..

by suicizer01 on 12/20/2013 09:08, refers to #26

Nice mod.

You've already added a chatbeep and fiendchatbeep as well?

reply to this message

#28: Re: ..

by suicizer01 on 12/20/2013 09:33, refers to #27

Nearly forgot, you could also add killchatbeep and killchat as well, to speak only to the person who had killed you.

reply to this message

#29: ..

by chark on 01/27/2014 15:34

thx =) but what do u mean in your last post? Something like auto-sorry but when YOU get killed? Wouldn't that be annoying after a couple of times?

I put it up on github https://github.com/thalieht/Sauerbraten_aMod I'm thinking i should push the friendlist (the rest are probably mod stuff :P) to eihrul considering there isn't one in the official. Too bad i dont know how to make it search all servers for friends. So what do you guys think, should i? Also, anyone knows if its possible to push from github to sourceforge?

reply to this message

#30: Re: ..

by suicizer01 on 01/27/2014 18:29, refers to #29

Not an autosorry, but a chat only to the person who killed you (As like "nice kill!").

reply to this message

Go to first 20 messagesGo to previous 20 messages    Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53862638 visitors requested 71637730 pages
page created in 0.026 seconds using 10 queries
hosted by Boost Digital