grenade ammo script

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Genesis
Private
Posts: 3
Joined: Wed Oct 15, 2003 7:51 am
Location: Perth, Australia
Contact:

grenade ammo script

Post by Genesis »

im pretty new to this whole scripting thing but know how to program and ive run into some problems as im sure most new scripters do...especially without ea releasing proper documentation for mohaa :( . here is my code for a server side mod im making that will allow an admin to dynamically limit the number of grenades each player has ingame. it works to some degree but after testing it with some of my clanmembers we found that the grenade ammo will not be subtracted from the players after the map changes and they spawn and after they change teams(ie they will have 6 nades as opposed to the number specified by the cvar) . the reason for finding what weapon the player has in their hands is simply to find out if they have actually spawned and then take away their ammo after that(thx to jv for telling me how to do that:P) but if there is a better way to do this id appreciate anyone telling me how :). here is the grenade section of my code for the server mod im making:
//Weapon Ammo Allowance module
grenadelimit:
level waittill spawn



for(local.a = 1; local.a <= $player.size; local.a++)
{
level.weaponammocheck[local.a] = 0
}

while(true)
{

local.numgrenades = int(getcvar(gi_numgrenades))
local.nades = 6-local.numgrenades


for(local.i = 1; local.i <= $player.size; local.i++)
{
local.person = $player[local.i]

local.numb = randomint 1000
$player[local.i] weaponcommand dual targetname local.numb


if(isalive(local.person) && (local.person.health > 0) && (local.person.dmteam != "spectator") && local.person != "NULL")
{
if($(local.numb).model != NIL)
{
if(level.weaponammocheck[local.i] == 0)
{
local.person ammo grenade -local.nades
level.weaponammocheck[local.i] = 1
}


}
}
else
{
level.weaponammocheck[local.i] = 0
}
}



wait 0.1
}
end
im sure the problem with this script is that when changing teams or maps...at no point are any of these conditions false:
if(isalive(local.person) && (local.person.health > 0) && (local.person.dmteam != "spectator") && local.person != "NULL")
which will therefore not reset the level.weaponammocheck[local.i] back to zero until they die again and will therefore not subtract ammo from them. i did try assigning the team of each player in an array at the beginning of the map then adding a condition to check if this was the same as when they started the map and if not deducting their ammo and assigning their current team to that array element...but i dont think i did this correctly :?. i tried a similar thing with the mapname but with no success. help appreciated :wink:
Image
Gi MOH:AA Server Admin
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Instead of level.weaponammocheck[local.i] use $player[number].weaponammocheck ... it really is a lot easier to work with ;). Moreover the number of the player in the $player array may change when players leave the server, so sooner or later the level.weaponammocheck array will hold no useful information anymore.
Image
Genesis
Private
Posts: 3
Joined: Wed Oct 15, 2003 7:51 am
Location: Perth, Australia
Contact:

Post by Genesis »

ok so i need something like:
local.playernum = int(getcvar(sv_maxclients))

for(local.a = 1; local.a <= local.playernum; local.a++)
{
$player[local.a].weaponammocheck = 0
}
would that work?
Image
Gi MOH:AA Server Admin
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Yep :) but instead of the maxclients cvar you could also simply use $player.size :wink:
Image
User avatar
diego
Captain
Posts: 245
Joined: Sun Dec 21, 2003 10:47 pm

Post by diego »

I'd like to use this idea for shotgun ammo. I want players that spawn with the shotgun to have no ammo. But I only want it to affect my own map, not every map on the server. I have 1 shotgun in my map they can pick up, but I want it to be the only one available --- kind of like a kind of the hill minigame.

Unfortunately, I'm not familiar with what is in that script or what variables I would need to modify. Do you mind If I am lazy and just ask someon to post the modified script for me? I'm sure you do, but I'll understand it better by studying the way it is written.
Diego
Post Reply