PDA

View Full Version : Save Player's Names to File



Crestfallen
11th March 2013, 00:26
Hi, I would like to know if it is possible to to save a player's name(s) in a file linked to their guid number?
For example, whenever someone changes their name, their new name is saved into the file on a new line, but only if it has not already been written.
(guid).txt
(inside file)-> name1
name2
name3
etc...

I have read this post & thread: http://killtube.org/showthread.php?660-MODDING-How-to-make-virtual-money&p=3069&viewfull=1#post3069 to get feel of how to read and write files but I do not know how to read or write multiple lines. I know that a player's name can be retrieved from the variable "self.name" but how would I go about checking the name against what is written in the file to prevent duplicate writes?
Thanks!

kung foo man
11th March 2013, 11:58
One name should be pretty easy to save, just reserve the first line for it.

But multiple names are bad:
- longer load/save-time (could be limited, by limiting the number of saved aliases (which makes it less useful again))
- workload of IO (input/output) could lag the gameserver
- possibly loss of saved stats

I wouldn't bet in such a system, when there is a much easier and more performant solution: B3 working on MySQL

Earliboy
11th March 2013, 12:00
Yes, B3 would be more usefull. Just install Echelon too and you can see the full alias list.

Mitch
11th March 2013, 13:14
Yes, B3 would be more usefull. Just install Echelon too and you can see the full alias list.
B3: http://www.bigbrotherbot.net/
Echelon: http://www.bigbrotherbot.net/echelon/home

Crestfallen
11th March 2013, 22:10
Okay, thanks guys! I'll look more into both B3 and Echelon :)
I have another question, is there a way to force hipshots? Such as a way to disable toggleads so that players can not aim down their sights? Thanks!

kung foo man
11th March 2013, 23:41
Hey, you are welcome!

You can write in callback_playerdamage:



if (attacker playerAds() > 0)
{
attacker iprintlnbold("only hipshots / no aim!");
return;
}


Disable the aim "for real" is not possible i guess, besides patching the function out (i would do that for you, if you want to rent a server :D).

Crestfallen
12th March 2013, 00:12
This works as well :) thanks kung foo man!
Oh, how much per slot and where are they located?

kung foo man
12th March 2013, 00:23
Hey, its 0.50€/Slot, like 16 Slots = 8€/Month

With free: B3, Fast-Download, CoD-Extension (MySQL inside CoDScript, get/set-Velocity etc.)

Edit: forgot to mention, location is in Germany.

Tally
12th March 2013, 00:46
Hey, you are welcome!

You can write in callback_playerdamage:



if (attacker playerAds() > 0)
{
attacker iprintlnbold("only hipshots / no aim!");
return;
}


Disable the aim "for real" is not possible i guess, besides patching the function out (i would do that for you, if you want to rent a server :D).

You can disable aimDownSight in the weapon files by changing the value from 1 to 0. This works for all weapons.

Crestfallen
12th March 2013, 00:58
Hey, its 0.50€/Slot, like 16 Slots = 8€/Month

With free: B3, Fast-Download, CoD-Extension (MySQL inside CoDScript, get/set-Velocity etc.)

Edit: forgot to mention, location is in Germany.

Hmm, well I live in the U.S so my ping wouldn't be so great :(


You can disable aimDownSight in the weapon files by changing the value from 1 to 0. This works for all weapons.
How can I toggle this between 0 and 1, though, through a cvar in a script?

Tally
12th March 2013, 01:11
Hmm, well I live in the U.S so my ping wouldn't be so great :(


How can I toggle this between 0 and 1, though, through a cvar in a script?

You can't. Most weapon settings are not accessible via script. However, you can create a set of weapon files named differently than the stock ones, and switch between them by giving them to the player, then taking them away again and replacing them with stock ones.

Crestfallen
12th March 2013, 06:23
You can't. Most weapon settings are not accessible via script. However, you can create a set of weapon files named differently than the stock ones, and switch between them by giving them to the player, then taking them away again and replacing them with stock ones.

Great, got this working! Thanks :)

