Weapon

Started by KAKAN, Sep 18, 2015, 10:17 AM

Previous topic - Next topic

KAKAN

I made a function like this:-
function GetWepName(reason)
{
switch(reason)
{
case 100: return "C-WEP 1";
case 101: return "C-WEP 2";
default: GetWeaponID(reason);
}
}

And onplayerkill
Message(killer.Name + " has killed " + player.Name + " with " + GetWepName(reason)

It gives me error, here's the error
parameter 1 has a invalid 'integer' expected: 'string'Or something like that
So help me guys pl0x
oh no

Mashreq

Do you get this error when you kill a player with custom weapons or default weapons?

:P

i have this prob too every where but when i add this ya remove my prob solved }
SLC is a good scripter but he always use bad words for abusing players :P

DizzasTeR

Find your answer in this example, This code will generate the same error but you have to see why is it being caused.

function onPlayerCommand( i_Player, Command, Arguments )
{
    if( Command == "Error" ) ShowMeError( i_Player.ID, i_Player );
}

function ShowMeError( Error, player )
{
    MessagePlayer( Error, player );
}

KAKAN

Quote from: Mashreq on Sep 18, 2015, 10:21 AMDo you get this error when you kill a player with custom weapons or default weapons?

Default Weapons
oh no

Mashreq

This should solve your problems:
function GetWepName(reason)
{
switch(reason.tointeger())
{
 case 100: return "C-WEP 1";
 case 101: return "C-WEP 2";
 default: return GetWeaponName(reason);
}
}

rObInX

Quote from: Mashreq on Sep 18, 2015, 02:11 PMThis should solve your problems:
function GetWepName(reason)
{
switch(reason.tointeger())
{
 case 100: return "C-WEP 1";
 case 101: return "C-WEP 2";
 default: return GetWeaponName(reason);
}
}

You forgot to convert the reason in default line to integer and also forgot break.
Dunno if break is necessary since return is present.
function GetWepName(reason)
{
    switch(reason.tointeger())
    {
         case 100: return "C-WEP 1";
                      break;
         case 101: return "C-WEP 2";
                      break;
         default: return GetWeaponName( reason.tointeger() );
    }
}

KAKAN

#7
break is not needed, okay robInx, i'll try it as soon as I get my laptop

Before that I used GetWeaponName(reason), and it gave me result like
(null0x0000000000000000000)idk how many zero's were there but it looked something like that, lets try reason.tointeger()
oh no

Thijn

I would also like to add that custom weapons will not report on the onPlayerKill signal. You will get the weapon ID of the weapon the custom weapon acts like.

As stated by @Stormeus 5 months ago.
Quote[Sat - 12:31:58] <Thijn> We have a few custom weapons in our server, but for some reason they only report the weaponID they're based on when you kill someone
[Sat - 12:32:14] <Thijn> Is this expected behaviour?
[Sat - 12:32:31] <Stormeus> That sounds logical but I can't say if it's necessarily expected behavior
[Sat - 12:32:49] <Stormeus> One sec, let me see if I can figure that out from max's implementation
[Sat - 12:32:56] <Thijn> Cheers, thanks
[Sat - 12:37:12] <Stormeus> I don't think it's so much expected behavior as it is a side effect of how this is implemented
[Sat - 12:37:24] <Stormeus> In order for the necessary game hooks to work the game is passed the "logical" ID of the weapon
[Sat - 12:37:32] <Stormeus> Which is what it records when a player gets shot, instead of the proper weapon ID
[Sat - 12:37:38] <Thijn> Ah, makes sense
[Sat - 12:37:58] <Thijn> No workound so squirrel knows the actual custom one?
[Sat - 12:39:44] <Stormeus> Not that I can think of right now at least
[Sat - 12:40:15] <Stormeus> Though I suppose you could keep track of if players have custom weapons instead of stock, and just intercept the ID on death
[Sat - 12:40:36] <Stormeus> A proper fix would involve messing with the client internals, and there's an update I'm trying to push right now, so I'll have to get to it later