Author Topic: Little help :)  (Read 752 times)

0 Members and 1 Guest are viewing this topic.

Offline JotEmI

  • Soldier
  • **
  • Posts: 188
Little help :)
« on: April 09, 2008, 08:23:25 am »
I'm trying to make a script which would allow players to spawn knifes on DB maps but only if they don't have knifes as primary or secondary weapon.

Here's a section of code which I have problem with:

Code: [Select]
for i:=1 to 10 do
begin
 if(GetPlayerStat(i,'Active')=true) then
 begin
  if(GetPlayerStat(i,'Primary') = 12) or (GetPlayerStat(i,'Secondary') = 12) then GiveThem:=0
 end;
end;

The problem is that 
Code: [Select]
if(GetPlayerStat(i,'Primary) = 12) or (GetPlayerStat(i,'Secondary') = 12) seems to be always false, even if all the players have knifes. Any help?

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Little help :)
« Reply #1 on: April 09, 2008, 06:14:38 pm »
Well, I don't see the point of a loop from 1 to 10? Why not just check it when they use the command? Also, the reason why that is always false is because knife is 14.

Here's how I would do it
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: String): Boolean;
begin
  if Text = '/zomg knife plz' then
    if (GetPlayerStat(ID, 'Primary') <> 14) and (GetPlayerStat(ID, 'Secondary') <> 14) then
      SpawnObject(GetPlayerStat(ID, 'X'), GetPlayerStat(ID, 'Y'), 12);
end;

Offline JotEmI

  • Soldier
  • **
  • Posts: 188
Re: Little help :)
« Reply #2 on: April 09, 2008, 06:34:49 pm »
The point is I want to spawn knifes only if all the players (after one of them performs the command) don't have knifes so I need to check all of them. e.g. If there are 4 players in game and one of them types "/give knife plz" then I want to spawn knifes for all that 4 players but only if they do not have knifes already. If one of them has a knife then I won't spawn any knife for anybody. And I was pretty sure the knife was 12... Well thanks anyway, I'll try with that 14.

EDIT:

I think I made it... it still needs testing but it seems to work for one player.
After typing !knifes script checks if any living player on the map has a knife. If so, then it does nothing but if no one has a knife then it checks if there are still active knifes from last spawn. When there aren't any it spawns one knife right in front of each player.

Code: [Select]
var
knifes: array[1..10] of integer;
players: array[1..10] of byte;
GiveKnifes: byte;

procedure spawn(ID: byte);
var
i: byte;
begin
for i:=1 to 10 do
begin
if (GetObjectStat(knifes[i],'Active') = true) then GiveKnifes:=0;
end;
if (GiveKnifes = 1) then
begin
knifes[ID]:=SpawnObject(GetPlayerStat(ID,'x'), GetPlayerStat(ID,'y'), 12);
end;
end;
 
procedure OnPlayerSpeak(ID: Byte; Text: string);
var
i: byte;
begin
GiveKnifes:=1;
if(Text = '!knifes') then
begin
for i:=1 to 10 do
begin
if (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Health') > 0) then
begin
players[i]:=1;
if (GetPlayerStat(i,'Primary') = 14) or (GetPlayerStat(i,'Secondary') = 14) then GiveKnifes:=0;
end;
end;
if (GiveKnifes =1) then
begin
for i:=1 to 10 do
begin
if players[i]=1 then spawn(i);
end;
end;
end;
end;

I'm still new to scripting so if someone knows how to make it more efficient or correct eventual bugs then please do it.
« Last Edit: April 09, 2008, 06:57:44 pm by JotEmI »