PDA

View Full Version : Kill() thread to a case "kill" ?



suck000
16th April 2016, 07:23
Am trying to make a script that depends on /rcon g_kill to a !kill ingame command .. i tried many times , some time when i do !kill playernumhere , it kills me instead of the other player :eek:

This is the g_kill script that am working with : (/rcon g_kill)


kill()
{
level endon("boot");

setcvar("g_kill", "");
while(1)
{
if(getcvar("g_kill") != "")
{
killNum = getcvarint("g_kill");
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
thisPlayerNum = players[i] getEntityNumber();
if(thisPlayerNum == killNum && isAlive(players[i]) )
{
players[i] unlink();
players[i] suicide();
iprintln(players[i].name + "^7 YOU WERE KILLED BRO.");
}
}
setcvar("g_kill", "");
}
wait 0.05;
}
}

i want to make it an ingame function "!kill"
I tried this by the way.

case "kill":
if(self getGUID() == XXXXXX)
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
thread getplayerbyid();
self execClientCmd("rcon " + getcvar("rcon_password") + " g_kill " + players[i]);
return;
}

and

case "kill":
{
level endon("boot");

setcvar("g_kill", "");
while(1)
{
if(getcvar("g_kill") != "")
{
killNum = getcvarint("g_kill");
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
thisPlayerNum = players[i] getEntityNumber();
if(thisPlayerNum == killNum && isAlive(players[i]) )
{
players[i] unlink();
players[i] suicide();
iprintln(players[i].name + "^7 YOU WERE KILLED BRO.");
}
}
setcvar("g_kill", "");
}
wait 0.05;
}
}


I just want some help on this one .. no more asking. promise :P

IzNoGoD
16th April 2016, 08:05
{
}

10characters

suck000
16th April 2016, 11:35
explain man , i don't get it !

maxdamage99
16th April 2016, 13:16
case "kill":
if(self getGUID() == XXXXXX)
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
//thread getplayerbyid(); //WHATA FUCK IS THIS?
//self execClientCmd("rcon " + getcvar("rcon_password") + " g_kill " + players[i]); //remove!!!
if(int(args[2])!=args[2]) { self iprintlnbold("!kill <num player>"); return; }
setCvar("g_kill", int(args[2])); //!kill 2 (args[0]="say", args[1]="kill", args[2]="2";
return;
}
}

suck000
16th April 2016, 13:43
Didn't work ! :S When i do !kill playernumhere , it just do an iprintinbold .. without killing :S

IzNoGoD
16th April 2016, 13:48
that is because in maxdmg's code:


int(args[2])!=args[2]
is always throwing an error. args[2] is of type string and int(args[2]) is of type int. WHICH YOU WOULD KNOW IF YOU HAD DEVELOPER ENABLED WHICH WE TOLD YOU FOREVER AND EVER

suck000
16th April 2016, 13:55
Please , just fix the code for me , i find it hard to understand you iznogod :/

IzNoGoD
16th April 2016, 14:13
You are trying to create a mod. You dont have enough knowledge to make a mod.

You try some random code someone on the internet has pasted. It doesnt work, so you cry for help.

Not ever in this process have you tried to debug anything yourself.

Moreover, you are not even enabling the debug messages that are BUILT IN to cod2 by enabling developer mode.

You dont even seem to have the basic C/C++ knowledge regarding brackets, which is programming 101.


If I may advise you anything, stop trying to mod.

The only thing you're currently creating is anger in everyone who reads this thread due to your incompetence and your inability to learn from previous mistakes (or learn at all).



Not once in this thread have you provided an accurate error message, not once in this thread have you accurately described what happens (No, it doesnt kill YOU specifically, it kills the player thats last in the players array). Edit: Just noticed you even use an execclientcmd which lets the player execute a rcon login + setcvar to set the data to the cvar. sigh.

Your basic code setup is so utterly garbage that I dont even want to touch it (loop through all players to find one matching the number, writing that number to a cvar, have a thread run every frame that reads from that cvar, runs through all players and kills the one that matches the number in the cvar, really?)

