PDA

View Full Version : 2 weapon problems



z0d
8th December 2012, 13:53
Hello guys,

I edit CoD2 PAM (ePAM actually) and I have 2 problems:

Problem 1.) Well, I don't really know how to describe that problem without giving you an example:
so we have 2 players: player A is in axis team and player B is in allies team.
Round 1. player A has a kar98k and player B has m1, player B kills player A and picks its weapon (kar98k)
Round 2. so now, player B has m1 and kar98k. player A changes its weapon in STRAT TIME (3-4 seconds before round starts for real). So player A who changed its weapon in strat time, kills player B while player B has kar98k as its primary weapon. Player A tries to pickup dropped kar98k and it can't.

So here are some things that I know that works:
A) If player A changed his weapon at the end of 1st round (after player B killed him), he's able to pickup kar98k dropped by player B when its killed - next round (so player A didn't change its weapon in strat time)
B) I made a for loop which does: var = getweaponslotweapon("primary") and sets pers["weapon"] = var. And then it also works, excepts I don't have right weapon next round.
C) When player is killed, in player_killed function pers["weapon1"], pers["weapon2"] and pers["spawnweapon"] sets to undefined. What I did is, changed their values to "none" instead of undefined and it worked. In spawnplayer() function there is if(isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"])) as you may know and it worked (apparently) because it never went in -else- .

I tried several things already:
-copied "weapon_saver" in endround() function
-modifined if(isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"])) to look something like if((isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"])) && (self.pers["weapon1"] != "none" && self.pers["weapon2"]!= "none"))
-added self setspawnweapon in menuweapon() function (put it in if which changes weapon straight away - in strat time)

Problem 2.) Okay, I'll give you another example:
we have 2 players (again). In round 1. player A has a scope and is allies, player B has a mp44 and is axis, player C has a mp44 and is axis as well.
Player A kills player C and switches his scope with mp44. Player B picks up scope dropped by player A.
Next round (no matter who won or was killed), player B who's not a real scoper of axis team now have a scope and it might happen that there are two scopes in team. I want to avoid that and heres what I've did:


real_weapon = self.pers["weapon"];

if (level.weapons[real_weapon].classname == "sniper")
self.sniper_owner = 1;
else
self.sniper_owner = 0;