Crestfallen
13th March 2013, 01:27
Hmm, well I take that back, there is just one bug that I can't seem to fix. When I toggle it on, it takes away the current gun and gives the player the modified gun. Up until then, it all works fine but when the player is killed and respawns, the gun appears in a strange way. It is only the animation though. Any solutions?
196

Tally
13th March 2013, 08:24
How are you giving the weapon on spawn? Post your code - complete, not parts.

Crestfallen
15th March 2013, 04:25
I call this script from the _callbacksetup.gsc


CodeCallback_StartGameType()
{
// If the gametype has not beed started, run the startup
if(!isDefined(level.gametypestarted) || !level.gametypestarted)
{


///Here
svr\hipshots::init();


[[level.callbackStartGameType]]();

level.gametypestarted = true; // so we know that the gametype has been started up
}
}



I also tried setWeaponSlotWeapon("primary", "Weapon_Name") instead of giveWeapon() but I got the same results.
Also the prefix ro_ and aw_ are just to distinguish between the stock weapon and hipshot weapon, ro_ being regular and aw_ being the modified one.



init()
{
thread hipshotMode();
}

hipshotMode()
{
level endon("rzrEndThread");

for (;;)
{
wait 0.1;

_hs = svr\utils::cvardef("rzr_hipshots", 0, 0, 1, "int");

if (_hs)
{
if (!isDefined(game["hipshotMsg"]))
{
iprintlnBold("", "^0|^2HipShots Activated!^0|");
}
setHipOn(true);
}
else
{
if (isDefined(game["hipshotMsg"]))
{
iprintlnBold("", "^0|^2HipShots Deactivated!^0|");
setHipOn(false);
}
}
}
}