Given your history on this forum you should not be allowed to mod at all.

IzNoGoD
16th April 2016, 14:30
Here's a line-by-line analysis of your code, comments are pre-fixed with //


kill()
{
level endon("boot");

setcvar("g_kill", "");
while(1)
{
if(getcvar("g_kill") != "")
{
killNum = getcvarint("g_kill");
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
thisPlayerNum = players[i] getEntityNumber();
if(thisPlayerNum == killNum && isAlive(players[i]) ) //only part that might be bugged about this function is that isAlive() sometimes bugs out. It's safer to check isdefined(player.sessionstate) && player.sessionstate == "playing"
{
players[i] unlink();
players[i] suicide();
iprintln(players[i].name + "^7 YOU WERE KILLED BRO.");
}
}
setcvar("g_kill", "");
}
wait 0.05;
}
}



case "kill": //there's no further reference where this code is put, but given proper placement, should work
if(self getGUID() == XXXXXX) //hardcoded guids, nice for when the masterserver goes down
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
thread getplayerbyid(); //where are you saving this? You are not saving this. You are also threading this, so it runs aside from this actual code
self execClientCmd("rcon " + getcvar("rcon_password") + " g_kill " + players[i]); //really? This must be THE shittiest implementation of setcvar() i've ever seen
//also, above code sets g_kill to the value of players[i]. This is not a string/integer, but a player entity. This should crash your code in developer mode. Outside developer mode, it might write a 0 to the string instead, which is why you're getting killed yourself.
return;
}


case "kill": //i have no idea why there's a case here. Not a clue. None at all.
{
level endon("boot");

setcvar("g_kill", "");
while(1)
{
if(getcvar("g_kill") != "")
{
killNum = getcvarint("g_kill");
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
thisPlayerNum = players[i] getEntityNumber();
if(thisPlayerNum == killNum && isAlive(players[i]) )
{
players[i] unlink();
players[i] suicide();
iprintln(players[i].name + "^7 YOU WERE KILLED BRO.");
}
}
setcvar("g_kill", "");
}
wait 0.05;
}
}




case "kill":
if(self getGUID() == XXXXXX)
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(int(args[2])!=args[2]) //i'm assuming that this is a from-memory copy of my isint() function, which is (int(input) + "" == input). This should also crash your server in developer mode.
{
self iprintlnbold("!kill <num player>");
return;
}
setCvar("g_kill", int(args[2])); //Why are you guys still using cvars to get this information across? Like, really?
return;
}
}

suck000
16th April 2016, 16:27
Ok language barrier again .. but no problem .. i have a _kill.gsc file in map\mp\gametypes already.. and it's working fine (rcon g_kill playernumhere) but , i just want to replace that thread to an ingame function (!kill playernum) .. i just want the correct form of the case "kill": and i wanna also know how to set it up correctly.. i don't have problems with other functions (!help , !guid , !myip , !kick , !status , !login , !id , !wh , !whoff) I just got that shitty problem with kill command and i just want to get (please) the correct command from you guys.

IzNoGoD
16th April 2016, 16:49
So, you want us to write you a mod?

Not gonna happen.

suck000
16th April 2016, 16:52
I said that this is the last time that i'll ask you to do that thing. please man , i swear am reading a book right now about C++ and am trying to learn .. please :/

IzNoGoD
16th April 2016, 17:45
Ok, here it is:


case "kill":
if(self getGUID() == XXXXXX)
{
if(!isdefined(args[2]) || args[2] != "" + int(args[2]))
{
self iprintln("Usage: !kill [playernum]");
return;
}
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i] getentitynumber() == int(args[2]))
{
if(isdefined(players[i].sessionstate) && players[i].sessionstate == "playing")
{
players[i] unlink();
players[i] suicide();
return;
}
}
}
self iprintln("Player not found");

Last time I write anything more than 2 lines of code for you.

suck000
16th April 2016, 18:19
Hahahahaha i love you man ! <3

maxdamage99
17th April 2016, 08:28
Pthh.... i write this... omg stupid kids