if(isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"]))
{
weapon1_checker = self.pers["weapon1"];
weapon2_checker = self.pers["weapon2"];

while(!isdefined(level.weapons[weapon1_checker].classname))
wait 0.05;

if (level.weapons[weapon1_checker].classname == "sniper" && level.weapons[weapon2_checker].classname == "sniper")
{
self setWeaponSlotWeapon("primary", self.pers["weapon"]);
self setWeaponSlotAmmo("primary", 999);
self setWeaponSlotClipAmmo("primary", 999);

self setSpawnWeapon(self.pers["weapon"]);
}
else if ((level.weapons[weapon1_checker].classname == "sniper" || level.weapons[weapon2_checker].classname == "sniper") && self.sniper_owner != 1)
{
if (level.weapons[weapon1_checker].classname == "sniper")
self setWeaponSlotWeapon("primary", self.pers["weapon"]);
else
self setWeaponSlotWeapon("primary", self.pers["weapon1"]);

self setWeaponSlotAmmo("primary", 999);
self setWeaponSlotClipAmmo("primary", 999);

if (level.weapons[weapon2_checker].classname == "sniper")
self setWeaponSlotWeapon("primaryb", self.pers["weapon"]);
else
self setWeaponSlotWeapon("primaryb", self.pers["weapon2"]);

self setWeaponSlotAmmo("primaryb", 999);
self setWeaponSlotClipAmmo("primaryb", 999);

self setSpawnWeapon(self.pers["spawnweapon"]);
}
else if ((level.weapons[weapon1_checker].classname == "sniper" || level.weapons[weapon2_checker].classname == "sniper") && self.sniper_owner == 1)
{
if (level.weapons[weapon1_checker].classname == "sniper")
{
if (weapon1_checker == self.pers["weapon"])
{
self setWeaponSlotWeapon("primary", self.pers["weapon1"]);
}
else
{
self setWeaponSlotWeapon("primary", self.pers["weapon"]);
}
}
else
self setWeaponSlotWeapon("primary", self.pers["weapon1"]);

self setWeaponSlotAmmo("primary", 999);
self setWeaponSlotClipAmmo("primary", 999);

if (level.weapons[weapon2_checker].classname == "sniper")
{
if (weapon2_checker == self.pers["weapon"])
{
self setWeaponSlotWeapon("primaryb", self.pers["weapon2"]);
}
else
{
self setWeaponSlotWeapon("primaryb", self.pers["weapon"]);
}
}
else
self setWeaponSlotWeapon("primaryb", self.pers["weapon2"]);

self setWeaponSlotAmmo("primaryb", 999);
self setWeaponSlotClipAmmo("primaryb", 999);

self setSpawnWeapon(self.pers["spawnweapon"]);
}
else
{
self setWeaponSlotWeapon("primary", self.pers["weapon1"]);
self setWeaponSlotAmmo("primary", 999);
self setWeaponSlotClipAmmo("primary", 999);

self setWeaponSlotWeapon("primaryb", self.pers["weapon2"]);
self setWeaponSlotAmmo("primaryb", 999);
self setWeaponSlotClipAmmo("primaryb", 999);

self setSpawnWeapon(self.pers["spawnweapon"]);
}
}
else
{
self setWeaponSlotWeapon("primary", self.pers["weapon"]);
self setWeaponSlotAmmo("primary", 999);
self setWeaponSlotClipAmmo("primary", 999);

self setSpawnWeapon(self.pers["weapon"]);
}

What I get as a error is this:


undefined is not a field object: (file 'maps/pam/sd.gsc', line 760)
else if ((level.weapons[weapon1_checker].classname == "sniper" || level.weapons[weapon2_checker].classname == "sniper") && self.sniper_owner != 1)
*
called from:
(file 'maps/pam/sd.gsc', line 289)
spawnPlayer();
*
called from:
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 38)
[[level.callbackPlayerConnect]]();
*
started from:
(file 'maps/pam/sd.gsc', line 1744)
wait 0; // Required for Callback_PlayerDisconnect to complete before updateTeamStatus can execute
*
************************************
********************
ERROR: script runtime error
(see console for details)
(file 'maps/pam/sd.gsc', line 1744)

********************

level.weapons is an array and here's an example how it looks like


level.weapons = [];
level.weapons["greasegun_mp"] = spawnstruct();
level.weapons["greasegun_mp"].server_allowcvar = "scr_allow_greasegun";
level.weapons["greasegun_mp"].client_allowcvar = "ui_allow_greasegun";
level.weapons["greasegun_mp"].allow_default = 1;
level.weapons["greasegun_mp"].classname = "smg";
level.weapons["greasegun_mp"].team = "allies";

So those are problems I have, I've been trying to find solution for a month now (no success). If there is someone who might know solution, please help me!

Cheers

serthy
9th December 2012, 00:19
2) you are only checking for weapon1_checker, do it also for weapon2_checker
my solution would look like this

while( true )
{
//wait of 0.5 seconds should be enough
wait( 0.5 );

//if the player is invalid, skip
if( !isDefined( self ) )
return;
else if( self.sessionstate != "playing" )
return;

weapon1_checker = self.pers["weapon1"];
weapon2_checker = self.pers["weapon2"];

//if any weapon is invalid, try again
if( !isDefined( weapon1_checker ) )
continue;
else if( !isDefined( level.weapons[weapon1_checker] ) )
continue;
if( !isDefined( weapon2_checker ) )
continue;
else if( !isDefined( level.weapons[weapon2_checker] ) )
continue;

break;
}