setHipOn(enable)
{
level endon("rzrEndThread");

players = getentarray("player", "classname");

for (i = 0; i<players.size; i++)
{
_p = players[i];

if (enable)
{
game["hipshotMsg"] = true;

if (_p getWeaponSlotWeapon("primary") != "none")
{


if(_p getWeaponSlotWeapon("primary") == "ro_enfield_mp"){
_p takeWeapon("ro_enfield_mp");
_p giveWeapon("aw_enfield_mp");
}

if(_p getWeaponSlotWeapon("primary") == "ro_enfield_scope_mp"){
_p takeWeapon("ro_enfield_scope_mp");
_p giveWeapon("aw_enfield_scope_mp");
}


if(_p getWeaponSlotWeapon("primary") == "ro_kar98k_mp"){
_p takeWeapon("ro_kar98k_mp");
_p giveWeapon("aw_kar98k_mp");
}


if(_p getWeaponSlotWeapon("primary") == "ro_kar98k_sniper_mp"){
_p takeWeapon("ro_kar98k_sniper_mp");
_p giveWeapon("aw_kar98k_sniper_mp");
}


if(_p getWeaponSlotWeapon("primary") == "ro_mosin_nagant_mp"){
_p takeWeapon("ro_mosin_nagant_mp");
_p giveWeapon("aw_mosin_nagant_mp");
}


if(_p getWeaponSlotWeapon("primary") == "ro_mosin_nagant_sniper_mp"){
_p takeWeapon("ro_mosin_nagant_sniper_mp");
_p giveWeapon("aw_mosin_nagant_sniper_mp");
}


if(_p getWeaponSlotWeapon("primary") == "ro_springfield_mp"){
_p takeWeapon("ro_springfield_mp");
_p giveWeapon("aw_springfield_mp");
}


}


if (_p getWeaponSlotWeapon("primaryb") != "none")
{


if (_p getWeaponSlotWeapon("primaryb") == "po_colt_mp"){
_p takeWeapon("po_colt_mp");
_p giveWeapon("aw_colt_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "po_luger_mp"){
_p takeWeapon("po_luger_mp");
_p giveWeapon("aw_bren_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "po_tt30_mp"){
_p takeWeapon("po_tt30_mp");
_p giveWeapon("aw_tt30_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "po_weebly_mp"){
_p takeWeapon("po_weebly_mp");
_p giveWeapon("aw_weebly_mp");
}


}
}
else
{
game["hipshotMsg"] = undefined;

_w = _p getWeaponSlotWeapon("primary");
if (_w != "none")
{

if(_p getWeaponSlotWeapon("primary") == "aw_enfield_mp"){
_p takeWeapon("aw_enfield_mp");
_p giveWeapon("ro_enfield_mp");
}

if(_p getWeaponSlotWeapon("primary") == "aw_enfield_scope_mp"){
_p takeWeapon("aw_enfield_scope_mp");
_p giveWeapon("ro_enfield_scope_mp");
}


if(_p getWeaponSlotWeapon("primary") == "aw_kar98k_mp"){
_p takeWeapon("aw_kar98k_mp");
_p giveWeapon("ro_kar98k_mp");
}


if(_p getWeaponSlotWeapon("primary") == "aw_kar98k_sniper_mp"){
_p takeWeapon("aw_kar98k_sniper_mp");
_p giveWeapon("ro_kar98k_sniper_mp");
}


if(_p getWeaponSlotWeapon("primary") == "aw_mosin_nagant_mp"){
_p takeWeapon("aw_mosin_nagant_mp");
_p giveWeapon("ro_mosin_nagant_mp");
}


if(_p getWeaponSlotWeapon("primary") == "aw_mosin_nagant_sniper_mp"){
_p takeWeapon("aw_mosin_nagant_sniper_mp");
_p giveWeapon("ro_mosin_nagant_sniper_mp");
}


if(_p getWeaponSlotWeapon("primary") == "aw_springfield_mp"){
_p takeWeapon("aw_springfield_mp");
_p giveWeapon("ro_springfield_mp");
}

}

_w = _p getWeaponSlotWeapon("primaryb");
if (_w != "none")
{


if (_p getWeaponSlotWeapon("primaryb") == "aw_bar_mp"){
_p takeWeapon("aw_bar_mp");
_p giveWeapon("po_colt_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "aw_luger_mp"){
_p takeWeapon("aw_luger_mp");
_p giveWeapon("po_luger_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "aw_tt30_mp"){
_p takeWeapon("aw_tt30_mp");
_p giveWeapon("po_tt30_mp");
}

if (_p getWeaponSlotWeapon("primaryb") == "aw_weebly_mp"){
_p takeWeapon("aw_weebly_mp");
_p giveWeapon("po_weebly_mp");
}

}


}
}
}

kung foo man
15th March 2013, 07:06
Maybe your editor messed up the weapon-files (added linebreaks e.g.)? Compare the file sizes, they should have same size :)

Also, another idea, which should work well:



// about execClientCommand: http://killtube.org/showthread.php?1230-Custom-Call-Vote
disableAds()
{
while (1)
{
players = getEntArray("player", "classname");
for (i=0; i<players.size; i++)
{
if (players[i] playerAds() > 0)
players[i] execClientCommand("-speed"); // disables ads, function is
}
wait 0.05;
}
}
thread disableAds();

serthy
15th March 2013, 09:55
you could do it alot shorter:


changeWeapon( player , slot )
{
pw = player getWeaponSlotWeapon( slot );

if( isValidWeapon( pw ) ) //check !none, and if you can toggle between them
{
prefix = getSubStr( pw , 0 , 2 ); //"aw" or "ro"
baseName = getSubStr( pw , 4 , pw.size ); //"thompson_mp"

if( prefix == "ro" )
player setWeaponSlotWeapon( slot , "aw_" + baseName );
else if( isPistol( baseName ) ) //check for pistol
player setWeaponSlotWeapon( slot , "po_" + baseName );
else
player setWeaponSlotWeapon( slot , "ro_" + baseName );
}
}

also you should use an else expression, or your code will call 'getWeaponSlotWeapon() everytime, also if the game already found the right one

for the animbug on spawn, maybe give the standard weapons on spawn and switch a second later?

Crestfallen
16th March 2013, 22:34
Well I tried everything and even compared the files but the bug still remained :( Instead, I decided to just disable damage if the hipshots cvar is true and if the player toggled ads, meaning the player can only kill if he shoots from the hip. Thanks anyways guys, great help :)