//now your stuff..
if( level.weapons[weapon1_checker].classname == "sniper" && level.weapons[weapon2_checker].classname == "sniper" )
{

btw which of those two players should keep the sniper?
just set player.isSniper when some1 selects one and on spawn just check if( !isTrue( player.isSniper) && playerHasSniper( player ) ) do{player giveWeapon( "mp44_mp" ) } (<<Pseudo code)

z0d
9th December 2012, 09:53
Thanks, will try it out.

About real sniper.

real_weapon = self.pers["weapon"];

if (level.weapons[real_weapon].classname == "sniper")
self.sniper_owner = 1;
else
self.sniper_owner = 0;

serthy
9th December 2012, 10:03
yh, but like said befor, better add some check, just in case of failure...

self.sniper_owner = ( isDefined( self.pers["weapon"] ) && isDefined( level.weapons[self.pers["weapon"]] ) && level.weapons[self.pers["weapon"]].classname == "sniper" );

but i was rather thinking of: if you select the sniper in the weapons menu ( player waittill( "menuresponse" , menu , response ) if( isSniper( response ) && player canHaveSniper() ) player.isSniper = true) so you set a flag on the real sniper, so that only he is allowed (and flagged) to have the only sniper upon spawn

z0d
9th December 2012, 10:23
thanks, ill fix it but i've found a problem.

while loop never brakes cuz of this:



if( !isDefined( weapon2_checker ) )
continue;
else if( !isDefined( level.weapons[weapon2_checker] ) )
continue;


and yeah thats true, cuz if u dont pick other weapon, ure second weapon (self.pers["weapon2"]) is undefined until you pick something up but i dont understand why does it go into that

if(isdefined(self.pers["weapon1"]) && isdefined(self.pers["weapon2"])) then

serthy
9th December 2012, 11:16
my loop should be equal to your
while(!isdefined(level.weapons[weapon1_checker].classname))
wait 0.05;

your code will fail because:
- if either weapon1_checker or level.weapons[weapon1_checker] is not defined, your server may crash if you check level.weapons[weapon1_checker].classname
- you set only 1 time your weapon1_checker, if level.weapons[weapon1_checker].classname is not defined this loop will continue until u stop your server or any endons will be triggered

so my loop does:
- check if the player is still valid, if not, it will skip the entire function (can also be done by player endon( "killed_player" ) / endon( "disconnect" ))
- resets weapon1_checker every cycle and does a check if weapon1_checker (or weapon2_checker..) is valid, if not, it will continue after a short delay
- compares the classnames of weapon1_checker & weapon2_checker. if theyre snipers, the function will break and you can continue with 2 valid weapons which will be snipers now

z0d
9th December 2012, 11:42
I totally udnerstand what ur loop does and I tried using it. If you didn't get killed and havent picked any weapon, at the end of round weapon1 will be defined but weapon2 will stay undefined. so when it goes into loop you gave me, it stops at this point


if( !isDefined( weapon2_checker ) )
continue;
else if( !isDefined( level.weapons[weapon2_checker] ) )
continue;

because weapon2 will be defined once u have to weapons (not pistols). any idea how to fix that?

z0d
9th December 2012, 12:00
nvm, fixed problem 2. . thanks for your help serthy!

does anyone have an idea how to fix problem 1?

z0d
14th December 2012, 21:40
bump, anyone got idea about first thingy?

Ni3ls
14th December 2012, 21:49
Did you check the weapondrop thing in _weapons.gsc?

z0d
14th December 2012, 21:59
yes i have.

Ni3ls
15th December 2012, 11:29
Maybe add some iprints to certain actions to debug it

z0d
15th December 2012, 18:09
did it already. any infos ud like to know?

Ni3ls
16th December 2012, 13:13
Check the weapon drop ammo. Maybe it doesnt drop anything. That's why u need to add some iprints...

z0d
16th December 2012, 18:09
but it happens only to that one player who droped his weapon when died. all his teammates are able to pick up weapon so i wouldnt say its about ammo.

z0d
18th January 2013, 11:54
if someone could help me with Problem 1.) i would really, really appreciate that. we are organising 10.000€ lan in March and this is only and the biggest bug in whole game. mod -> http://godfather-clan.com/zPAM/zPAM%20v2.04%20CoD2.rar